Re: [PATCH] bms_prev_member() can read beyond the end of the array of allocated words

From: Greg Burd <greg(at)burd(dot)me>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] bms_prev_member() can read beyond the end of the array of allocated words
Date: 2025-08-14 15:58:26
Message-ID: 833EA934-B153-4929-90DF-97DE49887932@getmailspring.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On Aug 14 2025, at 11:49 am, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:

> On Fri, 15 Aug 2025 at 03:43, Greg Burd <greg(at)burd(dot)me> wrote:
>> Well, that was rushed. Apologies.
>
> Would you be ok with adding the Assert after the "a == NULL" check?, i.e:
>
> if (a == NULL || prevbit == 0)
> return -2;
>
> /* Validate callers didn't give us something out of range */
> Assert(prevbit <= a->nwords * BITS_PER_BITMAPWORD);
>
> David

Good thinking, less contorted logic and a more obvious check for NULL
and the result to expect in that case.

-greg

Attachment Content-Type Size
v5-0001-Prevent-bms_prev_member-from-reading-beyond-the-e.patch application/octet-stream 1.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2025-08-14 15:59:20 Re: [PATCH] bms_prev_member() can read beyond the end of the array of allocated words
Previous Message Tom Lane 2025-08-14 15:53:56 Re: [Feature request] Add a way to get the length of a PQerrorMessage in libpq