diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-08-06 01:38:40 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-08-06 01:38:40 +0000 |
commit | fbf9179a2758f721ed460f6503e36c56b82eef4c (patch) | |
tree | dfdf19fa9ca975e50d57d8e8288861b897338685 /src/bin/pg_dump/pg_backup_archiver.c | |
parent | 2e24f4af49ddf6ed4d05446c132b1e33415a26b2 (diff) |
Fix pg_restore to guard against unexpected EOF while reading an archive file.
Per report and partial patch from Chad Wagner.
Diffstat (limited to 'src/bin/pg_dump/pg_backup_archiver.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index e9af7d5fd06..392f9f9db52 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.101.4.9 2006/02/05 20:59:06 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.101.4.10 2007/08/06 01:38:40 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1513,7 +1513,7 @@ ReadStr(ArchiveHandle *AH) int l; l = ReadInt(AH); - if (l == -1) + if (l < 0) buf = NULL; else { @@ -1521,7 +1521,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'; } @@ -2661,8 +2663,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"); |