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

Commit3d5c332

Browse files
committed
Repair various defects indc21234.
pg_combinebackup had various problems:* strncpy was used in various places where strlcpy should be used instead, to avoid any possibility of the result not being \0-terminated.* scan_for_existing_tablespaces() failed to close the directory, and an error when opening the directory was reported with the wrong pathname.* write_reconstructed_file() contained some redundant and therefore dead code.* flush_manifest() didn't check the result of pg_checksum_update() as we do in other places, and misused a local pathname variable that shouldn't exist at all.In pg_basebackup, the wrong variable name was used in one place,due to a copy and paste that was not properly adjusted.In blkreftable.c, the loop incorrectly doubled chunkno instead ofmax_chunks. Fix that. Also remove a nearby assertion per repeatedoff-list complaints from Tom Lane.Per Coverity and subsequent code inspection by me and by Tom Lane.Discussion:http://postgr.es/m/CA+Tgmobvqqj-DW9F7uUzT-cQqs6wcVb-Xhs=w=hzJnXSE-kRGw@mail.gmail.com
1 parentee1bfd1 commit3d5c332

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
709709
PQserverVersion(conn)<MINIMUM_VERSION_FOR_PG_WAL ?
710710
"pg_xlog" :"pg_wal");
711711

712-
if (pg_mkdir_p(statusdir,pg_dir_create_mode)!=0&&
712+
if (pg_mkdir_p(summarydir,pg_dir_create_mode)!=0&&
713713
errno!=EEXIST)
714714
pg_fatal("could not create directory \"%s\": %m",summarydir);
715715
}

‎src/bin/pg_combinebackup/pg_combinebackup.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,8 @@ process_directory_recursively(Oid tsoid,
773773
*/
774774
if (relative_path==NULL)
775775
{
776-
strncpy(ifulldir,input_directory,MAXPGPATH);
777-
strncpy(ofulldir,output_directory,MAXPGPATH);
776+
strlcpy(ifulldir,input_directory,MAXPGPATH);
777+
strlcpy(ofulldir,output_directory,MAXPGPATH);
778778
if (OidIsValid(tsoid))
779779
snprintf(manifest_prefix,MAXPGPATH,"pg_tblspc/%u/",tsoid);
780780
else
@@ -855,7 +855,7 @@ process_directory_recursively(Oid tsoid,
855855

856856
/* Append new pathname component to relative path. */
857857
if (relative_path==NULL)
858-
strncpy(new_relative_path,de->d_name,MAXPGPATH);
858+
strlcpy(new_relative_path,de->d_name,MAXPGPATH);
859859
else
860860
snprintf(new_relative_path,MAXPGPATH,"%s/%s",relative_path,
861861
de->d_name);
@@ -1131,7 +1131,7 @@ scan_for_existing_tablespaces(char *pathname, cb_options *opt)
11311131
pg_log_debug("scanning \"%s\"",pg_tblspc);
11321132

11331133
if ((dir=opendir(pg_tblspc))==NULL)
1134-
pg_fatal("could not open directory \"%s\": %m",pathname);
1134+
pg_fatal("could not open directory \"%s\": %m",pg_tblspc);
11351135

11361136
while (errno=0, (de=readdir(dir))!=NULL)
11371137
{
@@ -1203,8 +1203,8 @@ scan_for_existing_tablespaces(char *pathname, cb_options *opt)
12031203
{
12041204
if (strcmp(tsmap->old_dir,link_target)==0)
12051205
{
1206-
strncpy(ts->old_dir,tsmap->old_dir,MAXPGPATH);
1207-
strncpy(ts->new_dir,tsmap->new_dir,MAXPGPATH);
1206+
strlcpy(ts->old_dir,tsmap->old_dir,MAXPGPATH);
1207+
strlcpy(ts->new_dir,tsmap->new_dir,MAXPGPATH);
12081208
ts->in_place= false;
12091209
break;
12101210
}
@@ -1238,6 +1238,9 @@ scan_for_existing_tablespaces(char *pathname, cb_options *opt)
12381238
tslist=ts;
12391239
}
12401240

1241+
if (closedir(dir)!=0)
1242+
pg_fatal("could not close directory \"%s\": %m",pg_tblspc);
1243+
12411244
returntslist;
12421245
}
12431246

‎src/bin/pg_combinebackup/reconstruct.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,12 @@ write_reconstructed_file(char *input_filename,
577577
{
578578
if (current_block==start_of_range)
579579
appendStringInfo(&debug_buf," %u:%s@"UINT64_FORMAT,
580-
current_block,
581-
s==NULL ?"ZERO" :s->filename,
580+
current_block,s->filename,
582581
(uint64)offsetmap[current_block]);
583582
else
584583
appendStringInfo(&debug_buf," %u-%u:%s@"UINT64_FORMAT,
585584
start_of_range,current_block,
586-
s==NULL ?"ZERO" :s->filename,
585+
s->filename,
587586
(uint64)offsetmap[current_block]);
588587
}
589588

‎src/bin/pg_combinebackup/write_manifest.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ escape_json(StringInfo buf, const char *str)
241241
staticvoid
242242
flush_manifest(manifest_writer*mwriter)
243243
{
244-
charpathname[MAXPGPATH];
245-
246244
if (mwriter->fd==-1&&
247245
(mwriter->fd=open(mwriter->pathname,
248246
O_WRONLY |O_CREAT |O_EXCL |PG_BINARY,
@@ -260,13 +258,15 @@ flush_manifest(manifest_writer *mwriter)
260258
pg_fatal("could not write \"%s\": %m",mwriter->pathname);
261259
else
262260
pg_fatal("could not write file \"%s\": wrote only %d of %d bytes",
263-
pathname, (int)wb,mwriter->buf.len);
261+
mwriter->pathname, (int)wb,mwriter->buf.len);
264262
}
265263

266-
if (mwriter->still_checksumming)
264+
if (mwriter->still_checksumming&&
267265
pg_checksum_update(&mwriter->manifest_ctx,
268266
(uint8*)mwriter->buf.data,
269-
mwriter->buf.len);
267+
mwriter->buf.len)<0)
268+
pg_fatal("could not update checksum of file \"%s\"",
269+
mwriter->pathname);
270270
resetStringInfo(&mwriter->buf);
271271
}
272272
}

‎src/common/blkreftable.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,7 @@ BlockRefTableEntryMarkBlockModified(BlockRefTableEntry *entry,
988988
*/
989989
max_chunks=Max(16,entry->nchunks);
990990
while (max_chunks<chunkno+1)
991-
chunkno *=2;
992-
Assert(max_chunks>chunkno);
991+
max_chunks *=2;
993992
extra_chunks=max_chunks-entry->nchunks;
994993

995994
if (entry->nchunks==0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp