From: Noah Misch <noah@leadboat.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: plperl: don't save and re-use temp context in return_next().
Date: Mon, 09 Nov 2026 14:21:52 +0000
Message-ID: <E1xQQFs-000000003QD-2yF5@gemulon.postgresql.org> (raw)
plperl: don't save and re-use temp context in return_next().
Commit ebdefb93b arranged to run plperl_return_next_internal()
in a temporary memory context that got reset at the end of each
call, so as not to accumulate lots of leaked memory in a PL/Perl
function that returns many rows. But this arrangement is unsafe
because re-entrant calls of return_next are possible, as shown
by the new regression test. In that case the inner call's reset
destroys data the outer call still needs, leading to crashes.
Instead, just create and delete a temp context for each call.
That works correctly in the nested case, and in the normal case
it's not really much slower than the old way thanks to the context
recycling logic in aset.c (which long postdates ebdefb93b, but is
in every still-supported branch).
Reported-by: Anthropic OSS program
Author: Anthropic OSS program
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Backpatch-through: 14
Security: CVE-2026-116319
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/e51917d91d2eaa992b9f68823420d93b64723476
Author: Tom Lane <tgl@sss.pgh.pa.us>
Modified Files
--------------
src/pl/plperl/expected/plperl_tied.out | 21 +++++++++++++++++++++
src/pl/plperl/plperl.c | 22 ++++++++++++----------
src/pl/plperl/sql/plperl_tied.sql | 17 +++++++++++++++++
3 files changed, 50 insertions(+), 10 deletions(-)
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-committers@postgresql.org
Cc: noah@leadboat.com
Subject: Re: pgsql: plperl: don't save and re-use temp context in return_next().
In-Reply-To: <E1xQQFs-000000003QD-2yF5@gemulon.postgresql.org>
References: <E1xQQFs-000000003QD-2yF5@gemulon.postgresql.org>
* 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