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>
This commit is contained in:
Christian Göttsche 2024-03-22 15:50:48 +01:00 committed by James Carter
parent 6e2f703340
commit ca77c59299
2 changed files with 9 additions and 1 deletions

View File

@ -153,6 +153,7 @@ typedef int (* require_func_t)(int pass);
%token FILESYSTEM %token FILESYSTEM
%token DEFAULT_USER DEFAULT_ROLE DEFAULT_TYPE DEFAULT_RANGE %token DEFAULT_USER DEFAULT_ROLE DEFAULT_TYPE DEFAULT_RANGE
%token LOW_HIGH LOW HIGH GLBLUB %token LOW_HIGH LOW HIGH GLBLUB
%token INVALID_CHAR
%left OR %left OR
%left XOR %left XOR

View File

@ -308,7 +308,14 @@ GLBLUB { return(GLBLUB); }
"]" | "]" |
"~" | "~" |
"*" { return(yytext[0]); } "*" { 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) int yyerror(const char *msg)
{ {