BIND 10 trac2375, updated. e79c7f13e2ee7cfb6916d07ce2470236acaa66d2 [2375] Check we don't read past the end

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Nov 13 18:18:34 UTC 2012


The branch, trac2375 has been updated
       via  e79c7f13e2ee7cfb6916d07ce2470236acaa66d2 (commit)
      from  e70ed476bb19a8201e5ba09cbf63998e916afe20 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e79c7f13e2ee7cfb6916d07ce2470236acaa66d2
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Tue Nov 13 19:18:20 2012 +0100

    [2375] Check we don't read past the end

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/master_lexer.cc                |    3 ++-
 src/lib/dns/tests/master_lexer_unittest.cc |   12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_lexer.cc b/src/lib/dns/master_lexer.cc
index e5cadcc..2754d0c 100644
--- a/src/lib/dns/master_lexer.cc
+++ b/src/lib/dns/master_lexer.cc
@@ -128,7 +128,8 @@ MasterLexer::getNextToken(Options options) {
     // Reset the token now. This is to check a token was actually produced.
     // This is debugging aid.
     impl_->token_ = Token(Token::NO_TOKEN_PRODUCED);
-    if (impl_->source_ == NULL) {
+    // If the source is not available
+    if (impl_->source_ == NULL || impl_->source_->atEOF()) {
         isc_throw(isc::InvalidOperation, "No source to read tokens from");
     }
     for (const State *state = start(options); state != NULL;
diff --git a/src/lib/dns/tests/master_lexer_unittest.cc b/src/lib/dns/tests/master_lexer_unittest.cc
index fca2985..5a9448e 100644
--- a/src/lib/dns/tests/master_lexer_unittest.cc
+++ b/src/lib/dns/tests/master_lexer_unittest.cc
@@ -257,4 +257,16 @@ TEST_F(MasterLexerTest, realStart) {
               lexer.getNextToken(MasterLexer::INITIAL_WS).getType());
 }
 
+// Test we correctly find end of file. Then, upon more attempts to produce
+// tokens past the end, it throws.
+TEST_F(MasterLexerTest, eof) {
+    // Let the ss empty.
+    lexer.pushSource(ss);
+
+    // The first one is found to be EOF
+    EXPECT_EQ(MasterLexer::Token::END_OF_FILE, lexer.getNextToken().getType());
+    // And it is not allowed to use this one any more.
+    EXPECT_THROW(lexer.getNextToken(), isc::InvalidOperation);
+}
+
 }



More information about the bind10-changes mailing list