From 7063973ad6e0ef093d45d7a2a7cf15f09dd1d7af Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 9 Oct 2008 16:35:13 +0000 Subject: [PATCH] Fix overly tense optimization of PLpgSQL_func_hashkey: we must represent the isTrigger state explicitly, not rely on nonzero-ness of trigrelOid to indicate trigger-hood, because trigrelOid will be left zero when compiling for validation. The (useless) function hash entry built by the validator was able to match an ordinary non-trigger call later in the same session, thereby bypassing the check that is supposed to prevent such a call. Per report from Alvaro. It might be worth suppressing the useless hash entry altogether, but that's a bigger change than I want to consider back-patching. Back-patch to 8.0. 7.4 doesn't have the problem because it doesn't have validation mode. --- src/pl/plpgsql/src/pl_comp.c | 5 ++++- src/pl/plpgsql/src/plpgsql.h | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c index c6a01c9337..173658cc5e 100644 --- a/src/pl/plpgsql/src/pl_comp.c +++ b/src/pl/plpgsql/src/pl_comp.c @@ -1903,12 +1903,15 @@ compute_function_hashkey(FunctionCallInfo fcinfo, /* get function OID */ hashkey->funcOid = fcinfo->flinfo->fn_oid; + /* get call context */ + hashkey->isTrigger = CALLED_AS_TRIGGER(fcinfo); + /* * if trigger, get relation OID. In validation mode we do not know what * relation is intended to be used, so we leave trigrelOid zero; the hash * entry built in this case will never really be used. */ - if (CALLED_AS_TRIGGER(fcinfo) && !forValidator) + if (hashkey->isTrigger && !forValidator) { TriggerData *trigdata = (TriggerData *) fcinfo->context; diff --git a/src/pl/plpgsql/src/plpgsql.h b/src/pl/plpgsql/src/plpgsql.h index c5d0d89f83..ec1d524dcc 100644 --- a/src/pl/plpgsql/src/plpgsql.h +++ b/src/pl/plpgsql/src/plpgsql.h @@ -541,6 +541,10 @@ typedef struct PLpgSQL_func_hashkey { /* Hash lookup key for functions */ Oid funcOid; + bool isTrigger; /* true if called as a trigger */ + + /* be careful that pad bytes in this struct get zeroed! */ + /* * For a trigger function, the OID of the relation triggered on is part of * the hashkey --- we want to compile the trigger separately for each -- 2.39.5