Check for fseeko() failure in pg_dump's _tarAddFile().
authorTom Lane <[email protected]>
Sun, 9 Aug 2020 16:39:08 +0000 (12:39 -0400)
committerTom Lane <[email protected]>
Sun, 9 Aug 2020 16:39:08 +0000 (12:39 -0400)
Coverity pointed out, not unreasonably, that we checked fseeko's
result at every other call site but these.  Failure to seek in the
temp file (note this is NOT pg_dump's output file) seems quite
unlikely, and even if it did happen the file length cross-check
further down would probably detect the problem.  Still, that's a
poor excuse for not checking the result of a system call.

src/bin/pg_dump/pg_backup_tar.c

index ef9f7145b13640cf78793bcbaf00ce0ee40cc964..9226588ff28cea7d174d65751a12b1f1f90de413 100644 (file)
@@ -1096,12 +1096,16 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th)
    /*
     * Find file len & go back to start.
     */
-   fseeko(tmp, 0, SEEK_END);
+   if (fseeko(tmp, 0, SEEK_END) != 0)
+       exit_horribly(modulename, "error during file seek: %s\n",
+                     strerror(errno));
    th->fileLen = ftello(tmp);
    if (th->fileLen < 0)
        exit_horribly(modulename, "could not determine seek position in archive file: %s\n",
                      strerror(errno));
-   fseeko(tmp, 0, SEEK_SET);
+   if (fseeko(tmp, 0, SEEK_SET) != 0)
+       exit_horribly(modulename, "error during file seek: %s\n",
+                     strerror(errno));
 
    _tarWriteHeader(th);