ecpg: fix more minor mishandling of bad input in preprocessor.

Don't get confused by an unmatched right brace in the input.
(Previously, this led to discarding information about file-level
variables and then possibly crashing.)

Detect, rather than crash on, an attempt to index into a non-array
variable.

As before, in the absence of field complaints I'm not too
excited about back-patching these.

Per valgrind testing by Alexander Lakhin.

Discussion: https://postgr.es/m/a239aec2-6c79-5fc9-9272-cea41158a360@gmail.com
This commit is contained in:
Tom Lane 2024-10-17 15:28:32 -04:00
parent 98c7c7152d
commit 1fed234f9f
2 changed files with 10 additions and 6 deletions

View File

@ -42,14 +42,17 @@ statement: ecpgstart at toplevel_stmt ';'
fputs("{", base_yyout); fputs("{", base_yyout);
} }
| '}' | '}'
{
if (braces_open > 0)
{ {
remove_typedefs(braces_open); remove_typedefs(braces_open);
remove_variables(braces_open--); remove_variables(braces_open);
if (braces_open == 0) if (--braces_open == 0)
{ {
free(current_function); free(current_function);
current_function = NULL; current_function = NULL;
} }
}
fputs("}", base_yyout); fputs("}", base_yyout);
} }
; ;

View File

@ -233,7 +233,8 @@ find_variable(const char *name)
p = find_simple(name); p = find_simple(name);
if (p == NULL) if (p == NULL)
mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name); mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name);
if (p->type->type != ECPGt_array)
mmfatal(PARSE_ERROR, "variable \"%s\" is not a pointer", name);
*next = c; *next = c;
switch (p->type->u.element->type) switch (p->type->u.element->type)
{ {