Skip to content

Commit a3957ac

Browse files
committed
Correct off-by-one when reading from pipe
In pg_basebackup.c:reached_end_position(), we're reading from an internal pipe with our own background process but we're possibly reading more bytes than will actually fit into our buffer due to an off-by-one error. As we're reading from an internal pipe there's no real risk here, but it's good form to not depend on such convenient arrangements. Bug spotted by the Coverity scanner. Back-patch to 9.2 where this showed up.
1 parent 89c09fe commit a3957ac

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
166166
char xlogend[64];
167167

168168
MemSet(xlogend, 0, sizeof(xlogend));
169-
r = read(bgpipe[0], xlogend, sizeof(xlogend));
169+
r = read(bgpipe[0], xlogend, sizeof(xlogend)-1);
170170
if (r < 0)
171171
{
172172
fprintf(stderr, _("%s: could not read from ready pipe: %s\n"),

0 commit comments

Comments
 (0)