Re: pg_trigger.tgargs needs detoast

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Kenji Kawamura <kawamura(dot)kenji(at)oss(dot)ntt(dot)co(dot)jp>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_trigger.tgargs needs detoast
Date: 2007-01-19 18:06:10
Message-ID: 200701191806.l0JI6Ag14462@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------

Kenji Kawamura wrote:
> 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
>

> Index: src/backend/commands/tablecmds.c
> ===================================================================
> --- src/backend/commands/tablecmds.c (HEAD)
> +++ src/backend/commands/tablecmds.c (modified)
> @@ -1800,8 +1800,7 @@
> * line; so does trigger.c ...
> */
> tgnargs = pg_trigger->tgnargs;
> - val = (bytea *)
> - DatumGetPointer(fastgetattr(tuple,
> + val = DatumGetByteaP(fastgetattr(tuple,
> Anum_pg_trigger_tgargs,
> tgrel->rd_att, &isnull));
> if (isnull || tgnargs < RI_FIRST_ATTNAME_ARGNO ||
> Index: src/backend/commands/trigger.c
> ===================================================================
> --- src/backend/commands/trigger.c (HEAD)
> +++ src/backend/commands/trigger.c (modified)
> @@ -906,8 +906,7 @@
> char *p;
> int i;
>
> - val = (bytea *)
> - DatumGetPointer(fastgetattr(htup,
> + val = DatumGetByteaP(fastgetattr(htup,
> Anum_pg_trigger_tgargs,
> tgrel->rd_att, &isnull));
> if (isnull)
> Index: src/backend/utils/adt/ruleutils.c
> ===================================================================
> --- src/backend/utils/adt/ruleutils.c (HEAD)
> +++ src/backend/utils/adt/ruleutils.c (modified)
> @@ -521,8 +521,7 @@
> char *p;
> int i;
>
> - val = (bytea *)
> - DatumGetPointer(fastgetattr(ht_trig,
> + val = DatumGetByteaP(fastgetattr(ht_trig,
> Anum_pg_trigger_tgargs,
> tgrel->rd_att, &isnull));
> if (isnull)

>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
> http://www.postgresql.org/about/donate

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2007-01-19 18:12:27 Re: Planning aggregates which require sorted or distinct input
Previous Message FAST PostgreSQL 2007-01-19 17:44:51 Re: pg_get_domaindef