BIND 10 trac838, updated. 9c4b079aca67cffe9385e54671f8eb9ed232e1e5 [trac838] also fixed another STL related bugs in tests: avoid using &vector[0] when the vector can be empty.
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri May 6 06:36:45 UTC 2011
The branch, trac838 has been updated
via 9c4b079aca67cffe9385e54671f8eb9ed232e1e5 (commit)
via b1b486e59d86633e7b5e17aeedf0f78688ecef05 (commit)
via 45fb91884dc0741384a14e7f52633b0566779dff (commit)
from c166c0c96a476eea511fe363b90df3d78fae7506 (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 9c4b079aca67cffe9385e54671f8eb9ed232e1e5
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Thu May 5 23:19:49 2011 -0700
[trac838] also fixed another STL related bugs in tests: avoid using &vector[0]
when the vector can be empty.
commit b1b486e59d86633e7b5e17aeedf0f78688ecef05
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Thu May 5 23:18:05 2011 -0700
[trac838] counter proposal for the isspace() problem: use simply cast
rather than conditional call.
commit 45fb91884dc0741384a14e7f52633b0566779dff
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Thu May 5 23:14:35 2011 -0700
[trac838] counter proposal to the "dereferencing end iterator" (and related) problem:
- added more detailed comments about the exception
- removed the now unnecessary check for *base_ (against PADDING CHAR) when in_pad_
- handled beginning spaces correctly
-----------------------------------------------------------------------
Summary of changes:
src/lib/util/encode/base_n.cc | 27 ++++++++++++++++++++-------
src/lib/util/tests/base32hex_unittest.cc | 7 ++++++-
src/lib/util/tests/base64_unittest.cc | 2 +-
3 files changed, 27 insertions(+), 9 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/util/encode/base_n.cc b/src/lib/util/encode/base_n.cc
index 966ef8c..0e34181 100644
--- a/src/lib/util/encode/base_n.cc
+++ b/src/lib/util/encode/base_n.cc
@@ -160,23 +160,36 @@ public:
base_zero_code_(base_zero_code),
base_(base), base_beginpad_(base_beginpad), base_end_(base_end),
in_pad_(false)
- {}
+ {
+ // Skip beginning spaces, if any. We need do it here because
+ // otherwise the first call to operator*() would be confused.
+ skipSpaces();
+ }
DecodeNormalizer& operator++() {
++base_;
- while (base_ != base_end_ && (*base_ > 0) && isspace(*base_)) {
- ++base_;
- }
+ skipSpaces();
if (base_ == base_beginpad_) {
in_pad_ = true;
}
return (*this);
}
+ void skipSpaces() {
+ while (base_ != base_end_ &&
+ isspace(static_cast<unsigned char>(*base_)))
+ {
+ ++base_;
+ }
+ }
const char& operator*() const {
if (base_ == base_end_) {
- isc_throw(BadValue, "dereference the end iterator");
+ // binary_from_baseX calls this operator when it needs more bits
+ // even if the internal iterator (base_) has reached its end
+ // (if that happens it means the input is an incomplete baseX
+ // string and should be rejected). So this is the only point
+ // we can catch and reject this type of invalid input.
+ isc_throw(BadValue, "Unexpected end of input in BASE decoder");
}
-
- if (in_pad_ && *base_ == BASE_PADDING_CHAR) {
+ if (in_pad_) {
return (base_zero_code_);
} else {
return (*base_);
diff --git a/src/lib/util/tests/base32hex_unittest.cc b/src/lib/util/tests/base32hex_unittest.cc
index bf79627..fa4a290 100644
--- a/src/lib/util/tests/base32hex_unittest.cc
+++ b/src/lib/util/tests/base32hex_unittest.cc
@@ -66,7 +66,7 @@ decodeCheck(const string& input_string, vector<uint8_t>& output,
const string& expected)
{
decodeBase32Hex(input_string, output);
- EXPECT_EQ(expected, string(&output[0], &output[0] + output.size()));
+ EXPECT_EQ(expected, string(output.begin(), output.end()));
}
TEST_F(Base32HexTest, decode) {
@@ -79,6 +79,11 @@ TEST_F(Base32HexTest, decode) {
// whitespace should be allowed
decodeCheck("CP NM\tUOG=", decoded_data, "foob");
decodeCheck("CPNMU===\n", decoded_data, "foo");
+ decodeCheck(" CP NM\tUOG=", decoded_data, "foob");
+ decodeCheck(" ", decoded_data, "");
+
+ // Incomplete input
+ EXPECT_THROW(decodeBase32Hex("CPNMUOJ", decoded_data), BadValue);
// invalid number of padding characters
EXPECT_THROW(decodeBase32Hex("CPNMU0==", decoded_data), BadValue);
diff --git a/src/lib/util/tests/base64_unittest.cc b/src/lib/util/tests/base64_unittest.cc
index c2b2785..2e3d1f2 100644
--- a/src/lib/util/tests/base64_unittest.cc
+++ b/src/lib/util/tests/base64_unittest.cc
@@ -52,7 +52,7 @@ decodeCheck(const string& input_string, vector<uint8_t>& output,
const string& expected)
{
decodeBase64(input_string, output);
- EXPECT_EQ(expected, string(&output[0], &output[0] + output.size()));
+ EXPECT_EQ(expected, string(output.begin(), output.end()));
}
TEST_F(Base64Test, decode) {
More information about the bind10-changes
mailing list