8000 Fix access-off-end-of-array in clog.c. · lelisa2016/postgres@6d2ef1c · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d2ef1c

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 8000 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 c9c37e3 commit 6d2ef1c

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
@@ -223,21 +223,27 @@ set_status_by_pages(int nsubxids, TransactionId *subxids,
223223
int offset = 0;
224224
int i = 0;
225225

226+
Assert(nsubxids > 0); /* else the pageno fetch above is unsafe */
227+
226228
while (i < nsubxids)
227229
{
228230
int num_on_page = 0;
231+
int nextpageno;
229232

230-
while (TransactionIdToPage(subxids[i]) == pageno && i < nsubxids)
233+
do
231234
{
235+
nextpageno = TransactionIdToPage(subxids[i]);
236+
if (nextpageno != pageno)
237+
break;
232238
num_on_page++;
233239
i++;
234-
}
240+
} while (i < nsubxids);
235241

236242
TransactionIdSetPageStatus(InvalidTransactionId,
237243
num_on_page, subxids + offset,
238244
status, lsn, pageno);
239245
offset = i;
240-
pageno = TransactionIdToPage(subxids[offset]);
246+
pageno = nextpageno;
241247
}
242248
}
243249

0 commit comments

Comments
 (0)
0