Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2852a42

Browse filesBrowse files
bug #39788 [Cache] fix possible collision when writing tmp file in filesystem adapter (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [Cache] fix possible collision when writing tmp file in filesystem adapter | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #39786 | License | MIT | Doc PR | - Commits ------- 340d15e [Cache] fix possible collision when writing tmp file in filesystem adapter
2 parents b85611f + 340d15e commit 2852a42
Copy full SHA for 2852a42

File tree

1 file changed

+13
-2
lines changed
Filter options

1 file changed

+13
-2
lines changed

‎src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,20 @@ private function write(string $file, string $data, int $expiresAt = null)
9393
set_error_handler(__CLASS__.'::throwError');
9494
try {
9595
if (null === $this->tmp) {
96-
$this->tmp = $this->directory.uniqid('', true);
96+
$this->tmp = $this->directory.bin2hex(random_bytes(6));
9797
}
98-
file_put_contents($this->tmp, $data);
98+
try {
99+
$h = fopen($this->tmp, 'x');
100+
} catch (\ErrorException $e) {
101+
if (false === strpos($e->getMessage(), 'File exists')) {
102+
throw $e;
103+
}
104+
105+
$this->tmp = $this->directory.bin2hex(random_bytes(6));
106+
$h = fopen($this->tmp, 'x');
107+
}
108+
fwrite($h, $data);
109+
fclose($h);
99110

100111
if (null !== $expiresAt) {
101112
touch($this->tmp, $expiresAt);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.