SIDN / CycleHunter

Python software that reads zone files, extract NS records, and detect cyclic dependencies
https://tsuname.io
BSD 2-Clause "Simplified" License
37 stars 14 forks source link

Crashes when a name server is named ns #25

Open bortzmeyer opened 3 years ago

bortzmeyer commented 3 years ago
DEBUG: line ns  86400   IN  AAAA    2001:1291:200:84ba::1

Traceback (most recent call last):
  File "CycleHunter.py", line 41, in <module>
    zone_parser(zonefile=args.zonefile, zonename=args.origin, output_file=output1)
  File "/home/bortzmeyer/tmp/CycleHunter/largeZoneParser.py", line 45, in zone_parser
    nsset = get_ns_set(zonefile=zonefile, extension=zonename)
  File "/home/bortzmeyer/tmp/CycleHunter/largeZoneParser.py", line 38, in get_ns_set
    ns_entry = parseNS(line, extension)
  File "/home/bortzmeyer/tmp/CycleHunter/largeZoneParser.py", line 22, in parseNS
    if ns_entry[-1] != ".":
IndexError: string index out of range

(DEBUG was added by me to see the offending line)

This is apparently because the parser mistakes the name of the name server for a type NS.

This patch allows to continue:

diff --git a/largeZoneParser.py b/largeZoneParser.py
index 3584218..08b8ed4 100644
--- a/largeZoneParser.py
+++ b/largeZoneParser.py
@@ -10,8 +10,9 @@ def parseNS(s, extension=None):
     if s[0] != ";":
         sp = re.split('[\s]+', s.lower())
         foundNS = False
+        firstItem = True
         for item in sp:
-            if item == 'ns' and foundNS is False and 'rrsig' not in s.lower() and 'nsec' not in s.lower():
+            if item == 'ns' and not firstItem and foundNS is False and 'rrsig' not in s.lower() and 'nsec' not in s.lower():
                 ns_entry = sp[-1].rstrip()
                 if len(ns_entry) == 0:
                     # test if the one before the last has NS
@@ -21,7 +22,7 @@ def parseNS(s, extension=None):
                 if ns_entry[-1] != ".":
                     ns_entry = ns_entry + extension
                     foundNS = True
-
+            firstItem = False
     return ns_entry