Rewrite ProcessConfigFile() to avoid misbehavior at EOF, as per report
from Andrus Moor. The former state-machine-style coding wasn't actually doing much except obscuring the control flow, and it didn't extend readily to fix this case, so I just took it out. Also, add a YY_FLUSH_BUFFER call to ensure the lexer is reset correctly if the previous scan failed partway through the file.
This commit is contained in:
parent
0898033b1e
commit
fc6da31ae1
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.32 2005/09/21 20:33:34 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.33 2006/01/01 19:52:40 tgl Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
%{
|
%{
|
||||||
@ -126,7 +126,7 @@ void
|
|||||||
ProcessConfigFile(GucContext context)
|
ProcessConfigFile(GucContext context)
|
||||||
{
|
{
|
||||||
int elevel;
|
int elevel;
|
||||||
int token, parse_state;
|
int token;
|
||||||
char *opt_name, *opt_value;
|
char *opt_name, *opt_value;
|
||||||
struct name_value_pair *item, *head, *tail;
|
struct name_value_pair *item, *head, *tail;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@ -158,29 +158,28 @@ ProcessConfigFile(GucContext context)
|
|||||||
* Parse
|
* Parse
|
||||||
*/
|
*/
|
||||||
yyin = fp;
|
yyin = fp;
|
||||||
parse_state = 0;
|
YY_FLUSH_BUFFER; /* in case we abandoned a prior scan */
|
||||||
head = tail = NULL;
|
head = tail = NULL;
|
||||||
opt_name = opt_value = NULL;
|
opt_name = opt_value = NULL;
|
||||||
ConfigFileLineno = 1;
|
ConfigFileLineno = 1;
|
||||||
|
|
||||||
|
/* This loop iterates once per logical line */
|
||||||
while ((token = yylex()))
|
while ((token = yylex()))
|
||||||
{
|
{
|
||||||
switch(parse_state)
|
if (token == GUC_EOL) /* empty or comment line */
|
||||||
{
|
|
||||||
case 0: /* no previous input */
|
|
||||||
if (token == GUC_EOL) /* empty line */
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* first token on line is option name */
|
||||||
if (token != GUC_ID && token != GUC_QUALIFIED_ID)
|
if (token != GUC_ID && token != GUC_QUALIFIED_ID)
|
||||||
goto parse_error;
|
goto parse_error;
|
||||||
opt_name = pstrdup(yytext);
|
opt_name = pstrdup(yytext);
|
||||||
parse_state = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1: /* found name */
|
/* next we have an optional equal sign; discard if present */
|
||||||
/* ignore equals sign */
|
token = yylex();
|
||||||
if (token == GUC_EQUALS)
|
if (token == GUC_EQUALS)
|
||||||
token = yylex();
|
token = yylex();
|
||||||
|
|
||||||
|
/* now we must have the option value */
|
||||||
if (token != GUC_ID &&
|
if (token != GUC_ID &&
|
||||||
token != GUC_STRING &&
|
token != GUC_STRING &&
|
||||||
token != GUC_INTEGER &&
|
token != GUC_INTEGER &&
|
||||||
@ -191,13 +190,13 @@ ProcessConfigFile(GucContext context)
|
|||||||
opt_value = GUC_scanstr(yytext);
|
opt_value = GUC_scanstr(yytext);
|
||||||
else
|
else
|
||||||
opt_value = pstrdup(yytext);
|
opt_value = pstrdup(yytext);
|
||||||
parse_state = 2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2: /* now we'd like an end of line */
|
/* now we'd like an end of line, or possibly EOF */
|
||||||
if (token != GUC_EOL)
|
token = yylex();
|
||||||
|
if (token != GUC_EOL && token != 0)
|
||||||
goto parse_error;
|
goto parse_error;
|
||||||
|
|
||||||
|
/* OK, save the option name and value */
|
||||||
if (strcmp(opt_name, "custom_variable_classes") == 0)
|
if (strcmp(opt_name, "custom_variable_classes") == 0)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -229,10 +228,10 @@ ProcessConfigFile(GucContext context)
|
|||||||
tail = item;
|
tail = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_state = 0;
|
/* break out of loop if read EOF, else loop for next line */
|
||||||
|
if (token == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
FreeFile(fp);
|
FreeFile(fp);
|
||||||
|
|
||||||
@ -260,7 +259,7 @@ ProcessConfigFile(GucContext context)
|
|||||||
parse_error:
|
parse_error:
|
||||||
FreeFile(fp);
|
FreeFile(fp);
|
||||||
free_name_value_list(head);
|
free_name_value_list(head);
|
||||||
if (token == GUC_EOL)
|
if (token == GUC_EOL || token == 0)
|
||||||
ereport(elevel,
|
ereport(elevel,
|
||||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||||
errmsg("syntax error in file \"%s\" line %u, near end of line",
|
errmsg("syntax error in file \"%s\" line %u, near end of line",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user