Merge "libsepol: cil: Keep type[attribute] declarations when attributizing."

am: 970199321d

Change-Id: I5bcfbd00f4d4ec38718142a98720007d2b0b2632
This commit is contained in:
Dan Cashman 2017-10-15 03:08:47 +00:00 committed by android-build-merger
commit aa604d7ad5
2 changed files with 10 additions and 9 deletions

View File

@ -21,6 +21,8 @@ int cil_android_attrib_mapping(struct cil_db **mdb, struct cil_db *srcdb, const
/*
* cil_android_attributize - extract attributizable elements of the policy in
* srcdb and convert all usage of those elements in tgtdb to versioned attributes.
* Keep the attributes and type definitions so that tgtdb policy is more robust
* against future changes to the public policy.
* tgtdb - initialized and parsed cil_db reference to modify.
* srcdb - initialized and parsed cil_db reference to source public policy
* from which to extract attributizable elements.

View File

@ -200,23 +200,27 @@ static char *__cil_attrib_get_versname(char *old, const char *vers)
/*
* Change type to attribute - create new versioned name based on old, create
* typeattribute node and replace existing type node.
* typeattribute node add to the existing type node.
*/
static int __cil_attrib_convert_type(struct cil_tree_node *node, struct version_args *args)
{
int rc = SEPOL_ERR;
struct cil_type *type = (struct cil_type *)node->data;
struct cil_typeattribute *typeattr = NULL;
struct cil_tree_node *new_ast_node = NULL;
char *new_key;
cil_typeattribute_init(&typeattr);
new_key = __cil_attrib_get_versname(type->datum.name, args->num);
cil_symtab_datum_remove_node(&type->datum, node);
cil_destroy_type(type);
/* create new tree node to contain typeattribute and add to tree */
cil_tree_node_init(&new_ast_node);
new_ast_node->parent = node->parent;
new_ast_node->next = node->next;
node->next = new_ast_node;
rc = cil_gen_node(args->db, node, (struct cil_symtab_datum *) typeattr,
rc = cil_gen_node(args->db, new_ast_node, (struct cil_symtab_datum *) typeattr,
new_key, CIL_SYM_TYPES, CIL_TYPEATTRIBUTE);
if (rc != SEPOL_OK) {
goto exit;
@ -422,11 +426,6 @@ static int cil_attrib_typeattribute(struct cil_tree_node *node, struct version_a
if (rc != SEPOL_OK) {
goto exit;
}
} else if (__cil_get_plat_flavor(args->vers_map, key) == PLAT_ATTRIB) {
// platform attribute declaration to be provided by platform policy
cil_symtab_datum_remove_node(&typeattr->datum, node);
cil_destroy_typeattribute(typeattr);
node->flavor = CIL_NONE; // traversal relies on this node sticking around, empty it.
}
return SEPOL_OK;