]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2497] Return NULL upon exception in rdata::createRdata()
authorMukund Sivaraman <muks@isc.org>
Fri, 30 Nov 2012 14:31:49 +0000 (20:01 +0530)
committerMukund Sivaraman <muks@isc.org>
Fri, 30 Nov 2012 14:31:49 +0000 (20:01 +0530)
17 files changed:
src/lib/dns/rdata.cc
src/lib/dns/tests/rdata_afsdb_unittest.cc
src/lib/dns/tests/rdata_dhcid_unittest.cc
src/lib/dns/tests/rdata_dnskey_unittest.cc
src/lib/dns/tests/rdata_ds_like_unittest.cc
src/lib/dns/tests/rdata_hinfo_unittest.cc
src/lib/dns/tests/rdata_mx_unittest.cc
src/lib/dns/tests/rdata_naptr_unittest.cc
src/lib/dns/tests/rdata_ns_unittest.cc
src/lib/dns/tests/rdata_nsec3_unittest.cc
src/lib/dns/tests/rdata_nsec3param_like_unittest.cc
src/lib/dns/tests/rdata_nsec_unittest.cc
src/lib/dns/tests/rdata_opt_unittest.cc
src/lib/dns/tests/rdata_rp_unittest.cc
src/lib/dns/tests/rdata_rrsig_unittest.cc
src/lib/dns/tests/rdata_srv_unittest.cc
src/lib/dns/tests/rdata_tsig_unittest.cc

index 40b6d79dbc0c785d85b8937a468170b1a394c614..f8deec6d22a9c381f4dae2f0c49ae02141184897 100644 (file)
@@ -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
index 7da2be4d08b9542d682cc7e4795541521c0276b0..9bb64b7229b3cf3550df2c5d477fde36f65d594d 100644 (file)
@@ -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) {
index 748af96716b49f9fbcf4a98aee374c21ebcf9756..8d56c0e7a32a84e1b88d6112eed5ca34b2aeb2e7 100644 (file)
@@ -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) {
index 5481c055507820f036e02010ae86d781c1275144..58d29bf50135646c6e9293db73967fb1bedab7c7 100644 (file)
@@ -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) {
index 7838a3498028b44779516d4683d952c2d663b4a7..28a2e174f8bc6d3a6a751ad4f28dc92c5df0351a 100644 (file)
@@ -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) {
index 597c43d4d5579914ac81f394bab7498bc5ecc752..746904751fdcf8dba33605ce5608f6cb00b89314 100644 (file)
@@ -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) {
index 4747138eae0703defd5c5ccc585982090c56035b..6c6039aa6096362e1d243b59c8794445d0ba6d58 100644 (file)
@@ -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) {
index 7a6df496274caafda5f1ccc32ab7f372c6453052..e23fbcab15879f3d9ccb8dcb4af0231f4486d248 100644 (file)
@@ -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) {
index 569e43135c45ed4472a6eb72b96fd913d33fabc9..d53639308346a959b4ff3408e10547563a2a8d3e 100644 (file)
@@ -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) {
index c7ca93e2bb1e5d047f7a1b84bdb599d1cea0e5e8..0fec3ebb1a7398d5c826f95c4604e78a5fb9755a 100644 (file)
@@ -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) {
index 04aa42bfde231eecd4eb221f505e5ccd491abe98..23d6d0ed6849bbb73a49b15d68007cef8fb50886 100644 (file)
@@ -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>
index 5e5ac89a69f8e69438e12d3851b680d31a5de911..4092c6dbb9d3500ae457539feb572ed5d2cf3172 100644 (file)
@@ -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) {
index 86bf90a2f6d691d92ad664aa6d45b73ee4cd801a..569925993569ad8bc98c9d6868dfd720573f46ac 100644 (file)
@@ -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) {
index 449a6082126bf53847536e68f21b5ef905299cb2..5508d9cd2e509bdfa25eff9ae2e37759484191f5 100644 (file)
@@ -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) {
index 04ec481707546785ffa5eba2bd24e9ccbf41d8b6..726fc535df5ab74d12c2b2ea4f521090e6accdc5 100644 (file)
@@ -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) {
index 44ef94fe6d3e944bc4cf2ebc761a0085049ef111..066755f437fcd50b4336c0cd286110cedfa8d9de 100644 (file)
@@ -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) {
index f562d15e8c4230e5d70ffcfb4c77faad9332cbaf..df358422334ef90ef86d54c2ce5c3235082ad8ff 100644 (file)
@@ -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) {