Re: [PATCH] bms_prev_member() can read beyond the end of the array of allocated words
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Greg Burd <greg@burd.me>
Cc: David Rowley <dgrowleyml@gmail.com>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-08-14T15:52:49Z
Lists: pgsql-hackers
Greg Burd <greg@burd.me> writes:
> Well, that was rushed. Apologies.
I was thinking something more like
/* transform -1 to the highest possible bit we could have set */
if (prevbit == -1)
prevbit = a->nwords * BITS_PER_BITMAPWORD - 1;
else
+ {
+ Assert(prevbit > 0 && prevbit < a->nwords * BITS_PER_BITMAPWORD);
prevbit--;
+ }
Admittedly, this doesn't bother to check sanity of prevbit when
a == NULL, but I don't think doing so is useful enough to contort
the logic for it.
regards, tom lane
Commits
-
Add Asserts to validate prevbit values in bms_prev_member
- b4632883d44e 19 (unreleased) landed