From: Alexander Popov Date: Sat, 9 Mar 2024 17:27:08 +0000 (+0300) Subject: Parse all numbers of the kernel version X-Git-Tag: v0.6.10~105 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;ds=inline;h=ede0155bc3a99e1fa5ea7405b91f6cda5b28b5e7;p=kconfig-hardened-check.git Parse all numbers of the kernel version Refers to #88, #89, #97 --- diff --git a/kernel_hardening_checker/__init__.py b/kernel_hardening_checker/__init__.py index 4855a59..4841005 100644 --- a/kernel_hardening_checker/__init__.py +++ b/kernel_hardening_checker/__init__.py @@ -55,10 +55,11 @@ def detect_kernel_version(fname): parts = line.split() ver_str = parts[2].split('-', 1)[0] ver_numbers = ver_str.split('.') - if len(ver_numbers) < 3 or not ver_numbers[0].isdigit() or not ver_numbers[1].isdigit(): - msg = f'failed to parse the version "{ver_str}"' - return None, msg - return (int(ver_numbers[0]), int(ver_numbers[1])), None + if len(ver_numbers) >= 3: + if all(map(lambda x: x.isdigit(), ver_numbers)): + return tuple(map(int, ver_numbers)), None + msg = f'failed to parse the version "{parts[2]}"' + return None, msg return None, 'no kernel version detected' @@ -285,7 +286,7 @@ def main(): print('[!] Hint: provide the kernel version file through --kernel-version option') sys.exit(f'[!] ERROR: {msg}') if mode != 'json': - print(f'[+] Detected kernel version: {kernel_version[0]}.{kernel_version[1]}') + print(f'[+] Detected kernel version: {kernel_version}') compiler, msg = detect_compiler(args.config) if mode != 'json':