mirror of
https://github.com/postgres/postgres.git
synced 2025-08-11 04:22:52 +03:00
Fix pg_restore to guard against unexpected EOF while reading an archive file.
Per report and partial patch from Chad Wagner.
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.62.2.7 2005/05/17 17:31:15 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.62.2.8 2007/08/06 01:38:57 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@@ -1545,7 +1545,7 @@ ReadStr(ArchiveHandle *AH)
|
|||||||
int l;
|
int l;
|
||||||
|
|
||||||
l = ReadInt(AH);
|
l = ReadInt(AH);
|
||||||
if (l == -1)
|
if (l < 0)
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1553,7 +1553,9 @@ ReadStr(ArchiveHandle *AH)
|
|||||||
if (!buf)
|
if (!buf)
|
||||||
die_horribly(AH, modulename, "out of memory\n");
|
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';
|
buf[l] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2277,8 +2279,8 @@ ReadHead(ArchiveHandle *AH)
|
|||||||
/* If we haven't already read the header... */
|
/* If we haven't already read the header... */
|
||||||
if (!AH->readHeader)
|
if (!AH->readHeader)
|
||||||
{
|
{
|
||||||
|
if ((*AH->ReadBufPtr) (AH, tmpMag, 5) != 5)
|
||||||
(*AH->ReadBufPtr) (AH, tmpMag, 5);
|
die_horribly(AH, modulename, "unexpected end of file\n");
|
||||||
|
|
||||||
if (strncmp(tmpMag, "PGDMP", 5) != 0)
|
if (strncmp(tmpMag, "PGDMP", 5) != 0)
|
||||||
die_horribly(AH, modulename, "did not find magic string in file header\n");
|
die_horribly(AH, modulename, "did not find magic string in file header\n");
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.23 2002/10/25 01:33:17 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.23.2.1 2007/08/06 01:38:57 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@@ -713,7 +713,7 @@ _WriteByte(ArchiveHandle *AH, const int i)
|
|||||||
*
|
*
|
||||||
* Called by the archiver to read bytes & integers from the archive.
|
* Called by the archiver to read bytes & integers from the archive.
|
||||||
* These routines are only used to read & write headers & TOC.
|
* These routines are only used to read & write headers & TOC.
|
||||||
*
|
* EOF should be treated as a fatal error.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
_ReadByte(ArchiveHandle *AH)
|
_ReadByte(ArchiveHandle *AH)
|
||||||
@@ -721,9 +721,10 @@ _ReadByte(ArchiveHandle *AH)
|
|||||||
lclContext *ctx = (lclContext *) AH->formatData;
|
lclContext *ctx = (lclContext *) AH->formatData;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
res = fgetc(AH->FH);
|
res = getc(AH->FH);
|
||||||
if (res != EOF)
|
if (res == EOF)
|
||||||
ctx->filePos += 1;
|
die_horribly(AH, modulename, "unexpected end of file\n");
|
||||||
|
ctx->filePos += 1;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.21 2002/10/25 01:33:17 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.21.2.1 2007/08/06 01:38:57 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@@ -396,9 +396,10 @@ _ReadByte(ArchiveHandle *AH)
|
|||||||
lclContext *ctx = (lclContext *) AH->formatData;
|
lclContext *ctx = (lclContext *) AH->formatData;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
res = fgetc(AH->FH);
|
res = getc(AH->FH);
|
||||||
if (res != EOF)
|
if (res == EOF)
|
||||||
ctx->filePos += 1;
|
die_horribly(AH, modulename, "unexpected end of file\n");
|
||||||
|
ctx->filePos += 1;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.32.2.2 2003/02/01 19:29:26 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.32.2.3 2007/08/06 01:38:57 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@@ -484,7 +484,7 @@ _tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh)
|
|||||||
used = avail;
|
used = avail;
|
||||||
|
|
||||||
/* Copy, and adjust buffer pos */
|
/* Copy, and adjust buffer pos */
|
||||||
memcpy(buf, AH->lookahead, used);
|
memcpy(buf, AH->lookahead + AH->lookaheadPos, used);
|
||||||
AH->lookaheadPos += used;
|
AH->lookaheadPos += used;
|
||||||
|
|
||||||
/* Adjust required length */
|
/* Adjust required length */
|
||||||
@@ -728,12 +728,13 @@ static int
|
|||||||
_ReadByte(ArchiveHandle *AH)
|
_ReadByte(ArchiveHandle *AH)
|
||||||
{
|
{
|
||||||
lclContext *ctx = (lclContext *) AH->formatData;
|
lclContext *ctx = (lclContext *) AH->formatData;
|
||||||
int res;
|
size_t res;
|
||||||
char c = '\0';
|
unsigned char c;
|
||||||
|
|
||||||
res = tarRead(&c, 1, ctx->FH);
|
res = tarRead(&c, 1, ctx->FH);
|
||||||
if (res != EOF)
|
if (res != 1)
|
||||||
ctx->filePos += res;
|
die_horribly(AH, modulename, "unexpected end of file\n");
|
||||||
|
ctx->filePos += 1;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user