Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d16e84b

Browse filesBrowse files
committed
Fix ptrack map array index overflow when doing ptrackCheckpoint().
1 parent f490518 commit d16e84b
Copy full SHA for d16e84b

File tree

1 file changed

+7
-5
lines changed
Filter options

1 file changed

+7
-5
lines changed

‎engine.c

Copy file name to clipboardExpand all lines: engine.c
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ ptrackCheckpoint(void)
337337
XLogRecPtr init_lsn;
338338
pg_atomic_uint64 buf[PTRACK_BUF_SIZE];
339339
struct stat stat_buf;
340-
int i = 0;
341-
int j = 0;
340+
uint64 i = 0;
341+
uint64 j = 0;
342342

343343
elog(DEBUG1, "ptrack checkpoint");
344344

@@ -430,14 +430,16 @@ ptrackCheckpoint(void)
430430

431431
if (j == PTRACK_BUF_SIZE)
432432
{
433-
int writesz = sizeof(buf);
433+
int writesz = sizeof(buf); /* Up to ~2 GB for buffer size seems
434+
* to be more than enough, so never
435+
* going to overflow. */
434436

435437
/*
436438
* We should not have any allignment issues here, since sizeof()
437439
* takes into account all paddings for us.
438440
*/
439441
ptrack_write_chunk(ptrack_tmp_fd, &crc, (char *) buf, writesz);
440-
elog(DEBUG5, "ptrack checkpoint: i %d, j %d, writesz %d PtrackContentNblocks " UINT64_FORMAT,
442+
elog(DEBUG5, "ptrack checkpoint: i " UINT64_FORMAT ", j " UINT64_FORMAT ", writesz %d PtrackContentNblocks " UINT64_FORMAT,
441443
i, j, writesz, (uint64) PtrackContentNblocks);
442444

443445
j = 0;
@@ -450,7 +452,7 @@ ptrackCheckpoint(void)
450452
int writesz = sizeof(pg_atomic_uint64) * j;
451453

452454
ptrack_write_chunk(ptrack_tmp_fd, &crc, (char *) buf, writesz);
453-
elog(DEBUG5, "ptrack checkpoint: final i %d, j %d, writesz %d PtrackContentNblocks " UINT64_FORMAT,
455+
elog(DEBUG5, "ptrack checkpoint: final i " UINT64_FORMAT ", j " UINT64_FORMAT ", writesz %d PtrackContentNblocks " UINT64_FORMAT,
454456
i, j, writesz, (uint64) PtrackContentNblocks);
455457
}
456458

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.