Fix bogus CALLED_AS_TRIGGER() defenses.
authorTom Lane <[email protected]>
Fri, 3 Apr 2020 15:24:56 +0000 (11:24 -0400)
committerTom Lane <[email protected]>
Fri, 3 Apr 2020 15:24:56 +0000 (11:24 -0400)
commit85f0d470380902c8c62d0165c349c82d81c3e056
tree62af8a3e5fc194c7a9b4094ee9a785d47ec72e88
parentde7561f7d87df7dff8c6b29ac0d6435795d42372
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
contrib/lo/lo.c
src/backend/commands/constraint.c