From d8aa12692026607864113b25b6f19501412d3d94 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Fri, 24 Mar 2023 23:17:39 +0300 Subject: [PATCH] Prevent populating the checklist with empty data --- kconfig_hardened_check/engine.py | 2 ++ kconfig_hardened_check/test_engine.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/kconfig_hardened_check/engine.py b/kconfig_hardened_check/engine.py index 6308740..8a4ccb8 100644 --- a/kconfig_hardened_check/engine.py +++ b/kconfig_hardened_check/engine.py @@ -254,6 +254,8 @@ def populate_simple_opt_with_data(opt, data, data_type): f'invalid opt type "{opt.type}"' assert(data_type in SIMPLE_OPTION_TYPES), \ f'invalid data type "{data_type}"' + assert(data), \ + f'empty data' if data_type != opt.type: return diff --git a/kconfig_hardened_check/test_engine.py b/kconfig_hardened_check/test_engine.py index baabd96..710e99a 100644 --- a/kconfig_hardened_check/test_engine.py +++ b/kconfig_hardened_check/test_engine.py @@ -53,9 +53,12 @@ class TestEngine(unittest.TestCase): parsed_kconfig_options, parsed_cmdline_options, kernel_version, result): # populate the checklist with data - populate_with_data(checklist, parsed_kconfig_options, 'kconfig') - populate_with_data(checklist, parsed_cmdline_options, 'cmdline') - populate_with_data(checklist, kernel_version, 'version') + if parsed_kconfig_options: + populate_with_data(checklist, parsed_kconfig_options, 'kconfig') + if parsed_cmdline_options: + populate_with_data(checklist, parsed_cmdline_options, 'cmdline') + if kernel_version: + populate_with_data(checklist, kernel_version, 'version') # now everything is ready, perform the checks perform_checks(checklist) -- 2.31.1