Browse Source

[3287] Don't passthrough BadValue exceptions in decoding hex from SSHFP

Mukund Sivaraman 11 years ago
parent
commit
e71ef05f86
2 changed files with 8 additions and 13 deletions
  1. 6 6
      src/lib/dns/rdata/generic/sshfp_44.cc
  2. 2 7
      src/lib/dns/tests/rdata_sshfp_unittest.cc

+ 6 - 6
src/lib/dns/rdata/generic/sshfp_44.cc

@@ -80,7 +80,11 @@ SSHFP::constructFromLexer(MasterLexer& lexer) {
     // If fingerprint is missing, it's OK. See the API documentation of the
     // constructor.
     if (fingerprint_str.size() > 0) {
-        decodeHex(fingerprint_str, fingerprint);
+        try {
+            decodeHex(fingerprint_str, fingerprint);
+        } catch (const isc::BadValue& e) {
+            isc_throw(InvalidRdataText, "Bad SSHFP fingerprint: " << e.what());
+        }
     }
 
     return (new SSHFPImpl(algorithm, fingerprint_type, fingerprint));
@@ -126,9 +130,6 @@ SSHFP::SSHFP(const string& sshfp_str) :
     } catch (const MasterLexer::LexerError& ex) {
         isc_throw(InvalidRdataText, "Failed to construct SSHFP from '" <<
                   sshfp_str << "': " << ex.what());
-    } catch (const isc::BadValue& e) {
-        isc_throw(InvalidRdataText,
-                  "Bad SSHFP fingerprint: " << e.what());
     }
 
     impl_ = impl_ptr.release();
@@ -141,8 +142,7 @@ SSHFP::SSHFP(const string& sshfp_str) :
 ///
 /// \throw MasterLexer::LexerError General parsing error such as missing field.
 /// \throw InvalidRdataText Fields are out of their valid range, or are
-/// incorrect.
-/// \throw BadValue Fingerprint is not a valid hex string.
+/// incorrect, or if the fingerprint is not a valid hex string.
 ///
 /// \param lexer A \c MasterLexer object parsing a master file for the
 /// RDATA to be created

+ 2 - 7
src/lib/dns/tests/rdata_sshfp_unittest.cc

@@ -59,11 +59,6 @@ protected:
                 rdata_str, rdata_sshfp, true, true);
     }
 
-    void checkFromText_BadValue(const string& rdata_str) {
-        checkFromText<generic::SSHFP, InvalidRdataText, BadValue>(
-            rdata_str, rdata_sshfp, true, true);
-    }
-
     void checkFromText_BadString(const string& rdata_str) {
         checkFromText
             <generic::SSHFP, InvalidRdataText, isc::Exception>(
@@ -138,8 +133,8 @@ TEST_F(Rdata_SSHFP_Test, badText) {
     checkFromText_LexerError("1");
     checkFromText_LexerError("ONE 2 123456789abcdef67890123456789abcdef67890");
     checkFromText_LexerError("1 TWO 123456789abcdef67890123456789abcdef67890");
-    checkFromText_BadValue("1 2 BUCKLEMYSHOE");
-    checkFromText_BadValue(sshfp_txt + " extra text");
+    checkFromText_InvalidText("1 2 BUCKLEMYSHOE");
+    checkFromText_InvalidText(sshfp_txt + " extra text");
 
     // yes, these are redundant to the last test cases in algorithmTypes
     checkFromText_InvalidText(