From: Tom Lane <tgl@sss.pgh.pa.us>
To: Marko Tiikkaja <pgmail@joh.to>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #7516: PL/Perl crash
Date: Sun, 09 Sep 2012 17:32:00 -0400
Message-ID: <16153.1347226320@sss.pgh.pa.us> (raw)
In-Reply-To: <5047BA9C.2040405@joh.to>
References: <E1T8YUZ-0006gb-Oz@wrigleys.postgresql.org>
<1194.1346688396@sss.pgh.pa.us>
<5047BA9C.2040405@joh.to>
Marko Tiikkaja <pgmail@joh.to> writes:
> On 03/09/2012 18:06, Tom Lane wrote:
>> Hm. Is it possible that the prepared statement recursively called the
>> *same* plperl function? And that somebody did a CREATE OR REPLACE on
>> that function meanwhile?
> No, that doesn't seem possible in this case. The function calls some
> prepared statements repeatedly, but no recursion should occur.
Hm. Well, I can definitely reproduce a segfault using this example:
CREATE OR REPLACE FUNCTION self_modify(INTEGER) RETURNS INTEGER AS $$
spi_exec_query('CREATE OR REPLACE FUNCTION self_modify(INTEGER) RETURNS INTEGER AS \'return $_[0] * 3;\' LANGUAGE plperl;');
spi_exec_query('select self_modify(42) AS a');
return $_[0] * 2;
$$ LANGUAGE plperl;
select self_modify(42);
The crash is 100% reproducible if you tweak plperl like this:
inline patch 1: src/pl/plperl/plperl.c (+1/-1 lines) download inline-1.patchdiff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.cindex bfa805d..307874c 100644--- a/src/pl/plperl/plperl.c+++ b/src/pl/plperl/plperl.c@@ -2393,7 +2393,7 @@ validate_plperl_function(plperl_proc_ptr *proc_ptr, HeapTu
activate_interpreter(oldinterp);
}
free(prodesc->proname);
- free(prodesc);+ memset(prodesc, 0, sizeof(plperl_proc_desc));
}
return false;
Without that it's probabilistic, since the subsequent malloc in
compile_plperl_function is likely to realloc the exact same space.
So I think we need to institute a reference counting scheme for
the plperl_proc_desc records ...
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, pgmail@joh.to
Subject: Re: BUG #7516: PL/Perl crash
In-Reply-To: <16153.1347226320@sss.pgh.pa.us>
References: <E1T8YUZ-0006gb-Oz@wrigleys.postgresql.org> <1194.1346688396@sss.pgh.pa.us> <5047BA9C.2040405@joh.to> <16153.1347226320@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox