Skip to content

Commit 3ed76bd

Browse files
committed
Check for fseeko() failure in pg_dump's _tarAddFile().
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.
1 parent 29cfa88 commit 3ed76bd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/bin/pg_dump/pg_backup_tar.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,12 +1096,16 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th)
10961096
/*
10971097
* Find file len & go back to start.
10981098
*/
1099-
fseeko(tmp, 0, SEEK_END);
1099+
if (fseeko(tmp, 0, SEEK_END) != 0)
1100+
exit_horribly(modulename, "error during file seek: %s\n",
1101+
strerror(errno));
11001102
th->fileLen = ftello(tmp);
11011103
if (th->fileLen < 0)
11021104
exit_horribly(modulename, "could not determine seek position in archive file: %s\n",
11031105
strerror(errno));
1104-
fseeko(tmp, 0, SEEK_SET);
1106+
if (fseeko(tmp, 0, SEEK_SET) != 0)
1107+
exit_horribly(modulename, "error during file seek: %s\n",
1108+
strerror(errno));
11051109

11061110
_tarWriteHeader(th);
11071111

0 commit comments

Comments
 (0)