From: JINMEI Tatuya Date: Sat, 1 Dec 2012 03:37:28 +0000 (-0800) Subject: [2382] warn if RDATA immediately followed by EOF X-Git-Tag: bind10-1.0.0-beta-release~44^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e441d6b05a022f3c0a7140ae43fe42d5fd12cce3;p=thirdparty%2Fkea.git [2382] warn if RDATA immediately followed by EOF --- diff --git a/src/lib/dns/rdata.cc b/src/lib/dns/rdata.cc index 962ff86a57..54644b7756 100644 --- a/src/lib/dns/rdata.cc +++ b/src/lib/dns/rdata.cc @@ -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 diff --git a/src/lib/dns/tests/rdata_unittest.cc b/src/lib/dns/tests/rdata_unittest.cc index cf438276ab..bb39d05fe0 100644 --- a/src/lib/dns/tests/rdata_unittest.cc +++ b/src/lib/dns/tests/rdata_unittest.cc @@ -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"); } }