Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit05db8b5

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 parent06ecacd commit05db8b5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

‎src/bin/pg_dump/pg_backup_tar.c

Lines changed: 9 additions & 9 deletions
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_tlen;
11561156
unsigned longullen;
11571157
off_thPos;
1158-
inti;
11591158
boolgotBlock= 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
return0;
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 withnext block...
1194+
* If the checksum failed, see if it is a null block. If so,
1195+
*silently continue to thenext block.
11961196
*/
1197-
11981197
if (chk==sum)
11991198
gotBlock= true;
12001199
else
12011200
{
1201+
inti;
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
charbuf[100];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp