| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Make plperl's handling of Perl arrays safer and more consistent. |
| Date: | 2026-08-17 19:06:17 |
| Message-ID: | E1ww2f2-00000000xFM-3H00@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Make plperl's handling of Perl arrays safer and more consistent.
plperl_func_handler()'s stanza for handling an arrayref result in
a SETOF function could loop forever (or at least till OOM) when
given a tied array, since av_fetch won't necessarily ever return
a null pointer in that case. Be consistent with the other places
where we traverse a perl array: call av_len() once and use len+1
as the loop limit, silently ignoring any null pointers we get back
from that range of subscripts.
But actually, Perl's preferred locution for this seems to be to
use av_count() not av_len()+1. av_count() seems better since
there's less risk of forgetting to add 1. Also, both of those
functions return Size_t (or SSize_t) not int, creating at least
a theoretical overflow hazard. While we're modernizing this,
let's use the correct variable type where we can, and include an
overflow check where we can't.
Reported-by: Claude Code (via Noah Misch)
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Reviewed-by: Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com>
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/794473ec222f937db15a4a419000d6278d97421b
Modified Files
--------------
contrib/jsonb_plperl/jsonb_plperl.c | 5 ++---
src/pl/plperl/plperl.c | 41 ++++++++++++++++++++++++++++---------
2 files changed, 33 insertions(+), 13 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nathan Bossart | 2026-08-17 19:42:27 | pgsql: Add an "unset" value for vacuum_index_cleanup. |
| Previous Message | Nathan Bossart | 2026-08-17 18:17:44 | pgsql: Make autovacuum_enabled a ternary reloption. |