aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-11-23 22:45:46 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2013-11-23 22:46:11 -0500
commit8bf45ea8ba1d04e3df20a288e58c5f45fc54d1e6 (patch)
treedc6e72051e52de647efe105d1fd975f9223f2fec
parent7b63528750a4a69875b75552f136947fa05aa1c9 (diff)
downloadpostgresql-8bf45ea8ba1d04e3df20a288e58c5f45fc54d1e6.tar.gz
postgresql-8bf45ea8ba1d04e3df20a288e58c5f45fc54d1e6.zip
Defend against bad trigger definitions in contrib/lo's lo_manage() trigger.
This function formerly crashed if called as a statement-level trigger, or if a column-name argument wasn't given. In passing, add the trigger name to all error messages from the function. (None of them are expected cases, so this shouldn't pose any compatibility risk.) Marc Cousin, reviewed by Sawada Masahiko
-rw-r--r--contrib/lo/lo.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/contrib/lo/lo.c b/contrib/lo/lo.c
index 0e3559c0201..f3656d8f883 100644
--- a/contrib/lo/lo.c
+++ b/contrib/lo/lo.c
@@ -44,7 +44,12 @@ lo_manage(PG_FUNCTION_ARGS)
HeapTuple trigtuple; /* The original value of tuple */
if (!CALLED_AS_TRIGGER(fcinfo)) /* internal error */
- elog(ERROR, "not fired by trigger manager");
+ elog(ERROR, "%s: not fired by trigger manager",
+ trigdata->tg_trigger->tgname);
+
+ if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) /* internal error */
+ elog(ERROR, "%s: must be fired for row",
+ trigdata->tg_trigger->tgname);
/*
* Fetch some values from trigdata
@@ -54,6 +59,10 @@ lo_manage(PG_FUNCTION_ARGS)
tupdesc = trigdata->tg_relation->rd_att;
args = trigdata->tg_trigger->tgargs;
+ if (args == NULL) /* internal error */
+ elog(ERROR, "%s: no column name provided in the trigger definition",
+ trigdata->tg_trigger->tgname);
+
/* tuple to return to Executor */
if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
rettuple = newtuple;
@@ -67,7 +76,8 @@ lo_manage(PG_FUNCTION_ARGS)
attnum = SPI_fnumber(tupdesc, args[0]);
if (attnum <= 0)
- elog(ERROR, "column \"%s\" does not exist", args[0]);
+ elog(ERROR, "%s: column \"%s\" does not exist",
+ trigdata->tg_trigger->tgname, args[0]);
/*
* Handle updates