8000 ecpg: fix more minor mishandling of bad input in preprocessor. · postgres/postgres@1fed234 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1fed234

Browse files
committed
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
1 parent 98c7c71 commit 1fed234

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/interfaces/ecpg/preproc/ecpg.trailer

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ statement: ecpgstart at toplevel_stmt ';'
4343
}
4444
| '}'
4545
{
46-
remove_typedefs(braces_open);
47-
remove_variables(braces_open--);
48-
if (braces_open == 0)
46+
if (braces_open > 0)
4947
{
50-
free(current_function);
51-
current_function = NULL;
48+
remove_typedefs(braces_open);
49+
remove_variables(braces_open);
50+
if (--braces_open == 0)
51+
{
52+
free(current_function);
53+
current_function = NULL;
54+
}
5255
}
5356
fputs("}", base_yyout);
5457
}

src/interfaces/ecpg/preproc/variable.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ find_variable(const char *name)
233233
p = find_simple(name);
234234 5F91
if (p == NULL)
235235
mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name);
236-
236+
if (p->type->type != ECPGt_array)
237+
mmfatal(PARSE_ERROR, "variable \"%s\" is not a pointer", name);
237238
*next = c;
238239
switch (p->type->u.element->type)
239240
{

0 commit comments

Comments
 (0)
0