]> granicus.if.org Git - postgresql/commitdiff
Correct off-by-one when reading from pipe
authorStephen Frost <sfrost@snowman.net>
Mon, 15 Jul 2013 14:42:27 +0000 (10:42 -0400)
committerStephen Frost <sfrost@snowman.net>
Mon, 15 Jul 2013 14:48:08 +0000 (10:48 -0400)
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.

src/bin/pg_basebackup/pg_basebackup.c

index 19cc9e864e378787fe727b39d7a3971abe0c829f..eaa69f612a2cf73ce70afebd668662e5ca605e27 100644 (file)
@@ -166,7 +166,7 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
                        char            xlogend[64];
 
                        MemSet(xlogend, 0, sizeof(xlogend));
-                       r = read(bgpipe[0], xlogend, sizeof(xlogend));
+                       r = read(bgpipe[0], xlogend, sizeof(xlogend)-1);
                        if (r < 0)
                        {
                                fprintf(stderr, _("%s: could not read from ready pipe: %s\n"),