]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2384] Little bit more range checking
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Sat, 10 Nov 2012 10:28:53 +0000 (11:28 +0100)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Sat, 10 Nov 2012 10:28:53 +0000 (11:28 +0100)
There was a gap when one thing could overflow to negative numbers.

src/lib/dns/rrttl.cc
src/lib/dns/tests/rrttl_unittest.cc

index 5f7dae509cb99f3b31773bdef028b017aca22842..620cf7c1e6eda5b9663f3cefe3d6ba222f2ec8d2 100644 (file)
@@ -116,7 +116,8 @@ RRTTL::RRTTL(const std::string& ttlstr) {
             // Check the partial value is still in range (the value can only
             // grow, so if we get out of range now, it won't get better, so
             // there's no need to continue).
-            if (value < 0 || val < 0 || val > 0xffffffff) {
+            if (value < 0 || value > 0xffffffff || val < 0 ||
+                val > 0xffffffff) {
                 isc_throw(InvalidRRTTL, "Part of TTL out of range: " <<
                           ttlstr);
             }
index 61e7849b0d6b8b2160834b8fb667817303d43474..754dd6c8b822869ac2f77ba4549afed9d9d34c83 100644 (file)
@@ -131,11 +131,11 @@ TEST_F(RRTTLTest, fromTextUnit) {
     EXPECT_THROW(RRTTL("9223372036854775807S9223372036854775807S2S"),
                  InvalidRRTTL);
     // Second part out of range, but it immediately wraps (2S+2^64-2S)
-    EXPECT_THROW(RRTTL("2S18446744073709551614S"),
-                 InvalidRRTTL);
+    EXPECT_THROW(RRTTL("2S18446744073709551614S"), InvalidRRTTL);
     // The whole thing wraps right away (2^64S)
-    EXPECT_THROW(RRTTL("18446744073709551616S"),
-                 InvalidRRTTL);
+    EXPECT_THROW(RRTTL("18446744073709551616S"), InvalidRRTTL);
+    // Second part out of range, and will become negative with the unit,
+    EXPECT_THROW(RRTTL("256S307445734561825856M"), InvalidRRTTL);
 
     // Missing before unit.
     EXPECT_THROW(RRTTL("W5H"), InvalidRRTTL);