]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
simplify TTL check when reading a zone file
authorBob Halley <halley@dnspython.org>
Wed, 17 Jun 2020 20:16:38 +0000 (13:16 -0700)
committerBob Halley <halley@dnspython.org>
Wed, 17 Jun 2020 20:16:45 +0000 (13:16 -0700)
dns/zone.py

index 13d121be8b91aedfe44a5d28c4e04eda86f496a8..e8413c0866fae157dfc7eff1ebc372b10e1f75b5 100644 (file)
@@ -772,23 +772,20 @@ class _MasterReader:
             raise dns.exception.SyntaxError(
                 "caught exception {}: {}".format(str(ty), str(va)))
 
-        if not self.default_ttl_known and \
-           isinstance(rd, dns.rdtypes.ANY.SOA.SOA):
+        if not self.default_ttl_known and rdtype == dns.rdatatype.SOA:
             # The pre-RFC2308 and pre-BIND9 behavior inherits the zone default
             # TTL from the SOA minttl if no $TTL statement is present before the
             # SOA is parsed.
             self.default_ttl = rd.minimum
             self.default_ttl_known = True
+            if ttl is None:
+                # if we didn't have a TTL on the SOA, set it!
+                ttl = rd.minimum
 
-        # TTL check
+        # TTL check.  We had to wait until now to do this as the SOA RR's
+        # own TTL can be inferred from its minimum.
         if ttl is None:
-            if not (self.last_ttl_known or self.default_ttl_known):
-                raise dns.exception.SyntaxError("Missing default TTL value")
-            else:
-                if self.default_ttl_known:
-                    ttl = self.default_ttl
-                else:
-                    ttl = self.last_ttl
+            raise dns.exception.SyntaxError("Missing default TTL value")
 
         covers = rd.covers()
         rds = n.find_rdataset(rdclass, rdtype, covers, True)