@@ -566,31 +566,29 @@ pgstat_reset_remove_files(const char *directory)
566566dir = AllocateDir (directory );
567567while ((entry = ReadDir (dir ,directory ))!= NULL )
568568{
569- int nitems ;
570- Oid tmp_oid ;
571- char tmp_type [8 ];
572- char tmp_rest [2 ];
573-
574- if (strncmp (entry -> d_name ,"." ,2 )== 0 ||
575- strncmp (entry -> d_name ,".." ,3 )== 0 )
576- continue ;
569+ int nchars ;
570+ Oid tmp_oid ;
577571
578572/*
579573 * Skip directory entries that don't match the file names we write.
580574 * See get_dbstat_filename for the database-specific pattern.
581575 */
582- nitems = sscanf ( entry -> d_name ,"db_%u.%5s%1s" ,
583- & tmp_oid , tmp_type , tmp_rest ) ;
584- if ( nitems != 2 )
576+ if ( strncmp ( entry -> d_name ,"global." , 7 ) == 0 )
577+ nchars = 7 ;
578+ else
585579{
586- nitems = sscanf (entry -> d_name ,"global.%5s%1s" ,
587- tmp_type ,tmp_rest );
588- if (nitems != 1 )
580+ nchars = 0 ;
581+ (void )sscanf (entry -> d_name ,"db_%u.%n" ,
582+ & tmp_oid ,& nchars );
583+ if (nchars <=0 )
584+ continue ;
585+ /* %u allows leading whitespace, so reject that */
586+ if (strchr ("0123456789" ,entry -> d_name [3 ])== NULL )
589587continue ;
590588}
591589
592- if (strncmp ( tmp_type ,"tmp" , 4 )!= 0 &&
593- strncmp ( tmp_type ,"stat" , 5 )!= 0 )
590+ if (strcmp ( entry -> d_name + nchars ,"tmp" )!= 0 &&
591+ strcmp ( entry -> d_name + nchars ,"stat" )!= 0 )
594592continue ;
595593
596594snprintf (fname ,MAXPGPATH ,"%s/%s" ,directory ,