BIND 10 trac2387, updated. 7b2ee20fb35a475916a817c30668d31d15fc8907 [2387] Add tests for trailing garbage in strings

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Apr 2 05:49:07 UTC 2013


The branch, trac2387 has been updated
       via  7b2ee20fb35a475916a817c30668d31d15fc8907 (commit)
       via  61dcaac0cfc5b764e0d5ca144128b1aa7d5a311f (commit)
       via  281c6ab13bf40a06055a64b3e5f69c0406d33db0 (commit)
      from  8b106d20e3afa459ef9ca13401145395d8a6dcc3 (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 7b2ee20fb35a475916a817c30668d31d15fc8907
Author: Mukund Sivaraman <muks at isc.org>
Date:   Tue Apr 2 11:16:21 2013 +0530

    [2387] Add tests for trailing garbage in strings

commit 61dcaac0cfc5b764e0d5ca144128b1aa7d5a311f
Author: Mukund Sivaraman <muks at isc.org>
Date:   Tue Apr 2 11:06:00 2013 +0530

    [2387] Remove unused includes

commit 281c6ab13bf40a06055a64b3e5f69c0406d33db0
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Apr 1 19:30:43 2013 +0530

    [2387] Update test data to be more consistent

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

Summary of changes:
 src/lib/dns/tests/rdata_dnskey_unittest.cc     |   12 +++++
 src/lib/dns/tests/rdata_nsec3_unittest.cc      |   60 +++++++++++++++---------
 src/lib/dns/tests/rdata_nsec3param_unittest.cc |   22 ++++++---
 3 files changed, 66 insertions(+), 28 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/tests/rdata_dnskey_unittest.cc b/src/lib/dns/tests/rdata_dnskey_unittest.cc
index 8da5f6f..95075de 100644
--- a/src/lib/dns/tests/rdata_dnskey_unittest.cc
+++ b/src/lib/dns/tests/rdata_dnskey_unittest.cc
@@ -78,6 +78,12 @@ protected:
                 rdata_str, rdata_dnskey2, true, true);
     }
 
+    void checkFromText_BadString(const string& rdata_str) {
+        checkFromText
+            <generic::DNSKEY, InvalidRdataText, isc::Exception>(
+                rdata_str, rdata_dnskey2, true, false);
+    }
+
     const string dnskey_txt;
     const string dnskey_txt2;
     const generic::DNSKEY rdata_dnskey;
@@ -118,6 +124,12 @@ TEST_F(Rdata_DNSKEY_Test, fromText) {
     checkFromText_LexerError("foo 3 5 YmluZDEwLmlzYy5vcmc=");
     checkFromText_LexerError("257 foo 5 YmluZDEwLmlzYy5vcmc=");
     checkFromText_LexerError("257 3 foo YmluZDEwLmlzYy5vcmc=");
+
+    // Trailing garbage. This should cause only the string constructor
+    // to fail, but the lexer constructor must be able to continue
+    // parsing from it.
+    checkFromText_BadString("257 3 5 YmluZDEwLmlzYy5vcmc= ; comment\n"
+                            "257 3 4 YmluZDEwLmlzYy5vcmc=");
 }
 
 TEST_F(Rdata_DNSKEY_Test, assign) {
diff --git a/src/lib/dns/tests/rdata_nsec3_unittest.cc b/src/lib/dns/tests/rdata_nsec3_unittest.cc
index c4817eb..8b6db0f 100644
--- a/src/lib/dns/tests/rdata_nsec3_unittest.cc
+++ b/src/lib/dns/tests/rdata_nsec3_unittest.cc
@@ -17,7 +17,6 @@
 #include <exceptions/exceptions.h>
 
 #include <util/buffer.h>
-#include <util/encode/hex.h>
 #include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
@@ -35,7 +34,6 @@ using namespace std;
 using namespace isc;
 using namespace isc::dns;
 using namespace isc::util;
-using namespace isc::util::encode;
 using namespace isc::dns::rdata;
 
 namespace {
@@ -46,8 +44,9 @@ class Rdata_NSEC3_Test : public RdataTest {
 protected:
     Rdata_NSEC3_Test() :
         nsec3_txt("1 1 1 D399EAAB H9RSFB7FPF2L8HG35CMPC765TDK23RP6 "
-                  "NS SOA RRSIG DNSKEY NSEC3PARAM"),
-        nsec3_nosalt_txt("1 1 1 - H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A"),
+                  "A NS SOA"),
+        nsec3_nosalt_txt("1 1 1 - H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA"),
+        nsec3_notype_txt("1 1 1 D399EAAB H9RSFB7FPF2L8HG35CMPC765TDK23RP6"),
         rdata_nsec3(nsec3_txt)
     {}
 
@@ -72,8 +71,15 @@ protected:
                 rdata_str, rdata_nsec3, true, true);
     }
 
+    void checkFromText_BadString(const string& rdata_str) {
+        checkFromText
+            <generic::NSEC3, InvalidRdataText, isc::Exception>(
+                rdata_str, rdata_nsec3, true, false);
+    }
+
     const string nsec3_txt;
     const string nsec3_nosalt_txt;
+    const string nsec3_notype_txt;
     const generic::NSEC3 rdata_nsec3;
 };
 
@@ -87,47 +93,57 @@ TEST_F(Rdata_NSEC3_Test, fromText) {
     // of the original to 8 characters, so 260 * 8 / 5 is the smallest length
     // of the encoded string that exceeds the max and doesn't require padding.
     checkFromText_InvalidText("1 1 1 D399EAAB " + string((260 * 8) / 5, '0') +
-                              " NS");
+                              " A NS SOA");
 
     // Type bitmap is empty.  it's possible and allowed for NSEC3.
-    EXPECT_NO_THROW(generic::NSEC3(
-                        "1 1 1 D399EAAB H9RSFB7FPF2L8HG35CMPC765TDK23RP6"));
+    EXPECT_NO_THROW(const generic::NSEC3 rdata_notype_nsec3(nsec3_notype_txt));
 
     // Empty salt is also okay.
     EXPECT_NO_THROW(const generic::NSEC3 rdata_nosalt_nsec3(nsec3_nosalt_txt));
 
     // Bad type mnemonics
-    checkFromText_InvalidText("1 1 1 ADDAFEEE 0123456789ABCDEFGHIJKLMNOPQRSTUV "
+    checkFromText_InvalidText("1 1 1 D399EAAB H9RSFB7FPF2L8HG35CMPC765TDK23RP6 "
                               "BIFF POW SPOON");
 
     // Bad base32hex
-    checkFromText_BadValue("1 1 1 ADDAFEEE "
+    checkFromText_BadValue("1 1 1 D399EAAB "
                            "WXYZWXYZWXYZ=WXYZWXYZ==WXYZWXYZW A NS SOA");
 
     // Hash algorithm out of range
-    checkFromText_InvalidText("256 1 1 ADDAFEEE "
-                              "0123456789ABCDEFGHIJKLMNOPQRSTUV A NS SOA");
+    checkFromText_InvalidText("256 1 1 D399EAAB "
+                              "H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA");
 
     // Flags out of range
-    checkFromText_InvalidText("1 256 1 ADDAFEEE "
-                              "0123456789ABCDEFGHIJKLMNOPQRSTUV A NS SOA");
+    checkFromText_InvalidText("1 256 1 D399EAAB "
+                              "H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA");
 
     // Iterations out of range
-    checkFromText_InvalidText("1 1 65536 ADDAFEEE "
-                              "0123456789ABCDEFGHIJKLMNOPQRSTUV A NS SOA");
+    checkFromText_InvalidText("1 1 65536 D399EAAB "
+                              "H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA");
 
-    // Space is not allowed in salt (this actually causes the Base64
+    // Space is not allowed in salt (this actually causes the Base32
     // decoder to throw)
     checkFromText_BadValue("1 1 1 D399 EAAB H9RSFB7FPF2L8"
-                           "HG35CMPC765TDK23RP6");
+                           "HG35CMPC765TDK23RP6 A NS SOA");
 
-    // Next hash shouldn't be padded
-    checkFromText_InvalidText("1 1 1 ADDAFEEE CPNMU=== A NS SOA");
+    // Next hash must not contain padding (trailing '=' characters)
+    checkFromText_InvalidText("1 1 1 D399EAAB "
+                              "AAECAwQFBgcICQoLDA0ODw== A NS SOA");
 
     // String instead of number
-    checkFromText_LexerError("foo 1 1 ADDAFEEECPNMU=== A NS SOA");
-    checkFromText_LexerError("1 foo 1 ADDAFEEECPNMU=== A NS SOA");
-    checkFromText_LexerError("1 1 foo ADDAFEEECPNMU=== A NS SOA");
+    checkFromText_LexerError("foo 1 1 D399EAAB "
+                             "H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA");
+    checkFromText_LexerError("1 foo 1 D399EAAB "
+                             "H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA");
+    checkFromText_LexerError("1 1 foo D399EAAB "
+                             "H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA");
+
+    // Trailing garbage. This should cause only the string constructor
+    // to fail, but the lexer constructor must be able to continue
+    // parsing from it.
+    checkFromText_BadString(
+        "1 1 1 D399EAAB H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA ;comment\n"
+        "1 1 1 D399EAAB H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA");
 }
 
 TEST_F(Rdata_NSEC3_Test, createFromWire) {
diff --git a/src/lib/dns/tests/rdata_nsec3param_unittest.cc b/src/lib/dns/tests/rdata_nsec3param_unittest.cc
index 2ca5c1e..4c1b2ab 100644
--- a/src/lib/dns/tests/rdata_nsec3param_unittest.cc
+++ b/src/lib/dns/tests/rdata_nsec3param_unittest.cc
@@ -16,8 +16,6 @@
 
 #include <exceptions/exceptions.h>
 
-#include <util/encode/base32hex.h>
-#include <util/encode/hex.h>
 #include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
@@ -35,7 +33,6 @@ using namespace std;
 using namespace isc;
 using namespace isc::dns;
 using namespace isc::util;
-using namespace isc::util::encode;
 using namespace isc::dns::rdata;
 
 namespace {
@@ -68,6 +65,14 @@ protected:
                 rdata_str, rdata_nsec3param, true, true);
     }
 
+    void checkFromText_BadString(const string& rdata_str,
+                                 const generic::NSEC3PARAM& rdata)
+    {
+        checkFromText
+            <generic::NSEC3PARAM, InvalidRdataText, isc::Exception>(
+                rdata_str, rdata, true, false);
+    }
+
     const string nsec3param_txt;
     const string nsec3param_nosalt_txt;
     const generic::NSEC3PARAM rdata_nsec3param;
@@ -84,8 +89,7 @@ TEST_F(Rdata_NSEC3PARAM_Test, fromText) {
     // constructor, as the lexer constructor stops reading at the end of
     // its RDATA.
     const generic::NSEC3PARAM rdata_nsec3param2("1 1 1 D399");
-    checkFromText<generic::NSEC3PARAM, InvalidRdataText, isc::Exception>(
-        "1 1 1 D399 EAAB", rdata_nsec3param2, true, false);
+    checkFromText_BadString("1 1 1 D399 EAAB", rdata_nsec3param2);
 
     // Hash algorithm out of range.
     checkFromText_InvalidText("256 1 1 D399EAAB");
@@ -96,13 +100,19 @@ TEST_F(Rdata_NSEC3PARAM_Test, fromText) {
     // Iterations out of range.
     checkFromText_InvalidText("1 1 65536 D399EAAB");
 
-    // Bad base32 hex sequence
+    // Bad hex sequence
     checkFromText_BadValue("1 1 256 D399EAABZOO");
 
     // String instead of number
     checkFromText_LexerError("foo 1 256 D399EAAB");
     checkFromText_LexerError("1 foo 256 D399EAAB");
     checkFromText_LexerError("1 1 foo D399EAAB");
+
+    // Trailing garbage. This should cause only the string constructor
+    // to fail, but the lexer constructor must be able to continue
+    // parsing from it.
+    checkFromText_BadString("1 1 1 D399EAAB ; comment\n"
+                            "1 1 1 D399EAAB", rdata_nsec3param);
 }
 
 TEST_F(Rdata_NSEC3PARAM_Test, toText) {



More information about the bind10-changes mailing list