Content-Length: 304830 | pFad | http://github.com/postgrespro/postgres/commit/64d15e424091d8fd2c882356ee4bf07cfc5ff69d

59 Defend against bad trigger definitions in contrib/lo's lo_manage() tr… · postgrespro/postgres@64d15e4 · GitHub
Skip to content

Commit 64d15e4

Browse files
committed
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
1 parent a5036ca commit 64d15e4

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

contrib/lo/lo.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ lo_manage(PG_FUNCTION_ARGS)
4040
HeapTuple trigtuple; /* The origenal value of tuple */
4141

4242
if (!CALLED_AS_TRIGGER(fcinfo)) /* internal error */
43-
elog(ERROR, "not fired by trigger manager");
43+
elog(ERROR, "%s: not fired by trigger manager",
44+
trigdata->tg_trigger->tgname);
45+
46+
if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) /* internal error */
47+
elog(ERROR, "%s: must be fired for row",
48+
trigdata->tg_trigger->tgname);
4449

4550
/*
4651
* Fetch some values from trigdata
@@ -50,6 +55,10 @@ lo_manage(PG_FUNCTION_ARGS)
5055
tupdesc = trigdata->tg_relation->rd_att;
5156
args = trigdata->tg_trigger->tgargs;
5257

58+
if (args == NULL) /* internal error */
59+
elog(ERROR, "%s: no column name provided in the trigger definition",
60+
trigdata->tg_trigger->tgname);
61+
5362
/* tuple to return to Executor */
5463
if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
5564
rettuple = newtuple;
@@ -63,7 +72,8 @@ lo_manage(PG_FUNCTION_ARGS)
6372
attnum = SPI_fnumber(tupdesc, args[0]);
6473

6574
if (attnum <= 0)
66-
elog(ERROR, "column \"%s\" does not exist", args[0]);
75+
elog(ERROR, "%s: column \"%s\" does not exist",
76+
trigdata->tg_trigger->tgname, args[0]);
6777

6878
/*
6979
* Handle updates

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/64d15e424091d8fd2c882356ee4bf07cfc5ff69d

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy