Commit ad710ab6 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

fixed a crash bug in rendering the root name.

added a test case to catch this bug.


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@630 e5f2f494-b856-4b98-b285-d166d9295462
parent c30eded1
......@@ -219,7 +219,8 @@ MessageRenderer::writeName(const Name& name, bool compress)
name.toWire(impl_->nbuffer_);
unsigned int i;
std::set<NameCompressNode>::const_iterator n;
std::set<NameCompressNode>::const_iterator notfound = impl_->nodeset_.end();
std::set<NameCompressNode>::const_iterator n = notfound;
// Find the longest ancestor name in the rendered set that matches the
// given name.
......@@ -231,7 +232,7 @@ MessageRenderer::writeName(const Name& name, bool compress)
n = impl_->nodeset_.find(NameCompressNode(impl_->nbuffer_, i,
impl_->nbuffer_.getLength() -
i));
if (n != impl_->nodeset_.end()) {
if (n != notfound) {
break;
}
}
......@@ -241,7 +242,7 @@ MessageRenderer::writeName(const Name& name, bool compress)
// Write uncompress part...
impl_->buffer_.writeData(impl_->nbuffer_.getData(),
compress ? i : impl_->nbuffer_.getLength());
if (compress && n != impl_->nodeset_.end()) {
if (compress && n != notfound) {
// ...and compression pointer if available.
uint16_t pointer = (*n).pos_;
pointer |= Name::COMPRESS_POINTER_MARK16;
......
......@@ -113,4 +113,24 @@ TEST_F(MessageRendererTest, writeNameCaseCompress)
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, buffer.getData(),
buffer.getLength(), &data[0], data.size());
}
TEST_F(MessageRendererTest, writeRootName)
{
// root name is special: it never causes compression or can (reasonably)
// be a compression pointer. So it makes sense to check this case
// explicitly.
Name example_name = Name("www.example.com");
OutputBuffer expected(0);
expected.writeUint8(0); // root name
example_name.toWire(expected);
renderer.writeName(Name("."));
renderer.writeName(example_name);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
static_cast<const uint8_t*>(buffer.getData()),
buffer.getLength(),
static_cast<const uint8_t*>(expected.getData()),
expected.getLength());
}
}
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