Browse Source

[2497] Return NULL upon exception in rdata::createRdata()

Mukund Sivaraman 12 years ago
parent
commit
45b4e930c9

+ 11 - 3
src/lib/dns/rdata.cc

@@ -87,9 +87,17 @@ createRdata(const RRType& rrtype, const RRClass& rrclass,
             MasterLoader::Options options,
             MasterLoaderCallbacks& callbacks)
 {
-     return (RRParamRegistry::getRegistry().createRdata(rrtype, rrclass,
-                                                        lexer, origin,
-                                                        options, callbacks));
+    RdataPtr ret;
+
+    try {
+        ret = RRParamRegistry::getRegistry().createRdata(rrtype, rrclass,
+                                                         lexer, origin,
+                                                         options, callbacks);
+    } catch (...) {
+        // ret is NULL here.
+    }
+
+    return (ret);
 }
 
 int

+ 3 - 5
src/lib/dns/tests/rdata_afsdb_unittest.cc

@@ -119,11 +119,9 @@ TEST_F(Rdata_AFSDB_Test, createFromLexer) {
         *test::createRdataUsingLexer(RRType::AFSDB(), RRClass::IN(),
                                      afsdb_text)));
 
-    // Check that bad input throws as usual
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRType::AFSDB(), RRClass::IN(),
-                                     "1root.example.com.");
-    }, InvalidRdataText);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::AFSDB(), RRClass::IN(),
+                                             "1root.example.com."));
 }
 
 TEST_F(Rdata_AFSDB_Test, toWireBuffer) {

+ 3 - 4
src/lib/dns/tests/rdata_dhcid_unittest.cc

@@ -68,10 +68,9 @@ TEST_F(Rdata_DHCID_Test, createFromLexer) {
         *test::createRdataUsingLexer(RRType::DHCID(), RRClass::IN(),
                                      string_dhcid)));
 
-    // Check that bad input throws as usual
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRType::DHCID(), RRClass::IN(), "00");
-    }, isc::BadValue);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::DHCID(), RRClass::IN(),
+                                             "00"));
 }
 
 TEST_F(Rdata_DHCID_Test, toWireRenderer) {

+ 3 - 5
src/lib/dns/tests/rdata_dnskey_unittest.cc

@@ -88,11 +88,9 @@ TEST_F(Rdata_DNSKEY_Test, createFromLexer) {
         *test::createRdataUsingLexer(RRType::DNSKEY(), RRClass::IN(),
                                      dnskey_txt)));
 
-    // Check that bad input throws as usual
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRType::DNSKEY(), RRClass::IN(),
-                                     "257 3 5");
-    }, InvalidRdataText);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::DNSKEY(), RRClass::IN(),
+                                             "257 3 5"));
 }
 
 TEST_F(Rdata_DNSKEY_Test, toWireRenderer) {

+ 3 - 5
src/lib/dns/tests/rdata_ds_like_unittest.cc

@@ -90,11 +90,9 @@ TYPED_TEST(Rdata_DS_LIKE_Test, createFromLexer_DS_LIKE) {
         *test::createRdataUsingLexer(RRTYPE<TypeParam>(), RRClass::IN(),
                                      ds_like_txt)));
 
-    // Check that bad input throws as usual
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRTYPE<TypeParam>(), RRClass::IN(),
-                                     "99999 5 2 BEEF");
-    }, InvalidRdataText);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRTYPE<TypeParam>(), RRClass::IN(),
+                                             "99999 5 2 BEEF"));
 }
 
 TYPED_TEST(Rdata_DS_LIKE_Test, assignment_DS_LIKE) {

+ 3 - 5
src/lib/dns/tests/rdata_hinfo_unittest.cc

@@ -83,11 +83,9 @@ TEST_F(Rdata_HINFO_Test, createFromLexer) {
         *test::createRdataUsingLexer(RRType::HINFO(), RRClass::IN(),
                                      hinfo_str)));
 
-    // Check that bad input throws as usual
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRType::HINFO(), RRClass::IN(),
-                                     "\"Pentium\"\"Linux\"");
-    }, InvalidRdataText);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::HINFO(), RRClass::IN(),
+                                             "\"Pentium\"\"Linux\""));
 }
 
 TEST_F(Rdata_HINFO_Test, toText) {

+ 3 - 4
src/lib/dns/tests/rdata_mx_unittest.cc

@@ -67,10 +67,9 @@ TEST_F(Rdata_MX_Test, createFromLexer) {
         *test::createRdataUsingLexer(RRType::MX(), RRClass::IN(),
                                      "10 mx.example.com")));
 
-    EXPECT_THROW({
-        test::createRdataUsingLexer(RRType::MX(), RRClass::IN(),
-                                    "10 mx. example.com");
-    }, InvalidRdataText);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::MX(), RRClass::IN(),
+                                             "10 mx. example.com"));
 }
 
 TEST_F(Rdata_MX_Test, toWireRenderer) {

+ 4 - 6
src/lib/dns/tests/rdata_naptr_unittest.cc

@@ -135,12 +135,10 @@ TEST_F(Rdata_NAPTR_Test, createFromLexer) {
         *test::createRdataUsingLexer(RRType::NAPTR(), RRClass::IN(),
                                      naptr_str)));
 
-    // Check that bad input throws as usual (order > 65535)
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRType::NAPTR(), RRClass::IN(),
-                                     "65536 10 S SIP \"\" "
-                                     "_sip._udp.example.com.");
-    }, InvalidRdataText);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::NAPTR(), RRClass::IN(),
+                                             "65536 10 S SIP \"\" "
+                                             "_sip._udp.example.com."));
 }
 
 TEST_F(Rdata_NAPTR_Test, toWire) {

+ 3 - 4
src/lib/dns/tests/rdata_ns_unittest.cc

@@ -91,10 +91,9 @@ TEST_F(Rdata_NS_Test, createFromLexer) {
         *test::createRdataUsingLexer(RRType::NS(), RRClass::IN(),
                                      "ns.example.com")));
 
-    EXPECT_THROW({
-        test::createRdataUsingLexer(RRType::NS(), RRClass::IN(),
-                                    "");
-    }, IncompleteName);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::NS(), RRClass::IN(),
+                                             ""));
 }
 
 TEST_F(Rdata_NS_Test, toWireBuffer) {

+ 4 - 6
src/lib/dns/tests/rdata_nsec3_unittest.cc

@@ -136,12 +136,10 @@ TEST_F(Rdata_NSEC3_Test, createFromLexer) {
         *test::createRdataUsingLexer(RRType::NSEC3(), RRClass::IN(),
                                      nsec3_txt)));
 
-    // Check that bad input throws as usual (next hash shouldn't be
-    // padded)
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRType::NSEC3(), RRClass::IN(),
-                                     "1 1 1 ADDAFEEE CPNMU=== A NS SOA");
-    }, InvalidRdataText);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::NSEC3(), RRClass::IN(),
+                                             "1 1 1 ADDAFEEE CPNMU=== "
+                                             "A NS SOA"));
 }
 
 TEST_F(Rdata_NSEC3_Test, assign) {

+ 4 - 6
src/lib/dns/tests/rdata_nsec3param_like_unittest.cc

@@ -213,12 +213,10 @@ TYPED_TEST(NSEC3PARAMLikeTest, createFromLexer) {
         *test::createRdataUsingLexer(this->getType(), RRClass::IN(),
                                      this->salt_txt)));
 
-    // Check that bad input throws as usual (too large algorithm)
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(this->getType(), RRClass::IN(),
-                                     "1000000 1 1 ADDAFEEE" +
-                                     this->getCommonText());
-    }, InvalidRdataText);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(this->getType(), RRClass::IN(),
+                                             "1000000 1 1 ADDAFEEE" +
+                                             this->getCommonText()));
 }
 
 template <typename OUTPUT_TYPE>

+ 3 - 5
src/lib/dns/tests/rdata_nsec_unittest.cc

@@ -72,11 +72,9 @@ TEST_F(Rdata_NSEC_Test, createFromLexer_NSEC) {
         *test::createRdataUsingLexer(RRType::NSEC(), RRClass::IN(),
                                      nsec_txt)));
 
-    // Check that bad input throws as usual
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRType::NSEC(), RRClass::IN(),
-                                     "www.isc.org.");
-    }, InvalidRdataText);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::NSEC(), RRClass::IN(),
+                                             "www.isc.org."));
 }
 
 TEST_F(Rdata_NSEC_Test, toWireRenderer_NSEC) {

+ 4 - 5
src/lib/dns/tests/rdata_opt_unittest.cc

@@ -57,11 +57,10 @@ TEST_F(Rdata_OPT_Test, createFromWire) {
 }
 
 TEST_F(Rdata_OPT_Test, createFromLexer) {
-    // OPT RR cannot be created from text.
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRType::OPT(), RRClass::IN(),
-                                     "this does not matter");
-    }, InvalidRdataText);
+    // OPT RR cannot be created from text. Exceptions cause NULL to be
+    // returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::OPT(), RRClass::IN(),
+                                             "this does not matter"));
 }
 
 TEST_F(Rdata_OPT_Test, toWireBuffer) {

+ 3 - 5
src/lib/dns/tests/rdata_rp_unittest.cc

@@ -112,11 +112,9 @@ TEST_F(Rdata_RP_Test, createFromLexer) {
                                      "root.example.com. "
                                      "rp-text.example.com.")));
 
-    // Check that bad input throws as usual
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRType::RP(), RRClass::IN(),
-                                     "mailbox.example.com.");
-    }, InvalidRdataText);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::RP(), RRClass::IN(),
+                                             "mailbox.example.com."));
 }
 
 TEST_F(Rdata_RP_Test, toWireBuffer) {

+ 3 - 5
src/lib/dns/tests/rdata_rrsig_unittest.cc

@@ -106,11 +106,9 @@ TEST_F(Rdata_RRSIG_Test, createFromLexer) {
         *test::createRdataUsingLexer(RRType::RRSIG(), RRClass::IN(),
                                      rrsig_txt)));
 
-    // Check that bad input throws as usual
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRType::RRSIG(), RRClass::IN(),
-                                     "INVALIDINPUT");
-    }, InvalidRdataText);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::RRSIG(), RRClass::IN(),
+                                             "INVALIDINPUT"));
 }
 
 TEST_F(Rdata_RRSIG_Test, toWireRenderer) {

+ 5 - 5
src/lib/dns/tests/rdata_srv_unittest.cc

@@ -123,11 +123,11 @@ TEST_F(Rdata_SRV_Test, createFromLexer) {
     EXPECT_EQ(0, rdata_srv.compare(
         *test::createRdataUsingLexer(RRType::SRV(), RRClass::IN(),
                                      "1 5 1500 a.example.com.")));
-    // port is too large
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRType::SRV(), RRClass::IN(),
-                                     "1 5 281474976710656 a.example.com.");
-    }, InvalidRdataText);
+
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::SRV(), RRClass::IN(),
+                                             "1 5 281474976710656 "
+                                             "a.example.com."));
 }
 
 TEST_F(Rdata_SRV_Test, toWireBuffer) {

+ 3 - 5
src/lib/dns/tests/rdata_tsig_unittest.cc

@@ -252,11 +252,9 @@ TEST_F(Rdata_TSIG_Test, createFromLexer) {
         *test::createRdataUsingLexer(RRType::TSIG(), RRClass::ANY(),
                                      valid_text1)));
 
-    // Check that bad input throws as usual
-    EXPECT_THROW({
-        *test::createRdataUsingLexer(RRType::TSIG(), RRClass::ANY(),
-                                     "foo 0 0 0 0 BADKEY 0 0");
-    }, InvalidRdataText);
+    // Exceptions cause NULL to be returned.
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::TSIG(), RRClass::ANY(),
+                                             "foo 0 0 0 0 BADKEY 0 0"));
 }
 
 TEST_F(Rdata_TSIG_Test, assignment) {