diff --git a/utils/apparmor/aa.py b/utils/apparmor/aa.py index 6c0b32522..372c5e2a2 100644 --- a/utils/apparmor/aa.py +++ b/utils/apparmor/aa.py @@ -480,7 +480,7 @@ def create_new_profile(localfile, is_stub=False): for hatglob in cfg['required_hats'].keys(): if re.search(hatglob, localfile): for hat in sorted(cfg['required_hats'][hatglob].split()): - full_hat = combine_profname([localfile, hat]) + full_hat = combine_profname((localfile, hat)) if not local_profile.get(full_hat, False): local_profile[full_hat] = ProfileStorage('NEW', hat, 'create_new_profile() required_hats') local_profile[full_hat]['is_hat'] = True @@ -1855,7 +1855,7 @@ def parse_profile_data(data, file, do_include, in_preamble): if do_include: profile = file hat = None - profname = combine_profname([profile, hat]) + profname = combine_profname((profile, hat)) profile_data[profname] = ProfileStorage(profile, hat, 'parse_profile_data() do_include') profile_data[profname]['filename'] = file @@ -1899,7 +1899,7 @@ def parse_profile_data(data, file, do_include, in_preamble): if profile == hat: hat = None - profname = combine_profname([profile, hat]) + profname = combine_profname((profile, hat)) if profile_data.get(profname, False): raise AppArmorException( @@ -1924,7 +1924,7 @@ def parse_profile_data(data, file, do_include, in_preamble): if in_contained_hat: hat = None in_contained_hat = False - profname = combine_profname([profile, hat]) + profname = combine_profname((profile, hat)) else: parsed_profiles.append(profile) profile = None @@ -2065,7 +2065,7 @@ def parse_profile_data(data, file, do_include, in_preamble): for parsed_prof in sorted(parsed_profiles): if re.search(hatglob, parsed_prof): for hat in cfg['required_hats'][hatglob].split(): - profname = combine_profname([parsed_prof, hat]) + profname = combine_profname((parsed_prof, hat)) if not profile_data.get(profname, False): profile_data[profname] = ProfileStorage(parsed_prof, hat, 'parse_profile_data() required_hats') profile_data[profname]['is_hat'] = True @@ -2140,7 +2140,7 @@ def split_to_merged(profile_data): if profile == hat: merged_name = profile else: - merged_name = combine_profname([profile, hat]) + merged_name = combine_profname((profile, hat)) merged[merged_name] = profile_data[profile][hat] diff --git a/utils/apparmor/common.py b/utils/apparmor/common.py index fac1901a0..3f35b71ad 100644 --- a/utils/apparmor/common.py +++ b/utils/apparmor/common.py @@ -277,12 +277,12 @@ def split_name(full_profile): def combine_profname(name_parts): """combine name_parts (main profile, child) into a joint main//child profile name""" - if not isinstance(name_parts, list): - raise AppArmorBug('combine_name() called with parameter of type %s, must be a list' % type(name_parts)) + if not isinstance(name_parts, (list, tuple)): + raise AppArmorBug('combine_profname() called with parameter of type %s, must be a list or tuple' % type(name_parts)) # if last item is None, drop it (can happen when called with [profile, hat] when hat is None) - if name_parts[len(name_parts)-1] is None: - name_parts.pop(-1) + if name_parts[-1] is None: + name_parts = name_parts[:-1] return '//'.join(name_parts) diff --git a/utils/test/test-common.py b/utils/test/test-common.py index 7f885da18..99706fa25 100644 --- a/utils/test/test-common.py +++ b/utils/test/test-common.py @@ -30,11 +30,11 @@ class AaTest_split_name(AATest): class AaTest_combine_profname(AATest): tests = ( # name parts expected full profile name - (['foo'], 'foo'), - (['foo', 'bar'], 'foo//bar'), - (['foo', 'bar', 'baz'], 'foo//bar//baz'), - (['foo', 'bar', None], 'foo//bar'), - (['foo', 'bar', 'baz', None], 'foo//bar//baz'), + (('foo',), 'foo'), + (('foo', 'bar'), 'foo//bar'), + (('foo', 'bar', 'baz'), 'foo//bar//baz'), + (('foo', 'bar', None), 'foo//bar'), + (('foo', 'bar', 'baz', None), 'foo//bar//baz'), ) def _run_test(self, params, expected):