From: Alexander Popov Date: Sun, 6 Oct 2024 17:29:22 +0000 (+0300) Subject: Handle empty files properly X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=9794436b44ccf76a18e37c3f9ac5c4a38135d016;p=kconfig-hardened-check.git Handle empty files properly --- 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()