7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.46 1999/05/25 16:10:17 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.47 1999/06/17 22:21:40 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -83,8 +83,6 @@ static Oid agg_select_candidate(Oid typeid, CandidateList candidates);
83
83
84
84
#define ISCOMPLEX (type ) (typeidTypeRelid(type) ? true : false)
85
85
86
- #define MAXFARGS 8 /* max # args to a c or postquel function */
87
-
88
86
typedef struct _SuperQE
89
87
{
90
88
Oid sqe_relid ;
@@ -241,9 +239,9 @@ Node *
241
239
ParseFuncOrColumn (ParseState * pstate , char * funcname , List * fargs ,
242
240
int * curr_resno , int precedence )
243
241
{
244
- Oid rettype = ( Oid ) 0 ;
245
- Oid argrelid = ( Oid ) 0 ;
246
- Oid funcid = ( Oid ) 0 ;
242
+ Oid rettype = InvalidOid ;
243
+ Oid argrelid = InvalidOid ;
244
+ Oid funcid = InvalidOid ;
247
245
List * i = NIL ;
248
246
Node * first_arg = NULL ;
249
247
char * relname = NULL ;
@@ -252,12 +250,12 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
252
250
Oid relid ;
253
251
int nargs ;
254
252
Func * funcnode ;
255
- Oid oid_array [8 ];
253
+ Oid oid_array [MAXFARGS ];
256
254
Oid * true_oid_array ;
257
255
Node * retval ;
258
256
bool retset ;
259
257
bool attisset = false;
260
- Oid toid = ( Oid ) 0 ;
258
+ Oid toid = InvalidOid ;
261
259
Expr * expr ;
262
260
263
261
if (fargs )
@@ -425,7 +423,7 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
425
423
* transform relation name arguments into varnodes of the appropriate
426
424
* form.
427
425
*/
428
- MemSet (& oid_array [ 0 ] , 0 , 8 * sizeof (Oid ));
426
+ MemSet (oid_array , 0 , MAXFARGS * sizeof (Oid ));
429
427
430
428
nargs = 0 ;
431
429
foreach (i , fargs )
@@ -477,6 +475,14 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
477
475
toid = exprType (pair );
478
476
}
479
477
478
+ /* Most of the rest of the parser just assumes that functions do not
479
+ * have more than MAXFARGS parameters. We have to test here to protect
480
+ * against array overruns, etc.
481
+ */
482
+ if (nargs >= MAXFARGS )
483
+ elog (ERROR , "Cannot pass more than %d arguments to a function" ,
484
+ MAXFARGS );
485
+
480
486
oid_array [nargs ++ ] = toid ;
481
487
}
482
488
@@ -638,7 +644,7 @@ static Oid
638
644
funcid_get_rettype (Oid funcid )
639
645
{
640
646
HeapTuple func_tuple = NULL ;
641
- Oid funcrettype = ( Oid ) 0 ;
647
+ Oid funcrettype = InvalidOid ;
642
648
643
649
func_tuple = SearchSysCacheTuple (PROOID ,
644
650
ObjectIdGetDatum (funcid ),
@@ -701,8 +707,8 @@ func_get_candidates(char *funcname, int nargs)
701
707
current_candidate = (CandidateList )
702
708
palloc (sizeof (struct _CandidateList ));
703
709
current_candidate -> args = (Oid * )
704
- palloc (8 * sizeof (Oid ));
705
- MemSet (current_candidate -> args , 0 , 8 * sizeof (Oid ));
710
+ palloc (MAXFARGS * sizeof (Oid ));
711
+ MemSet (current_candidate -> args , 0 , MAXFARGS * sizeof (Oid ));
706
712
for (i = 0 ; i < nargs ; i ++ )
707
713
current_candidate -> args [i ] = pgProcP -> proargtypes [i ];
708
714
@@ -1337,7 +1343,7 @@ setup_tlist(char *attname, Oid relid)
1337
1343
type_mod ,
1338
1344
get_attname (relid , attno ),
1339
1345
0 ,
1340
- ( Oid ) 0 ,
1346
+ InvalidOid ,
1341
1347
false);
1342
1348
varnode = makeVar (-1 , attno , typeid , type_mod , 0 , -1 , attno );
1343
1349
@@ -1362,7 +1368,7 @@ setup_base_tlist(Oid typeid)
1362
1368
-1 ,
1363
1369
"<noname>" ,
1364
1370
0 ,
1365
- ( Oid ) 0 ,
1371
+ InvalidOid ,
1366
1372
false);
1367
1373
varnode = makeVar (-1 , 1 , typeid , -1 , 0 , -1 , 1 );
1368
1374
tle = makeTargetEntry (resnode , (Node * ) varnode );
0 commit comments