Commit 4d514f5b authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2384] Little bit more range checking

There was a gap when one thing could overflow to negative numbers.
parent 09e72e68
......@@ -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);
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment