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

[2382] warn if RDATA immediately followed by EOF

parent 0ad163bb
......@@ -138,27 +138,33 @@ createRdata(const RRType& rrtype, const RRClass& rrclass,
// finer.
fromtextError(error_issued, lexer, callbacks, NULL, ex.what());
}
// Other exceptions mean a serious implementation bug; it doesn't make
// sense to catch and try to recover from them here. Just propagate.
// Other exceptions mean a serious implementation bug or fatal system
// error; it doesn't make sense to catch and try to recover from them
// here. Just propagate.
// Consume to end of line / file.
// If not at end of line initially set error code.
// Call callback via fromtextError once if there was an error.
do {
const MasterToken& token = lexer.getNextToken();
if (token.getType() != MasterToken::END_OF_LINE &&
token.getType() != MasterToken::END_OF_FILE) {
switch (token.getType()) {
case MasterToken::END_OF_LINE:
return (rdata);
case MasterToken::END_OF_FILE:
callbacks.warning(lexer.getSourceName(), lexer.getSourceLine(),
"file does not end with newline");
return (rdata);
default:
rdata.reset(); // we'll return NULL
if (!error_issued) {
fromtextError(error_issued, lexer, callbacks, &token,
"extra input text");
}
} else { // reached EOL or EOF
break;
fromtextError(error_issued, lexer, callbacks, &token,
"extra input text");
// Continue until we see EOL or EOF
}
} while (true);
return (rdata);
// We shouldn't reach here
assert(false);
return (RdataPtr()); // add explicit return to silence some compilers
}
int
......
......@@ -136,6 +136,7 @@ TEST_F(RdataTest, createRdataWithLexer) {
ss << aaaa_rdata.toText() << " extra token\n"; // 2 extra tokens
ss << ")\n"; // causing lexer error in parsing the RDATA text
ss << "192.0.2.1\n"; // semantics error: IPv4 address is given for AAAA
ss << aaaa_rdata.toText(); // valid, but end with EOF, not EOL
lexer.pushSource(ss);
CreateRdataCallback callback;
......@@ -185,6 +186,15 @@ TEST_F(RdataTest, createRdataWithLexer) {
callback.check(src_name, 5, CreateRdataCallback::ERROR,
"createRdata from text failed: Failed to convert "
"'192.0.2.1' to IN/AAAA RDATA");
// Input is valid and parse will succeed, but with a warning that the
// file is not ended with a newline.
callback.clear();
rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL,
MasterLoader::MANY_ERRORS, callbacks);
EXPECT_EQ(0, aaaa_rdata.compare(*rdata));
callback.check(src_name, 6, CreateRdataCallback::WARN,
"file does not end with newline");
}
}
......
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