From 1c56a76bb6f04f039f39fb5299ed99eadb24584c Mon Sep 17 00:00:00 2001 From: Dan Cashman <dcashman@google.com> Date: Thu, 3 Aug 2017 07:21:17 -0700 Subject: [PATCH] treble sepolicy tests: Add removed attribute check. Make sure that any attributes removed from policy are declared in the mapping file, in case they are relied upon by vendor policy. Bug: 36899958 Test: Builds successfull, but not with removed attribute not in mapping file. Change-Id: I25526cd88a50e90513ae298ccf4f2660e4627fb4 --- tests/policy.py | 4 ++-- tests/sepol_wrap.cpp | 10 ++++++---- tests/treble_sepolicy_tests.py | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/policy.py b/tests/policy.py index 15a537ec3..b8a362129 100644 --- a/tests/policy.py +++ b/tests/policy.py @@ -124,8 +124,8 @@ class Policy: yield Rule - def GetAllTypes(self): - TypeIterP = self.__libsepolwrap.init_type_iter(self.__policydbP, None, False) + def GetAllTypes(self, isAttr): + TypeIterP = self.__libsepolwrap.init_type_iter(self.__policydbP, None, isAttr) if (TypeIterP == None): sys.exit("Failed to initialize type iterator") buf = create_string_buffer(self.__BUFSIZE) diff --git a/tests/sepol_wrap.cpp b/tests/sepol_wrap.cpp index cd5336795..8fea2d5b4 100644 --- a/tests/sepol_wrap.cpp +++ b/tests/sepol_wrap.cpp @@ -98,13 +98,15 @@ int get_type(char *out, size_t max_size, void *policydbp, void *type_iterp) break; } } - if (i->bit >= i->length) - return 1; - while ((i->alltypes == TYPE_ITER_ALLATTRS + while (i->bit < i->length && + ((i->alltypes == TYPE_ITER_ALLATTRS && db->type_val_to_struct[i->bit]->flavor != TYPE_ATTRIB) || (i->alltypes == TYPE_ITER_ALLTYPES - && db->type_val_to_struct[i->bit]->flavor != TYPE_TYPE)) + && db->type_val_to_struct[i->bit]->flavor != TYPE_TYPE))) { i->bit++; + } + if (i->bit >= i->length) + return 1; len = snprintf(out, max_size, "%s", db->p_type_val_to_name[i->bit]); if (len >= max_size) { std::cerr << "type name exceeds buffer size." << std::endl; diff --git a/tests/treble_sepolicy_tests.py b/tests/treble_sepolicy_tests.py index c48066d1b..58fd85bc3 100644 --- a/tests/treble_sepolicy_tests.py +++ b/tests/treble_sepolicy_tests.py @@ -155,8 +155,8 @@ def GetAttributes(pol): def GetAllTypes(pol, oldpol): global alltypes global oldalltypes - alltypes = pol.GetAllTypes() - oldalltypes = oldpol.GetAllTypes() + alltypes = pol.GetAllTypes(False) + oldalltypes = oldpol.GetAllTypes(False) def setup(pol): GetAllDomains(pol) -- GitLab