pgsql: Hold a reference on a Perl array or hash while scanning it.

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Hold a reference on a Perl array or hash while scanning it.
Date: 2026-11-09 14:21:57
Message-ID: E1xQQFx-000000003b1-26SF@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)sss(dot)pgh(dot)pa(dot)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(at)sss(dot)pgh(dot)pa(dot)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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2026-11-09 14:21:58 pgsql: Handle composite type changes in ExecEvalFieldStore[De]Form
Previous Message Noah Misch 2026-11-09 14:21:56 pgsql: Add some very basic tests for make_expanded_record_from_datum()