From: Michael R Sweet Date: Fri, 5 Dec 2025 15:28:44 +0000 (-0500) Subject: Don't follow symlinks when cleaning out the temporary directory (Issue #1448) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bee93f270fd1a14576a3be3250c7c88817592ab;p=thirdparty%2Fcups.git Don't follow symlinks when cleaning out the temporary directory (Issue #1448) --- diff --git a/scheduler/file.c b/scheduler/file.c index 298533b7ea..e909ed7cd1 100644 --- a/scheduler/file.c +++ b/scheduler/file.c @@ -30,6 +30,7 @@ cupsdCleanFiles(const char *path, /* I - Directory to clean */ cups_dir_t *dir; /* Directory */ cups_dentry_t *dent; /* Directory entry */ char filename[1024]; /* Filename */ + struct stat fileinfo; /* File link information */ int status; /* Status from unlink/rmdir */ @@ -48,15 +49,19 @@ cupsdCleanFiles(const char *path, /* I - Directory to clean */ continue; snprintf(filename, sizeof(filename), "%s/%s", path, dent->filename); + if (lstat(filename, &fileinfo)) + continue; - if (S_ISDIR(dent->fileinfo.st_mode)) + if (S_ISDIR(fileinfo.st_mode)) { cupsdCleanFiles(filename, pattern); status = rmdir(filename); } else + { status = cupsdUnlinkOrRemoveFile(filename); + } if (status) cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to remove \"%s\" - %s", filename,