Skip to content

Commit

Permalink
checkpolicy: use YYerror only when available
Browse files Browse the repository at this point in the history
The special error value YYerror is only available since bison 3.6
(released 2020).  For example the version used by oss-fuzz does not
support it.

Use a special token in case YYerror is not available.  Only downside is
a duplicate error message, one from the manual yyerror() call and one
from within bison for the unexpected special token (which would be
omitted by using YYerror).

Signed-off-by: Christian Göttsche <[email protected]>
Acked-by: James Carter <[email protected]>
  • Loading branch information
cgzones authored and jwcart2 committed Mar 27, 2024
1 parent 6e2f703 commit ca77c59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions checkpolicy/policy_parse.y
Expand Up @@ -153,6 +153,7 @@ typedef int (* require_func_t)(int pass);
%token FILESYSTEM
%token DEFAULT_USER DEFAULT_ROLE DEFAULT_TYPE DEFAULT_RANGE
%token LOW_HIGH LOW HIGH GLBLUB
%token INVALID_CHAR

%left OR
%left XOR
Expand Down
9 changes: 8 additions & 1 deletion checkpolicy/policy_scan.l
Expand Up @@ -308,7 +308,14 @@ GLBLUB { return(GLBLUB); }
"]" |
"~" |
"*" { return(yytext[0]); }
. { yyerror("unrecognized character"); return YYerror; }
. { yyerror("unrecognized character");
/* Available since bison 3.6, avoids duplicate error message */
#ifdef YYerror
return YYerror;
#else
return INVALID_CHAR;
#endif
}
%%
int yyerror(const char *msg)
{
Expand Down

0 comments on commit ca77c59

Please sign in to comment.