2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-29 13:28:19 +00:00

utils: wrap ValueError in AppArmorBug w/better reporting

This patch converts a ValueError raised when parsing of a permission
mode fails into an AppArmorBug with better diagnostic information, and
adds a test case to confirm that the exception is raised.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
This commit is contained in:
Steve Beattie 2014-11-29 00:15:17 -08:00
parent b1c28c7a23
commit ad17e03b9d
2 changed files with 10 additions and 2 deletions

View File

@ -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):

View File

@ -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):