Skip to content

Commit 69e931f

Browse files
committed
Fix access-off-end-of-array in clog.c.
Sloppy loop coding in set_status_by_pages() resulted in fetching one array element more than it should from the subxids[] array. The odds of this resulting in SIGSEGV are pretty small, but we've certainly seen that happen with similar mistakes elsewhere. While at it, we can get rid of an extra TransactionIdToPage() calculation per loop. Per report from David Binderman. Back-patch to all supported branches, since this code is quite old. Discussion: https://postgr.es/m/HE1PR0802MB2331CBA919CBFFF0C465EB429C710@HE1PR0802MB2331.eurprd08.prod.outlook.com
1 parent d441cff commit 69e931f

File tree

1 file changed

+9
-3
lines changed
  • src/backend/access/transam

1 file changed

+9
-3
lines changed

src/backend/access/transam/clog.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,27 @@ set_status_by_pages(int nsubxids, TransactionId *subxids,
226226
int offset = 0;
227227
int i = 0;
228228

229+
Assert(nsubxids > 0); /* else the pageno fetch above is unsafe */
230+
229231
while (i < nsubxids)
230232
{
231233
int num_on_page = 0;
234+
int nextpageno;
232235

233-
while (TransactionIdToPage(subxids[i]) == pageno && i < nsubxids)
236+
do
234237
{
238+
nextpageno = TransactionIdToPage(subxids[i]);
239+
if (nextpageno != pageno)
240+
break;
235241
num_on_page++;
236242
i++;
237-
}
243+
} while (i < nsubxids);
238244

239245
TransactionIdSetPageStatus(InvalidTransactionId,
240246
num_on_page, subxids + offset,
241247
status, lsn, pageno);
242248
offset = i;
243-
pageno = TransactionIdToPage(subxids[offset]);
249+
pageno = nextpageno;
244250
}
245251
}
246252

0 commit comments

Comments
 (0)