]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix trim_array() for zero-dimensional array argument.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 31 Jul 2022 17:43:17 +0000 (13:43 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 31 Jul 2022 17:43:17 +0000 (13:43 -0400)
commite71d4254f710bef53fa40d0b49b5af9bad10ce40
treefa8813d531086a8b568dbab016dfafacbe6012cc
parente90c4fc881e2c836b4d4fb9fae03310f9c0d8597
Fix trim_array() for zero-dimensional array argument.

The code tried to access ARR_DIMS(v)[0] and ARR_LBOUND(v)[0]
whether or not those values exist.  This made the range check
on the "n" argument unstable --- it might or might not fail, and
if it did it would report garbage for the allowed upper limit.
These bogus accesses would probably annoy Valgrind, and if you
were very unlucky even lead to SIGSEGV.

Report and fix by Martin Kalcher.  Back-patch to v14 where this
function was added.

Discussion: https://postgr.es/m/baaeb413-b8a8-4656-5757-ef347e5ec11f@aboutsource.net
src/backend/utils/adt/arrayfuncs.c
src/test/regress/expected/arrays.out
src/test/regress/sql/arrays.sql