From: Michael Meskes Date: Thu, 4 Mar 2004 07:38:50 +0000 (+0000) Subject: - Fixed segfault due to missing check for variable declaration. X-Git-Tag: REL7_4_2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ea41a8cc5f0b6af81a6f447e066339ed877a455c;p=postgresql - Fixed segfault due to missing check for variable declaration. - Added check for multidimensional array usage. --- diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index 26eaaa015a..bd111b72d2 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.263.2.9 2004/03/02 06:52:18 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.263.2.10 2004/03/04 07:38:50 meskes Exp $ */ /* Copyright comment */ %{ @@ -541,6 +541,7 @@ add_additional_variables(char *name, bool insert) %type ECPGTypeName using_list ECPGColLabelCommon UsingConst %type inf_val_list inf_col_list using_descriptor into_descriptor %type ecpg_into_using prepared_name struct_union_type_with_symbol +%type cvariable %type s_struct_union_symbol @@ -4217,7 +4218,7 @@ connection_target: database_name opt_server opt_port } ; -db_prefix: ident CVARIABLE +db_prefix: ident cvariable { if (strcmp($2, "postgresql") != 0 && strcmp($2, "postgres") != 0) { @@ -4308,7 +4309,7 @@ user_name: UserId } ; -char_variable: CVARIABLE +char_variable: cvariable { /* check if we have a char variable */ struct variable *p = find_variable($1); @@ -5369,14 +5370,14 @@ ECPGAllocateDescr: SQL_ALLOCATE SQL_DESCRIPTOR quoted_ident_stringvar * read from descriptor */ -ECPGGetDescHeaderItem: CVARIABLE '=' desc_header_item +ECPGGetDescHeaderItem: cvariable '=' desc_header_item { push_assignment($1, $3); } ; desc_header_item: SQL_COUNT { $$ = ECPGd_count; } ; -ECPGGetDescItem: CVARIABLE '=' descriptor_item { push_assignment($1, $3); }; +ECPGGetDescItem: cvariable '=' descriptor_item { push_assignment($1, $3); }; descriptor_item: SQL_CARDINALITY { $$ = ECPGd_cardinality; } | SQL_DATA { $$ = ECPGd_data; } @@ -5408,7 +5409,7 @@ ECPGGetDescriptorHeader: GET SQL_DESCRIPTOR quoted_ident_stringvar { $$ = $3; } ; -ECPGGetDescriptor: GET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE CVARIABLE ECPGGetDescItems +ECPGGetDescriptor: GET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE cvariable ECPGGetDescItems { $$.str = $5; $$.name = $3; } | GET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE Iconst ECPGGetDescItems { $$.str = $5; $$.name = $3; } @@ -6158,14 +6159,14 @@ c_args: /*EMPTY*/ { $$ = EMPTY; } | c_list { $$ = $1; } ; -coutputvariable: CVARIABLE indicator +coutputvariable: cvariable indicator { add_variable_to_head(&argsresult, find_variable($1), find_variable($2)); } - | CVARIABLE + | cvariable { add_variable_to_head(&argsresult, find_variable($1), &no_indicator); } ; -civarind: CVARIABLE indicator +civarind: cvariable indicator { if (find_variable($2)->type->type == ECPGt_array) mmerror(PARSE_ERROR, ET_ERROR, "arrays of indicators are not allowed on input"); @@ -6175,18 +6176,48 @@ civarind: CVARIABLE indicator } ; -civar: CVARIABLE +civar: cvariable { add_variable_to_head(&argsinsert, find_variable($1), &no_indicator); $$ = create_questionmarks($1, false); } ; -indicator: CVARIABLE { check_indicator((find_variable($1))->type); $$ = $1; } - | SQL_INDICATOR CVARIABLE { check_indicator((find_variable($2))->type); $$ = $2; } +indicator: cvariable { check_indicator((find_variable($1))->type); $$ = $1; } + | SQL_INDICATOR cvariable { check_indicator((find_variable($2))->type); $$ = $2; } | SQL_INDICATOR name { check_indicator((find_variable($2))->type); $$ = $2; } ; +cvariable: CVARIABLE + { + /* As long as multidimensional arrays are not implemented we have to check for those here */ + char *ptr = $1; + int brace_open=0, brace = false; + + for (; *ptr; ptr++) + { + switch (*ptr) + { + case '[': if (brace) + { + mmerror(PARSE_ERROR, ET_FATAL, "No multidimensional array support for simple data types"); + } + brace_open++; + break; + case ']': brace_open--; + if (brace_open == 0) brace = true; + break; + case '\t': + case ' ': break; + default: if (brace_open == 0) brace = false; + break; + } + } + + $$ = $1; + } + ; + ident: IDENT { $$ = $1; } | CSTRING { $$ = make3_str(make_str("\""), $1, make_str("\"")); } ; diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c index e12b943499..f1a875f0cc 100644 --- a/src/interfaces/ecpg/preproc/variable.c +++ b/src/interfaces/ecpg/preproc/variable.c @@ -218,7 +218,7 @@ find_variable(char *name) { /* * We don't care about what's inside the array braces so just - * eat up the character + * eat up the characters */ for (count = 1, end = next + 1; count; end++) { @@ -242,6 +242,11 @@ find_variable(char *name) *next = '\0'; p = find_simple(name); + if (p == NULL) + { + snprintf(errortext, sizeof(errortext), "The variable %s is not declared", name); + mmerror(PARSE_ERROR, ET_FATAL, errortext); + } *next = c; switch (p->type->u.element->type) {