sysctl parsing: Allow comments (they usually exist in sysctl.conf)
authorAlexander Popov <alex.popov@linux.com>
Wed, 4 Sep 2024 13:21:31 +0000 (16:21 +0300)
committerAlexander Popov <alex.popov@linux.com>
Wed, 4 Sep 2024 13:21:31 +0000 (16:21 +0300)
kernel_hardening_checker/__init__.py

index e0f1c97a94e79767b4f840ec18772484132dc5a4..4fe2ef29cfbd4ebd3b443db01974a363a88ff64f 100755 (executable)
@@ -209,6 +209,8 @@ def parse_sysctl_file(mode: StrOrNone, parsed_options: Dict[str, str], fname: st
         sysctl_pattern = re.compile(r"[a-zA-Z0-9/\._-]+ ?=.*$")
         for line in f.readlines():
             line = line.strip()
+            if line.startswith('#'):
+                continue
             if not sysctl_pattern.match(line):
                 sys.exit(f'[!] ERROR: unexpected line in sysctl file: "{line}"')
             option, value = line.split('=', 1)