BIND 10 trac2384, updated. d265c83bdf38b1b136d447c2c1585a8f824c1c46 [2384] Disallow empty TTLs and units-only TTLs

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Nov 7 08:52:27 UTC 2012


The branch, trac2384 has been updated
       via  d265c83bdf38b1b136d447c2c1585a8f824c1c46 (commit)
      from  4e410c83e9fb78be7c548c1184769f5a8a584b2c (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 d265c83bdf38b1b136d447c2c1585a8f824c1c46
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Nov 7 09:51:12 2012 +0100

    [2384] Disallow empty TTLs and units-only TTLs
    
    These are questionable and bind9 does not support them. Even the units
    are bind extension of some kind probably.

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

Summary of changes:
 src/lib/dns/rrttl.cc                |    9 +++++++--
 src/lib/dns/tests/rrttl_unittest.cc |    9 ++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/rrttl.cc b/src/lib/dns/rrttl.cc
index e8a3de4..0924439 100644
--- a/src/lib/dns/rrttl.cc
+++ b/src/lib/dns/rrttl.cc
@@ -58,6 +58,9 @@ namespace isc {
 namespace dns {
 
 RRTTL::RRTTL(const std::string& ttlstr) {
+    if (ttlstr.empty()) {
+        isc_throw(InvalidRRTTL, "Empty TTL string");
+    }
     // We use a larger data type during the computation. This is because
     // some compilers don't fail when out of range, so we check the range
     // ourselves later.
@@ -87,8 +90,10 @@ RRTTL::RRTTL(const std::string& ttlstr) {
                 }
             }
             // Now extract the number, defaut to 1 if there's no digit
-            const int64_t value = (unit == pos) ? 1 :
-                                  boost::lexical_cast<int64_t>(string(pos,
+            if (unit == pos) {
+                isc_throw(InvalidRRTTL, "Missing number in TTL ");
+            }
+            const int64_t value = boost::lexical_cast<int64_t>(string(pos,
                                                                       unit));
             // Add what we found
             val += multiply * value;
diff --git a/src/lib/dns/tests/rrttl_unittest.cc b/src/lib/dns/tests/rrttl_unittest.cc
index cef5816..bf73c3a 100644
--- a/src/lib/dns/tests/rrttl_unittest.cc
+++ b/src/lib/dns/tests/rrttl_unittest.cc
@@ -105,9 +105,12 @@ TEST_F(RRTTLTest, fromTextUnit) {
     EXPECT_EQ(60 * 60 + 3, RRTTL("1H3S").getValue());
     EXPECT_EQ(2 * 24 * 60 * 60 + 75 * 60 + 4, RRTTL("75M2D4").getValue());
 
-    // Missing number is taken as 1 (or should we disallow that?)
-    EXPECT_EQ(7 * 24 * 60 * 60 + 5 * 60 * 60, RRTTL("W5H").getValue());
-    EXPECT_EQ(7 * 24 * 60 * 60 + 5 * 60 * 60, RRTTL("5hW").getValue());
+    // Missing before unit.
+    EXPECT_THROW(RRTTL("W5H"), InvalidRRTTL);
+    EXPECT_THROW(RRTTL("5hW"), InvalidRRTTL);
+
+    // Empty string is not allowed
+    EXPECT_THROW(RRTTL(""), InvalidRRTTL);
 
     // There are some wrong units
     EXPECT_THROW(RRTTL("13X"), InvalidRRTTL);



More information about the bind10-changes mailing list