checkpolicy/backport-checkpolicy-use-YYerror-only-when-available.patch
wjiang b993887e8d backport patches from upstream
(cherry picked from commit c2ba662a7864600cc027fdb3d39f616df22d7a44)
2025-03-20 15:43:06 +08:00

60 lines
1.8 KiB
Diff

From ca77c5929905216fb1c0f70ed632664aa3ec85a7 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:48 +0100
Subject: [PATCH] checkpolicy: use YYerror only when available
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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>
---
policy_parse.y | 1 +
policy_scan.l | 9 ++++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/policy_parse.y b/policy_parse.y
index e0103502..1b275ebc 100644
--- a/policy_parse.y
+++ b/policy_parse.y
@@ -155,6 +155,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
diff --git a/policy_scan.l b/policy_scan.l
index 1926129c..c4d8e937 100644
--- a/policy_scan.l
+++ b/policy_scan.l
@@ -310,7 +310,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.33.0