Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6dd9f35

Browse files
committed
Fix bogus CALLED_AS_TRIGGER() defenses.
contrib/lo's lo_manage() thought it could use trigdata->tg_trigger->tgname in its error message about not being called as a trigger. That naturally led to a core dump. unique_key_recheck() figured it could Assert that fcinfo->context is a TriggerData node in advance of having checked that it's being called as a trigger. That's harmless in production builds, and perhaps not that easy to reach in any case, but it's logically wrong. The first of these per bug #16340 from William Crowell; the second from manual inspection of other CALLED_AS_TRIGGER call sites. Back-patch the lo.c change to all supported branches, the other to v10 where the thinko crept in. Discussion: https://postgr.es/m/16340-591c7449dc7c8c47@postgresql.org
1 parent 19db23b commit 6dd9f35

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

contrib/lo/lo.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ lo_manage(PG_FUNCTION_ARGS)
3333
HeapTuple trigtuple; /* The original value of tuple */
3434

3535
if (!CALLED_AS_TRIGGER(fcinfo)) /* internal error */
36-
elog(ERROR, "%s: not fired by trigger manager",
37-
trigdata->tg_trigger->tgname);
36+
elog(ERROR, "lo_manage: not fired by trigger manager");
3837

3938
if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) /* internal error */
4039
elog(ERROR, "%s: must be fired for row",

src/backend/commands/constraint.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
Datum
4141
unique_key_recheck(PG_FUNCTION_ARGS)
4242
{
43-
TriggerData *trigdata = castNode(TriggerData, fcinfo->context);
43+
TriggerData *trigdata = (TriggerData *) fcinfo->context;
4444
const char *funcname = "unique_key_recheck";
4545
ItemPointerData checktid;
4646
ItemPointerData tmptid;

0 commit comments

Comments
 (0)