BIND 10 trac2427, updated. b5904bd8eed8e36d1d6fd6d4305f687f53fe6733 [2427] Warn about relative $ORIGIN

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Dec 18 12:25:02 UTC 2012


The branch, trac2427 has been updated
       via  b5904bd8eed8e36d1d6fd6d4305f687f53fe6733 (commit)
      from  bdc390376f18c7a858744eb9fb11827e792c6243 (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 b5904bd8eed8e36d1d6fd6d4305f687f53fe6733
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Tue Dec 18 13:23:25 2012 +0100

    [2427] Warn about relative $ORIGIN
    
    It is probably unusual and most probably a typo, resulting in broken
    zone.

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

Summary of changes:
 src/lib/dns/master_loader.cc                |    7 +++++
 src/lib/dns/tests/master_loader_unittest.cc |   42 +++++++++++++++------------
 2 files changed, 30 insertions(+), 19 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc
index 0848d5d..7274002 100644
--- a/src/lib/dns/master_loader.cc
+++ b/src/lib/dns/master_loader.cc
@@ -157,6 +157,13 @@ private:
                 name_string(name_tok.getStringRegion());
             active_origin_ = Name(name_string.beg, name_string.len,
                                   &active_origin_);
+            if (name_string.len > 0 &&
+                name_string.beg[name_string.len - 1] != '.') {
+                callbacks_.warning(lexer_.getSourceName(),
+                                   lexer_.getSourceLine(),
+                                   "The new origin is relative, did you really"
+                                   " mean " + active_origin_.toText() + "?");
+            }
         } else {
             // If it is not optional, we must not get anything but
             // a string token.
diff --git a/src/lib/dns/tests/master_loader_unittest.cc b/src/lib/dns/tests/master_loader_unittest.cc
index 934902d..26d24a7 100644
--- a/src/lib/dns/tests/master_loader_unittest.cc
+++ b/src/lib/dns/tests/master_loader_unittest.cc
@@ -195,6 +195,22 @@ TEST_F(MasterLoaderTest, include) {
     }
 }
 
+// A commonly used helper to check callback message.
+void
+checkCallbackMessage(const string& actual_msg, const string& expected_msg,
+                     size_t expected_line) {
+    // The actual message should begin with the expected message.
+    EXPECT_EQ(0, actual_msg.find(expected_msg)) << "actual message: " <<
+                                                actual_msg << " expected: " <<
+                                                expected_msg;
+
+    // and it should end with "...:<line_num>]"
+    const string line_desc = ":" + lexical_cast<string>(expected_line) + "]";
+    EXPECT_EQ(actual_msg.size() - line_desc.size(),
+              actual_msg.find(line_desc)) << "Expected on line " <<
+        expected_line;
+}
+
 TEST_F(MasterLoaderTest, origin) {
     // Various forms of the directive
     const char* origins[] = {
@@ -226,7 +242,11 @@ TEST_F(MasterLoaderTest, origin) {
         loader_->load();
         EXPECT_TRUE(loader_->loadedSucessfully());
         EXPECT_TRUE(errors_.empty());
-        EXPECT_TRUE(warnings_.empty());
+        // There's a relative origin in it, we warn about that.
+        EXPECT_EQ(1, warnings_.size());
+        checkCallbackMessage(warnings_.at(0),
+                             "The new origin is relative, did you really mean "
+                             "relative.sub.example.org.?", 4);
 
         checkARR("example.org");
         checkARR("www.sub.example.org");
@@ -370,22 +390,6 @@ struct ErrorCase {
     { NULL, NULL, NULL }
 };
 
-// A commonly used helper to check callback message.
-void
-checkCallbackMessage(const string& actual_msg, const string& expected_msg,
-                     size_t expected_line) {
-    // The actual message should begin with the expected message.
-    EXPECT_EQ(0, actual_msg.find(expected_msg)) << "actual message: " <<
-                                                actual_msg << " expected: " <<
-                                                expected_msg;
-
-    // and it should end with "...:<line_num>]"
-    const string line_desc = ":" + lexical_cast<string>(expected_line) + "]";
-    EXPECT_EQ(actual_msg.size() - line_desc.size(),
-              actual_msg.find(line_desc)) << "Expected on line " <<
-        expected_line;
-}
-
 // Test a broken zone is handled properly. We test several problems,
 // both in strict and lenient mode.
 TEST_F(MasterLoaderTest, brokenZone) {
@@ -480,7 +484,7 @@ TEST_F(MasterLoaderTest, includeWithGarbage) {
 // Check we error about garbage at the end of $ORIGIN line (but the line
 // works).
 TEST_F(MasterLoaderTest, originWithGarbage) {
-    const string origin_str = "$ORIGIN www More garbage here\n"
+    const string origin_str = "$ORIGIN www.example.org. More garbage here\n"
         "@  1H  IN  A   192.0.2.1\n";
     stringstream ss(origin_str);
     setLoader(ss, Name("example.org."), RRClass::IN(),
@@ -497,7 +501,7 @@ TEST_F(MasterLoaderTest, originWithGarbage) {
 TEST_F(MasterLoaderTest, includeAndOrigin) {
     // First, switch origin to something else, so we can check it is
     // switched back.
-    const string include_string = "$ORIGIN www\n"
+    const string include_string = "$ORIGIN www.example.org.\n"
         "@  1H  IN  A   192.0.2.1\n"
         // Then include the file with data and switch origin back
         "$INCLUDE " TEST_DATA_SRCDIR "/example.org example.org.\n"



More information about the bind10-changes mailing list