]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2124] Add wiredata tests where the record is shorter than rdata len indicates
authorMukund Sivaraman <muks@isc.org>
Wed, 25 Jul 2012 05:54:52 +0000 (11:24 +0530)
committerMukund Sivaraman <muks@isc.org>
Wed, 25 Jul 2012 05:54:59 +0000 (11:24 +0530)
src/lib/dns/rdata/generic/sshfp_44.cc
src/lib/dns/tests/rdata_sshfp_unittest.cc
src/lib/dns/tests/testdata/Makefile.am
src/lib/dns/tests/testdata/rdata_sshfp_fromWire10 [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_sshfp_fromWire11 [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_sshfp_fromWire9 [new file with mode: 0644]

index b4175b887a84b9acf27a134ab93a8f595606d78e..b183180b64d2a0a81c9c4860ef318bfdf84a6586 100644 (file)
@@ -40,12 +40,18 @@ SSHFP::SSHFP(InputBuffer& buffer, size_t rdata_len) {
         isc_throw(InvalidRdataLength, "SSHFP record too short");
     }
 
-    algorithm_ = buffer.readUint8();
-    fingerprint_type_ = buffer.readUint8();
+    try {
+        algorithm_ = buffer.readUint8();
+        fingerprint_type_ = buffer.readUint8();
+
+        rdata_len -= 2;
+        fingerprint_.resize(rdata_len);
 
-    rdata_len -= 2;
-    fingerprint_.resize(rdata_len);
-    buffer.readData(&fingerprint_[0], 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());
+    }
 }
 
 SSHFP::SSHFP(const std::string& sshfp_str) {
index 7759bfd40fbdd50e6c238c10dbf6dc050fcc57f9..8c493a4ed12eaa08c4b25405f43e98f761bc2e38 100644 (file)
@@ -126,6 +126,21 @@ TEST_F(Rdata_SSHFP_Test, createFromWire) {
     // short fingerprint data
     EXPECT_NO_THROW(rdataFactoryFromFile(RRType("SSHFP"), RRClass("IN"),
                                          "rdata_sshfp_fromWire8.wire"));
+
+    // fingerprint is shorter than rdata len
+    EXPECT_THROW(rdataFactoryFromFile(RRType("SSHFP"), RRClass("IN"),
+                                      "rdata_sshfp_fromWire9"),
+                 InvalidRdataLength);
+
+    // fingerprint is missing
+    EXPECT_THROW(rdataFactoryFromFile(RRType("SSHFP"), RRClass("IN"),
+                                      "rdata_sshfp_fromWire10"),
+                 InvalidRdataLength);
+
+    // all rdata is missing
+    EXPECT_THROW(rdataFactoryFromFile(RRType("SSHFP"), RRClass("IN"),
+                                      "rdata_sshfp_fromWire11"),
+                 InvalidRdataLength);
 }
 
 TEST_F(Rdata_SSHFP_Test, toText) {
index 86de47630101f19b5e258cef43d9650d9d74faf8..77308a7310ffd14a8f3d2caccc29fd5672c3fe27 100644 (file)
@@ -135,6 +135,8 @@ EXTRA_DIST += rdata_sshfp_fromWire1.spec rdata_sshfp_fromWire2.spec
 EXTRA_DIST += rdata_sshfp_fromWire3.spec rdata_sshfp_fromWire4.spec
 EXTRA_DIST += rdata_sshfp_fromWire5.spec rdata_sshfp_fromWire6.spec
 EXTRA_DIST += rdata_sshfp_fromWire7.spec rdata_sshfp_fromWire8.spec
+EXTRA_DIST += rdata_sshfp_fromWire9 rdata_sshfp_fromWire10
+EXTRA_DIST += rdata_sshfp_fromWire11
 EXTRA_DIST += rdata_afsdb_fromWire1.spec rdata_afsdb_fromWire2.spec
 EXTRA_DIST += rdata_afsdb_fromWire3.spec rdata_afsdb_fromWire4.spec
 EXTRA_DIST += rdata_afsdb_fromWire5.spec
diff --git a/src/lib/dns/tests/testdata/rdata_sshfp_fromWire10 b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire10
new file mode 100644 (file)
index 0000000..7e04a20
--- /dev/null
@@ -0,0 +1,6 @@
+# Test where fingerprint is missing
+
+# SSHFP RDATA, RDLEN=22
+0020
+# ALGORITHM=2 FINGERPRINT_TYPE=1 FINGERPRINT=123456789abcdef67890123456789abcdef67890
+02 01
diff --git a/src/lib/dns/tests/testdata/rdata_sshfp_fromWire11 b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire11
new file mode 100644 (file)
index 0000000..0756c83
--- /dev/null
@@ -0,0 +1,4 @@
+# Test where RDATA is completely missing
+
+# SSHFP RDATA, RDLEN=22
+0020
diff --git a/src/lib/dns/tests/testdata/rdata_sshfp_fromWire9 b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire9
new file mode 100644 (file)
index 0000000..05fc806
--- /dev/null
@@ -0,0 +1,6 @@
+# Test where fingerprint length is smaller than what RDATA len indicates
+
+# SSHFP RDATA, RDLEN=32
+0020
+# ALGORITHM=2 FINGERPRINT_TYPE=1 FINGERPRINT=123456789abcdef67890123456789abcdef67890
+02 01 123456789abcdef67890123456789abcdef67890