Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6b87416

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 c3d9a66 commit 6b87416

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
@@ -241,21 +241,27 @@ set_status_by_pages(int nsubxids, TransactionId *subxids,
241241
int offset = 0;
242242
int i = 0;
243243

244+
Assert(nsubxids > 0); /* else the pageno fetch above is unsafe */
245+
244246
while (i < nsubxids)
245247
{
246248
int num_on_page = 0;
249+
int nextpageno;
247250

248-
while (TransactionIdToPage(subxids[i]) == pageno && i < nsubxids)
251+
do
249252
{
253+
nextpageno = TransactionIdToPage(subxids[i]);
254+
if (nextpageno != pageno)
255+
break;
250256
num_on_page++;
251257
i++;
252-
}
258+
} while (i < nsubxids);
253259

254260
TransactionIdSetPageStatus(InvalidTransactionId,
255261
num_on_page, subxids + offset,
256262
status, lsn, pageno, false);
257263
offset = i;
258-
pageno = TransactionIdToPage(subxids[offset]);
264+
pageno = nextpageno;
259265
}
260266
}
261267

0 commit comments

Comments
 (0)