plpython crash on exception - Mailing list pgsql-patches

From Marko Kreen
Subject plpython crash on exception
Date
Msg-id e51f66da0711220416p60b150fek237fca7384cb6e3@mail.gmail.com
Whole thread Raw
Responses Re: plpython crash on exception
Re: plpython crash on exception
List 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

pgsql-patches by date:

Previous
From: Simon Riggs
Date:
Subject: [Fwd: Re: [HACKERS] Postgres 8.3 archive_command]
Next
From: Gregory Stark
Date:
Subject: Ordered Append WIP patch v1