diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-08-06 01:38:32 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-08-06 01:38:32 +0000 |
commit | 6d1607dc3f83d1de9b4daeba2f0622e29cafc524 (patch) | |
tree | 16d67e7e8db7ebdd36dd1ae15e92b4b5f390fc92 /src/bin/pg_dump/pg_backup_tar.c | |
parent | f99e72fa51d1a0de26dff3878832c9e2ed3f4f12 (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_tar.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_tar.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c index b50919f3f5a..506c9a639be 100644 --- a/src/bin/pg_dump/pg_backup_tar.c +++ b/src/bin/pg_dump/pg_backup_tar.c @@ -16,7 +16,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.49.2.3 2006/11/01 15:59:31 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.49.2.4 2007/08/06 01:38:32 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -509,7 +509,7 @@ _tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh) 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 */ @@ -766,12 +766,13 @@ static int _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; } |