Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions system/src/Grav/Framework/Cache/Adapter/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private function write($file, $data, $expiresAt = null)

try {
if ($this->tmp === null) {
$this->tmp = $this->directory . uniqid('', true);
$this->tmp = $this->directory . uniqid(__CLASS__, true);
}
Comment on lines 202 to 205

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Sanitize temp-file prefix on Windows

The new temp filename uses uniqid(__CLASS__, true), but __CLASS__ contains backslashes. On Windows these are treated as path separators, so the prefix Grav\Framework\Cache\Adapter\FileCache... expands into nested directories under $this->directory that are never created. As soon as file_put_contents($this->tmp, $data) runs, cache writes will fail with "No such file or directory" and the cache backend becomes unusable on Windows installations. Consider stripping namespace separators or using a simple prefix like FileCache.

Useful? React with 👍 / 👎.


file_put_contents($this->tmp, $data);
Expand Down Expand Up @@ -259,7 +259,7 @@ public static function throwError($type, $message, $file, $line)
#[\ReturnTypeWillChange]
public function __destruct()
{
if ($this->tmp !== null && file_exists($this->tmp)) {
if ($this->tmp !== null && (strpos(basename($this->tmp), __CLASS__) === 0) && file_exists($this->tmp)) {
unlink($this->tmp);
}
}
Expand Down