Skip to content

Commit f3c6d59

Browse files
author
Michael Meskes
committed
- Fixed segfault due to missing check for variable declaration.
- Added check for multidimensional array usage.
1 parent c934cf1 commit f3c6d59

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,11 @@ Tue Feb 24 16:48:57 CET 2004
17541754
Mon Mar 1 08:56:37 CET 2004
17551755

17561756
- Added partly missing VOLATILE keyword.
1757+
1758+
Thu Mar 4 08:29:02 CET 2004
1759+
1760+
- Fixed segfault due to missing check for variable declaration.
1761+
- Added check for multidimensional array usage.
17571762
- Set pgtypeslib version to 1.2.
17581763
- Set ecpg version to 3.2.0.
17591764

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.276 2004/03/02 06:45:05 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.277 2004/03/04 07:32:01 meskes Exp $ */
22

33
/* Copyright comment */
44
%{
@@ -541,7 +541,7 @@ add_additional_variables(char *name, bool insert)
541541
%type <str> ECPGTypeName using_list ECPGColLabelCommon UsingConst
542542
%type <str> inf_val_list inf_col_list using_descriptor into_descriptor
543543
%type <str> ecpg_into_using prepared_name struct_union_type_with_symbol
544-
%type <str> ECPGunreserved ECPGunreserved_interval
544+
%type <str> ECPGunreserved ECPGunreserved_interval cvariable
545545

546546
%type <struct_union> s_struct_union_symbol
547547

@@ -4220,7 +4220,7 @@ connection_target: database_name opt_server opt_port
42204220
}
42214221
;
42224222

4223-
db_prefix: ident CVARIABLE
4223+
db_prefix: ident cvariable
42244224
{
42254225
if (strcmp($2, "postgresql") != 0 && strcmp($2, "postgres") != 0)
42264226
{
@@ -4311,7 +4311,7 @@ user_name: UserId
43114311
}
43124312
;
43134313

4314-
char_variable: CVARIABLE
4314+
char_variable: cvariable
43154315
{
43164316
/* check if we have a char variable */
43174317
struct variable *p = find_variable($1);
@@ -5241,14 +5241,14 @@ ECPGAllocateDescr: SQL_ALLOCATE SQL_DESCRIPTOR quoted_ident_stringvar
52415241
* read from descriptor
52425242
*/
52435243

5244-
ECPGGetDescHeaderItem: CVARIABLE '=' desc_header_item
5244+
ECPGGetDescHeaderItem: cvariable '=' desc_header_item
52455245
{ push_assignment($1, $3); }
52465246
;
52475247

52485248
desc_header_item: SQL_COUNT { $$ = ECPGd_count; }
52495249
;
52505250

5251-
ECPGGetDescItem: CVARIABLE '=' descriptor_item { push_assignment($1, $3); };
5251+
ECPGGetDescItem: cvariable '=' descriptor_item { push_assignment($1, $3); };
52525252

52535253
descriptor_item: SQL_CARDINALITY { $$ = ECPGd_cardinality; }
52545254
| SQL_DATA { $$ = ECPGd_data; }
@@ -5280,7 +5280,7 @@ ECPGGetDescriptorHeader: GET SQL_DESCRIPTOR quoted_ident_stringvar
52805280
{ $$ = $3; }
52815281
;
52825282

5283-
ECPGGetDescriptor: GET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE CVARIABLE ECPGGetDescItems
5283+
ECPGGetDescriptor: GET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE cvariable ECPGGetDescItems
52845284
{ $$.str = $5; $$.name = $3; }
52855285
| GET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE Iconst ECPGGetDescItems
52865286
{ $$.str = $5; $$.name = $3; }
@@ -6047,14 +6047,14 @@ c_args: /*EMPTY*/ { $$ = EMPTY; }
60476047
| c_list { $$ = $1; }
60486048
;
60496049

6050-
coutputvariable: CVARIABLE indicator
6050+
coutputvariable: cvariable indicator
60516051
{ add_variable_to_head(&argsresult, find_variable($1), find_variable($2)); }
6052-
| CVARIABLE
6052+
| cvariable
60536053
{ add_variable_to_head(&argsresult, find_variable($1), &no_indicator); }
60546054
;
60556055

60566056

6057-
civarind: CVARIABLE indicator
6057+
civarind: cvariable indicator
60586058
{
60596059
if (find_variable($2)->type->type == ECPGt_array)
60606060
mmerror(PARSE_ERROR, ET_ERROR, "arrays of indicators are not allowed on input");
@@ -6064,18 +6064,47 @@ civarind: CVARIABLE indicator
60646064
}
60656065
;
60666066

6067-
civar: CVARIABLE
6067+
civar: cvariable
60686068
{
60696069
add_variable_to_head(&argsinsert, find_variable($1), &no_indicator);
60706070
$$ = create_questionmarks($1, false);
60716071
}
60726072
;
60736073

6074-
indicator: CVARIABLE { check_indicator((find_variable($1))->type); $$ = $1; }
6075-
| SQL_INDICATOR CVARIABLE { check_indicator((find_variable($2))->type); $$ = $2; }
6074+
indicator: cvariable { check_indicator((find_variable($1))->type); $$ = $1; }
6075+
| SQL_INDICATOR cvariable { check_indicator((find_variable($2))->type); $$ = $2; }
60766076
| SQL_INDICATOR name { check_indicator((find_variable($2))->type); $$ = $2; }
60776077
;
60786078

6079+
cvariable: CVARIABLE
6080+
{
6081+
/* As long as multidimensional arrays are not implemented we have to check for those here */
6082+
char *ptr = $1;
6083+
int brace_open=0, brace = false;
6084+
6085+
for (; *ptr; ptr++)
6086+
{
6087+
switch (*ptr)
6088+
{
6089+
case '[': if (brace)
6090+
{
6091+
mmerror(PARSE_ERROR, ET_FATAL, "No multidimensional array support for simple data types");
6092+
}
6093+
brace_open++;
6094+
break;
6095+
case ']': brace_open--;
6096+
if (brace_open == 0) brace = true;
6097+
break;
6098+
case '\t':
6099+
case ' ': break;
6100+
default: if (brace_open == 0) brace = false;
6101+
break;
6102+
}
6103+
}
6104+
6105+
$$ = $1;
6106+
}
6107+
;
60796108
ident: IDENT { $$ = $1; }
60806109
| CSTRING { $$ = make3_str(make_str("\""), $1, make_str("\"")); }
60816110
;

src/interfaces/ecpg/preproc/variable.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ find_variable(char *name)
218218
{
219219
/*
220220
* We don't care about what's inside the array braces so just
221-
* eat up the character
221+
* eat up the characters
222222
*/
223223
for (count = 1, end = next + 1; count; end++)
224224
{
@@ -242,6 +242,11 @@ find_variable(char *name)
242242

243243
*next = '\0';
244244
p = find_simple(name);
245+
if (p == NULL)
246+
{
247+
snprintf(errortext, sizeof(errortext), "The variable %s is not declared", name);
248+
mmerror(PARSE_ERROR, ET_FATAL, errortext);
249+
}
245250
*next = c;
246251
switch (p->type->u.element->type)
247252
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy