Improve print_unknown_options()
authorAlexander Popov <alex.popov@linux.com>
Mon, 14 Feb 2022 14:47:21 +0000 (17:47 +0300)
committerAlexander Popov <alex.popov@linux.com>
Mon, 14 Feb 2022 22:02:47 +0000 (01:02 +0300)
Don't miss options behind the second level of ComplexOptCheck

kconfig_hardened_check/__init__.py

index 32b3198e065eebf6da0e245b36ac93ac47ce28a3..12edc9f9d3c06e617261ef4537f2edd95d0ebd54 100644 (file)
@@ -614,16 +614,25 @@ def add_kconfig_checks(l, arch):
 
 def print_unknown_options(checklist, parsed_options):
     known_options = []
-    for opt in checklist:
-        if hasattr(opt, 'opts'):
-            for o in opt.opts:
-                if hasattr(o, 'name'):
-                    known_options.append(o.name)
-        else:
-            known_options.append(opt.name)
+
+    for o1 in checklist:
+        if not hasattr(o1, 'opts'):
+            known_options.append(o1.name)
+            continue
+        for o2 in o1.opts:
+            if not hasattr(o2, 'opts'):
+                if hasattr(o2, 'name'):
+                    known_options.append(o2.name)
+                continue
+            for o3 in o2.opts:
+                if hasattr(o3, 'opts'):
+                    sys.exit('[!] ERROR: unexpected ComplexOptCheck inside {}'.format(o2.name))
+                if hasattr(o3, 'name'):
+                    known_options.append(o3.name)
+
     for option, value in parsed_options.items():
         if option not in known_options:
-            print('[?] No rule for option {} ({})'.format(option, value))
+            print('[?] No check for option {} ({})'.format(option, value))
 
 
 def print_checklist(mode, checklist, with_results):