Browse Source

[2124] Catch isc::BadValue and throw InvalidRdataText instead

Mukund Sivaraman 12 years ago
parent
commit
63c345f544
2 changed files with 13 additions and 3 deletions
  1. 12 2
      src/lib/dns/rdata/generic/sshfp_44.cc
  2. 1 1
      src/lib/dns/tests/rdata_sshfp_unittest.cc

+ 12 - 2
src/lib/dns/rdata/generic/sshfp_44.cc

@@ -85,7 +85,12 @@ SSHFP::SSHFP(const std::string& sshfp_str) {
 
 
     algorithm_ = algorithm;
     algorithm_ = algorithm;
     fingerprint_type_ = fingerprint_type;
     fingerprint_type_ = fingerprint_type;
-    decodeHex(fingerprintbuf.str(), fingerprint_);
+
+    try {
+        decodeHex(fingerprintbuf.str(), fingerprint_);
+    } catch (const isc::BadValue& e) {
+        isc_throw(InvalidRdataText, "Bad SSHFP fingerprint: " << e.what());
+    }
 }
 }
 
 
 SSHFP::SSHFP(uint8_t algorithm, uint8_t fingerprint_type,
 SSHFP::SSHFP(uint8_t algorithm, uint8_t fingerprint_type,
@@ -101,7 +106,12 @@ SSHFP::SSHFP(uint8_t algorithm, uint8_t fingerprint_type,
 
 
     algorithm_ = algorithm;
     algorithm_ = algorithm;
     fingerprint_type_ = fingerprint_type;
     fingerprint_type_ = fingerprint_type;
-    decodeHex(fingerprint, fingerprint_);
+
+    try {
+        decodeHex(fingerprint, fingerprint_);
+    } catch (const isc::BadValue& e) {
+        isc_throw(InvalidRdataText, "Bad SSHFP fingerprint: " << e.what());
+    }
 }
 }
 
 
 SSHFP::SSHFP(const SSHFP& other) :
 SSHFP::SSHFP(const SSHFP& other) :

+ 1 - 1
src/lib/dns/tests/rdata_sshfp_unittest.cc

@@ -82,7 +82,7 @@ TEST_F(Rdata_SSHFP_Test, badText) {
     EXPECT_THROW(const generic::SSHFP rdata_sshfp("1"), InvalidRdataText);
     EXPECT_THROW(const generic::SSHFP rdata_sshfp("1"), InvalidRdataText);
     EXPECT_THROW(const generic::SSHFP rdata_sshfp("1 2"), InvalidRdataText);
     EXPECT_THROW(const generic::SSHFP rdata_sshfp("1 2"), InvalidRdataText);
     EXPECT_THROW(const generic::SSHFP rdata_sshfp("BUCKLE MY SHOES"), InvalidRdataText);
     EXPECT_THROW(const generic::SSHFP rdata_sshfp("BUCKLE MY SHOES"), InvalidRdataText);
-    EXPECT_THROW(const generic::SSHFP rdata_sshfp("1 2 foo bar"), isc::BadValue);
+    EXPECT_THROW(const generic::SSHFP rdata_sshfp("1 2 foo bar"), InvalidRdataText);
 }
 }
 
 
 TEST_F(Rdata_SSHFP_Test, copy) {
 TEST_F(Rdata_SSHFP_Test, copy) {