Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes when a name server is named ns #25

Open
bortzmeyer opened this issue May 3, 2021 · 0 comments
Open

Crashes when a name server is named ns #25

bortzmeyer opened this issue May 3, 2021 · 0 comments

Comments

@bortzmeyer
Copy link

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
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant