]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
TTLs are now bounds checked to be within the closed interval [0, 2^31 - 1]
authorBob Halley <halley@dnspython.org>
Tue, 10 Jan 2006 23:05:26 +0000 (23:05 +0000)
committerBob Halley <halley@dnspython.org>
Tue, 10 Jan 2006 23:05:26 +0000 (23:05 +0000)
ChangeLog
dns/ttl.py

index 522f29ddd719a584d55d5af5eb2ffaa4cf744621..7ad275805657cde72acbc2b279eed678b73260d5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-01-11  Bob Halley  <halley@dnspython.org>
+
+       * dns/ttl.py: TTLs are now bounds checked to be within the closed
+         interval [0, 2^31 - 1].
+
 2006-01-04  Bob Halley  <halley@dnspython.org>
 
        * dns/resolver.py: The windows registry irritatingly changes the
index 9de851b91cc8cd5a45d2ec47433c8e1f593208a5..0da79616d63266d12fc697a4e309f23a6e6ce889 100644 (file)
@@ -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