]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2387] Update std::string DNSSEC constructor
authorMukund Sivaraman <muks@isc.org>
Thu, 7 Mar 2013 04:29:51 +0000 (09:59 +0530)
committerMukund Sivaraman <muks@isc.org>
Thu, 7 Mar 2013 04:29:51 +0000 (09:59 +0530)
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.

src/lib/dns/rdata/generic/dnskey_48.cc
src/lib/dns/rdata/generic/dnskey_48.h

index 8a964cad7888840800fbbfcde1c30b7eb195c433..6adef783f8e519476a914300db3d6538cf2d3a79 100644 (file)
@@ -26,7 +26,6 @@
 #include <dns/name.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
-#include <dns/master_lexer.h>
 
 #include <stdio.h>
 #include <time.h>
@@ -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<uint8_t> 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,
index 14fad9ff094b73c1db5131d734cabe1c293ae25e..1e48782a150cc5940aa57a92286354ee791dbe35 100644 (file)
@@ -20,6 +20,7 @@
 #include <dns/rrtype.h>
 #include <dns/rrttl.h>
 #include <dns/rdata.h>
+#include <dns/master_lexer.h>
 
 // BEGIN_HEADER_GUARD
 
@@ -47,6 +48,8 @@ public:
     uint8_t getAlgorithm() const;
 
 private:
+    void constructFromLexer(MasterLexer& lexer);
+
     DNSKEYImpl* impl_;
 };