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 0a52d378b0
. 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
This commit is contained in:
parent
8c951687f5
commit
dcb7d3cafa
|
@ -171,7 +171,6 @@ CreateEventTrigger(CreateEventTrigStmt *stmt)
|
||||||
HeapTuple tuple;
|
HeapTuple tuple;
|
||||||
Oid funcoid;
|
Oid funcoid;
|
||||||
Oid funcrettype;
|
Oid funcrettype;
|
||||||
Oid fargtypes[1]; /* dummy */
|
|
||||||
Oid evtowner = GetUserId();
|
Oid evtowner = GetUserId();
|
||||||
ListCell *lc;
|
ListCell *lc;
|
||||||
List *tags = NULL;
|
List *tags = NULL;
|
||||||
|
@ -237,7 +236,7 @@ CreateEventTrigger(CreateEventTrigStmt *stmt)
|
||||||
stmt->trigname)));
|
stmt->trigname)));
|
||||||
|
|
||||||
/* Find and validate the trigger function. */
|
/* Find and validate the trigger function. */
|
||||||
funcoid = LookupFuncName(stmt->funcname, 0, fargtypes, false);
|
funcoid = LookupFuncName(stmt->funcname, 0, NULL, false);
|
||||||
funcrettype = get_func_rettype(funcoid);
|
funcrettype = get_func_rettype(funcoid);
|
||||||
if (funcrettype != EVTTRIGGEROID)
|
if (funcrettype != EVTTRIGGEROID)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
|
|
|
@ -475,13 +475,12 @@ static Oid
|
||||||
lookup_fdw_handler_func(DefElem *handler)
|
lookup_fdw_handler_func(DefElem *handler)
|
||||||
{
|
{
|
||||||
Oid handlerOid;
|
Oid handlerOid;
|
||||||
Oid funcargtypes[1]; /* dummy */
|
|
||||||
|
|
||||||
if (handler == NULL || handler->arg == NULL)
|
if (handler == NULL || handler->arg == NULL)
|
||||||
return InvalidOid;
|
return InvalidOid;
|
||||||
|
|
||||||
/* handlers have no arguments */
|
/* handlers have no arguments */
|
||||||
handlerOid = LookupFuncName((List *) handler->arg, 0, funcargtypes, false);
|
handlerOid = LookupFuncName((List *) handler->arg, 0, NULL, false);
|
||||||
|
|
||||||
/* check that handler has correct return type */
|
/* check that handler has correct return type */
|
||||||
if (get_func_rettype(handlerOid) != FDW_HANDLEROID)
|
if (get_func_rettype(handlerOid) != FDW_HANDLEROID)
|
||||||
|
|
|
@ -105,7 +105,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||||
* return type.
|
* return type.
|
||||||
*/
|
*/
|
||||||
funcname = SystemFuncName(pltemplate->tmplhandler);
|
funcname = SystemFuncName(pltemplate->tmplhandler);
|
||||||
handlerOid = LookupFuncName(funcname, 0, funcargtypes, true);
|
handlerOid = LookupFuncName(funcname, 0, NULL, true);
|
||||||
if (OidIsValid(handlerOid))
|
if (OidIsValid(handlerOid))
|
||||||
{
|
{
|
||||||
funcrettype = get_func_rettype(handlerOid);
|
funcrettype = get_func_rettype(handlerOid);
|
||||||
|
@ -263,7 +263,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||||
* Lookup the PL handler function and check that it is of the expected
|
* Lookup the PL handler function and check that it is of the expected
|
||||||
* return type
|
* return type
|
||||||
*/
|
*/
|
||||||
handlerOid = LookupFuncName(stmt->plhandler, 0, funcargtypes, false);
|
handlerOid = LookupFuncName(stmt->plhandler, 0, NULL, false);
|
||||||
funcrettype = get_func_rettype(handlerOid);
|
funcrettype = get_func_rettype(handlerOid);
|
||||||
if (funcrettype != LANGUAGE_HANDLEROID)
|
if (funcrettype != LANGUAGE_HANDLEROID)
|
||||||
{
|
{
|
||||||
|
|
|
@ -179,7 +179,6 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
|
||||||
ScanKeyData key;
|
ScanKeyData key;
|
||||||
Relation pgrel;
|
Relation pgrel;
|
||||||
HeapTuple tuple;
|
HeapTuple tuple;
|
||||||
Oid fargtypes[1]; /* dummy */
|
|
||||||
Oid funcrettype;
|
Oid funcrettype;
|
||||||
Oid trigoid;
|
Oid trigoid;
|
||||||
char internaltrigname[NAMEDATALEN];
|
char internaltrigname[NAMEDATALEN];
|
||||||
|
@ -690,7 +689,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
|
||||||
* Find and validate the trigger function.
|
* Find and validate the trigger function.
|
||||||
*/
|
*/
|
||||||
if (!OidIsValid(funcoid))
|
if (!OidIsValid(funcoid))
|
||||||
funcoid = LookupFuncName(stmt->funcname, 0, fargtypes, false);
|
funcoid = LookupFuncName(stmt->funcname, 0, NULL, false);
|
||||||
if (!isInternal)
|
if (!isInternal)
|
||||||
{
|
{
|
||||||
aclresult = pg_proc_aclcheck(funcoid, GetUserId(), ACL_EXECUTE);
|
aclresult = pg_proc_aclcheck(funcoid, GetUserId(), ACL_EXECUTE);
|
||||||
|
|
|
@ -2035,8 +2035,8 @@ LookupFuncNameInternal(List *funcname, int nargs, const Oid *argtypes,
|
||||||
{
|
{
|
||||||
FuncCandidateList clist;
|
FuncCandidateList clist;
|
||||||
|
|
||||||
/* Passing NULL for argtypes is no longer allowed */
|
/* NULL argtypes allowed for nullary functions only */
|
||||||
Assert(argtypes);
|
Assert(argtypes != NULL || nargs == 0);
|
||||||
|
|
||||||
/* Always set *lookupError, to forestall uninitialized-variable warnings */
|
/* Always set *lookupError, to forestall uninitialized-variable warnings */
|
||||||
*lookupError = FUNCLOOKUP_NOSUCHFUNC;
|
*lookupError = FUNCLOOKUP_NOSUCHFUNC;
|
||||||
|
@ -2070,7 +2070,9 @@ LookupFuncNameInternal(List *funcname, int nargs, const Oid *argtypes,
|
||||||
*/
|
*/
|
||||||
while (clist)
|
while (clist)
|
||||||
{
|
{
|
||||||
if (memcmp(argtypes, clist->args, nargs * sizeof(Oid)) == 0)
|
/* if nargs==0, argtypes can be null; don't pass that to memcmp */
|
||||||
|
if (nargs == 0 ||
|
||||||
|
memcmp(argtypes, clist->args, nargs * sizeof(Oid)) == 0)
|
||||||
return clist->oid;
|
return clist->oid;
|
||||||
clist = clist->next;
|
clist = clist->next;
|
||||||
}
|
}
|
||||||
|
|
|
@ -592,7 +592,6 @@ call_pltcl_start_proc(Oid prolang, bool pltrusted)
|
||||||
const char *gucname;
|
const char *gucname;
|
||||||
ErrorContextCallback errcallback;
|
ErrorContextCallback errcallback;
|
||||||
List *namelist;
|
List *namelist;
|
||||||
Oid fargtypes[1]; /* dummy */
|
|
||||||
Oid procOid;
|
Oid procOid;
|
||||||
HeapTuple procTup;
|
HeapTuple procTup;
|
||||||
Form_pg_proc procStruct;
|
Form_pg_proc procStruct;
|
||||||
|
@ -616,7 +615,7 @@ call_pltcl_start_proc(Oid prolang, bool pltrusted)
|
||||||
|
|
||||||
/* Parse possibly-qualified identifier and look up the function */
|
/* Parse possibly-qualified identifier and look up the function */
|
||||||
namelist = stringToQualifiedNameList(start_proc);
|
namelist = stringToQualifiedNameList(start_proc);
|
||||||
procOid = LookupFuncName(namelist, 0, fargtypes, false);
|
procOid = LookupFuncName(namelist, 0, NULL, false);
|
||||||
|
|
||||||
/* Current user must have permission to call function */
|
/* Current user must have permission to call function */
|
||||||
aclresult = pg_proc_aclcheck(procOid, GetUserId(), ACL_EXECUTE);
|
aclresult = pg_proc_aclcheck(procOid, GetUserId(), ACL_EXECUTE);
|
||||||
|
|
Loading…
Reference in New Issue