checkpolicy: use YYerror only when available
PATCH 1/2 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).
--- checkpolicy/policy_parse.y | 1 + checkpolicy/policy_scan.l | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-)
checkpolicy/policy_parse.y +1 -0
@@ -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
checkpolicy/policy_scan.l +8 -1
@@ -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) {
Signature · 1 line
2.43.0
PATCH 2/2 checkpolicy: handle unprintable token
In case the erroneous token is unprintable, e.g. a control character, print its hex value instead.
--- checkpolicy/policy_scan.l | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
checkpolicy/policy_scan.l +11 -1
@@ -320,6 +320,16 @@ GLBLUB { return(GLBLUB); } int yyerror(const char *msg) { #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION + const char *token; + char buf[8]; + + if (isprint((unsigned char)yytext[0])) { + token = yytext; + } else { + snprintf(buf, sizeof(buf), "%#x", yytext[0]); + token = buf; + } + if (source_file[0]) fprintf(stderr, "%s:%lu:", source_file, source_lineno);
@@ -327,7 +337,7 @@ int yyerror(const char *msg) fprintf(stderr, "(unknown source)::"); fprintf(stderr, "ERROR '%s' at token '%s' on line %lu:\n%s\n%s\n", msg, - yytext, + token, policydb_lineno, linebuf[0], linebuf[1]); #else
Signature · 1 line
2.43.0
Quoted 11 lines · Christian Göttsche
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]>
For these two patches:
Quoted 41 lines
--- checkpolicy/policy_parse.y | 1 + checkpolicy/policy_scan.l | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-)checkpolicy/policy_parse.y +1
-0@@ -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 XORcheckpolicy/policy_scan.l +8
-2@@ -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) { --2.43.0
Quoted 13 lines · James Carter
Quoted 10 lines · Christian Göttsche
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).
Quoted 5 lines
Quoted 1 line
Signed-off-by Christian Göttsche <[email protected]>For these two patches:
Acked-by James Carter <[email protected]>
These two patches have been merged.
Thanks,
Jim
Quoted 41 lines
Quoted 41 lines
--- checkpolicy/policy_parse.y | 1 + checkpolicy/policy_scan.l | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-)checkpolicy/policy_parse.y +1
-0@@ -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 XORcheckpolicy/policy_scan.l +8
-2@@ -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) { --2.43.0