summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane2008-10-09 16:35:33 +0000
committerTom Lane2008-10-09 16:35:33 +0000
commit603ce026546552747ef8ee165a49de4d10380527 (patch)
treebabc1da177bfaf8b254148d4b8376ef4f634845a /src
parentcb0a4fed984ebedd060d5bcf2c683ba3b4ab85f6 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/pl/plpgsql/src/pl_comp.c7
-rw-r--r--src/pl/plpgsql/src/plpgsql.h6
2 files changed, 10 insertions, 3 deletions
diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c
index 8c9f6483234..63f0e1b77b3 100644
--- a/src/pl/plpgsql/src/pl_comp.c
+++ b/src/pl/plpgsql/src/pl_comp.c
@@ -3,7 +3,7 @@
* procedural language
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.83.4.1 2007/02/08 18:38:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.83.4.2 2008/10/09 16:35:33 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -1880,12 +1880,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 b38b08bce4b..994b1787db3 100644
--- a/src/pl/plpgsql/src/plpgsql.h
+++ b/src/pl/plpgsql/src/plpgsql.h
@@ -3,7 +3,7 @@
* procedural language
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.56 2004/09/16 16:58:44 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.56.4.1 2008/10/09 16:35:33 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -552,6 +552,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