Browse Source

[2387] Add tests for trailing garbage in strings

Mukund Sivaraman 12 years ago
parent
commit
7b2ee20fb3

+ 12 - 0
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) {

+ 13 - 0
src/lib/dns/tests/rdata_nsec3_unittest.cc

@@ -71,6 +71,12 @@ 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;
@@ -131,6 +137,13 @@ TEST_F(Rdata_NSEC3_Test, fromText) {
                              "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) {

+ 15 - 2
src/lib/dns/tests/rdata_nsec3param_unittest.cc

@@ -65,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;
@@ -81,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");
@@ -100,6 +107,12 @@ TEST_F(Rdata_NSEC3PARAM_Test, fromText) {
     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) {