Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix bogus CALLED_AS_TRIGGER() defenses.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 3 Apr 2020 15:24:56 +0000 (11:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 3 Apr 2020 15:24:56 +0000 (11:24 -0400)
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

contrib/lo/lo.c
src/backend/commands/constraint.c

index 4585923ee2b5aa257905a29ab9102dd50ec6daa1..2833dff7720de9edd0936aa0e49a24dc725103e5 100644 (file)
@@ -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",
index 806962a686bf2437ae1afdfa7d4be49f8ff5de77..ab888022e7828cd4c28c2cba7e549a222987a926 100644 (file)
@@ -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;