pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
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:57 +0000
Message-ID: <E1xQQFx-000000003b1-26SF@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
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5215e9d6a13955c949bfe07b643927b733bd0033
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                | 84 +++++++++++++++++++++++++++++++----
3 files changed, 106 insertions(+), 9 deletions(-)



view thread (3+ messages)

Message-ID: <E1xQQFx-000000003b1-26SF@gemulon.postgresql.org>
Permalink:  ../E1xQQFx-000000003b1-26SF@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xQQFx-000000003b1-26SF@gemulon.postgresql.org

 · 

reply

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: <E1xQQFx-000000003b1-26SF@gemulon.postgresql.org>
  References: <E1xQQFx-000000003b1-26SF@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