pg_trigger.tgargs needs detoast

Started by Kenji Kawamuraover 19 years ago1 messageshackers
Jump to latest
#1Kenji Kawamura
kawamura@intellilink.co.jp

Hello,

This patch fixes a bug of case of extraction of pg_trigger.tgargs.
There was a problem when we used a long argument in defining trigger,
possibly resulting in a server crash.

Example:

We defined a CREATE TRIGGER such as follows and registered trigger.
In this case, the argument value which we received in the trigger
procedure was not right.

CREATE TRIGGER trigger_test BEFORE INSERT OR UPDATE ON sample FOR EACH
ROW EXECUTE PROCEDURE sample_trig('XXX...(more than 1823 characters)');

The trigger procedure which receives the argument:

Datum sample_trig(PG_FUNCTION_ARGS)
{
TriggerData* trigdata = (TriggerData*)fcinfo->context;
char** args = trigdata->tg_trigger->tgargs;
int nargs = trigdata->tg_trigger->tgnargs;

int i;
for (i = 0; i < nargs; i++) {
elog(LOG, "%s", args[i]);
}
...
}

Result:

Before: LOG: (the character that is not right, for example '%')
After : LOG: XXX...(more than 1823 characters)

Regards,

---
Kenji Kawamura
NTT Open Source Center, Japan

Attachments:

detoast_pg_trigger_tgargs.patchtext/plain; name=detoast_pg_trigger_tgargs.patchDownload+3-6