pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Defend against null "SV *" pointers in plperl modules.
Date: Tue, 18 Aug 2026 21:34:21 +0000
Message-ID: <E1wwRRs-000000017Dg-1VGS@gemulon.postgresql.org> (raw)

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@sss.pgh.pa.us>
Discussion: https://postgr.es/m/569769.1786901901@sss.pgh.pa.us
Backpatch-through: 14

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2860d322ae98dd3c1f8608fc02fb777dd51d41f2

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(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1wwRRs-000000017Dg-1VGS@gemulon.postgresql.org>
Permalink:  ../E1wwRRs-000000017Dg-1VGS@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wwRRs-000000017Dg-1VGS@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Defend against null "SV *" pointers in plperl modules.
  In-Reply-To: <E1wwRRs-000000017Dg-1VGS@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