Re: function returning a row - Mailing list pgsql-novice

From Tom Lane
Subject Re: function returning a row
Date
Msg-id 20648.1107192211@sss.pgh.pa.us
Whole thread Raw
In response to Re: function returning a row  (Kjetil Haaland <kjetil.haaland@student.uib.no>)
Responses Re: function returning a row  (Kjetil Haaland <kjetil.haaland@student.uib.no>)
List pgsql-novice
Kjetil Haaland <kjetil.haaland@student.uib.no> writes:
>     text *intext = PG_GETARG_TEXT_P(0);
>     text *smltext = PG_GETARG_TEXT_P(1);
>     in = (char*)palloc(VARSIZE(intext)-VARHDRSZ+1);
>     sml = (char*)palloc(VARSIZE(smltext)-VARHDRSZ+1);
>     snprintf (in, VARSIZE(intext) - VARHDRSZ + 1, VARDATA(intext));
>     snprintf (sml, VARSIZE(smltext) - VARHDRSZ + 1, VARDATA(smltext));

I'm not sure what you think the above snprintf's are going to do, but
it seems certain to be bad.  The "format string" you are passing is
neither null-terminated nor guaranteed to be free of %'s.

memcpy would be safer; and of course you need to explicitly append a
null byte afterwards.

            regards, tom lane

pgsql-novice by date:

Previous
From: Kjetil Haaland
Date:
Subject: Re: function returning a row
Next
From: "Van Ingen, Lane"
Date:
Subject: Date / Time Data Type