autofs-5.1.0 - fix reset amd lexer scan buffer From: Ian Kent When the amd parser encounters an error often the lexer is left in a state where a new parse can't be started. Fix this by explicitly naming our start states and resetting to the proper start state at buffer initialization on each scan. --- CHANGELOG | 1 + modules/amd_tok.l | 59 +++++++++++++++++++++++++++++++-------------------- modules/parse_amd.c | 3 +++ 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 51c935d..fe9b2f9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -27,6 +27,7 @@ - fix memory leak in get_exports(). - fix memory leak in get_defaults_entry(). - fix out of order clearing of options buffer. +- fix reset amd lexer scan buffer. 04/06/2014 autofs-5.1.0 ======================= diff --git a/modules/amd_tok.l b/modules/amd_tok.l index 1d9c234..36bce49 100644 --- a/modules/amd_tok.l +++ b/modules/amd_tok.l @@ -1,4 +1,3 @@ -%{ /* ----------------------------------------------------------------------- * * * Copyright 2013 Ian Kent @@ -18,6 +17,12 @@ * * ----------------------------------------------------------------------- */ +%s START MAPOPTVAL FSOPTVAL MNTOPTVAL SELOPTVAL SELARGVAL + +%{ + +static int reset_start_state = 0; + #ifdef ECHO # undef ECHO #endif @@ -71,8 +76,6 @@ int amd_yyinput(char *, int); %option nounput -%x MAPOPTVAL FSOPTVAL MNTOPTVAL SELOPTVAL SELARGVAL - NL \r?\n OPTWS [[:blank:]]* OTHR [^!;:=/|\- \t\r\n#]* @@ -120,7 +123,14 @@ CUTSEP (\|\||\/) %% -{ +%{ + if (reset_start_state) { + BEGIN START; + reset_start_state = 0; + } +%} + +{ {NL} | \x00 { } @@ -179,23 +189,23 @@ CUTSEP (\|\||\/) { {NL} { - BEGIN(INITIAL); + BEGIN(START); yyless(1); } \x00 { - BEGIN(INITIAL); + BEGIN(START); return SEPERATOR; yyless(1); } ";" { - BEGIN(INITIAL); + BEGIN(START); return SEPERATOR; } {OPTWS} { - BEGIN(INITIAL); + BEGIN(START); return SPACE; } @@ -224,23 +234,23 @@ CUTSEP (\|\||\/) { {NL} { - BEGIN(INITIAL); + BEGIN(START); yyless(1); } \x00 { - BEGIN(INITIAL); + BEGIN(START); return SEPERATOR; yyless(1); } ";" { - BEGIN(INITIAL); + BEGIN(START); return SEPERATOR; } {OPTWS} { - BEGIN(INITIAL); + BEGIN(START); return SPACE; } @@ -254,23 +264,23 @@ CUTSEP (\|\||\/) { {NL} { - BEGIN(INITIAL); + BEGIN(START); yyless(1); } \x00 { - BEGIN(INITIAL); + BEGIN(START); return SEPERATOR; yyless(1); } ";" { - BEGIN(INITIAL); + BEGIN(START); return SEPERATOR; } {OPTWS} { - BEGIN(INITIAL); + BEGIN(START); return SPACE; } @@ -286,23 +296,23 @@ CUTSEP (\|\||\/) { {NL} { - BEGIN(INITIAL); + BEGIN(START); yyless(1); } \x00 { - BEGIN(INITIAL); + BEGIN(START); return SEPERATOR; yyless(1); } ";" { - BEGIN(INITIAL); + BEGIN(START); return SEPERATOR; } {OPTWS} { - BEGIN(INITIAL); + BEGIN(START); return SPACE; } @@ -318,18 +328,18 @@ CUTSEP (\|\||\/) { {NL} { - BEGIN(INITIAL); + BEGIN(START); yyless(1); } \x00 { - BEGIN(INITIAL); + BEGIN(START); return SEPERATOR; yyless(1); } ";" { - BEGIN(INITIAL); + BEGIN(START); return SEPERATOR; } @@ -391,6 +401,9 @@ static void amd_echo(void) void amd_set_scan_buffer(const char *buffer) { + YY_FLUSH_BUFFER; + reset_start_state = 1; + line = buffer; line_pos = &line[0]; /* diff --git a/modules/parse_amd.c b/modules/parse_amd.c index ebf3807..9590cf4 100644 --- a/modules/parse_amd.c +++ b/modules/parse_amd.c @@ -1798,6 +1798,9 @@ static struct amd_entry *get_defaults_entry(struct autofs_point *ap, if (!expand_selectors(ap, defaults, &expand, sv)) goto out; if (amd_parse_list(ap, expand, &dflts, &sv)) { + error(ap->logopt, MODPREFIX + "failed to parse defaults entry, " + "attempting to use internal default"); free(expand); goto out; }