summaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_backup_archiver.c
diff options
context:
space:
mode:
authorStephen Frost <sfrost@snowman.net>2014-02-08 21:25:47 -0500
committerStephen Frost <sfrost@snowman.net>2014-02-08 21:25:47 -0500
commitcfa1b4a711dd03f824a9c3ab50911e61419d1eeb (patch)
treeaf9d3c16f8c15ce562e09a9c97bfe19baf9395b0 /src/bin/pg_dump/pg_backup_archiver.c
parent66c04c981dfe7c1d1e633dddcecf01982d0bde65 (diff)
Minor pg_dump improvements
Improve pg_dump by checking results on various fgetc() calls which previously were unchecked, ditto for ftello. Also clean up a couple of very minor memory leaks by waiting to allocate structures until after the initial check(s). Issues spotted by Coverity.
Diffstat (limited to 'src/bin/pg_dump/pg_backup_archiver.c')
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 7fc0288d0e3..8ea40ea7b76 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -1898,13 +1898,22 @@ _discoverArchiveFormat(ArchiveHandle *AH)
if (strncmp(sig, "PGDMP", 5) == 0)
{
+ int byteread;
+
/*
* Finish reading (most of) a custom-format header.
*
* NB: this code must agree with ReadHead().
*/
- AH->vmaj = fgetc(fh);
- AH->vmin = fgetc(fh);
+ if ((byteread = fgetc(fh)) == EOF)
+ exit_horribly(modulename, "could not read input file: %s\n", strerror(errno));
+
+ AH->vmaj = byteread;
+
+ if ((byteread = fgetc(fh)) == EOF)
+ exit_horribly(modulename, "could not read input file: %s\n", strerror(errno));
+
+ AH->vmin = byteread;
/* Save these too... */
AH->lookahead[AH->lookaheadLen++] = AH->vmaj;
@@ -1913,7 +1922,10 @@ _discoverArchiveFormat(ArchiveHandle *AH)
/* Check header version; varies from V1.0 */
if (AH->vmaj > 1 || ((AH->vmaj == 1) && (AH->vmin > 0))) /* Version > 1.0 */
{
- AH->vrev = fgetc(fh);
+ if ((byteread = fgetc(fh)) == EOF)
+ exit_horribly(modulename, "could not read input file: %s\n", strerror(errno));
+
+ AH->vrev = byteread;
AH->lookahead[AH->lookaheadLen++] = AH->vrev;
}
else
@@ -1922,18 +1934,21 @@ _discoverArchiveFormat(ArchiveHandle *AH)
/* Make a convenient integer <maj><min><rev>00 */
AH->version = ((AH->vmaj * 256 + AH->vmin) * 256 + AH->vrev) * 256 + 0;
- AH->intSize = fgetc(fh);
+ if ((AH->intSize = fgetc(fh)) == EOF)
+ exit_horribly(modulename, "could not read input file: %s\n", strerror(errno));
AH->lookahead[AH->lookaheadLen++] = AH->intSize;
if (AH->version >= K_VERS_1_7)
{
- AH->offSize = fgetc(fh);
+ if ((AH->offSize = fgetc(fh)) == EOF)
+ exit_horribly(modulename, "could not read input file: %s\n", strerror(errno));
AH->lookahead[AH->lookaheadLen++] = AH->offSize;
}
else
AH->offSize = AH->intSize;
- AH->format = fgetc(fh);
+ if ((AH->format = fgetc(fh)) == EOF)
+ exit_horribly(modulename, "could not read input file: %s\n", strerror(errno));
AH->lookahead[AH->lookaheadLen++] = AH->format;
}
else