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

[3286] Clear Message before parsing fromWire()

parent 9c9e6fb5
......@@ -645,6 +645,9 @@ Message::fromWire(InputBuffer& buffer, ParseOptions options) {
"Message parse attempted in non parse mode");
}
// Clear any old parsed data
clear(Message::PARSE);
if (!impl_->header_parsed_) {
parseHeader(buffer);
}
......
......@@ -572,12 +572,10 @@ TEST_F(MessageTest, parseHeader) {
message_parse.endSection(Message::SECTION_ADDITIONAL));
}
TEST_F(MessageTest, fromWire) {
// fromWire() isn't allowed in the render mode.
EXPECT_THROW(factoryFromFile(message_render, "message_fromWire1"),
InvalidMessageOperation);
factoryFromFile(message_parse, "message_fromWire1");
void
checkMessageFromWire(const Message& message_parse,
const Name& test_name)
{
EXPECT_EQ(0x1035, message_parse.getQid());
EXPECT_EQ(Opcode::QUERY(), message_parse.getOpcode());
EXPECT_EQ(Rcode::NOERROR(), message_parse.getRcode());
......@@ -608,6 +606,25 @@ TEST_F(MessageTest, fromWire) {
EXPECT_TRUE(it->isLast());
}
TEST_F(MessageTest, fromWire) {
// fromWire() isn't allowed in the render mode.
EXPECT_THROW(factoryFromFile(message_render, "message_fromWire1"),
InvalidMessageOperation);
factoryFromFile(message_parse, "message_fromWire1");
checkMessageFromWire(message_parse, test_name);
}
TEST_F(MessageTest, fromWireMultiple) {
// Parse from wire multiple times.
factoryFromFile(message_parse, "message_fromWire1");
factoryFromFile(message_parse, "message_fromWire1");
factoryFromFile(message_parse, "message_fromWire1");
factoryFromFile(message_parse, "message_fromWire1");
checkMessageFromWire(message_parse, test_name);
}
TEST_F(MessageTest, fromWireShortBuffer) {
// We trim a valid message (ending with an SOA RR) for one byte.
// fromWire() should throw an exception while parsing the trimmed RR.
......
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