mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
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.
This commit is contained in:
@ -1898,13 +1898,22 @@ _discoverArchiveFormat(ArchiveHandle *AH)
|
|||||||
|
|
||||||
if (strncmp(sig, "PGDMP", 5) == 0)
|
if (strncmp(sig, "PGDMP", 5) == 0)
|
||||||
{
|
{
|
||||||
|
int byteread;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Finish reading (most of) a custom-format header.
|
* Finish reading (most of) a custom-format header.
|
||||||
*
|
*
|
||||||
* NB: this code must agree with ReadHead().
|
* NB: this code must agree with ReadHead().
|
||||||
*/
|
*/
|
||||||
AH->vmaj = fgetc(fh);
|
if ((byteread = fgetc(fh)) == EOF)
|
||||||
AH->vmin = fgetc(fh);
|
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... */
|
/* Save these too... */
|
||||||
AH->lookahead[AH->lookaheadLen++] = AH->vmaj;
|
AH->lookahead[AH->lookaheadLen++] = AH->vmaj;
|
||||||
@ -1913,7 +1922,10 @@ _discoverArchiveFormat(ArchiveHandle *AH)
|
|||||||
/* Check header version; varies from V1.0 */
|
/* Check header version; varies from V1.0 */
|
||||||
if (AH->vmaj > 1 || ((AH->vmaj == 1) && (AH->vmin > 0))) /* Version > 1.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;
|
AH->lookahead[AH->lookaheadLen++] = AH->vrev;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1922,18 +1934,21 @@ _discoverArchiveFormat(ArchiveHandle *AH)
|
|||||||
/* Make a convenient integer <maj><min><rev>00 */
|
/* Make a convenient integer <maj><min><rev>00 */
|
||||||
AH->version = ((AH->vmaj * 256 + AH->vmin) * 256 + AH->vrev) * 256 + 0;
|
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;
|
AH->lookahead[AH->lookaheadLen++] = AH->intSize;
|
||||||
|
|
||||||
if (AH->version >= K_VERS_1_7)
|
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;
|
AH->lookahead[AH->lookaheadLen++] = AH->offSize;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
AH->offSize = AH->intSize;
|
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;
|
AH->lookahead[AH->lookaheadLen++] = AH->format;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -708,6 +708,9 @@ _CloseArchive(ArchiveHandle *AH)
|
|||||||
{
|
{
|
||||||
WriteHead(AH);
|
WriteHead(AH);
|
||||||
tpos = ftello(AH->FH);
|
tpos = ftello(AH->FH);
|
||||||
|
if (tpos < 0 || errno)
|
||||||
|
exit_horribly(modulename, "could not determine seek position in archive file: %s\n",
|
||||||
|
strerror(errno));
|
||||||
WriteToc(AH);
|
WriteToc(AH);
|
||||||
ctx->dataStart = _getFilePos(AH, ctx);
|
ctx->dataStart = _getFilePos(AH, ctx);
|
||||||
WriteDataChunks(AH, NULL);
|
WriteDataChunks(AH, NULL);
|
||||||
@ -756,7 +759,7 @@ _ReopenArchive(ArchiveHandle *AH)
|
|||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
tpos = ftello(AH->FH);
|
tpos = ftello(AH->FH);
|
||||||
if (errno)
|
if (tpos < 0 || errno)
|
||||||
exit_horribly(modulename, "could not determine seek position in archive file: %s\n",
|
exit_horribly(modulename, "could not determine seek position in archive file: %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
|
@ -7145,7 +7145,7 @@ getForeignDataWrappers(Archive *fout, int *numForeignDataWrappers)
|
|||||||
PGresult *res;
|
PGresult *res;
|
||||||
int ntups;
|
int ntups;
|
||||||
int i;
|
int i;
|
||||||
PQExpBuffer query = createPQExpBuffer();
|
PQExpBuffer query;
|
||||||
FdwInfo *fdwinfo;
|
FdwInfo *fdwinfo;
|
||||||
int i_tableoid;
|
int i_tableoid;
|
||||||
int i_oid;
|
int i_oid;
|
||||||
@ -7163,6 +7163,8 @@ getForeignDataWrappers(Archive *fout, int *numForeignDataWrappers)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query = createPQExpBuffer();
|
||||||
|
|
||||||
/* Make sure we are in proper schema */
|
/* Make sure we are in proper schema */
|
||||||
selectSourceSchema(fout, "pg_catalog");
|
selectSourceSchema(fout, "pg_catalog");
|
||||||
|
|
||||||
@ -7251,7 +7253,7 @@ getForeignServers(Archive *fout, int *numForeignServers)
|
|||||||
PGresult *res;
|
PGresult *res;
|
||||||
int ntups;
|
int ntups;
|
||||||
int i;
|
int i;
|
||||||
PQExpBuffer query = createPQExpBuffer();
|
PQExpBuffer query;
|
||||||
ForeignServerInfo *srvinfo;
|
ForeignServerInfo *srvinfo;
|
||||||
int i_tableoid;
|
int i_tableoid;
|
||||||
int i_oid;
|
int i_oid;
|
||||||
@ -7270,6 +7272,8 @@ getForeignServers(Archive *fout, int *numForeignServers)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query = createPQExpBuffer();
|
||||||
|
|
||||||
/* Make sure we are in proper schema */
|
/* Make sure we are in proper schema */
|
||||||
selectSourceSchema(fout, "pg_catalog");
|
selectSourceSchema(fout, "pg_catalog");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user