]> granicus.if.org Git - sudo/commitdiff
If we match a rule anchored to the beginning of a line after parsing
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 21 Mar 2011 21:49:16 +0000 (17:49 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 21 Mar 2011 21:49:16 +0000 (17:49 -0400)
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

diff --git a/toke.l b/toke.l
index 3f5e8ba99ceb2ffc5ec39cfd7ff1ebeeb5b5ea3d..153c97055131fe85d578b1103ab0b55c1b9c9386 100644 (file)
--- 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_]+
 <INITIAL>^#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_]+
 <INITIAL>^#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_]+
 <INITIAL>^[[: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_]+
 
 <INITIAL>^[[: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 \ */
 
 <INITIAL,STARTDEFS,INDEFS>#(-[^\n0-9].*|[^\n0-9-].*)?\n        {
                            BEGIN INITIAL;
                            ++sudolineno;
-                           LEXTRACE("\n");
+                           continued = FALSE;
+                           LEXTRACE("#\n");
                            return COMMENT;
                        }                       /* comment, not uid/gid */