diff mbox series

[1/2] checkpolicy: use YYerror only when available

Message ID 20240322145049.60340-1-cgzones@googlemail.com (mailing list archive)
State Accepted
Commit ca77c5929905
Delegated to: Petr Lautrbach
Headers show
Series [1/2] checkpolicy: use YYerror only when available | expand

Commit Message

Christian Göttsche March 22, 2024, 2:50 p.m. UTC
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>
---
 checkpolicy/policy_parse.y | 1 +
 checkpolicy/policy_scan.l  | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

Comments

James Carter March 25, 2024, 5:13 p.m. UTC | #1
On Fri, Mar 22, 2024 at 10:54 AM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> 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>

For these two patches:
Acked-by: James Carter <jwcart2@gmail.com>

> ---
>  checkpolicy/policy_parse.y | 1 +
>  checkpolicy/policy_scan.l  | 9 ++++++++-
>  2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/checkpolicy/policy_parse.y b/checkpolicy/policy_parse.y
> index e0103502..1b275ebc 100644
> --- a/checkpolicy/policy_parse.y
> +++ b/checkpolicy/policy_parse.y
> @@ -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
> diff --git a/checkpolicy/policy_scan.l b/checkpolicy/policy_scan.l
> index 1926129c..c4d8e937 100644
> --- a/checkpolicy/policy_scan.l
> +++ b/checkpolicy/policy_scan.l
> @@ -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
>
>
James Carter March 27, 2024, 7:07 p.m. UTC | #2
On Mon, Mar 25, 2024 at 1:13 PM James Carter <jwcart2@gmail.com> wrote:
>
> On Fri, Mar 22, 2024 at 10:54 AM Christian Göttsche
> <cgzones@googlemail.com> wrote:
> >
> > 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>
>
> For these two patches:
> Acked-by: James Carter <jwcart2@gmail.com>
>

These two patches have been merged.
Thanks,
Jim

> > ---
> >  checkpolicy/policy_parse.y | 1 +
> >  checkpolicy/policy_scan.l  | 9 ++++++++-
> >  2 files changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/checkpolicy/policy_parse.y b/checkpolicy/policy_parse.y
> > index e0103502..1b275ebc 100644
> > --- a/checkpolicy/policy_parse.y
> > +++ b/checkpolicy/policy_parse.y
> > @@ -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
> > diff --git a/checkpolicy/policy_scan.l b/checkpolicy/policy_scan.l
> > index 1926129c..c4d8e937 100644
> > --- a/checkpolicy/policy_scan.l
> > +++ b/checkpolicy/policy_scan.l
> > @@ -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
> >
> >
diff mbox series

Patch

diff --git a/checkpolicy/policy_parse.y b/checkpolicy/policy_parse.y
index e0103502..1b275ebc 100644
--- a/checkpolicy/policy_parse.y
+++ b/checkpolicy/policy_parse.y
@@ -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
diff --git a/checkpolicy/policy_scan.l b/checkpolicy/policy_scan.l
index 1926129c..c4d8e937 100644
--- a/checkpolicy/policy_scan.l
+++ b/checkpolicy/policy_scan.l
@@ -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)
 {