summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2020-04-03 15:24:56 +0000
committerTom Lane2020-04-03 15:24:56 +0000
commit6dd9f357792545b626e28b2e1f73cb4c32c437f1 (patch)
tree809a34ce755e1ace0632fa1394d1ca37fbdd705f
parent19db23bcbda99e93321cb0636677ec9c6e121a2a (diff)
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/[email protected]
-rw-r--r--contrib/lo/lo.c3
-rw-r--r--src/backend/commands/constraint.c2
2 files changed, 2 insertions, 3 deletions
diff --git a/contrib/lo/lo.c b/contrib/lo/lo.c
index b9847081db6..457be26c4ed 100644
--- a/contrib/lo/lo.c
+++ b/contrib/lo/lo.c
@@ -33,8 +33,7 @@ lo_manage(PG_FUNCTION_ARGS)
HeapTuple trigtuple; /* The original value of tuple */
if (!CALLED_AS_TRIGGER(fcinfo)) /* internal error */
- elog(ERROR, "%s: not fired by trigger manager",
- trigdata->tg_trigger->tgname);
+ elog(ERROR, "lo_manage: not fired by trigger manager");
if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) /* internal error */
elog(ERROR, "%s: must be fired for row",
diff --git a/src/backend/commands/constraint.c b/src/backend/commands/constraint.c
index 20dee119099..fc19307bf2f 100644
--- a/src/backend/commands/constraint.c
+++ b/src/backend/commands/constraint.c
@@ -40,7 +40,7 @@
Datum
unique_key_recheck(PG_FUNCTION_ARGS)
{
- TriggerData *trigdata = castNode(TriggerData, fcinfo->context);
+ TriggerData *trigdata = (TriggerData *) fcinfo->context;
const char *funcname = "unique_key_recheck";
ItemPointerData checktid;
ItemPointerData tmptid;