]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Don't reference out-of-bounds array elements in brin_minmax_multi.c
authorDavid Rowley <drowley@postgresql.org>
Mon, 12 Sep 2022 23:05:13 +0000 (11:05 +1200)
committerDavid Rowley <drowley@postgresql.org>
Mon, 12 Sep 2022 23:05:13 +0000 (11:05 +1200)
commitc2aa5d01e3e33776f77e68a60ca5b60b58c5c674
tree9648ba09906e5f7517eddb573ad08ec7155e4644
parent293a6ac4b9898febe1cf9a4614facf6128be5d77
Don't reference out-of-bounds array elements in brin_minmax_multi.c

The primary fix here is to fix has_matching_range() so it does not
reference ranges->values[-1] when nranges == 0.  Similar problems existed
in AssertCheckRanges() too.  It does not look like any of these problems
could lead to a crash as the array in question is at the end of the Ranges
struct, and values[-1] is memory that belongs to other fields in the
struct.  However, let's get rid of these rather unsafe coding practices.

In passing, I (David) adjusted some comments to try to make it more clear
what some of the fields are for in the Ranges struct.  I had to study the
code to find out what nsorted was for as I couldn't tell from the
comments.

Author: Ranier Vilela
Discussion: https://postgr.es/m/CAEudQAqJQzPitufX-jR=YUbJafpCDAKUnwgdbX_MzSc93wuvdw@mail.gmail.com
Backpatch-through: 14, where multi-range brin was added.
src/backend/access/brin/brin_minmax_multi.c