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

Commit59bc4a4

Browse files
committed
Be more wary of unwanted whitespace in pgstat_reset_remove_files().
sscanf isn't the easiest thing to use for exact pattern checks ...also, don't use strncmp where strcmp will do.
1 parentdb5b49c commit59bc4a4

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -565,31 +565,29 @@ pgstat_reset_remove_files(const char *directory)
565565
dir=AllocateDir(directory);
566566
while ((entry=ReadDir(dir,directory))!=NULL)
567567
{
568-
intnitems;
569-
Oidtmp_oid;
570-
chartmp_type[8];
571-
chartmp_rest[2];
572-
573-
if (strncmp(entry->d_name,".",2)==0||
574-
strncmp(entry->d_name,"..",3)==0)
575-
continue;
568+
intnchars;
569+
Oidtmp_oid;
576570

577571
/*
578572
* Skip directory entries that don't match the file names we write.
579573
* See get_dbstat_filename for the database-specific pattern.
580574
*/
581-
nitems=sscanf(entry->d_name,"db_%u.%5s%1s",
582-
&tmp_oid,tmp_type,tmp_rest);
583-
if (nitems!=2)
575+
if (strncmp(entry->d_name,"global.",7)==0)
576+
nchars=7;
577+
else
584578
{
585-
nitems=sscanf(entry->d_name,"global.%5s%1s",
586-
tmp_type,tmp_rest);
587-
if (nitems!=1)
579+
nchars=0;
580+
(void)sscanf(entry->d_name,"db_%u.%n",
581+
&tmp_oid,&nchars);
582+
if (nchars <=0)
583+
continue;
584+
/* %u allows leading whitespace, so reject that */
585+
if (strchr("0123456789",entry->d_name[3])==NULL)
588586
continue;
589587
}
590588

591-
if (strncmp(tmp_type,"tmp",4)!=0&&
592-
strncmp(tmp_type,"stat",5)!=0)
589+
if (strcmp(entry->d_name+nchars,"tmp")!=0&&
590+
strcmp(entry->d_name+nchars,"stat")!=0)
593591
continue;
594592

595593
snprintf(fname,MAXPGPATH,"%s/%s",directory,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp