From: Mukund Sivaraman Date: Thu, 7 Mar 2013 04:29:51 +0000 (+0530) Subject: [2387] Update std::string DNSSEC constructor X-Git-Tag: bind10-1.2.0beta1-release~481^2~69 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3de4ecaf232d8a75e9da6e54384da948807a0659;p=thirdparty%2Fkea.git [2387] Update std::string DNSSEC constructor This causes various MasterLoadTest unittests to fail because there is whitespace in the public key field, and a trailing comment. Even before, only a part of this string (before the first whitespace) was handled. The rest was silently discarded. The failures will be fixed in the next few commits. --- diff --git a/src/lib/dns/rdata/generic/dnskey_48.cc b/src/lib/dns/rdata/generic/dnskey_48.cc index 8a964cad78..6adef783f8 100644 --- a/src/lib/dns/rdata/generic/dnskey_48.cc +++ b/src/lib/dns/rdata/generic/dnskey_48.cc @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -55,32 +54,22 @@ struct DNSKEYImpl { DNSKEY::DNSKEY(const std::string& dnskey_str) : impl_(NULL) { - istringstream iss(dnskey_str); - unsigned int flags, protocol, algorithm; - stringbuf keydatabuf; - - iss >> flags >> protocol >> algorithm >> &keydatabuf; - if (iss.bad() || iss.fail()) { - isc_throw(InvalidRdataText, "Invalid DNSKEY text"); - } - if (flags > 0xffff) { - isc_throw(InvalidRdataText, "DNSKEY flags out of range"); - } - if (protocol > 0xff) { - isc_throw(InvalidRdataText, "DNSKEY protocol out of range"); - } - if (algorithm > 0xff) { - isc_throw(InvalidRdataText, "DNSKEY algorithm out of range"); - } - - vector keydata; - decodeBase64(keydatabuf.str(), keydata); - - if (algorithm == 1 && keydata.size() < 3) { - isc_throw(InvalidRdataLength, "DNSKEY keydata too short"); + try { + std::istringstream ss(dnskey_str); + MasterLexer lexer; + lexer.pushSource(ss); + + constructFromLexer(lexer); + + if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) { + isc_throw(InvalidRdataText, + "Extra input text for DNSKEY: " << dnskey_str); + } + } catch (const MasterLexer::LexerError& ex) { + isc_throw(InvalidRdataText, + "Failed to construct DNSKEY from '" << dnskey_str << "': " + << ex.what()); } - - impl_ = new DNSKEYImpl(flags, protocol, algorithm, keydata); } DNSKEY::DNSKEY(InputBuffer& buffer, size_t rdata_len) { @@ -100,8 +89,14 @@ DNSKEY::DNSKEY(InputBuffer& buffer, size_t rdata_len) { } DNSKEY::DNSKEY(MasterLexer& lexer, const Name*, - MasterLoader::Options, MasterLoaderCallbacks&) + MasterLoader::Options, MasterLoaderCallbacks&) : + impl_(NULL) { + constructFromLexer(lexer); +} + +void +DNSKEY::constructFromLexer(MasterLexer& lexer) { const uint32_t flags = lexer.getNextToken(MasterToken::NUMBER).getNumber(); if (flags > 0xffff) { isc_throw(InvalidRdataText, diff --git a/src/lib/dns/rdata/generic/dnskey_48.h b/src/lib/dns/rdata/generic/dnskey_48.h index 14fad9ff09..1e48782a15 100644 --- a/src/lib/dns/rdata/generic/dnskey_48.h +++ b/src/lib/dns/rdata/generic/dnskey_48.h @@ -20,6 +20,7 @@ #include #include #include +#include // BEGIN_HEADER_GUARD @@ -47,6 +48,8 @@ public: uint8_t getAlgorithm() const; private: + void constructFromLexer(MasterLexer& lexer); + DNSKEYImpl* impl_; };