From d2f2bf4d3ad878596bba04cc4767c7559fe56b59 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 21 Mar 2011 17:49:16 -0400 Subject: [PATCH] If we match a rule anchored to the beginning of a line after parsing a line continuation character, return an ERROR token. It would be nicer to use REJECT instead but that substantially slows down the lexer. --HG-- branch : 1.7 --- toke.l | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/toke.l b/toke.l index 3f5e8ba99..153c97055 100644 --- a/toke.l +++ b/toke.l @@ -75,7 +75,8 @@ extern YYSTYPE yylval; extern int parse_error; int sudolineno = 1; char *sudoers; -static int sawspace = 0; +static int sawspace = FALSE; +static int continued = FALSE; static int prev_state = INITIAL; static int _push_include __P((char *, int)); @@ -173,7 +174,7 @@ DEFVAR [a-z_]+ \\[[:blank:]]*\n[[:blank:]]* { /* Line continuation char followed by newline. */ ++sudolineno; - LEXTRACE("\n"); + continued = TRUE; } \" { @@ -240,6 +241,11 @@ DEFVAR [a-z_]+ ^#include[[:blank:]]+\/.*\n { char *path; + if (continued) { + LEXTRACE("ERROR "); + return ERROR; + } + if ((path = parse_include(yytext)) == NULL) yyterminate(); @@ -253,6 +259,11 @@ DEFVAR [a-z_]+ ^#includedir[[:blank:]]+\/.*\n { char *path; + if (continued) { + LEXTRACE("ERROR "); + return ERROR; + } + if ((path = parse_include(yytext)) == NULL) yyterminate(); @@ -269,6 +280,12 @@ DEFVAR [a-z_]+ ^[[:blank:]]*Defaults([:@>\!][[:blank:]]*\!*\"?{WORD})? { char deftype; int n; + + if (continued) { + LEXTRACE("ERROR "); + return ERROR; + } + for (n = 0; isblank((unsigned char)yytext[n]); n++) continue; n += sizeof("Defaults") - 1; @@ -302,6 +319,12 @@ DEFVAR [a-z_]+ ^[[:blank:]]*(Host|Cmnd|User|Runas)_Alias { int n; + + if (continued) { + LEXTRACE("ERROR "); + return ERROR; + } + for (n = 0; isblank((unsigned char)yytext[n]); n++) continue; switch (yytext[n]) { @@ -524,6 +547,7 @@ sudoedit { <*>\n { BEGIN INITIAL; ++sudolineno; + continued = FALSE; LEXTRACE("\n"); return COMMENT; } /* return newline */ @@ -535,13 +559,14 @@ sudoedit { <*>\\[[:blank:]]*\n { sawspace = TRUE; /* remember for fill_args */ ++sudolineno; - LEXTRACE("\n\t"); + continued = TRUE; } /* throw away EOL after \ */ #(-[^\n0-9].*|[^\n0-9-].*)?\n { BEGIN INITIAL; ++sudolineno; - LEXTRACE("\n"); + continued = FALSE; + LEXTRACE("#\n"); return COMMENT; } /* comment, not uid/gid */ -- 2.50.1