]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
More correctly implement ends with label sequence check
authorMark Andrews <marka@isc.org>
Mon, 16 Aug 2021 04:15:17 +0000 (14:15 +1000)
committerMark Andrews <marka@isc.org>
Mon, 16 Aug 2021 04:15:17 +0000 (14:15 +1000)
string.endswith("label.sequence") doesn't check for the implict
period before "label.sequence" when matching longer strings.

"foo.label.sequence" should match but "foolabel.sequence shouldn't".

bin/tests/system/qmin/ans2/ans.py
bin/tests/system/qmin/ans3/ans.py
bin/tests/system/qmin/ans4/ans.py

index f607112c20effb66adf1bc4c145b7621239a9230..1430401235df7f8e382e40525577f4df42284376 100755 (executable)
@@ -31,6 +31,9 @@ def logquery(type, qname):
     with open("qlog", "a") as f:
         f.write("%s %s\n", type, qname)
 
+def endswith(domain, labels):
+    return domain.endswith("." + labels) or domain == labels
+
 ############################################################################
 # Respond to a DNS query.
 # For good. it serves:
@@ -81,9 +84,9 @@ def create_response(msg):
     r = dns.message.make_response(m)
     r.set_rcode(NOERROR)
 
-    if lqname.endswith("1.0.0.2.ip6.arpa."):
+    if endswith(lqname, "1.0.0.2.ip6.arpa."):
         # Direct query - give direct answer
-        if lqname.endswith("8.2.6.0.1.0.0.2.ip6.arpa."):
+        if endswith(lqname, "8.2.6.0.1.0.0.2.ip6.arpa."):
             # Delegate to ns3
             r.authority.append(dns.rrset.from_text("8.2.6.0.1.0.0.2.ip6.arpa.", 60, IN, NS, "ns3.good."))
             r.additional.append(dns.rrset.from_text("ns3.good.", 60, IN, A, "10.53.0.3"))
@@ -95,7 +98,7 @@ def create_response(msg):
             # NS query at the apex
             r.answer.append(dns.rrset.from_text("1.0.0.2.ip6.arpa.", 30, IN, NS, "ns2.good."))
             r.flags |= dns.flags.AA
-        elif "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.f.4.0.1.0.0.2.ip6.arpa.".endswith(lqname):
+        elif endswith("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.f.4.0.1.0.0.2.ip6.arpa.", lqname):
             # NODATA answer
             r.authority.append(dns.rrset.from_text("1.0.0.2.ip6.arpa.", 30, IN, SOA, "ns2.good. hostmaster.arpa. 2018050100 1 1 1 1"))
         else:
@@ -103,12 +106,12 @@ def create_response(msg):
             r.authority.append(dns.rrset.from_text("1.0.0.2.ip6.arpa.", 30, IN, SOA, "ns2.good. hostmaster.arpa. 2018050100 1 1 1 1"))
             r.set_rcode(NXDOMAIN)
         return r
-    elif lqname.endswith("ip6.arpa."):
+    elif endswith(lqname, "ip6.arpa."):
         if lqname == "ip6.arpa." and rrtype == NS:
             # NS query at the apex
             r.answer.append(dns.rrset.from_text("ip6.arpa.", 30, IN, NS, "ns2.good."))
             r.flags |= dns.flags.AA
-        elif "1.0.0.2.ip6.arpa.".endswith(lqname):
+        elif endswith("1.0.0.2.ip6.arpa.", lqname):
             # NODATA answer
             r.authority.append(dns.rrset.from_text("ip6.arpa.", 30, IN, SOA, "ns2.good. hostmaster.arpa. 2018050100 1 1 1 1"))
         else:
@@ -116,12 +119,12 @@ def create_response(msg):
             r.authority.append(dns.rrset.from_text("ip6.arpa.", 30, IN, SOA, "ns2.good. hostmaster.arpa. 2018050100 1 1 1 1"))
             r.set_rcode(NXDOMAIN)
         return r
-    elif lqname.endswith("stale."):
-        if lqname.endswith("a.b.stale."):
+    elif endswith(lqname, "stale."):
+        if endswith(lqname, "a.b.stale."):
             # Delegate to ns.a.b.stale.
             r.authority.append(dns.rrset.from_text("a.b.stale.", 2, IN, NS, "ns.a.b.stale."))
             r.additional.append(dns.rrset.from_text("ns.a.b.stale.", 2, IN, A, "10.53.0.3"))
-        elif lqname.endswith("b.stale."):
+        elif endswith(lqname, "b.stale."):
             # Delegate to ns.b.stale.
             r.authority.append(dns.rrset.from_text("b.stale.", 2, IN, NS, "ns.b.stale."))
             r.additional.append(dns.rrset.from_text("ns.b.stale.", 2, IN, A, "10.53.0.4"))
@@ -141,22 +144,22 @@ def create_response(msg):
             r.authority.append(dns.rrset.from_text("stale.", 2, IN, SOA, "ns2.stale. hostmaster.arpa. 1 2 3 4 5"))
             r.set_rcode(NXDOMAIN)
         return r
-    elif lqname.endswith("bad."):
+    elif endswith(lqname, "bad."):
         bad = True
         suffix = "bad."
         lqname = lqname[:-4]
-    elif lqname.endswith("ugly."):
+    elif endswith(lqname, "ugly."):
         ugly = True
         suffix = "ugly."
         lqname = lqname[:-5]
-    elif lqname.endswith("good."):
+    elif endswith(lqname, "good."):
         suffix = "good."
         lqname = lqname[:-5]
-    elif lqname.endswith("slow."):
+    elif endswith(lqname, "slow."):
         slow = True
         suffix = "slow."
         lqname = lqname[:-5]
-    elif lqname.endswith("fwd."):
+    elif endswith(lqname, "fwd."):
         suffix = "fwd."
         lqname = lqname[:-4]
     else:
@@ -164,7 +167,7 @@ def create_response(msg):
         return r
 
     # Good/bad/ugly differs only in how we treat non-empty terminals
-    if lqname.endswith("zoop.boing."):
+    if endswith(lqname, "zoop.boing."):
         r.authority.append(dns.rrset.from_text("zoop.boing." + suffix, 1, IN, NS, "ns3." + suffix))
     elif lqname == "many.labels.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z." and rrtype == A:
         r.answer.append(dns.rrset.from_text(lqname + suffix, 1, IN, A, "192.0.2.2"))
@@ -199,9 +202,9 @@ def create_response(msg):
     else:
         r.authority.append(dns.rrset.from_text(suffix, 1, IN, SOA, "ns2." + suffix + " hostmaster.arpa. 2018050100 1 1 1 1"))
         if bad or not \
-            ("icky.icky.icky.ptang.zoop.boing.".endswith(lqname) or \
-             "many.labels.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.".endswith(lqname) or \
-             "a.bit.longer.ns.name.".endswith(lqname)):
+            (endswith("icky.icky.icky.ptang.zoop.boing.", lqname) or \
+             endswith("many.labels.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.", lqname) or \
+             endswith("a.bit.longer.ns.name.", lqname)):
             r.set_rcode(NXDOMAIN)
         if ugly:
             r.set_rcode(FORMERR)
index e5eb12ac0de7ee9ae319a651a5df1754a91ae98e..6d583904a94a625be7e992328316edd726fe0110 100755 (executable)
@@ -31,6 +31,9 @@ def logquery(type, qname):
     with open("qlog", "a") as f:
         f.write("%s %s\n", type, qname)
 
+def endswith(domain, labels):
+    return domain.endswith("." + labels) or domain == labels
+
 ############################################################################
 # Respond to a DNS query.
 # For good. it serves:
@@ -72,24 +75,24 @@ def create_response(msg):
 
     ip6req = False
 
-    if lqname.endswith("bad."):
+    if endswith(lqname, "bad."):
         bad = True
         suffix = "bad."
         lqname = lqname[:-4]
-    elif lqname.endswith("ugly."):
+    elif endswith(lqname, "ugly."):
         ugly = True
         suffix = "ugly."
         lqname = lqname[:-5]
-    elif lqname.endswith("good."):
+    elif endswith(lqname, "good."):
         suffix = "good."
         lqname = lqname[:-5]
-    elif lqname.endswith("slow."):
+    elif endswith(lqname, "slow."):
         slow = True
         suffix = "slow."
         lqname = lqname[:-5]
-    elif lqname.endswith("8.2.6.0.1.0.0.2.ip6.arpa."):
+    elif endswith(lqname, "8.2.6.0.1.0.0.2.ip6.arpa."):
         ip6req = True
-    elif lqname.endswith("a.b.stale."):
+    elif endswith(lqname, "a.b.stale."):
         if lqname == "a.b.stale.":
             if rrtype == TXT:
                 # Direct query.
@@ -120,15 +123,15 @@ def create_response(msg):
     if lqname == "zoop.boing." and rrtype == NS:
         r.answer.append(dns.rrset.from_text(lqname + suffix, 1, IN, NS, "ns3."+suffix))
         r.flags |= dns.flags.AA
-    elif lqname.endswith("icky.ptang.zoop.boing."):
+    elif endswith(lqname, "icky.ptang.zoop.boing."):
         r.authority.append(dns.rrset.from_text("icky.ptang.zoop.boing." + suffix, 1, IN, NS, "a.bit.longer.ns.name." + suffix))
-    elif "icky.ptang.zoop.boing.".endswith(lqname):
+    elif endswith("icky.ptang.zoop.boing.", lqname):
         r.authority.append(dns.rrset.from_text("zoop.boing." + suffix, 1, IN, SOA, "ns3." + suffix + " hostmaster.arpa. 2018050100 1 1 1 1"))
         if bad:
             r.set_rcode(NXDOMAIN)
         if ugly:
             r.set_rcode(FORMERR)
-    elif lqname.endswith("zoop.boing."):
+    elif endswith(lqname, "zoop.boing."):
         r.authority.append(dns.rrset.from_text("zoop.boing." + suffix, 1, IN, SOA, "ns3." + suffix + " hostmaster.arpa. 2018050100 1 1 1 1"))
         r.set_rcode(NXDOMAIN)
     elif ip6req:
index a26483bddf1ed71ee2a15c9f85731b0d1ec1778c..110c09679de39f6216f1ae803ad86c920816f4f1 100755 (executable)
@@ -31,6 +31,9 @@ def logquery(type, qname):
     with open("qlog", "a") as f:
         f.write("%s %s\n", type, qname)
 
+def endswith(domain, labels):
+    return domain.endswith("." + labels) or domain == labels
+
 ############################################################################
 # Respond to a DNS query.
 # For good. it serves:
@@ -73,24 +76,24 @@ def create_response(msg):
 
     ip6req = False
 
-    if lqname.endswith("bad."):
+    if endswith(lqname, "bad."):
         bad = True
         suffix = "bad."
         lqname = lqname[:-4]
-    elif lqname.endswith("ugly."):
+    elif endswith(lqname, "ugly."):
         ugly = True
         suffix = "ugly."
         lqname = lqname[:-5]
-    elif lqname.endswith("good."):
+    elif endswith(lqname, "good."):
         suffix = "good."
         lqname = lqname[:-5]
-    elif lqname.endswith("slow."):
+    elif endswith(lqname, "slow."):
         slow = True
         suffix = "slow."
         lqname = lqname[:-5]
-    elif lqname.endswith("1.1.1.1.8.2.6.0.1.0.0.2.ip6.arpa."):
+    elif endswith(lqname, "1.1.1.1.8.2.6.0.1.0.0.2.ip6.arpa."):
         ip6req = True
-    elif lqname.endswith("b.stale."):
+    elif endswith(lqname, "b.stale."):
         if lqname == "a.b.stale.":
             if rrtype == TXT:
                 # Direct query.
@@ -140,9 +143,9 @@ def create_response(msg):
     elif lqname == "icky.ptang.zoop.boing." and rrtype == NS:
         r.answer.append(dns.rrset.from_text(lqname + suffix, 1, IN, NS, "a.bit.longer.ns.name."+suffix))
         r.flags |= dns.flags.AA
-    elif lqname.endswith("icky.ptang.zoop.boing."):
+    elif endswith(lqname, "icky.ptang.zoop.boing."):
         r.authority.append(dns.rrset.from_text("icky.ptang.zoop.boing." + suffix, 1, IN, SOA, "ns2." + suffix + " hostmaster.arpa. 2018050100 1 1 1 1"))
-        if bad or not "more.icky.icky.icky.ptang.zoop.boing.".endswith(lqname):
+        if bad or not endswith("more.icky.icky.icky.ptang.zoop.boing.", lqname):
             r.set_rcode(NXDOMAIN)
         if ugly:
             r.set_rcode(FORMERR)
@@ -150,7 +153,7 @@ def create_response(msg):
         r.flags |= dns.flags.AA
         if lqname == "test1.test2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.9.0.9.4.1.1.1.1.8.2.6.0.1.0.0.2.ip6.arpa." and rrtype == TXT:
             r.answer.append(dns.rrset.from_text("test1.test2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.9.0.9.4.1.1.1.1.8.2.6.0.1.0.0.2.ip6.arpa.", 1, IN, TXT, "long_ip6_name"))
-        elif "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.9.0.9.4.1.1.1.1.8.2.6.0.1.0.0.2.ip6.arpa.".endswith(lqname):
+        elif endswith("0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.9.0.9.4.1.1.1.1.8.2.6.0.1.0.0.2.ip6.arpa.", lqname):
             #NODATA answer
             r.authority.append(dns.rrset.from_text("1.1.1.1.8.2.6.0.1.0.0.2.ip6.arpa.", 60, IN, SOA, "ns4.good. hostmaster.arpa. 2018050100 120 30 320 16"))
         else: