Commit cb81101a authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

Merge branch 'trac2443'

parents 2002e7a1 84de42ee
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -12,6 +12,8 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <config.h>
#include <dns/labelsequence.h>
#include <dns/name_internal.h>
#include <exceptions/exceptions.h>
......@@ -24,24 +26,34 @@ namespace isc {
namespace dns {
LabelSequence::LabelSequence(const void* buf) {
#ifdef ENABLE_DEBUG
// In non-debug mode, derefencing the NULL pointer further below
// will lead to a crash, so disabling this check is not
// unsafe. Except for a programming mistake, this case should not
// happen.
if (buf == NULL) {
isc_throw(BadValue,
"Null pointer passed to LabelSequence constructor");
}
#endif
const uint8_t* bp = reinterpret_cast<const uint8_t*>(buf);
first_label_ = 0;
const uint8_t offsets_len = *bp++;
#ifdef ENABLE_DEBUG
if (offsets_len == 0 || offsets_len > Name::MAX_LABELS) {
isc_throw(BadValue,
"Bad offsets len in serialized LabelSequence data: "
<< static_cast<unsigned int>(offsets_len));
}
#endif
last_label_ = offsets_len - 1;
offsets_ = bp;
data_ = bp + offsets_len;
#ifdef ENABLE_DEBUG
// Check the integrity on the offsets and the name data
const uint8_t* dp = data_;
for (size_t cur_offset = 0; cur_offset < offsets_len; ++cur_offset) {
......@@ -52,6 +64,7 @@ LabelSequence::LabelSequence(const void* buf) {
}
dp += (1 + *dp);
}
#endif
}
LabelSequence::LabelSequence(const LabelSequence& src,
......
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -12,6 +12,8 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <config.h>
#include <util/buffer.h>
#include <dns/labelsequence.h>
......@@ -853,6 +855,10 @@ TEST_F(LabelSequenceTest, serialize) {
isc::BadValue);
}
#ifdef ENABLE_DEBUG
// These checks are enabled only in debug mode in the LabelSequence
// class.
TEST_F(LabelSequenceTest, badDeserialize) {
EXPECT_THROW(LabelSequence(NULL), isc::BadValue);
const uint8_t zero_offsets[] = { 0 };
......@@ -879,6 +885,8 @@ TEST_F(LabelSequenceTest, badDeserialize) {
EXPECT_THROW(LabelSequence ls(offsets_noincrease), isc::BadValue);
}
#endif
namespace {
// Helper function; repeatedly calls
......
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