]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Use SBuf for Fs::Ufs::RebuildState file paths (#1063)
authorFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 8 Jun 2022 16:23:59 +0000 (16:23 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Wed, 8 Jun 2022 18:17:38 +0000 (18:17 +0000)
In theory, a combination of a non-terminating-on-overflows snprintf()
and an incorrectly guessed MAXPATHLEN (or a cache_dir root path being at
the edge of a correctly guessed MAXPATHLEN) may result in non-terminated
fullpath. Use SBuf to avoid these particular headaches.

Detected by Coverity. CID 1461166: Copy of overlapping memory
(OVERLAPPING_COPY).

src/fs/ufs/RebuildState.cc
src/fs/ufs/RebuildState.h

index eb7fc175d2c07b7cd4e5a21bb178560c8da31328..edb94e55f4b3f78ec5cdb990b0411d9ca224d20a 100644 (file)
@@ -43,8 +43,6 @@ Fs::Ufs::RebuildState::RebuildState(RefCount<UFSSwapDir> aSwapDir) :
     _done(false),
     cbdata(NULL)
 {
-    *fullpath = 0;
-    *fullfilename = 0;
 
     /*
      * If the swap.state file exists in the cache_dir, then
@@ -379,14 +377,14 @@ Fs::Ufs::RebuildState::getNextFile(sfileno * filn_p, int *)
         }
 
         if (0 == in_dir) {  /* we need to read in a new directory */
-            snprintf(fullpath, sizeof(fullpath), "%s/%02X/%02X",
+            fullpath.Printf("%s/%02X/%02X",
                      sd->path,
                      curlvl1, curlvl2);
 
             if (dirs_opened)
                 return -1;
 
-            td = opendir(fullpath);
+            td = opendir(fullpath.c_str());
 
             ++dirs_opened;
 
@@ -425,10 +423,10 @@ Fs::Ufs::RebuildState::getNextFile(sfileno * filn_p, int *)
                 continue;
             }
 
-            snprintf(fullfilename, sizeof(fullfilename), "%s/%s",
-                     fullpath, entry->d_name);
+            fullfilename.Printf(SQUIDSBUFPH "/%s",
+                         SQUIDSBUFPRINT(fullpath), entry->d_name);
             debugs(47, 3, "Opening " << fullfilename);
-            fd = file_open(fullfilename, O_RDONLY | O_BINARY);
+            fd = file_open(fullfilename.c_str(), O_RDONLY | O_BINARY);
 
             if (fd < 0) {
                 int xerrno = errno;
index d9c6f918f0a06483a815a21437c27635930b9e44..203c65ecd0fb85a4be2250062613befcfbf68fa3 100644 (file)
@@ -53,8 +53,8 @@ public:
 
     dirent_t *entry;
     DIR *td;
-    char fullpath[MAXPATHLEN];
-    char fullfilename[MAXPATHLEN*2];
+    SBuf fullpath;
+    SBuf fullfilename;
 
     StoreRebuildData counts;