Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0a52d37

Browse files
committed
Avoid passing NULL to memcmp() in lookups of zero-argument functions.
A few places assumed they could pass NULL for the argtypes array whenlooking up functions known to have zero arguments. At first glanceit seems that this should be safe enough, since memcmp() is surely notallowed to fetch any bytes if its count argument is zero. However,close reading of the C standard says that such calls have undefinedbehavior, so we'd probably best avoid it.Since the number of places doing this is quite small, and some otherplaces looking up zero-argument functions were already passing dummyarrays, let's standardize on the latter solution rather than hackingthe function lookup code to avoid calling memcmp() in these cases.I also added Asserts to catch any future violations of the new rule.Given the utter lack of any evidence that this actually causes anyproblems in the field, I don't feel a need to back-patch this change.Per report from Piotr Stefaniak, though this is not his patch.
1 parentd47a113 commit0a52d37

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

‎src/backend/commands/event_trigger.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ CreateEventTrigger(CreateEventTrigStmt *stmt)
165165
HeapTupletuple;
166166
Oidfuncoid;
167167
Oidfuncrettype;
168+
Oidfargtypes[1];/* dummy */
168169
Oidevtowner=GetUserId();
169170
ListCell*lc;
170171
List*tags=NULL;
@@ -230,7 +231,7 @@ CreateEventTrigger(CreateEventTrigStmt *stmt)
230231
stmt->trigname)));
231232

232233
/* Find and validate the trigger function. */
233-
funcoid=LookupFuncName(stmt->funcname,0,NULL, false);
234+
funcoid=LookupFuncName(stmt->funcname,0,fargtypes, false);
234235
funcrettype=get_func_rettype(funcoid);
235236
if (funcrettype!=EVTTRIGGEROID)
236237
ereport(ERROR,

‎src/backend/commands/foreigncmds.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,13 @@ static Oid
474474
lookup_fdw_handler_func(DefElem*handler)
475475
{
476476
OidhandlerOid;
477+
Oidfuncargtypes[1];/* dummy */
477478

478479
if (handler==NULL||handler->arg==NULL)
479480
returnInvalidOid;
480481

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

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

‎src/backend/parser/parse_func.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,9 @@ func_get_detail(List *funcname,
14151415
FuncCandidateListraw_candidates;
14161416
FuncCandidateListbest_candidate;
14171417

1418+
/* Passing NULL for argtypes is no longer allowed */
1419+
Assert(argtypes);
1420+
14181421
/* initialize output arguments to silence compiler warnings */
14191422
*funcid=InvalidOid;
14201423
*rettype=InvalidOid;
@@ -2043,6 +2046,9 @@ LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool noError)
20432046
{
20442047
FuncCandidateListclist;
20452048

2049+
/* Passing NULL for argtypes is no longer allowed */
2050+
Assert(argtypes);
2051+
20462052
clist=FuncnameGetCandidates(funcname,nargs,NIL, false, false,noError);
20472053

20482054
while (clist)

‎src/backend/utils/adt/ruleutils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
718718
SysScanDesctgscan;
719719
intfindx=0;
720720
char*tgname;
721+
Oidargtypes[1];/* dummy */
721722
Datumvalue;
722723
boolisnull;
723724

@@ -893,7 +894,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
893894

894895
appendStringInfo(&buf,"EXECUTE PROCEDURE %s(",
895896
generate_function_name(trigrec->tgfoid,0,
896-
NIL,NULL,
897+
NIL,argtypes,
897898
false,NULL,EXPR_KIND_NONE));
898899

899900
if (trigrec->tgnargs>0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp