From: "Christian Göttsche" <cgzones@googlemail.com>
To: selinux@vger.kernel.org
Subject: [PATCH 2/2] checkpolicy: handle unprintable token
Date: Fri, 22 Mar 2024 15:50:49 +0100 [thread overview]
Message-ID: <20240322145049.60340-2-cgzones@googlemail.com> (raw)
In-Reply-To: <20240322145049.60340-1-cgzones@googlemail.com>
In case the erroneous token is unprintable, e.g. a control character,
print its hex value instead.
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
checkpolicy/policy_scan.l | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/checkpolicy/policy_scan.l b/checkpolicy/policy_scan.l
index c4d8e937..d7cf2896 100644
--- a/checkpolicy/policy_scan.l
+++ b/checkpolicy/policy_scan.l
@@ -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
--
2.43.0
next prev parent reply other threads:[~2024-03-22 14:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-22 14:50 [PATCH 1/2] checkpolicy: use YYerror only when available Christian Göttsche
2024-03-22 14:50 ` Christian Göttsche [this message]
2024-03-25 17:13 ` James Carter
2024-03-27 19:07 ` James Carter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240322145049.60340-2-cgzones@googlemail.com \
--to=cgzones@googlemail.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).