From a1dafa428d45b71da23c65238013c7d0bca3863a Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sat, 6 Jul 2024 23:55:09 +0300 Subject: [PATCH] Allow the empty values for Kconfig options This prevents breaking on handling the strange Broadcom configs. Refers to #143. --- kernel_hardening_checker/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel_hardening_checker/__init__.py b/kernel_hardening_checker/__init__.py index 487eff4..6f551e5 100755 --- a/kernel_hardening_checker/__init__.py +++ b/kernel_hardening_checker/__init__.py @@ -142,7 +142,7 @@ def print_checklist(mode: StrOrNone, checklist: List[ChecklistObjType], with_res def parse_kconfig_file(_mode: StrOrNone, parsed_options: Dict[str, str], fname: str) -> None: with _open(fname) as f: - opt_is_on = re.compile(r"CONFIG_[a-zA-Z0-9_]+=.+$") + opt_is_on = re.compile(r"CONFIG_[a-zA-Z0-9_]+=.*$") opt_is_off = re.compile(r"# CONFIG_[a-zA-Z0-9_]+ is not set$") for line in f.readlines(): @@ -154,6 +154,8 @@ def parse_kconfig_file(_mode: StrOrNone, parsed_options: Dict[str, str], fname: option, value = line.split('=', 1) if value == 'is not set': sys.exit(f'[!] ERROR: bad enabled Kconfig option "{line}"') + if value == '': + print(f'[!] WARNING: found strange Kconfig option {option} with empty value') elif opt_is_off.match(line): option, value = line[2:].split(' ', 1) assert(value == 'is not set'), \ @@ -165,7 +167,7 @@ def parse_kconfig_file(_mode: StrOrNone, parsed_options: Dict[str, str], fname: sys.exit(f'[!] ERROR: Kconfig option "{line}" is found multiple times') if option: - assert(value), f'unexpected empty value for {option}' + assert(value is not None), f'unexpected None value for {option}' parsed_options[option] = value -- 2.31.1