From 9794436b44ccf76a18e37c3f9ac5c4a38135d016 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sun, 6 Oct 2024 20:29:22 +0300 Subject: [PATCH] Handle empty files properly --- kernel_hardening_checker/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel_hardening_checker/__init__.py b/kernel_hardening_checker/__init__.py index 740356e..13094b2 100755 --- a/kernel_hardening_checker/__init__.py +++ b/kernel_hardening_checker/__init__.py @@ -199,7 +199,7 @@ def parse_cmdline_file(mode: StrOrNone, parsed_options: Dict[str, str], fname: s with open(fname, 'r', encoding='utf-8') as f: line = f.readline() if not line: - sys.exit(f'[!] ERROR: empty "{fname}"') + sys.exit(f'[!] ERROR: empty cmdline file "{fname}"') opts = line.split() @@ -225,6 +225,9 @@ def parse_sysctl_file(mode: StrOrNone, parsed_options: Dict[str, str], fname: st sys.exit(f'[!] ERROR: unable to open {fname}, are you sure it exists?') with open(fname, 'r', encoding='utf-8') as f: + if os.stat(fname).st_size == 0: + sys.exit(f'[!] ERROR: empty sysctl file "{fname}"') + sysctl_pattern = re.compile(r"[a-zA-Z0-9/\._-]+ ?=.*$") for line in f.readlines(): line = line.strip() -- 2.31.1