From: Bob Halley Date: Tue, 21 Jul 2020 17:40:51 +0000 (-0700) Subject: set min ttl to max_ttl instead of special case -1 X-Git-Tag: v2.1.0rc1~162^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49d81afcc17f5d44c571a9e8724e83b009fe898b;p=thirdparty%2Fdnspython.git set min ttl to max_ttl instead of special case -1 --- diff --git a/dns/message.py b/dns/message.py index 87484f51..fd9ddb50 100644 --- a/dns/message.py +++ b/dns/message.py @@ -35,6 +35,7 @@ import dns.rdataclass import dns.rdatatype import dns.rrset import dns.renderer +import dns.ttl import dns.tsig import dns.rdtypes.ANY.OPT import dns.rdtypes.ANY.TSIG @@ -735,14 +736,14 @@ class QueryMessage(Message): raise dns.exception.FormError question = self.question[0] qname = question.name - min_ttl = -1 + min_ttl = dns.ttl.MAX_TTL rrset = None count = 0 while count < MAX_CHAIN: try: rrset = self.find_rrset(self.answer, qname, question.rdclass, question.rdtype) - if min_ttl == -1 or rrset.ttl < min_ttl: + if rrset.ttl < min_ttl: min_ttl = rrset.ttl break except KeyError: @@ -751,7 +752,7 @@ class QueryMessage(Message): crrset = self.find_rrset(self.answer, qname, question.rdclass, dns.rdatatype.CNAME) - if min_ttl == -1 or crrset.ttl < min_ttl: + if crrset.ttl < min_ttl: min_ttl = crrset.ttl for rd in crrset: qname = rd.target @@ -775,7 +776,7 @@ class QueryMessage(Message): srrset = self.find_rrset(self.authority, auname, question.rdclass, dns.rdatatype.SOA) - if min_ttl == -1 or srrset.ttl < min_ttl: + if srrset.ttl < min_ttl: min_ttl = srrset.ttl if srrset[0].minimum < min_ttl: min_ttl = srrset[0].minimum diff --git a/dns/ttl.py b/dns/ttl.py index 55ae5e16..6c67d385 100644 --- a/dns/ttl.py +++ b/dns/ttl.py @@ -19,6 +19,7 @@ import dns.exception +MAX_TTL = 2147483647 class BadTTL(dns.exception.SyntaxError): """DNS TTL value is not well-formed.""" @@ -64,6 +65,6 @@ def from_text(text): current = 0 if not current == 0: raise BadTTL("trailing integer") - if total < 0 or total > 2147483647: + if total < 0 or total > MAX_TTL: raise BadTTL("TTL should be between 0 and 2^31 - 1 (inclusive)") return total