From: Michal 'vorner' Vaner Date: Sat, 10 Nov 2012 10:28:53 +0000 (+0100) Subject: [2384] Little bit more range checking X-Git-Tag: trac2487_base~1^2~29^2~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d514f5b0ec7b9eff71c067604bb41ad5c850221;p=thirdparty%2Fkea.git [2384] Little bit more range checking There was a gap when one thing could overflow to negative numbers. --- diff --git a/src/lib/dns/rrttl.cc b/src/lib/dns/rrttl.cc index 5f7dae509c..620cf7c1e6 100644 --- a/src/lib/dns/rrttl.cc +++ b/src/lib/dns/rrttl.cc @@ -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); } diff --git a/src/lib/dns/tests/rrttl_unittest.cc b/src/lib/dns/tests/rrttl_unittest.cc index 61e7849b0d..754dd6c8b8 100644 --- a/src/lib/dns/tests/rrttl_unittest.cc +++ b/src/lib/dns/tests/rrttl_unittest.cc @@ -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);