]> git.ipfire.org Git - thirdparty/postgresql.git/commit
plperl: Fix NULL pointer dereference for forged array object
authorRichard Guo <rguo@postgresql.org>
Wed, 24 Jun 2026 00:09:48 +0000 (09:09 +0900)
committerRichard Guo <rguo@postgresql.org>
Wed, 24 Jun 2026 00:17:36 +0000 (09:17 +0900)
commite520ad34b482cc3a441f10ded0320d42db2625ed
tree0c74aae355a824ae645bcf085fd64ecdd4b75379
parente8fbe5d838f50d0641d40f98b44f3698ad0846c1
plperl: Fix NULL pointer dereference for forged array object

In get_perl_array_ref(), for a PostgreSQL::InServer::ARRAY object, we
look up its "array" key with hv_fetch_string() and then inspect the
returned SV.  However, hv_fetch_string() returns a NULL pointer when
the key is absent, and the code dereferenced that result without first
checking whether the pointer itself was NULL.  As a result, a plperl
function returning a forged PostgreSQL::InServer::ARRAY object that
lacks the "array" key would crash the backend with a segmentation
fault.

Fix this by checking the pointer returned by hv_fetch_string() before
dereferencing it, matching how other callers in this file already
guard the result.  With the check in place, such an object falls
through to the existing error report instead of crashing.

Author: Xing Guo <higuoxing@gmail.com>
Reviewed-by: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CACpMh+DYgcnqZwQLXXuxQcehJTd7T8UmKWSLsK4mFBEp9G2ajA@mail.gmail.com
Backpatch-through: 14
src/pl/plperl/expected/plperl_array.out
src/pl/plperl/plperl.c
src/pl/plperl/sql/plperl_array.sql