Skip to content
Snippets Groups Projects
Commit 03010366 authored by Stephen Frost's avatar Stephen Frost
Browse files

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.
parent 3355443f
No related branches found
No related tags found
No related merge requests found
...@@ -174,7 +174,7 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline, ...@@ -174,7 +174,7 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
lo; lo;
MemSet(xlogend, 0, sizeof(xlogend)); MemSet(xlogend, 0, sizeof(xlogend));
r = read(bgpipe[0], xlogend, sizeof(xlogend)); r = read(bgpipe[0], xlogend, sizeof(xlogend)-1);
if (r < 0) if (r < 0)
{ {
fprintf(stderr, _("%s: could not read from ready pipe: %s\n"), fprintf(stderr, _("%s: could not read from ready pipe: %s\n"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment