83 lines
2.7 KiB
Diff
83 lines
2.7 KiB
Diff
|
From 4d8ad1c0363fc21f5d8a557f3319a6efacac9f2a Mon Sep 17 00:00:00 2001
|
||
|
From: SandakovMM <G0odvinSun@gmail.com>
|
||
|
Date: Thu, 24 Aug 2023 16:01:39 +0300
|
||
|
Subject: [PATCH 15/38] Fix the issue of going out of bounds in the isccfg
|
||
|
parser.
|
||
|
|
||
|
This problem can occur when attempting to parse an empty file.
|
||
|
---
|
||
|
.../el7toel8/libraries/isccfg.py | 5 ++-
|
||
|
.../el7toel8/libraries/tests/test_isccfg.py | 32 +++++++++++++++++++
|
||
|
2 files changed, 36 insertions(+), 1 deletion(-)
|
||
|
|
||
|
diff --git a/repos/system_upgrade/el7toel8/libraries/isccfg.py b/repos/system_upgrade/el7toel8/libraries/isccfg.py
|
||
|
index 45baba0b..6cebb289 100644
|
||
|
--- a/repos/system_upgrade/el7toel8/libraries/isccfg.py
|
||
|
+++ b/repos/system_upgrade/el7toel8/libraries/isccfg.py
|
||
|
@@ -688,9 +688,12 @@ class IscConfigParser(object):
|
||
|
|
||
|
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)
|
||
|
diff --git a/repos/system_upgrade/el7toel8/libraries/tests/test_isccfg.py b/repos/system_upgrade/el7toel8/libraries/tests/test_isccfg.py
|
||
|
index 7438fa37..00753681 100644
|
||
|
--- a/repos/system_upgrade/el7toel8/libraries/tests/test_isccfg.py
|
||
|
+++ b/repos/system_upgrade/el7toel8/libraries/tests/test_isccfg.py
|
||
|
@@ -116,6 +116,10 @@ view "v2" {
|
||
|
};
|
||
|
""")
|
||
|
|
||
|
+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
|
||
|
@@ -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()
|
||
|
--
|
||
|
2.41.0
|
||
|
|