diff --git a/utils/apparmor/aamode.py b/utils/apparmor/aamode.py index 4ae6606f0..cb0f61c36 100644 --- a/utils/apparmor/aamode.py +++ b/utils/apparmor/aamode.py @@ -12,6 +12,7 @@ # # ---------------------------------------------------------------------- import re +from apparmor.common import AppArmorBug def AA_OTHER(mode): other = set() @@ -103,11 +104,14 @@ def split_log_mode(mode): other = '' if "::" in mode: - user, other = mode.split("::") + try: + user, other = mode.split("::") + except ValueError as e: + raise AppArmorBug("Got ValueError '%s' when splitting %s" % (str(e), mode)) else: user = mode other = mode - #print ('split_logmode:', user, mode) + return user, other def mode_contains(mode, subset): diff --git a/utils/test/test-aamode.py b/utils/test/test-aamode.py index e876760e7..169be5838 100644 --- a/utils/test/test-aamode.py +++ b/utils/test/test-aamode.py @@ -12,6 +12,7 @@ import unittest from apparmor.aamode import split_log_mode, sub_str_to_mode +from apparmor.common import AppArmorBug class AamodeTest_split_log_mode(unittest.TestCase): def test_split_log_mode_1(self): @@ -26,6 +27,9 @@ class AamodeTest_split_log_mode(unittest.TestCase): self.assertEqual(split_log_mode('r::w'), ('r', 'w')) def test_split_log_mode_6(self): self.assertEqual(split_log_mode('rw::rw'), ('rw', 'rw')) + def test_split_log_mode_invalid_1(self): + with self.assertRaises(AppArmorBug): + split_log_mode('r::w::r') class AamodeTest_sub_str_to_mode(unittest.TestCase): def test_sub_str_to_mode_1(self):