aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Conway <neilc@samurai.com>2005-06-22 02:12:19 +0000
committerNeil Conway <neilc@samurai.com>2005-06-22 02:12:19 +0000
commit0592a1ebc1f5aa2c91025d1cc631e9c6cccff245 (patch)
tree9c0f9d56a0c91a1bcc8e7eabe00e2f9bfb5d907a
parenta6f0dee7757aa843eb021c051fb2e85b03efc05e (diff)
downloadpostgresql-0592a1ebc1f5aa2c91025d1cc631e9c6cccff245.tar.gz
postgresql-0592a1ebc1f5aa2c91025d1cc631e9c6cccff245.zip
Correct some code in pg_restore when reading the header of a tar archive:
(1) The code doesn't initialize `sum', so the initial "does the checksum match?" test is wrong. (2) The loop that is intended to check for a "null block" just checks the first byte of the tar block 512 times, rather than each of the 512 bytes one time (!), which I'm guessing was the intent. It was only through sheer luck that this worked in the first place. Per Coverity static analysis performed by EnterpriseDB.
-rw-r--r--src/bin/pg_dump/pg_backup_tar.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
index 8cf9b15e1b8..0124481d9c7 100644
--- a/src/bin/pg_dump/pg_backup_tar.c
+++ b/src/bin/pg_dump/pg_backup_tar.c
@@ -16,7 +16,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.38 2003/10/08 03:52:32 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.38.2.1 2005/06/22 02:12:19 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1153,7 +1153,6 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
size_t len;
unsigned long ullen;
off_t hPos;
- int i;
bool gotBlock = false;
while (!gotBlock)
@@ -1176,7 +1175,7 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
hPos = ctx->tarFHpos;
/* Read a 512 byte block, return EOF, exit if short */
- len = _tarReadRaw(AH, &h[0], 512, NULL, ctx->tarFH);
+ len = _tarReadRaw(AH, h, 512, NULL, ctx->tarFH);
if (len == 0) /* EOF */
return 0;
@@ -1186,20 +1185,22 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
(unsigned long) len);
/* Calc checksum */
- chk = _tarChecksum(&h[0]);
+ chk = _tarChecksum(h);
+ sscanf(&h[148], "%8o", &sum);
/*
- * If the checksum failed, see if it is a null block. If so, then
- * just try with next block...
+ * If the checksum failed, see if it is a null block. If so,
+ * silently continue to the next block.
*/
-
if (chk == sum)
gotBlock = true;
else
{
+ int i;
+
for (i = 0; i < 512; i++)
{
- if (h[0] != 0)
+ if (h[i] != 0)
{
gotBlock = true;
break;
@@ -1211,7 +1212,6 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
sscanf(&h[0], "%99s", tag);
sscanf(&h[124], "%12lo", &ullen);
len = (size_t) ullen;
- sscanf(&h[148], "%8o", &sum);
{
char buf[100];