plpython crash on exception

Поиск
Список
Период
Сортировка
От Marko Kreen
Тема plpython crash on exception
Дата
Msg-id e51f66da0711220416p60b150fek237fca7384cb6e3@mail.gmail.com
обсуждение исходный текст
Ответы Re: plpython crash on exception  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: plpython crash on exception  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Список 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

Вложения

В списке pgsql-patches по дате отправления:

Предыдущее
От: Simon Riggs
Дата:
Сообщение: [Fwd: Re: [HACKERS] Postgres 8.3 archive_command]
Следующее
От: Gregory Stark
Дата:
Сообщение: Ordered Append WIP patch v1