Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 05db8b5

Browse files
author
Neil Conway
committed
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.
1 parent 06ecacd commit 05db8b5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/bin/pg_dump/pg_backup_tar.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.47 2005/01/25 22:44:31 tgl Exp $
19+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.48 2005/06/22 02:00:47 neilc Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -1155,7 +1155,6 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
11551155
size_t len;
11561156
unsigned long ullen;
11571157
off_t hPos;
1158-
int i;
11591158
bool gotBlock = false;
11601159

11611160
while (!gotBlock)
@@ -1178,7 +1177,7 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
11781177
hPos = ctx->tarFHpos;
11791178

11801179
/* Read a 512 byte block, return EOF, exit if short */
1181-
len = _tarReadRaw(AH, &h[0], 512, NULL, ctx->tarFH);
1180+
len = _tarReadRaw(AH, h, 512, NULL, ctx->tarFH);
11821181
if (len == 0) /* EOF */
11831182
return 0;
11841183

@@ -1188,20 +1187,22 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
11881187
(unsigned long) len);
11891188

11901189
/* Calc checksum */
1191-
chk = _tarChecksum(&h[0]);
1190+
chk = _tarChecksum(h);
1191+
sscanf(&h[148], "%8o", &sum);
11921192

11931193
/*
1194-
* If the checksum failed, see if it is a null block. If so, then
1195-
* just try with next block...
1194+
* If the checksum failed, see if it is a null block. If so,
1195+
* silently continue to the next block.
11961196
*/
1197-
11981197
if (chk == sum)
11991198
gotBlock = true;
12001199
else
12011200
{
1201+
int i;
1202+
12021203
for (i = 0; i < 512; i++)
12031204
{
1204-
if (h[0] != 0)
1205+
if (h[i] != 0)
12051206
{
12061207
gotBlock = true;
12071208
break;
@@ -1213,7 +1214,6 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
12131214
sscanf(&h[0], "%99s", tag);
12141215
sscanf(&h[124], "%12lo", &ullen);
12151216
len = (size_t) ullen;
1216-
sscanf(&h[148], "%8o", &sum);
12171217

12181218
{
12191219
char buf[100];

0 commit comments

Comments
 (0)