From 4ae6ad03ba4f9512bc62bc6d4bfb9bb370f3ffb8 Mon Sep 17 00:00:00 2001 From: Tyler Hicks Date: Fri, 26 Feb 2016 18:44:16 -0600 Subject: [PATCH] parser: Clean up pivot_root target parsing Instead of reusing opt_named_transition and be forced to reconstruct the target path when is looks like ":odd:target", create simpler grammer rules that have nothing to do with named transitions and namespaces. Signed-off-by: Tyler Hicks Acked-by: John Johansen --- parser/parser_yacc.y | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/parser/parser_yacc.y b/parser/parser_yacc.y index 1f004805c..7af78ce5c 100644 --- a/parser/parser_yacc.y +++ b/parser/parser_yacc.y @@ -276,6 +276,7 @@ void add_local_entry(Profile *prof); %type net_perms %type opt_net_perm %type unix_rule +%type opt_target %type opt_named_transition %type opt_unsafe %type opt_file @@ -1044,6 +1045,9 @@ expr: TOK_DEFINED TOK_BOOL_VAR id_or_var: TOK_ID { $$ = $1; } id_or_var: TOK_SET_VAR { $$ = $1; }; +opt_target: /* nothing */ { $$ = NULL; } +opt_target: TOK_ARROW id_or_var { $$ = $2; }; + opt_named_transition: { /* nothing */ parse_named_transition_target(&$$, NULL); @@ -1242,23 +1246,9 @@ mnt_rule: TOK_UMOUNT opt_conds opt_id TOK_END_OF_RULE $$ = do_mnt_rule($2, NULL, NULL, $3, AA_MAY_UMOUNT); } -mnt_rule: TOK_PIVOTROOT opt_conds opt_id opt_named_transition TOK_END_OF_RULE +mnt_rule: TOK_PIVOTROOT opt_conds opt_id opt_target TOK_END_OF_RULE { - char *name = NULL; - if ($4.present && $4.ns) { - name = (char *) malloc(strlen($4.ns) + - strlen($4.name) + 3); - if (!name) { - PERROR("Memory allocation error\n"); - exit(1); - } - sprintf(name, ":%s:%s", $4.ns, $4.name); - free($4.ns); - free($4.name); - } else if ($4.present) - name = $4.name; - - $$ = do_pivot_rule($2, $3, name); + $$ = do_pivot_rule($2, $3, $4); } dbus_perm: TOK_VALUE