BIND 10 trac2124, updated. d71f7e9f7c16bbe923a2d3e473b1118e762f73ef [2124] Add another toWire() test

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Jul 26 17:01:05 UTC 2012


The branch, trac2124 has been updated
       via  d71f7e9f7c16bbe923a2d3e473b1118e762f73ef (commit)
       via  73080d999ec47baa78877697fadccc2cb5e99c51 (commit)
       via  595b447c655af350fdb1f93528f4f05af3f5aa9f (commit)
      from  26401e4e861462c03f689c32f97f49d582a64a5b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d71f7e9f7c16bbe923a2d3e473b1118e762f73ef
Author: Mukund Sivaraman <muks at isc.org>
Date:   Thu Jul 26 22:30:14 2012 +0530

    [2124] Add another toWire() test

commit 73080d999ec47baa78877697fadccc2cb5e99c51
Author: Mukund Sivaraman <muks at isc.org>
Date:   Thu Jul 26 22:29:40 2012 +0530

    [2124] Don't add trailing space in toText() if fingerprint is empty
    
    Also add some tests.

commit 595b447c655af350fdb1f93528f4f05af3f5aa9f
Author: Mukund Sivaraman <muks at isc.org>
Date:   Thu Jul 26 22:28:47 2012 +0530

    [2124] Don't access fingerprint_ data when size is 0

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/rdata/generic/sshfp_44.cc     |   13 +++++++++----
 src/lib/dns/tests/rdata_sshfp_unittest.cc |   30 +++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 4 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/rdata/generic/sshfp_44.cc b/src/lib/dns/rdata/generic/sshfp_44.cc
index 4c221b8..0a2f49b 100644
--- a/src/lib/dns/rdata/generic/sshfp_44.cc
+++ b/src/lib/dns/rdata/generic/sshfp_44.cc
@@ -45,9 +45,10 @@ SSHFP::SSHFP(InputBuffer& buffer, size_t rdata_len) {
         fingerprint_type_ = buffer.readUint8();
 
         rdata_len -= 2;
-        fingerprint_.resize(rdata_len);
-
-        buffer.readData(&fingerprint_[0], rdata_len);
+        if (rdata_len > 0) {
+            fingerprint_.resize(rdata_len);
+            buffer.readData(&fingerprint_[0], rdata_len);
+        }
     } catch (const isc::util::InvalidBufferPosition& e) {
         isc_throw(InvalidRdataLength,
                   "SSHFP record shorter than RDATA len: " << e.what());
@@ -127,7 +128,7 @@ string
 SSHFP::toText() const {
     return (lexical_cast<string>(static_cast<int>(algorithm_)) +
             " " + lexical_cast<string>(static_cast<int>(fingerprint_type_)) +
-            " " + encodeHex(fingerprint_));
+            (fingerprint_.size() > 0 ? " " + encodeHex(fingerprint_) : ""));
 }
 
 int
@@ -152,6 +153,10 @@ SSHFP::compare(const Rdata& other) const {
     size_t this_len = fingerprint_.size();
     size_t other_len = other_sshfp.fingerprint_.size();
     size_t cmplen = min(this_len, other_len);
+    if (cmplen == 0) {
+        return ((this_len == other_len)
+                ? 0 : (this_len < other_len) ? -1 : 1);
+    }
     int cmp = memcmp(&fingerprint_[0], &other_sshfp.fingerprint_[0], cmplen);
     if (cmp != 0) {
         return (cmp);
diff --git a/src/lib/dns/tests/rdata_sshfp_unittest.cc b/src/lib/dns/tests/rdata_sshfp_unittest.cc
index b6f13f6..ebe52ad 100644
--- a/src/lib/dns/tests/rdata_sshfp_unittest.cc
+++ b/src/lib/dns/tests/rdata_sshfp_unittest.cc
@@ -156,6 +156,13 @@ TEST_F(Rdata_SSHFP_Test, createFromWire) {
 
 TEST_F(Rdata_SSHFP_Test, toText) {
     EXPECT_TRUE(boost::iequals(sshfp_txt, rdata_sshfp.toText()));
+
+    const string sshfp_txt2("2 1");
+    const generic::SSHFP rdata_sshfp2(sshfp_txt2);
+    EXPECT_TRUE(boost::iequals(sshfp_txt2, rdata_sshfp2.toText()));
+
+    const generic::SSHFP rdata_sshfp3("2 1 ");
+    EXPECT_TRUE(boost::iequals(sshfp_txt2, rdata_sshfp3.toText()));
 }
 
 TEST_F(Rdata_SSHFP_Test, toWire) {
@@ -170,6 +177,12 @@ TEST_F(Rdata_SSHFP_Test, toWire) {
                         rdata_sshfp_wiredata, sizeof(rdata_sshfp_wiredata));
 }
 
+TEST_F(Rdata_SSHFP_Test, compare) {
+    const generic::SSHFP rdata_sshfp2("2 1");
+    EXPECT_EQ(-1, rdata_sshfp2.compare(rdata_sshfp));
+    EXPECT_EQ(1, rdata_sshfp.compare(rdata_sshfp2));
+}
+
 TEST_F(Rdata_SSHFP_Test, getSSHFPAlgorithmNumber) {
     EXPECT_EQ(2, rdata_sshfp.getSSHFPAlgorithmNumber());
 }
@@ -183,6 +196,13 @@ TEST_F(Rdata_SSHFP_Test, getFingerprintLen) {
 }
 
 TEST_F(Rdata_SSHFP_Test, emptyFingerprintFromWire) {
+    const uint8_t rdf_wiredata[] = {
+        // algorithm
+        0x04,
+        // fingerprint type
+        0x09
+    };
+
     const generic::SSHFP rdf =
         dynamic_cast<const generic::SSHFP&>
         (*rdataFactoryFromFile(RRType("SSHFP"), RRClass("IN"),
@@ -191,6 +211,16 @@ TEST_F(Rdata_SSHFP_Test, emptyFingerprintFromWire) {
     EXPECT_EQ(4, rdf.getSSHFPAlgorithmNumber());
     EXPECT_EQ(9, rdf.getSSHFPFingerprintType());
     EXPECT_EQ(0, rdf.getFingerprintLen());
+
+    this->obuffer.clear();
+    rdf.toWire(this->obuffer);
+
+    EXPECT_EQ(2, this->obuffer.getLength());
+
+    EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
+                        this->obuffer.getData(),
+                        this->obuffer.getLength(),
+                        rdf_wiredata, sizeof(rdf_wiredata));
 }
 
 TEST_F(Rdata_SSHFP_Test, emptyFingerprintFromString) {



More information about the bind10-changes mailing list