mirror of
https://github.com/postgres/postgres.git
synced 2025-10-16 17:07:43 +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
|
||||
* $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 $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1472,7 +1472,7 @@ ReadStr(ArchiveHandle *AH)
|
||||
int l;
|
||||
|
||||
l = ReadInt(AH);
|
||||
if (l == -1)
|
||||
if (l < 0)
|
||||
buf = NULL;
|
||||
else
|
||||
{
|
||||
@@ -1480,7 +1480,9 @@ ReadStr(ArchiveHandle *AH)
|
||||
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';
|
||||
}
|
||||
|
||||
@@ -2675,8 +2677,8 @@ ReadHead(ArchiveHandle *AH)
|
||||
/* 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");
|
||||
|
Reference in New Issue
Block a user