Per report and partial patch from Chad Wagner.
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.144 2007/03/26 16:58:39 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.145 2007/08/06 01:38:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
int l;
l = ReadInt(AH);
- if (l == -1)
+ if (l < 0)
buf = NULL;
else
{
if (!buf)
die_horribly(AH, modulename, "out of memory\n");
- (*AH->ReadBufPtr) (AH, (void *) buf, l);
+ if ((*AH->ReadBufPtr) (AH, (void *) buf, l) != l)
+ die_horribly(AH, modulename, "unexpected end of file\n");
+
buf[l] = '\0';
}
/* If we haven't already read the header... */
if (!AH->readHeader)
{
-
- (*AH->ReadBufPtr) (AH, tmpMag, 5);
+ if ((*AH->ReadBufPtr) (AH, tmpMag, 5) != 5)
+ die_horribly(AH, modulename, "unexpected end of file\n");
if (strncmp(tmpMag, "PGDMP", 5) != 0)
die_horribly(AH, modulename, "did not find magic string in file header\n");
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.38 2007/03/18 16:50:44 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.39 2007/08/06 01:38:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*
* Called by the archiver to read bytes & integers from the archive.
* These routines are only used to read & write headers & TOC.
- *
+ * EOF should be treated as a fatal error.
*/
static int
_ReadByte(ArchiveHandle *AH)
lclContext *ctx = (lclContext *) AH->formatData;
int res;
- res = fgetc(AH->FH);
- if (res != EOF)
- ctx->filePos += 1;
+ res = getc(AH->FH);
+ if (res == EOF)
+ die_horribly(AH, modulename, "unexpected end of file\n");
+ ctx->filePos += 1;
return res;
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.32 2007/03/18 16:50:44 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.33 2007/08/06 01:38:15 tgl Exp $
*
*-------------------------------------------------------------------------
*/
lclContext *ctx = (lclContext *) AH->formatData;
int res;
- res = fgetc(AH->FH);
- if (res != EOF)
- ctx->filePos += 1;
+ res = getc(AH->FH);
+ if (res == EOF)
+ die_horribly(AH, modulename, "unexpected end of file\n");
+ ctx->filePos += 1;
return res;
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.58 2007/03/18 16:50:44 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.59 2007/08/06 01:38:15 tgl Exp $
*
*-------------------------------------------------------------------------
*/
used = avail;
/* Copy, and adjust buffer pos */
- memcpy(buf, AH->lookahead, used);
+ memcpy(buf, AH->lookahead + AH->lookaheadPos, used);
AH->lookaheadPos += used;
/* Adjust required length */
_ReadByte(ArchiveHandle *AH)
{
lclContext *ctx = (lclContext *) AH->formatData;
- int res;
- char c = '\0';
+ size_t res;
+ unsigned char c;
res = tarRead(&c, 1, ctx->FH);
- if (res != EOF)
- ctx->filePos += res;
+ if (res != 1)
+ die_horribly(AH, modulename, "unexpected end of file\n");
+ ctx->filePos += 1;
return c;
}