Skip to content

Commit 4c20ee5

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 2257673 commit 4c20ee5

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
@@ -227,21 +227,27 @@ set_status_by_pages(int nsubxids, TransactionId *subxids,
227227
int offset = 0;
228228
int i = 0;
229229

230+
Assert(nsubxids > 0); /* else the pageno fetch above is unsafe */
231+
230232
while (i < nsubxids)
231233
{
232234
int num_on_page = 0;
235+
int nextpageno;
233236

234-
while (TransactionIdToPage(subxids[i]) == pageno && i < nsubxids)
237+
do
235238
{
239+
nextpageno = TransactionIdToPage(subxids[i]);
240+
if (nextpageno != pageno)
241+
break;
236242
num_on_page++;
237243
i++;
238-
}
244+
} while (i < nsubxids);
239245

240246
TransactionIdSetPageStatus(InvalidTransactionId,
241247
num_on_page, subxids + offset,
242248
status, lsn, pageno);
243249
offset = i;
244-
pageno = TransactionIdToPage(subxids[offset]);
250+
pageno = nextpageno;
245251
}
246252
}
247253

0 commit comments

Comments
 (0)