[svn] commit: r1355 - in /trunk/src/lib/dns: name.cc name.h tests/name_unittest.cc tests/question_unittest.cc tests/rdata_cname_unittest.cc tests/rdata_dname_unittest.cc tests/rdata_ns_unittest.cc tests/rdata_ptr_unittest.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Mar 12 08:08:36 UTC 2010
Author: jinmei
Date: Fri Mar 12 08:08:35 2010
New Revision: 1355
Log:
returned DNSMessageFORMERR when the "from wire" name constructor encounters
malformed input.
Modified:
trunk/src/lib/dns/name.cc
trunk/src/lib/dns/name.h
trunk/src/lib/dns/tests/name_unittest.cc
trunk/src/lib/dns/tests/question_unittest.cc
trunk/src/lib/dns/tests/rdata_cname_unittest.cc
trunk/src/lib/dns/tests/rdata_dname_unittest.cc
trunk/src/lib/dns/tests/rdata_ns_unittest.cc
trunk/src/lib/dns/tests/rdata_ptr_unittest.cc
Modified: trunk/src/lib/dns/name.cc
==============================================================================
--- trunk/src/lib/dns/name.cc (original)
+++ trunk/src/lib/dns/name.cc Fri Mar 12 08:08:35 2010
@@ -24,6 +24,7 @@
#include <algorithm>
#include "buffer.h"
+#include "exceptions.h"
#include "name.h"
#include "messagerenderer.h"
@@ -288,8 +289,7 @@
} 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 @@
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 @@
} 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 @@
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 @@
}
if (!done) {
- isc_throw(IncompleteName, "incomplete wire-format name");
+ isc_throw(DNSMessageFORMERR, "incomplete wire-format name");
}
labelcount_ = offsets.size();
Modified: trunk/src/lib/dns/name.h
==============================================================================
--- trunk/src/lib/dns/name.h (original)
+++ trunk/src/lib/dns/name.h Fri Mar 12 08:08:35 2010
@@ -79,16 +79,6 @@
class BadEscape : public Exception {
public:
BadEscape(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 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) {}
};
Modified: trunk/src/lib/dns/tests/name_unittest.cc
==============================================================================
--- trunk/src/lib/dns/tests/name_unittest.cc (original)
+++ trunk/src/lib/dns/tests/name_unittest.cc Fri Mar 12 08:08:35 2010
@@ -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 @@
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 @@
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 @@
// 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",
Modified: trunk/src/lib/dns/tests/question_unittest.cc
==============================================================================
--- trunk/src/lib/dns/tests/question_unittest.cc (original)
+++ trunk/src/lib/dns/tests/question_unittest.cc Fri Mar 12 08:08:35 2010
@@ -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 @@
// 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);
}
Modified: trunk/src/lib/dns/tests/rdata_cname_unittest.cc
==============================================================================
--- trunk/src/lib/dns/tests/rdata_cname_unittest.cc (original)
+++ trunk/src/lib/dns/tests/rdata_cname_unittest.cc Fri Mar 12 08:08:35 2010
@@ -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 @@
// 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"),
Modified: trunk/src/lib/dns/tests/rdata_dname_unittest.cc
==============================================================================
--- trunk/src/lib/dns/tests/rdata_dname_unittest.cc (original)
+++ trunk/src/lib/dns/tests/rdata_dname_unittest.cc Fri Mar 12 08:08:35 2010
@@ -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 @@
// 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"),
Modified: trunk/src/lib/dns/tests/rdata_ns_unittest.cc
==============================================================================
--- trunk/src/lib/dns/tests/rdata_ns_unittest.cc (original)
+++ trunk/src/lib/dns/tests/rdata_ns_unittest.cc Fri Mar 12 08:08:35 2010
@@ -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 @@
// 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"),
Modified: trunk/src/lib/dns/tests/rdata_ptr_unittest.cc
==============================================================================
--- trunk/src/lib/dns/tests/rdata_ptr_unittest.cc (original)
+++ trunk/src/lib/dns/tests/rdata_ptr_unittest.cc Fri Mar 12 08:08:35 2010
@@ -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 @@
// 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"),
More information about the bind10-changes
mailing list