Skip to content

Commit dcb7d3c

Browse files
committed
Have LookupFuncName accept NULL argtypes for 0 args
Prior to this change, it requires to be passed a valid pointer just to be able to pass it to a zero-byte memcmp, per 0a52d37. Given the strange resulting code in callsites, it seems better to test for the case specifically and remove the requirement. Reported-by: Ranier Vilela Discussion: https://postgr.es/m/MN2PR18MB2927F24692485D754794F01BE3740@MN2PR18MB2927.namprd18.prod.outlook.com Discussion: https://postgr.es/m/MN2PR18MB2927F6873DF2774A505AC298E3740@MN2PR18MB2927.namprd18.prod.outlook.com
1 parent 8c95168 commit dcb7d3c

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

src/backend/commands/event_trigger.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ CreateEventTrigger(CreateEventTrigStmt *stmt)
171171
HeapTuple tuple;
172172
Oid funcoid;
173173
Oid funcrettype;
174-
Oid fargtypes[1]; /* dummy */
175174
Oid evtowner = GetUserId();
176175
ListCell *lc;
177176
List *tags = NULL;
@@ -237,7 +236,7 @@ CreateEventTrigger(CreateEventTrigStmt *stmt)
237236
stmt->trigname)));
238237

239238
/* Find and validate the trigger function. */
240-
funcoid = LookupFuncName(stmt->funcname, 0, fargtypes, false);
239+
funcoid = LookupFuncName(stmt->funcname, 0, NULL, false);
241240
funcrettype = get_func_rettype(funcoid);
242241
if (funcrettype != EVTTRIGGEROID)
243242
ereport(ERROR,

src/backend/commands/foreigncmds.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,12 @@ static Oid
475475
lookup_fdw_handler_func(DefElem *handler)
476476
{
477477
Oid handlerOid;
478-
Oid funcargtypes[1]; /* dummy */
479478

480479
if (handler == NULL || handler->arg == NULL)
481480
return InvalidOid;
482481

483482
/* handlers have no arguments */
484-
handlerOid = LookupFuncName((List *) handler->arg, 0, funcargtypes, false);
483+
handlerOid = LookupFuncName((List *) handler->arg, 0, NULL, false);
485484

486485
/* check that handler has correct return type */
487486
if (get_func_rettype(handlerOid) != FDW_HANDLEROID)

src/backend/commands/proclang.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
105105
* return type.
106106
*/
107107
funcname = SystemFuncName(pltemplate->tmplhandler);
108-
handlerOid = LookupFuncName(funcname, 0, funcargtypes, true);
108+
handlerOid = LookupFuncName(funcname, 0, NULL, true);
109109
if (OidIsValid(handlerOid))
110110
{
111111
funcrettype = get_func_rettype(handlerOid);
@@ -263,7 +263,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
263263
* Lookup the PL handler function and check that it is of the expected
264264
* return type
265265
*/
266-
handlerOid = LookupFuncName(stmt->plhandler, 0, funcargtypes, false);
266+
handlerOid = LookupFuncName(stmt->plhandler, 0, NULL, false);
267267
funcrettype = get_func_rettype(handlerOid);
268268
if (funcrettype != LANGUAGE_HANDLEROID)
269269
{

src/backend/commands/trigger.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
179179
ScanKeyData key;
180180
Relation pgrel;
181181
HeapTuple tuple;
182-
Oid fargtypes[1]; /* dummy */
183182
Oid funcrettype;
184183
Oid trigoid;
185184
char internaltrigname[NAMEDATALEN];
@@ -690,7 +689,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
690689
* Find and validate the trigger function.
691690
*/
692691
if (!OidIsValid(funcoid))
693-
funcoid = LookupFuncName(stmt->funcname, 0, fargtypes, false);
692+
funcoid = LookupFuncName(stmt->funcname, 0, NULL, false);
694693
if (!isInternal)
695694
{
696695
aclresult = pg_proc_aclcheck(funcoid, GetUserId(), ACL_EXECUTE);

src/backend/parser/parse_func.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -2035,8 +2035,8 @@ LookupFuncNameInternal(List *funcname, int nargs, const Oid *argtypes,
20352035
{
20362036
FuncCandidateList clist;
20372037

2038-
/* Passing NULL for argtypes is no longer allowed */
2039-
Assert(argtypes);
2038+
/* NULL argtypes allowed for nullary functions only */
2039+
Assert(argtypes != NULL || nargs == 0);
20402040

20412041
/* Always set *lookupError, to forestall uninitialized-variable warnings */
20422042
*lookupError = FUNCLOOKUP_NOSUCHFUNC;
@@ -2070,7 +2070,9 @@ LookupFuncNameInternal(List *funcname, int nargs, const Oid *argtypes,
20702070
*/
20712071
while (clist)
20722072
{
2073-
if (memcmp(argtypes, clist->args, nargs * sizeof(Oid)) == 0)
2073+
/* if nargs==0, argtypes can be null; don't pass that to memcmp */
2074+
if (nargs == 0 ||
2075+
memcmp(argtypes, clist->args, nargs * sizeof(Oid)) == 0)
20742076
return clist->oid;
20752077
clist = clist->next;
20762078
}

src/pl/tcl/pltcl.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ call_pltcl_start_proc(Oid prolang, bool pltrusted)
592592
const char *gucname;
593593
ErrorContextCallback errcallback;
594594
List *namelist;
595-
Oid fargtypes[1]; /* dummy */
596595
Oid procOid;
597596
HeapTuple procTup;
598597
Form_pg_proc procStruct;
@@ -616,7 +615,7 @@ call_pltcl_start_proc(Oid prolang, bool pltrusted)
616615

617616
/* Parse possibly-qualified identifier and look up the function */
618617
namelist = stringToQualifiedNameList(start_proc);
619-
procOid = LookupFuncName(namelist, 0, fargtypes, false);
618+
procOid = LookupFuncName(namelist, 0, NULL, false);
620619

621620
/* Current user must have permission to call function */
622621
aclresult = pg_proc_aclcheck(procOid, GetUserId(), ACL_EXECUTE);

0 commit comments

Comments
 (0)