diff options
-rw-r--r-- | src/lib/dns/messagerenderer.cc | 4 | ||||
-rw-r--r-- | src/lib/dns/messagerenderer.h | 10 | ||||
-rw-r--r-- | src/lib/dns/tests/messagerenderer_unittest.cc | 16 |
3 files changed, 23 insertions, 7 deletions
diff --git a/src/lib/dns/messagerenderer.cc b/src/lib/dns/messagerenderer.cc index 1019d96baf..33196c07b9 100644 --- a/src/lib/dns/messagerenderer.cc +++ b/src/lib/dns/messagerenderer.cc @@ -184,6 +184,10 @@ MessageRenderer::getCompressMode() const { void MessageRenderer::setCompressMode(const CompressMode mode) { + if (!impl_->names_.empty()) { + isc_throw(isc::InvalidParameter, + "compress mode cannot be changed during rendering"); + } impl_->compress_mode_ = mode; } diff --git a/src/lib/dns/messagerenderer.h b/src/lib/dns/messagerenderer.h index f7f2381dc0..4c1c92a34f 100644 --- a/src/lib/dns/messagerenderer.h +++ b/src/lib/dns/messagerenderer.h @@ -359,7 +359,17 @@ public: virtual CompressMode getCompressMode() const; virtual void setTruncated(); virtual void setLengthLimit(size_t len); + + /// This implementation does not allow this call in the middle of + /// rendering (i.e. after at least one name is rendered) due to + /// restriction specific to the internal implementation. Such attempts + /// will result in an \c isc::InvalidParameter exception. + /// + /// This shouldn't be too restrictive in practice; there's no known + /// practical case for such a mixed compression policy in a single + /// message. virtual void setCompressMode(CompressMode mode); + virtual void clear(); virtual void writeName(const Name& name, bool compress = true); private: diff --git a/src/lib/dns/tests/messagerenderer_unittest.cc b/src/lib/dns/tests/messagerenderer_unittest.cc index 2a1869f209..04082f1033 100644 --- a/src/lib/dns/tests/messagerenderer_unittest.cc +++ b/src/lib/dns/tests/messagerenderer_unittest.cc @@ -142,13 +142,15 @@ TEST_F(MessageRendererTest, writeNameMixedCaseCompress) { renderer.writeName(Name("a.example.com.")); renderer.writeName(Name("b.eXample.com.")); - // Change the compression mode in the middle of rendering. This is an - // unusual operation and is unlikely to happen in practice, but is still - // allowed in this API. - renderer.setCompressMode(MessageRenderer::CASE_INSENSITIVE); - renderer.writeName(Name("c.b.EXAMPLE.com.")); - EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, renderer.getData(), - renderer.getLength(), &data[0], data.size()); + // Change the compression mode in the middle of rendering. This is not + // allowed in this implementation. + EXPECT_THROW(renderer.setCompressMode(MessageRenderer::CASE_INSENSITIVE), + isc::InvalidParameter); + + // Once the renderer is cleared, it's okay again. + renderer.clear(); + EXPECT_NO_THROW(renderer.setCompressMode( + MessageRenderer::CASE_INSENSITIVE)); } TEST_F(MessageRendererTest, writeRootName) { |