plpython crash on exception

From: "Marko Kreen" <markokr(at)gmail(dot)com>
To: "Postgres Patches" <pgsql-patches(at)postgresql(dot)org>
Subject: plpython crash on exception
Date: 2007-11-22 12:16:26
Message-ID: e51f66da0711220416p60b150fek237fca7384cb6e3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Following function crashes plpython on x86-64 / gcc 4.1.2 / debian 4.0:

CREATE FUNCTION crashme(str_len integer)
RETURNS text AS $$
raise Exception("X" * str_len)
$$ LANGUAGE plpythonu;

SELECT crashme(1000);

Problem turns out to be va_list handling in PLy_vprintf() which
uses same va_list repeatedly. Fix is to va_copy to temp variable.

Additionally the atteched patch fixes 2 more problems in that function:

- its nonsensical to check existing buffer length for >0, instead the
function result should be checked. (which for vsnprintf() should
always be > 0, but maybe there are non-standard systems out there?)

- the * sizeof(char) in malloc() is pointless - even if we want to support
systems where sizeof(char) != 1, current code is wrong as from by reading
of manpage, vsnprintf() takes buffer length in bytes but returns chars,
so the 'blen' must be bytes anyway and the sizeof(char) must be in line:

blen = bchar + 1;

The function seems to be essentially same since 7.2 so the patch should
apply to all branches. If you prefer you can apply cleanups to HEAD only.

--
marko

Attachment Content-Type Size
plpy.vprintf.diff application/octet-stream 1.1 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Gregory Stark 2007-11-22 14:46:21 Ordered Append WIP patch v1
Previous Message Simon Riggs 2007-11-22 09:32:51 [Fwd: Re: [HACKERS] Postgres 8.3 archive_command]