From: Mukund Sivaraman Date: Mon, 23 Jul 2012 05:50:40 +0000 (+0530) Subject: [2124] Catch isc::BadValue and throw InvalidRdataText instead X-Git-Tag: trac2351_base~177 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=63c345f54424efeabf4e6e40ff9f62eee9f8b59e;p=thirdparty%2Fkea.git [2124] Catch isc::BadValue and throw InvalidRdataText instead --- diff --git a/src/lib/dns/rdata/generic/sshfp_44.cc b/src/lib/dns/rdata/generic/sshfp_44.cc index 5fa7626bfb..ef69789e4b 100644 --- a/src/lib/dns/rdata/generic/sshfp_44.cc +++ b/src/lib/dns/rdata/generic/sshfp_44.cc @@ -85,7 +85,12 @@ SSHFP::SSHFP(const std::string& sshfp_str) { algorithm_ = algorithm; 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, @@ -101,7 +106,12 @@ SSHFP::SSHFP(uint8_t algorithm, uint8_t fingerprint_type, algorithm_ = algorithm; 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) : diff --git a/src/lib/dns/tests/rdata_sshfp_unittest.cc b/src/lib/dns/tests/rdata_sshfp_unittest.cc index 51ce369d5c..69bbf9ffdf 100644 --- a/src/lib/dns/tests/rdata_sshfp_unittest.cc +++ b/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 2"), 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) {