Parcourir la source

returned DNSMessageFORMERR when the "from wire" name constructor encounters
malformed input.


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1355 e5f2f494-b856-4b98-b285-d166d9295462

JINMEI Tatuya il y a 15 ans
Parent
commit
dbcf762d9e

+ 9 - 6
src/lib/dns/name.cc

@@ -24,6 +24,7 @@
 #include <algorithm>
 
 #include "buffer.h"
+#include "exceptions.h"
 #include "name.h"
 #include "messagerenderer.h"
 
@@ -288,8 +289,7 @@ typedef enum {
 } fw_state;
 }
 
-Name::Name(InputBuffer& buffer, bool downcase)
-{
+Name::Name(InputBuffer& buffer, bool downcase) {
     std::vector<unsigned char> offsets;
     offsets.reserve(Name::MAX_LABELS);
 
@@ -332,7 +332,8 @@ Name::Name(InputBuffer& buffer, bool downcase)
             if (c <= MAX_LABELLEN) {
                 offsets.push_back(nused);
                 if (nused + c + 1 > Name::MAX_WIRE) {
-                    isc_throw(TooLongName, "wire name is too long");
+                    isc_throw(DNSMessageFORMERR, "wire name is too long: "
+                              << nused + c + 1 << " bytes");
                 }
                 nused += c + 1;
                 ndata_.push_back(c);
@@ -351,7 +352,7 @@ Name::Name(InputBuffer& buffer, bool downcase)
             } else {
                 // this case includes local compression pointer, which hasn't
                 // been standardized.
-                isc_throw(BadLabelType, "unknown label character");
+                isc_throw(DNSMessageFORMERR, "unknown label character: " << c);
             }
             break;
         case fw_ordinary:
@@ -370,7 +371,9 @@ Name::Name(InputBuffer& buffer, bool downcase)
                 break;
             }
             if (new_current >= biggest_pointer) {
-                isc_throw(BadPointer, "bad compression pointer: out of range");
+                isc_throw(DNSMessageFORMERR,
+                          "bad compression pointer (out of range): " <<
+                          new_current);
             }
             biggest_pointer = new_current;
             current = new_current;
@@ -384,7 +387,7 @@ Name::Name(InputBuffer& buffer, bool downcase)
     }
 
     if (!done) {
-        isc_throw(IncompleteName, "incomplete wire-format name");
+        isc_throw(DNSMessageFORMERR, "incomplete wire-format name");
     }
 
     labelcount_ = offsets.size();

+ 0 - 10
src/lib/dns/name.h

@@ -83,16 +83,6 @@ public:
 };
 
 ///
-/// \brief A standard DNS module exception that is thrown if the wire-format
-/// name contains an invalid compression pointer.
-///
-class BadPointer : public Exception {
-public:
-    BadPointer(const char* file, size_t line, const char* what) :
-        isc::Exception(file, line, what) {}
-};
-
-///
 /// \brief A standard DNS module exception that is thrown if the name parser
 /// finds the input (string or wire-format data) is incomplete.
 ///

+ 9 - 8
src/lib/dns/tests/name_unittest.cc

@@ -21,6 +21,7 @@
 #include <stdexcept>
 
 #include <dns/buffer.h>
+#include <dns/exceptions.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 
@@ -225,26 +226,26 @@ TEST_F(NameTest, fromWire)
                         Name("vix.com"));
     // bogus label character (looks like a local compression pointer)
     EXPECT_THROW(nameFactoryFromWire("testdata/name_fromWire2", 25),
-                 BadLabelType);
+                 DNSMessageFORMERR);
     // a bad compression pointer (too big)
     EXPECT_THROW(nameFactoryFromWire("testdata/name_fromWire3_1", 25),
-                 BadPointer);
+                 DNSMessageFORMERR);
     // forward reference
     EXPECT_THROW(nameFactoryFromWire("testdata/name_fromWire3_2", 25),
-                 BadPointer);
+                 DNSMessageFORMERR);
     // invalid name length
     EXPECT_THROW(nameFactoryFromWire("testdata/name_fromWire4", 550),
-                 TooLongName);
+                 DNSMessageFORMERR);
 
     // skip test for from Wire5.  It's for disabling decompression, but our
     // implementation always allows it.
 
     // bad pointer (too big)
     EXPECT_THROW(nameFactoryFromWire("testdata/name_fromWire6", 25),
-                 BadPointer);
+                 DNSMessageFORMERR);
     // input ends unexpectedly
     EXPECT_THROW(nameFactoryFromWire("testdata/name_fromWire7", 25),
-                 IncompleteName);
+                 DNSMessageFORMERR);
     // many hops of compression but valid.  should succeed.
     EXPECT_PRED_FORMAT2(UnitTestUtil::matchName,
                         nameFactoryFromWire("testdata/name_fromWire8", 383),
@@ -258,7 +259,7 @@ TEST_F(NameTest, fromWire)
     EXPECT_EQ(Name::MAX_WIRE,
               nameFactoryFromWire("testdata/name_fromWire9", 0).getLength());
     EXPECT_THROW(nameFactoryFromWire("testdata/name_fromWire10", 0).getLength(),
-                 TooLongName);
+                 DNSMessageFORMERR);
 
     // A name with possible maximum number of labels; awkward but valid
     EXPECT_EQ(nameFactoryFromWire("testdata/name_fromWire11",
@@ -267,7 +268,7 @@ TEST_F(NameTest, fromWire)
 
     // Wire format including an invalid label length
     EXPECT_THROW(nameFactoryFromWire("testdata/name_fromWire12", 0),
-                 BadLabelType);
+                 DNSMessageFORMERR);
 
     // converting upper-case letters to down-case
     EXPECT_EQ("vix.com.", nameFactoryFromWire("testdata/name_fromWire1",

+ 2 - 1
src/lib/dns/tests/question_unittest.cc

@@ -20,6 +20,7 @@
 #include <exceptions/exceptions.h>
 
 #include <dns/buffer.h>
+#include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
 #include <dns/question.h>
@@ -84,7 +85,7 @@ TEST_F(QuestionTest, fromWire)
     // Pathological cases: Corresponding exceptions will be thrown from
     // the underlying parser.
     EXPECT_THROW(questionFromWire("testdata/question_fromWire", 31),
-                 BadPointer);
+                 DNSMessageFORMERR);
     EXPECT_THROW(questionFromWire("testdata/question_fromWire", 36),
                  IncompleteRRClass);
 }

+ 2 - 1
src/lib/dns/tests/rdata_cname_unittest.cc

@@ -15,6 +15,7 @@
 // $Id$
 
 #include <dns/buffer.h>
+#include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
@@ -79,7 +80,7 @@ TEST_F(Rdata_CNAME_Test, createFromWire)
     // incomplete name.  the error should be detected in the name constructor
     EXPECT_THROW(rdataFactoryFromFile(RRType("CNAME"), RRClass("IN"),
                                       "testdata/rdata_cname_fromWire", 71),
-                 IncompleteName);
+                 DNSMessageFORMERR);
 
     EXPECT_EQ(0, generic::CNAME("cn2.example.com").compare(
                   *rdataFactoryFromFile(RRType("CNAME"), RRClass("IN"),

+ 2 - 1
src/lib/dns/tests/rdata_dname_unittest.cc

@@ -15,6 +15,7 @@
 // $Id$
 
 #include <dns/buffer.h>
+#include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
@@ -79,7 +80,7 @@ TEST_F(Rdata_DNAME_Test, createFromWire)
     // incomplete name.  the error should be detected in the name constructor
     EXPECT_THROW(rdataFactoryFromFile(RRType("DNAME"), RRClass("IN"),
                                       "testdata/rdata_dname_fromWire", 71),
-                 IncompleteName);
+                 DNSMessageFORMERR);
 
     EXPECT_EQ(0, generic::DNAME("dn2.example.com").compare(
                   *rdataFactoryFromFile(RRType("DNAME"), RRClass("IN"),

+ 2 - 1
src/lib/dns/tests/rdata_ns_unittest.cc

@@ -15,6 +15,7 @@
 // $Id$
 
 #include <dns/buffer.h>
+#include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
@@ -78,7 +79,7 @@ TEST_F(Rdata_NS_Test, createFromWire)
     // incomplete name.  the error should be detected in the name constructor
     EXPECT_THROW(rdataFactoryFromFile(RRType("NS"), RRClass("IN"),
                                       "testdata/rdata_ns_fromWire", 71),
-                 IncompleteName);
+                 DNSMessageFORMERR);
 
     EXPECT_EQ(0, generic::NS("ns2.example.com").compare(
                   *rdataFactoryFromFile(RRType("NS"), RRClass("IN"),

+ 2 - 1
src/lib/dns/tests/rdata_ptr_unittest.cc

@@ -15,6 +15,7 @@
 // $Id$
 
 #include <dns/buffer.h>
+#include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
@@ -82,7 +83,7 @@ TEST_F(Rdata_PTR_Test, createFromWire)
     // incomplete name.  the error should be detected in the name constructor
     EXPECT_THROW(rdataFactoryFromFile(RRType("PTR"), RRClass("IN"),
                                       "testdata/rdata_ns_fromWire", 71),
-                 IncompleteName);
+                 DNSMessageFORMERR);
 
     EXPECT_EQ(0, generic::PTR("ns2.example.com").compare(
                   *rdataFactoryFromFile(RRType("PTR"), RRClass("IN"),