]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Correct path manipulation when reading all files in a directory
authorNick Porter <nick@portercomputing.co.uk>
Tue, 14 Oct 2025 17:31:49 +0000 (18:31 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Tue, 14 Oct 2025 17:34:09 +0000 (18:34 +0100)
src/lib/util/file.c

index 84d4f14add0c4ee422532a0e2f5ed468f30a1407..3f8b7bc786dee6703308a2e0b3e3c7624ccc7844 100644 (file)
@@ -433,6 +433,7 @@ static bool fr_globdir_file_ok(char const *try, fr_globdir_iter_t *iter)
 {
        size_t len, room;
        char const *p;
+       char *filename;
        struct stat stat_buf;
 
        /*
@@ -489,12 +490,18 @@ static bool fr_globdir_file_ok(char const *try, fr_globdir_iter_t *iter)
        if ((len > 7) && (strncmp(&try[len - 7], ".rpmnew", 9) == 0)) return false;
        if ((len > 8) && (strncmp(&try[len - 8], ".rpmsave", 10) == 0)) return false;
 
+       /*
+        *      When reading all files in a directory, iter->filename points to the directory
+        *      name which is being read.  The file being tested needs to be added after that.
+        */
+       filename = iter->filename + (iter->type == FR_GLOBDIR_DIR ? strlen(iter->filename) : 0);
+
        /*
         *      strlcpy() returns the length of the input, which can be larger than the available space.
         */
-       room = (iter->path + PATH_MAX) - iter->filename;
+       room = (iter->path + PATH_MAX) - filename;
 
-       if (strlcpy(iter->filename, try, room) >= room) return false;
+       if (strlcpy(filename, try, room) >= room) return false;
 
        /*
         *      We only read normal files which are NOT executable, and symlinks.