Skip to content

Commit ca77c59

Browse files
cgzonesjwcart2
authored andcommitted
checkpolicy: use YYerror only when available
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 <cgzones@googlemail.com> Acked-by: James Carter <jwcart2@gmail.com>
1 parent 6e2f703 commit ca77c59

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

checkpolicy/policy_parse.y

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ typedef int (* require_func_t)(int pass);
153153
%token FILESYSTEM
154154
%token DEFAULT_USER DEFAULT_ROLE DEFAULT_TYPE DEFAULT_RANGE
155155
%token LOW_HIGH LOW HIGH GLBLUB
156+
%token INVALID_CHAR
156157

157158
%left OR
158159
%left XOR

checkpolicy/policy_scan.l

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,14 @@ GLBLUB { return(GLBLUB); }
308308
"]" |
309309
"~" |
310310
"*" { return(yytext[0]); }
311-
. { yyerror("unrecognized character"); return YYerror; }
311+
. { yyerror("unrecognized character");
312+
/* Available since bison 3.6, avoids duplicate error message */
313+
#ifdef YYerror
314+
return YYerror;
315+
#else
316+
return INVALID_CHAR;
317+
#endif
318+
}
312319
%%
313320
int yyerror(const char *msg)
314321
{

0 commit comments

Comments
 (0)