Check all 3 numbers of the kernel version in VersionCheck
authorAlexander Popov <alex.popov@linux.com>
Sat, 9 Mar 2024 20:46:51 +0000 (23:46 +0300)
committerAlexander Popov <alex.popov@linux.com>
Sat, 9 Mar 2024 21:52:00 +0000 (00:52 +0300)
Refers to #88, #89, #97

kernel_hardening_checker/engine.py

index 960f4f44c7278db7a2ee7ffe9e3e045fcb5bf7fc..844e9f07c243b52e1c0c1ec16632750bd781420b 100644 (file)
@@ -151,18 +151,26 @@ class VersionCheck:
 
     def check(self):
         if self.ver[0] > self.ver_expected[0]:
-            self.result = f'OK: version >= {self.ver_expected[0]}.{self.ver_expected[1]}'
+            self.result = f'OK: version >= {self.ver_expected}'
             return
         if self.ver[0] < self.ver_expected[0]:
-            self.result = f'FAIL: version < {self.ver_expected[0]}.{self.ver_expected[1]}'
+            self.result = f'FAIL: version < {self.ver_expected}'
             return
-        if self.ver[1] >= self.ver_expected[1]:
-            self.result = f'OK: version >= {self.ver_expected[0]}.{self.ver_expected[1]}'
+        # self.ver[0] and self.ver_expected[0] are equal
+        if self.ver[1] > self.ver_expected[1]:
+            self.result = f'OK: version >= {self.ver_expected}'
             return
-        self.result = f'FAIL: version < {self.ver_expected[0]}.{self.ver_expected[1]}'
+        if self.ver[1] < self.ver_expected[1]:
+            self.result = f'FAIL: version < {self.ver_expected}'
+            return
+        # self.ver[1] and self.ver_expected[1] are equal too
+        if self.ver[2] >= self.ver_expected[2]:
+            self.result = f'OK: version >= {self.ver_expected}'
+            return
+        self.result = f'FAIL: version < {self.ver_expected}'
 
     def table_print(self, _mode, with_results):
-        ver_req = f'kernel version >= {self.ver_expected[0]}.{self.ver_expected[1]}'
+        ver_req = f'kernel version >= {self.ver_expected}'
         print(f'{ver_req:<91}', end='')
         if with_results:
             print(f'| {colorize_result(self.result)}', end='')