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.
This commit is contained in:
Todd C. Miller
2011-03-21 12:48:33 -04:00
parent edfb5cd7a2
commit c7dd8399eb
2 changed files with 117 additions and 3600 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -77,7 +77,8 @@ int sudolineno = 1;
char *sudoers; char *sudoers;
int (*trace_print)(const char *msg); int (*trace_print)(const char *msg);
static int sawspace = 0; static int sawspace = FALSE;
static int continued = FALSE;
static int prev_state = INITIAL; static int prev_state = INITIAL;
static int _push_include(char *, int); static int _push_include(char *, int);
@@ -167,7 +168,7 @@ DEFVAR [a-z_]+
\\[[:blank:]]*\n[[:blank:]]* { \\[[:blank:]]*\n[[:blank:]]* {
/* Line continuation char followed by newline. */ /* Line continuation char followed by newline. */
++sudolineno; ++sudolineno;
LEXTRACE("\n"); continued = TRUE;
} }
\" { \" {
@@ -234,6 +235,11 @@ DEFVAR [a-z_]+
<INITIAL>^#include[[:blank:]]+\/.*\n { <INITIAL>^#include[[:blank:]]+\/.*\n {
char *path; char *path;
if (continued) {
LEXTRACE("ERROR ");
return ERROR;
}
if ((path = parse_include(yytext)) == NULL) if ((path = parse_include(yytext)) == NULL)
yyterminate(); yyterminate();
@@ -247,6 +253,11 @@ DEFVAR [a-z_]+
<INITIAL>^#includedir[[:blank:]]+\/.*\n { <INITIAL>^#includedir[[:blank:]]+\/.*\n {
char *path; char *path;
if (continued) {
LEXTRACE("ERROR ");
return ERROR;
}
if ((path = parse_include(yytext)) == NULL) if ((path = parse_include(yytext)) == NULL)
yyterminate(); yyterminate();
@@ -263,6 +274,12 @@ DEFVAR [a-z_]+
<INITIAL>^[[:blank:]]*Defaults([:@>\!][[:blank:]]*\!*\"?{WORD})? { <INITIAL>^[[:blank:]]*Defaults([:@>\!][[:blank:]]*\!*\"?{WORD})? {
char deftype; char deftype;
int n; int n;
if (continued) {
LEXTRACE("ERROR ");
return ERROR;
}
for (n = 0; isblank((unsigned char)yytext[n]); n++) for (n = 0; isblank((unsigned char)yytext[n]); n++)
continue; continue;
n += sizeof("Defaults") - 1; n += sizeof("Defaults") - 1;
@@ -296,6 +313,12 @@ DEFVAR [a-z_]+
<INITIAL>^[[:blank:]]*(Host|Cmnd|User|Runas)_Alias { <INITIAL>^[[:blank:]]*(Host|Cmnd|User|Runas)_Alias {
int n; int n;
if (continued) {
LEXTRACE("ERROR ");
return ERROR;
}
for (n = 0; isblank((unsigned char)yytext[n]); n++) for (n = 0; isblank((unsigned char)yytext[n]); n++)
continue; continue;
switch (yytext[n]) { switch (yytext[n]) {
@@ -518,6 +541,7 @@ sudoedit {
<*>\n { <*>\n {
BEGIN INITIAL; BEGIN INITIAL;
++sudolineno; ++sudolineno;
continued = FALSE;
LEXTRACE("\n"); LEXTRACE("\n");
return COMMENT; return COMMENT;
} /* return newline */ } /* return newline */
@@ -527,14 +551,14 @@ sudoedit {
} }
<*>\\[[:blank:]]*\n { <*>\\[[:blank:]]*\n {
sawspace = TRUE; /* remember for fill_args */
++sudolineno; ++sudolineno;
LEXTRACE("\n\t"); continued = TRUE;
} /* throw away EOL after \ */ } /* throw away EOL after \ */
<INITIAL,STARTDEFS,INDEFS>#(-[^\n0-9].*|[^\n0-9-].*)?\n { <INITIAL,STARTDEFS,INDEFS>#(-[^\n0-9].*|[^\n0-9-].*)?\n {
BEGIN INITIAL; BEGIN INITIAL;
++sudolineno; ++sudolineno;
continued = FALSE;
LEXTRACE("#\n"); LEXTRACE("#\n");
return COMMENT; return COMMENT;
} /* comment, not uid/gid */ } /* comment, not uid/gid */