bison isn't properly handling the 3 options of

TOK_CHANGE_PROFILE opt_id TOK_END_OF_RULE
TOK_CHANGE_PROFILE opt_id TOK_ARROW TOK_ID TOK_END_OF_RULE
TOK_CHANGE_PROFILE opt_id TOK_ARROW TOK_COLON TOK_ID TOK_COLON TOK_END_OF_RULE

specifying
  change_profile /exec,

results in an unexpected TOK_ID error

refactor so that they share the 3 options share a common head which fixes
the problem.

Signed-off-by: John Johansen <[email protected]>
---
 parser/parser_yacc.y | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/parser/parser_yacc.y b/parser/parser_yacc.y
index 4ae5bf3..baa900b 100644
--- a/parser/parser_yacc.y
+++ b/parser/parser_yacc.y
@@ -244,6 +244,7 @@ void add_local_entry(Profile *prof);
 %type <flags>  flagval
 %type <cap>    caps
 %type <cap>    capability
+%type <id>     change_profile_head
 %type <user_entry> change_profile
 %type <set_var> TOK_SET_VAR
 %type <bool_var> TOK_BOOL_VAR
@@ -1491,42 +1492,43 @@ file_mode: TOK_MODE
                free($1);
        }
 
-change_profile: TOK_CHANGE_PROFILE opt_id TOK_END_OF_RULE
+change_profile_head: TOK_CHANGE_PROFILE opt_id
+       {
+               if ($2 && !($2[0] == '/' || strncmp($2, "@{", 2) == 0))
+                       yyerror(_("Exec condition must begin with '/'."));
+               $$ = $2;
+       }
+
+change_profile: change_profile_head TOK_END_OF_RULE
        {
                struct cod_entry *entry;
                char *rule = strdup("**");
                if (!rule)
                        yyerror(_("Memory allocation error."));
                PDEBUG("Matched change_profile,\n");
-               if ($2 && !($2[0] == '/' || strncmp($2, "@{", 2) == 0))
-                       yyerror(_("Exec condition must begin with '/'."));
-               entry = new_entry(NULL, rule, AA_CHANGE_PROFILE, $2);
+               entry = new_entry(NULL, rule, AA_CHANGE_PROFILE, $1);
                if (!entry)
                        yyerror(_("Memory allocation error."));
                PDEBUG("change_profile,\n");
                $$ = entry;
        };
 
-change_profile:        TOK_CHANGE_PROFILE opt_id TOK_ARROW TOK_ID 
TOK_END_OF_RULE
+change_profile:        change_profile_head TOK_ARROW TOK_ID TOK_END_OF_RULE
        {
                struct cod_entry *entry;
-               PDEBUG("Matched change_profile: tok_id (%s)\n", $4);
-               if ($2 && !($2[0] == '/' || strncmp($2, "@{", 2) == 0))
-                       yyerror(_("Exec condition must begin with '/'."));
-               entry = new_entry(NULL, $4, AA_CHANGE_PROFILE, $2);
+               PDEBUG("Matched change_profile: tok_id (%s)\n", $3);
+               entry = new_entry(NULL, $3, AA_CHANGE_PROFILE, $1);
                if (!entry)
                        yyerror(_("Memory allocation error."));
                PDEBUG("change_profile.entry: (%s)\n", entry->name);
                $$ = entry;
        };
 
-change_profile:        TOK_CHANGE_PROFILE opt_id TOK_ARROW TOK_COLON TOK_ID 
TOK_COLON TOK_ID TOK_END_OF_RULE
+change_profile:        change_profile_head TOK_ARROW TOK_COLON TOK_ID 
TOK_COLON TOK_ID TOK_END_OF_RULE
        {
                struct cod_entry *entry;
-               PDEBUG("Matched change_profile: tok_id (%s:%s)\n", $5, $7);
-               if ($2 && !($2[0] == '/' || strncmp($2, "@{", 2) == 0))
-                       yyerror(_("Exec condition must begin with '/'."));
-               entry = new_entry($5, $7, AA_CHANGE_PROFILE, $2);
+               PDEBUG("Matched change_profile: tok_id (%s:%s)\n", $4, $6);
+               entry = new_entry($4, $6, AA_CHANGE_PROFILE, $1);
                if (!entry)
                        yyerror(_("Memory allocation error."));
                PDEBUG("change_profile.entry: (%s)\n", entry->name);
-- 
2.1.4


-- 
AppArmor mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to