Commit d265c83b authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[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.
parent 4e410c83
......@@ -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;
......
......@@ -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);
......
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