pgsql: Defend against null "SV *" pointers in plperl modules.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Defend against null "SV *" pointers in plperl modules.
Date: 2026-08-18 21:34:21
Message-ID: E1wwRRs-000000017Di-1ZRt@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Defend against null "SV *" pointers in plperl modules.

Tied hashes, and probably tied arrays, are capable of returning Perl
value pointers that are actually NULL, not the usual pointer to an
undef SV. We were not defending against that everywhere, leading
to possible SIGSEGV. Fix the code to consistently treat a null
pointer returned from hv_iternext or av_fetch like a !SvOK one.
(Note that the large diff in SV_to_JsonbValue is actually quite
trivial, but it required reindenting a chunk of existing code.)

Claude Code found the instance in hstore_plperl, and I found the
others by code auditing. Perhaps the other instances aren't
actually reachable, but I see little reason to assume that.

The known test cases for these errors require perl's Tie modules,
which may not be present, so it doesn't seem worth the trouble
to create regression test cases that would cover them.

Reported-by: Claude Code (via Noah Misch)
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/569769.1786901901@sss.pgh.pa.us
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d54d3f5d954e2ffa1df4ad7199847e2bc5afd101

Modified Files
--------------
contrib/hstore_plperl/hstore_plperl.c | 2 +-
contrib/jsonb_plperl/jsonb_plperl.c | 155 ++++++++++++++++++----------------
src/pl/plperl/plperl.c | 2 +-
3 files changed, 83 insertions(+), 76 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2026-08-18 21:47:20 pgsql: Make plperl's handling of Perl hashes more consistent.
Previous Message Masahiko Sawada 2026-08-18 20:57:40 pgsql: test_decoding: Don't print virtual generated columns.