Skip to content

Commit

Permalink
libsepol/cil: Refactor helper function for cil_gen_node()
Browse files Browse the repository at this point in the history
Change the name of cil_is_datum_multiple_decl() to
cil_allow_multiple_decls() and make it static. The new function
takes the CIL db and the flavors of the old and new datum as
arguments. Also, put all of the logic of determining if multiple
declarations are allowed into the new function. Finally, update
the call from cil_gen_node().

Signed-off-by: James Carter <jwcart2@gmail.com>
  • Loading branch information
jwcart2 committed Apr 19, 2021
1 parent 22fb6f4 commit 63ce05b
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions libsepol/cil/src/cil_build_ast.c
Expand Up @@ -82,30 +82,24 @@ int cil_fill_list(struct cil_tree_node *current, enum cil_flavor flavor, struct
return rc;
}

/*
* Determine whether or not multiple declarations of the same key can share a
* datum, given the new datum and the one already present in a given symtab.
*/
int cil_is_datum_multiple_decl(__attribute__((unused)) struct cil_symtab_datum *cur,
struct cil_symtab_datum *old,
enum cil_flavor f)
static int cil_allow_multiple_decls(struct cil_db *db, enum cil_flavor f_new, enum cil_flavor f_old)
{
int rc = CIL_FALSE;
if (f_new != f_old) {
return CIL_FALSE;
}

switch (f) {
switch (f_new) {
case CIL_TYPE:
case CIL_TYPEATTRIBUTE:
if (!old || f != FLAVOR(old)) {
rc = CIL_FALSE;
} else {
/* type and typeattribute statements insert empty datums */
rc = CIL_TRUE;
if (db->multiple_decls) {
return CIL_TRUE;
}
break;
default:
break;
}
return rc;

return CIL_FALSE;
}

int cil_gen_node(struct cil_db *db, struct cil_tree_node *ast_node, struct cil_symtab_datum *datum, hashtab_key_t key, enum cil_sym_index sflavor, enum cil_flavor nflavor)
Expand Down Expand Up @@ -135,8 +129,7 @@ int cil_gen_node(struct cil_db *db, struct cil_tree_node *ast_node, struct cil_s
cil_log(CIL_ERR, "Re-declaration of %s %s, but previous declaration could not be found\n",cil_node_to_string(ast_node), key);
goto exit;
}
if (!db->multiple_decls ||
!cil_is_datum_multiple_decl(datum, prev, nflavor)) {
if (!cil_allow_multiple_decls(db, nflavor, FLAVOR(prev))) {
/* multiple_decls not ok, ret error */
struct cil_tree_node *node = NODE(prev);
cil_log(CIL_ERR, "Re-declaration of %s %s\n",
Expand Down

0 comments on commit 63ce05b

Please sign in to comment.