Skip to content

Commit

Permalink
Fix the issue of going out of bounds in the isccfg parser.
Browse files Browse the repository at this point in the history
This problem can occur when attempting to parse an empty file.
  • Loading branch information
SandakovMM authored and fernflower committed Sep 11, 2023
1 parent 6ae2d5a commit 4d8ad1c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion repos/system_upgrade/el7toel8/libraries/isccfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,12 @@ def find_next_key(self, cfg, index=0, end_index=-1, end_report=False):

while index != -1:
keystart = index
while istr[index] in self.CHAR_KEYWORD and index < end_index:
while index < end_index and istr[index] in self.CHAR_KEYWORD:
index += 1

if index >= end_index:
break

if keystart < index <= end_index and istr[index] not in self.CHAR_KEYWORD:
# key has been found
return ConfigSection(cfg, istr[keystart:index], keystart, index-1)
Expand Down
32 changes: 32 additions & 0 deletions repos/system_upgrade/el7toel8/libraries/tests/test_isccfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
};
""")

config_empty = isccfg.MockConfig('')

config_empty_include = isccfg.MockConfig('options { include "/dev/null"; };')


def check_in_section(parser, section, key, value):
""" Helper to check some section was found
Expand Down Expand Up @@ -343,5 +347,33 @@ def test_walk():
assert 'dnssec-validation' not in state


def test_empty_config():
""" Test empty configuration """

callbacks = {}

parser = isccfg.IscConfigParser(config_empty)
assert len(parser.FILES_TO_CHECK) == 1
cfg = parser.FILES_TO_CHECK[0]
parser.walk(cfg.root_section(), callbacks)
assert cfg.buffer == ''


def test_empty_include_config():
""" Test empty configuration """

callbacks = {}

parser = isccfg.IscConfigParser(config_empty_include)
assert len(parser.FILES_TO_CHECK) == 2
cfg = parser.FILES_TO_CHECK[0]
parser.walk(cfg.root_section(), callbacks)
assert cfg.buffer == 'options { include "/dev/null"; };'

null_cfg = parser.FILES_TO_CHECK[1]
parser.walk(null_cfg.root_section(), callbacks)
assert null_cfg.buffer == ''


if __name__ == '__main__':
test_key_views_lookaside()

0 comments on commit 4d8ad1c

Please sign in to comment.