Commit 48cfa00b authored by Mukund Sivaraman's avatar Mukund Sivaraman

bug #1627: Add common base class for name parser exceptions

parent 061f5a1a
......@@ -31,34 +31,43 @@ class OutputBuffer;
namespace dns {
class AbstractMessageRenderer;
///
/// \brief Base class for name parser exceptions.
///
class NameParserException : public Exception {
public:
NameParserException(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
/// encounters an empty label in the middle of a name.
///
class EmptyLabel : public Exception {
class EmptyLabel : public NameParserException {
public:
EmptyLabel(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) {}
NameParserException(file, line, what) {}
};
///
/// \brief A standard DNS module exception that is thrown if the name parser
/// encounters too long a name.
///
class TooLongName : public Exception {
class TooLongName : public NameParserException {
public:
TooLongName(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) {}
NameParserException(file, line, what) {}
};
///
/// \brief A standard DNS module exception that is thrown if the name parser
/// encounters too long a label.
///
class TooLongLabel : public Exception {
class TooLongLabel : public NameParserException {
public:
TooLongLabel(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) {}
NameParserException(file, line, what) {}
};
///
......@@ -67,20 +76,20 @@ public:
/// applies to bitstring labels, which would begin with "\[". Incomplete cases
/// include an incomplete escaped sequence such as "\12".
///
class BadLabelType : public Exception {
class BadLabelType : public NameParserException {
public:
BadLabelType(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) {}
NameParserException(file, line, what) {}
};
///
/// \brief A standard DNS module exception that is thrown if the name parser
/// fails to decode a "\"-escaped sequence.
///
class BadEscape : public Exception {
class BadEscape : public NameParserException {
public:
BadEscape(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) {}
NameParserException(file, line, what) {}
};
///
......@@ -90,10 +99,10 @@ public:
/// An attempt of constructing a name from an empty string will trigger this
/// exception.
///
class IncompleteName : public Exception {
class IncompleteName : public NameParserException {
public:
IncompleteName(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) {}
NameParserException(file, line, what) {}
};
///
......
......@@ -151,7 +151,7 @@ TEST_F(NameTest, fromText) {
EXPECT_EQ(Name("Www.eXample.coM", true).toText(), example_name.toText());
//
// Tests for bogus names. These should trigger an exception.
// Tests for bogus names. These should trigger exceptions.
//
// empty label cannot be followed by another label
EXPECT_THROW(Name(".a"), EmptyLabel);
......@@ -212,6 +212,43 @@ TEST_F(NameTest, fromText) {
EXPECT_EQ(Name::MAX_LABELS, maxlabels.getLabelCount());
}
TEST_F(NameTest, testNameParserExceptions) {
//
// Tests for bogus names. These should trigger exceptions.
//
// empty label cannot be followed by another label
EXPECT_THROW(Name(".a"), NameParserException);
// duplicate period
EXPECT_THROW(Name("a.."), NameParserException);
// label length must be < 64
EXPECT_THROW(Name("012345678901234567890123456789"
"012345678901234567890123456789"
"0123"), NameParserException);
// now-unsupported bitstring labels
EXPECT_THROW(Name("\\[b11010000011101]"), NameParserException);
// label length must be < 64
EXPECT_THROW(Name("012345678901234567890123456789"
"012345678901234567890123456789"
"012\\x"), NameParserException);
// incomplete \DDD pattern (exactly 3 D's must appear)
EXPECT_THROW(Name("\\12abc"), NameParserException);
// \DDD must not exceed 255
EXPECT_THROW(Name("\\256"), NameParserException);
// Same tests for \111 as for \\x above
EXPECT_THROW(Name("012345678901234567890123456789"
"012345678901234567890123456789"
"012\\111"), NameParserException);
// A domain name must be 255 octets or less
EXPECT_THROW(Name("123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789."
"1234"), NameParserException);
// \DDD must consist of 3 digits.
EXPECT_THROW(Name("\\12"), NameParserException);
}
TEST_F(NameTest, fromWire) {
//
// test cases derived from BIND9 tests.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment