Skip to content

Parser appears to choke on valid bind 9.11 configuration file (named.conf) #69

@drfu

Description

@drfu

Attempting to parse a valid BIND 9.11 named.conf file can result in a stack trace:

import bind9_parser as bp
named_filepath = "./named.conf"
with open(named_filepath, "r") as named:
    named_data = named.read()
parsed = bp.clause_statements.parseString(named_data, parseAll=True)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\LST\src\named\.venv\Lib\site-packages\pyparsing\util.py", line 417, in _inner
    return fn(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\LST\src\named\.venv\Lib\site-packages\pyparsing\core.py", line 1219, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected end of text, found '/'  (at char 0), (line:1, col:1)

head of named.conf file

head named.conf

//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html

Removing the leading comments then lead to this stack trace:

named_filepath = "./named.hacked.conf"
with open(named_filepath, "r") as named:
    named_data = named.read()
parsed = bp.clause_statements.parseString(named_data, parseAll=True)
pyparsing.exceptions.ParseException: Expected <boolean>, found '-'  (at char 248), (line:8, col:22)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\LST\src\named\.venv\Lib\site-packages\pyparsing\util.py", line 417, in _inner
    return fn(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\LST\src\named\.venv\Lib\site-packages\pyparsing\core.py", line 1219, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseSyntaxException: Expected <boolean>, found '-'  (at char 248), (line:8, col:22)

Offending line is memstatistics-file "/var/named/data/named_mem_stats.txt";

Removing this and attempting parsing again, it results in a stack trace due to the previous issue, when it encounters the forward slash of a block comment /*.

removing all comments and parsing again, I got the following:

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\LST\src\named\.venv\Lib\site-packages\pyparsing\util.py", line 417, in _inner
    return fn(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\LST\src\named\.venv\Lib\site-packages\pyparsing\core.py", line 1219, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseSyntaxException: Expected '}', found 'max'  (at char 519), (line:16, col:9)

here is the relevant line of the named.conf:
max-udp-size 4096;

removing the max-udp-size statement and trying again, I got the following:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\LST\src\named\.venv\Lib\site-packages\pyparsing\util.py", line 417, in _inner
    return fn(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\LST\src\named\.venv\Lib\site-packages\pyparsing\core.py", line 1219, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected end of text, found 'include'  (at char 4521), (line:154, col:1)

again, the relevant section:

zone "." IN {
  150         type hint;
  151         file "named.ca";
  152 };
  153
  154 include "/etc/named.rfc1912.zones";
  155 include "/etc/named.root.key";

I note it would also emit a stack trace when it encountered a comment using #.

Am I misusing this library or are comments unsupported? What about include and max-udp-size?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions