Skip to content

Commit

Permalink
checkpolicy: handle unprintable token
Browse files Browse the repository at this point in the history
In case the erroneous token is unprintable, e.g. a control character,
print its hex value instead.

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 ca77c59 commit 39b3cc5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion checkpolicy/policy_scan.l
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,24 @@ 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);
else
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
Expand Down

0 comments on commit 39b3cc5

Please sign in to comment.