From 498f2e786d06c38dc4bf0a16f9cf2f1c89603df6 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Tue, 10 Jan 2006 23:05:26 +0000 Subject: [PATCH] TTLs are now bounds checked to be within the closed interval [0, 2^31 - 1] --- ChangeLog | 5 +++++ dns/ttl.py | 53 ++++++++++++++++++++++++++++------------------------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 522f29dd..7ad27580 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-01-11 Bob Halley + + * dns/ttl.py: TTLs are now bounds checked to be within the closed + interval [0, 2^31 - 1]. + 2006-01-04 Bob Halley * dns/resolver.py: The windows registry irritatingly changes the diff --git a/dns/ttl.py b/dns/ttl.py index 9de851b9..0da79616 100644 --- a/dns/ttl.py +++ b/dns/ttl.py @@ -32,30 +32,33 @@ def from_text(text): """ if text.isdigit(): - return int(text) - if not text[0].isdigit(): - raise BadTTL - total = 0 - current = 0 - for c in text: - if c.isdigit(): - current *= 10 - current += int(c) - else: - c = c.lower() - if c == 'w': - total += current * 604800 - elif c == 'd': - total += current * 86400 - elif c == 'h': - total += current * 3600 - elif c == 'm': - total += current * 60 - elif c == 's': - total += current + total = long(text) + else: + if not text[0].isdigit(): + raise BadTTL + total = 0L + current = 0L + for c in text: + if c.isdigit(): + current *= 10 + current += long(c) else: - raise BadTTL, "unknown unit '%s'" % c - current = 0 - if not current == 0: - raise BadTTL, "trailing integer" + c = c.lower() + if c == 'w': + total += current * 604800L + elif c == 'd': + total += current * 86400L + elif c == 'h': + total += current * 3600L + elif c == 'm': + total += current * 60L + elif c == 's': + total += current + else: + raise BadTTL, "unknown unit '%s'" % c + current = 0 + if not current == 0: + raise BadTTL, "trailing integer" + if total < 0L or total > 2147483647L: + raise BadTTL, "TTL should be between 0 and 2^31 - 1 (inclusive)" return total -- 2.47.3