pgsql: In array_position()/array_positions(), beware of empty input arr

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: In array_position()/array_positions(), beware of empty input arr
Date: 2023-05-04 15:48:40
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

In array_position()/array_positions(), beware of empty input array.

These functions incautiously fetched the array's first lower bound
even when the array is zero-dimensional, thus fetching the word
after the allocated array space. While almost always harmless,
with very bad luck this could result in SIGSEGV. Fix by adding
an early exit for empty input.

Per bug #17920 from Alexander Lakhin.

Discussion: https://postgr.es/m/17920-f7c228c627b6d02e%40postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4c40995f61227c579bd7269a829c00013ac66492

Modified Files
--------------
src/backend/utils/adt/array_userfuncs.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alvaro Herrera 2023-05-04 17:58:26 pgsql: Fix ExecCheckPermissions call in RI_Initial_Check
Previous Message Tom Lane 2023-05-04 15:00:54 pgsql: Tighten array dimensionality checks in Python -> SQL array conve