From: Noah Misch <noah@leadboat.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Hold a reference on a Perl array or hash while scanning it.
Date: Mon, 09 Nov 2026 14:21:48 +0000
Message-ID: <E1xQQFo-000000003G3-0dbL@gemulon.postgresql.org> (raw)
Hold a reference on a Perl array or hash while scanning it.
Previously we assumed that the object would stick around while we
examined it, but there are a few ways that the last refcount could get
dropped meanwhile, allowing the object to be recycled and creating a
use-after-free hazard. To prevent that, we must acquire our own
refcount and release it when we're done. The tricky part is to ensure
that the refcount gets released if an error is thrown partway through.
A TRY/FINALLY block would work, but that answer would be expensive
and notationally invasive. The method used here is to push a
refcount-carrying RV onto Perl's temporaries stack so that temporaries
cleanup will release the reference. A simple benchmark suggests that
that adds just a couple percent of overhead, which seems acceptable.
The first draft of this patch was created by Anthropic's OSS program.
Reported-by: Anthropic OSS program
Author: Tom Lane <tgl@sss.pgh.pa.us>
Co-authored-by: Anthropic OSS program
Backpatch-through: 14
Security: CVE-2026-116320
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/bcb007a721371dfebaa20b5250784b896a33304f
Author: Tom Lane <tgl@sss.pgh.pa.us>
Modified Files
--------------
contrib/hstore_plperl/hstore_plperl.c | 9 ++++
contrib/jsonb_plperl/jsonb_plperl.c | 22 +++++++++-
src/pl/plperl/plperl.c | 83 ++++++++++++++++++++++++++++++++---
3 files changed, 106 insertions(+), 8 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: Hold a reference on a Perl array or hash while scanning it.
In-Reply-To: <E1xQQFo-000000003G3-0dbL@gemulon.postgresql.org>
References: <E1xQQFo-000000003G3-0dbL@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