BIND 10 trac1774, updated. 24c9af463a1087f54918f6e1206f72b50b43d9bf [1774] Add tests with zero name data
BIND 10 source code commits
bind10-changes at lists.isc.org
Sun Jun 24 17:04:23 UTC 2012
The branch, trac1774 has been updated
via 24c9af463a1087f54918f6e1206f72b50b43d9bf (commit)
via bf0f1e06d99d7f4fc36a0eb53e1bf8420e86bb35 (commit)
via 846dbfde91d54302568407175b54bc3cfb0f6bae (commit)
via 31ee75a034bad0d43d30368fa1ed7a3643aea402 (commit)
from de9c0a0b8ce9eb7b7aa7319aef68a209f27f1421 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 24c9af463a1087f54918f6e1206f72b50b43d9bf
Author: Mukund Sivaraman <muks at isc.org>
Date: Sun Jun 24 22:33:28 2012 +0530
[1774] Add tests with zero name data
commit bf0f1e06d99d7f4fc36a0eb53e1bf8420e86bb35
Author: Mukund Sivaraman <muks at isc.org>
Date: Sun Jun 24 22:18:27 2012 +0530
[1774] Use uint8_t instead of unsigned char (more places)
commit 846dbfde91d54302568407175b54bc3cfb0f6bae
Author: Mukund Sivaraman <muks at isc.org>
Date: Sun Jun 24 22:11:35 2012 +0530
[1774] Use uint8_t instead of unsigned char
commit 31ee75a034bad0d43d30368fa1ed7a3643aea402
Author: Mukund Sivaraman <muks at isc.org>
Date: Sun Jun 24 22:11:30 2012 +0530
[1774] Define and use type for Name data
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/labelsequence.cc | 18 ++++++++----------
src/lib/dns/labelsequence.h | 2 +-
src/lib/dns/messagerenderer.cc | 6 +++---
src/lib/dns/name.cc | 24 ++++++++++++------------
src/lib/dns/name.h | 5 ++++-
src/lib/dns/name_internal.h | 2 +-
src/lib/dns/tests/labelsequence_unittest.cc | 25 +++++++++++++++++++++----
7 files changed, 50 insertions(+), 32 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/labelsequence.cc b/src/lib/dns/labelsequence.cc
index 5a3b51c..d6521e0 100644
--- a/src/lib/dns/labelsequence.cc
+++ b/src/lib/dns/labelsequence.cc
@@ -23,7 +23,7 @@
namespace isc {
namespace dns {
-const unsigned char*
+const uint8_t*
LabelSequence::getData(size_t *len) const {
*len = getDataLength();
return (&name_.ndata_[name_.offsets_[first_label_]]);
@@ -47,24 +47,22 @@ LabelSequence::getDataLength() const {
bool
LabelSequence::equals(const LabelSequence& other, bool case_sensitive) const {
size_t len, other_len;
- const unsigned char* data = getData(&len);
- const unsigned char* other_data = other.getData(&other_len);
+ const uint8_t* data = getData(&len);
+ const uint8_t* other_data = other.getData(&other_len);
if (len != other_len) {
return (false);
}
if (case_sensitive) {
- return (std::strncmp((const char*) data,
- (const char*) other_data,
- len) == 0);
+ return (std::memcmp(data, other_data, len) == 0);
}
// As long as the data was originally validated as (part of) a name,
// label length must never be a capital ascii character, so we can
// simply compare them after converting to lower characters.
for (size_t i = 0; i < len; ++i) {
- const unsigned char ch = data[i];
- const unsigned char other_ch = other_data[i];
+ const uint8_t ch = data[i];
+ const uint8_t other_ch = other_data[i];
if (isc::dns::name::internal::maptolower[ch] !=
isc::dns::name::internal::maptolower[other_ch]) {
return (false);
@@ -99,14 +97,14 @@ LabelSequence::isAbsolute() const {
size_t
LabelSequence::getHash(bool case_sensitive) const {
size_t length;
- const unsigned char* s = getData(&length);
+ const uint8_t* s = getData(&length);
if (length > 16) {
length = 16;
}
size_t hash_val = 0;
while (length > 0) {
- const unsigned char c = *s++;
+ const uint8_t c = *s++;
boost::hash_combine(hash_val, case_sensitive ? c :
isc::dns::name::internal::maptolower[c]);
--length;
diff --git a/src/lib/dns/labelsequence.h b/src/lib/dns/labelsequence.h
index 5b55515..12fb4f4 100644
--- a/src/lib/dns/labelsequence.h
+++ b/src/lib/dns/labelsequence.h
@@ -67,7 +67,7 @@ public:
/// \param len Pointer to a size_t where the length of the data
/// will be stored (in number of octets)
/// \return Pointer to the wire-format data of this label sequence
- const unsigned char* getData(size_t* len) const;
+ const uint8_t* getData(size_t* len) const;
/// \brief Return the length of the wire-format data of this LabelSequence
///
diff --git a/src/lib/dns/messagerenderer.cc b/src/lib/dns/messagerenderer.cc
index ff712b3..ca4ea54 100644
--- a/src/lib/dns/messagerenderer.cc
+++ b/src/lib/dns/messagerenderer.cc
@@ -100,8 +100,8 @@ struct NameCompare {
uint16_t item_label_len = 0;
for (size_t i = 0; i < item.len_; ++i, ++item_pos) {
item_pos = nextPosition(*buffer_, item_pos, item_label_len);
- const unsigned char ch1 = (*buffer_)[item_pos];
- const unsigned char ch2 = name_buf_->readUint8();
+ const uint8_t ch1 = (*buffer_)[item_pos];
+ const uint8_t ch2 = name_buf_->readUint8();
if (CASE_SENSITIVE) {
if (ch1 != ch2) {
return (false);
@@ -293,7 +293,7 @@ MessageRenderer::writeName(const Name& name, const bool compress) {
LabelSequence sequence(name);
const size_t nlabels = sequence.getLabelCount();
size_t data_len;
- const unsigned char* data;
+ const uint8_t* data;
// Find the offset in the offset table whose name gives the longest
// match against the name to be rendered.
diff --git a/src/lib/dns/name.cc b/src/lib/dns/name.cc
index 00b9aeb..0a92d29 100644
--- a/src/lib/dns/name.cc
+++ b/src/lib/dns/name.cc
@@ -75,7 +75,7 @@ const char digitvalue[256] = {
namespace name {
namespace internal {
-const unsigned char maptolower[] = {
+const uint8_t maptolower[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@@ -151,7 +151,7 @@ Name::Name(const std::string &namestring, bool downcase) {
offsets.reserve(Name::MAX_LABELS);
offsets.push_back(0);
- std::basic_string<uint8_t> ndata;
+ NameString ndata;
ndata.reserve(Name::MAX_WIRE);
// should we refactor this code using, e.g, the state pattern? Probably
@@ -436,8 +436,8 @@ Name::toText(bool omit_final_dot) const {
return (".");
}
- std::basic_string<uint8_t>::const_iterator np = ndata_.begin();
- std::basic_string<uint8_t>::const_iterator np_end = ndata_.end();
+ NameString::const_iterator np = ndata_.begin();
+ NameString::const_iterator np_end = ndata_.end();
unsigned int labels = labelcount_; // use for integrity check
// init with an impossible value to catch error cases in the end:
unsigned int count = MAX_LABELLEN + 1;
@@ -467,7 +467,7 @@ Name::toText(bool omit_final_dot) const {
}
while (count-- > 0) {
- unsigned char c = *np++;
+ uint8_t c = *np++;
switch (c) {
case 0x22: // '"'
case 0x28: // '('
@@ -534,8 +534,8 @@ Name::compare(const Name& other) const {
unsigned int count = (cdiff < 0) ? count1 : count2;
while (count > 0) {
- unsigned char label1 = ndata_[pos1];
- unsigned char label2 = other.ndata_[pos2];
+ uint8_t label1 = ndata_[pos1];
+ uint8_t label2 = other.ndata_[pos2];
int chdiff = (int)maptolower[label1] - (int)maptolower[label2];
if (chdiff != 0) {
@@ -571,15 +571,15 @@ Name::equals(const Name& other) const {
}
for (unsigned int l = labelcount_, pos = 0; l > 0; --l) {
- unsigned char count = ndata_[pos];
+ uint8_t count = ndata_[pos];
if (count != other.ndata_[pos]) {
return (false);
}
++pos;
while (count-- > 0) {
- unsigned char label1 = ndata_[pos];
- unsigned char label2 = other.ndata_[pos];
+ uint8_t label1 = ndata_[pos];
+ uint8_t label2 = other.ndata_[pos];
if (maptolower[label1] != maptolower[label2]) {
return (false);
@@ -665,7 +665,7 @@ Name::reverse() const {
// Copy the original name, label by label, from tail to head.
vector<unsigned char>::const_reverse_iterator rit0 = offsets_.rbegin();
vector<unsigned char>::const_reverse_iterator rit1 = rit0 + 1;
- basic_string<uint8_t>::const_iterator n0 = ndata_.begin();
+ NameString::const_iterator n0 = ndata_.begin();
retname.offsets_.push_back(0);
while (rit1 != offsets_.rend()) {
retname.ndata_.append(n0 + *rit1, n0 + *rit0);
@@ -746,7 +746,7 @@ Name::downcase() {
while (count > 0) {
ndata_.at(pos) =
- maptolower[static_cast<unsigned char>(ndata_.at(pos))];
+ maptolower[ndata_.at(pos)];
++pos;
--nlen;
--count;
diff --git a/src/lib/dns/name.h b/src/lib/dns/name.h
index 56e7816..84c243a 100644
--- a/src/lib/dns/name.h
+++ b/src/lib/dns/name.h
@@ -229,6 +229,9 @@ class Name {
///
//@{
private:
+ /// \brief Name data string
+ typedef std::basic_string<uint8_t> NameString;
+
/// The default constructor
///
/// This is used internally in the class implementation, but at least at
@@ -679,7 +682,7 @@ public:
//@}
private:
- std::basic_string<uint8_t> ndata_;
+ NameString ndata_;
std::vector<unsigned char> offsets_;
unsigned int length_;
unsigned int labelcount_;
diff --git a/src/lib/dns/name_internal.h b/src/lib/dns/name_internal.h
index e1eab8c..8595df1 100644
--- a/src/lib/dns/name_internal.h
+++ b/src/lib/dns/name_internal.h
@@ -31,7 +31,7 @@ namespace isc {
namespace dns {
namespace name {
namespace internal {
-extern const unsigned char maptolower[];
+extern const uint8_t maptolower[];
} // end of internal
} // end of name
} // end of dns
diff --git a/src/lib/dns/tests/labelsequence_unittest.cc b/src/lib/dns/tests/labelsequence_unittest.cc
index 0dac7fb..6452e84 100644
--- a/src/lib/dns/tests/labelsequence_unittest.cc
+++ b/src/lib/dns/tests/labelsequence_unittest.cc
@@ -34,14 +34,21 @@ public:
n3("example.org"), n4("foo.bar.test.example"),
n5("example.ORG"), n6("ExAmPlE.org"),
n7("."), n8("foo.example.org.bar"),
+ n9("\\000xample.org"),
+ n10("\\000xample.org"),
+ n11("\\000xample.com"),
+ n12("\\000xamplE.com"),
ls1(n1), ls2(n2), ls3(n3), ls4(n4), ls5(n5),
- ls6(n6), ls7(n7), ls8(n8)
+ ls6(n6), ls7(n7), ls8(n8),
+ ls9(n9), ls10(n10), ls11(n11), ls12(n12)
{};
// Need to keep names in scope for at least the lifetime of
// the labelsequences
Name n1, n2, n3, n4, n5, n6, n7, n8;
+ Name n9, n10, n11, n12;
LabelSequence ls1, ls2, ls3, ls4, ls5, ls6, ls7, ls8;
+ LabelSequence ls9, ls10, ls11, ls12;
};
// Basic equality tests
@@ -81,6 +88,11 @@ TEST_F(LabelSequenceTest, equals_sensitive) {
EXPECT_FALSE(ls5.equals(ls6, true));
EXPECT_FALSE(ls5.equals(ls7, true));
EXPECT_FALSE(ls5.equals(ls8, true));
+
+ EXPECT_TRUE(ls9.equals(ls10, true));
+ EXPECT_FALSE(ls9.equals(ls11, true));
+ EXPECT_FALSE(ls9.equals(ls12, true));
+ EXPECT_FALSE(ls11.equals(ls12, true));
}
TEST_F(LabelSequenceTest, equals_insensitive) {
@@ -123,6 +135,11 @@ TEST_F(LabelSequenceTest, equals_insensitive) {
EXPECT_TRUE(ls5.equals(ls5));
EXPECT_TRUE(ls5.equals(ls6));
EXPECT_FALSE(ls5.equals(ls7));
+
+ EXPECT_TRUE(ls9.equals(ls10));
+ EXPECT_FALSE(ls9.equals(ls11));
+ EXPECT_FALSE(ls9.equals(ls12));
+ EXPECT_TRUE(ls11.equals(ls12));
}
void
@@ -130,14 +147,14 @@ getDataCheck(const char* expected_data, size_t expected_len,
const LabelSequence& ls)
{
size_t len;
- const unsigned char* data = ls.getData(&len);
+ const uint8_t* data = ls.getData(&len);
ASSERT_EQ(expected_len, len) << "Expected data: " << expected_data <<
" name: " << ls.getName().toText();
EXPECT_EQ(expected_len, ls.getDataLength()) <<
"Expected data: " << expected_data <<
" name: " << ls.getName().toText();
for (size_t i = 0; i < len; ++i) {
- EXPECT_EQ((const unsigned char) expected_data[i], data[i]) <<
+ EXPECT_EQ(static_cast<const uint8_t>(expected_data[i]), data[i]) <<
"Difference at pos " << i << ": Expected data: " << expected_data <<
" name: " << ls.getName().toText();;
}
@@ -241,7 +258,7 @@ TEST_F(LabelSequenceTest, comparePart) {
// Data comparison
size_t len;
- const unsigned char* data = ls1.getData(&len);
+ const uint8_t* data = ls1.getData(&len);
getDataCheck((const char*) data, len, ls8);
}
More information about the bind10-changes
mailing list