51 lines
1.3 KiB
Diff
51 lines
1.3 KiB
Diff
From 39b3cc51350a4ba670f9f38493311ec316e4d84d Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
|
|
Date: Fri, 22 Mar 2024 15:50:49 +0100
|
|
Subject: [PATCH] checkpolicy: handle unprintable token
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
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>
|
|
Acked-by: James Carter <jwcart2@gmail.com>
|
|
---
|
|
policy_scan.l | 12 +++++++++++-
|
|
1 file changed, 11 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/policy_scan.l b/policy_scan.l
|
|
index c4d8e937..d7cf2896 100644
|
|
--- a/policy_scan.l
|
|
+++ b/policy_scan.l
|
|
@@ -321,6 +321,16 @@ GLBLUB { return(GLBLUB); }
|
|
%%
|
|
int yyerror(const char *msg)
|
|
{
|
|
+ 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);
|
|
@@ -328,7 +338,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]);
|
|
policydb_errors++;
|
|
--
|
|
2.33.0
|
|
|