mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 21:45:37 +00:00
bug #1627: Add common base class for name parser exceptions
This commit is contained in:
@@ -31,34 +31,43 @@ class OutputBuffer;
|
|||||||
namespace dns {
|
namespace dns {
|
||||||
class AbstractMessageRenderer;
|
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
|
/// \brief A standard DNS module exception that is thrown if the name parser
|
||||||
/// encounters an empty label in the middle of a name.
|
/// encounters an empty label in the middle of a name.
|
||||||
///
|
///
|
||||||
class EmptyLabel : public Exception {
|
class EmptyLabel : public NameParserException {
|
||||||
public:
|
public:
|
||||||
EmptyLabel(const char* file, size_t line, const char* what) :
|
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
|
/// \brief A standard DNS module exception that is thrown if the name parser
|
||||||
/// encounters too long a name.
|
/// encounters too long a name.
|
||||||
///
|
///
|
||||||
class TooLongName : public Exception {
|
class TooLongName : public NameParserException {
|
||||||
public:
|
public:
|
||||||
TooLongName(const char* file, size_t line, const char* what) :
|
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
|
/// \brief A standard DNS module exception that is thrown if the name parser
|
||||||
/// encounters too long a label.
|
/// encounters too long a label.
|
||||||
///
|
///
|
||||||
class TooLongLabel : public Exception {
|
class TooLongLabel : public NameParserException {
|
||||||
public:
|
public:
|
||||||
TooLongLabel(const char* file, size_t line, const char* what) :
|
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
|
/// applies to bitstring labels, which would begin with "\[". Incomplete cases
|
||||||
/// include an incomplete escaped sequence such as "\12".
|
/// include an incomplete escaped sequence such as "\12".
|
||||||
///
|
///
|
||||||
class BadLabelType : public Exception {
|
class BadLabelType : public NameParserException {
|
||||||
public:
|
public:
|
||||||
BadLabelType(const char* file, size_t line, const char* what) :
|
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
|
/// \brief A standard DNS module exception that is thrown if the name parser
|
||||||
/// fails to decode a "\"-escaped sequence.
|
/// fails to decode a "\"-escaped sequence.
|
||||||
///
|
///
|
||||||
class BadEscape : public Exception {
|
class BadEscape : public NameParserException {
|
||||||
public:
|
public:
|
||||||
BadEscape(const char* file, size_t line, const char* what) :
|
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
|
/// An attempt of constructing a name from an empty string will trigger this
|
||||||
/// exception.
|
/// exception.
|
||||||
///
|
///
|
||||||
class IncompleteName : public Exception {
|
class IncompleteName : public NameParserException {
|
||||||
public:
|
public:
|
||||||
IncompleteName(const char* file, size_t line, const char* what) :
|
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());
|
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
|
// empty label cannot be followed by another label
|
||||||
EXPECT_THROW(Name(".a"), EmptyLabel);
|
EXPECT_THROW(Name(".a"), EmptyLabel);
|
||||||
@@ -212,6 +212,43 @@ TEST_F(NameTest, fromText) {
|
|||||||
EXPECT_EQ(Name::MAX_LABELS, maxlabels.getLabelCount());
|
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_F(NameTest, fromWire) {
|
||||||
//
|
//
|
||||||
// test cases derived from BIND9 tests.
|
// test cases derived from BIND9 tests.
|
||||||
|
Reference in New Issue
Block a user