pg_standby: Avoid writing one byte beyond the end of the buffer.
authorRobert Haas
Thu, 15 Jan 2015 14:26:03 +0000 (09:26 -0500)
committerRobert Haas
Thu, 15 Jan 2015 14:29:55 +0000 (09:29 -0500)
Previously, read() might have returned a length equal to the buffer
length, and then the subsequent store to buf[len] would write a
zero-byte one byte past the end.  This doesn't seem likely to be
a security issue, but there's some chance it could result in
pg_standby misbehaving.

Spotted by Coverity; patch by Michael Paquier, reviewed by me.

contrib/pg_standby/pg_standby.c

index 87255b9ee83583948f134a0ea8db3673405375f6..59b71dedcb7bb1c3434b85048ea186f6d4fe0dc4 100644 (file)
@@ -435,7 +435,7 @@ CheckForExternalTrigger(void)
        return;
    }
 
-   if ((len = read(fd, buf, sizeof(buf))) < 0)
+   if ((len = read(fd, buf, sizeof(buf) - 1)) < 0)
    {
        fprintf(stderr, "WARNING: could not read \"%s\": %s\n",
                triggerPath, strerror(errno));