8000 [Filesystem] Strengthen the check of file permissions in `dumpFile` · symfony/symfony@e91d15d · GitHub
[go: up one dir, main page]

Skip to content

Commit e91d15d

Browse files
[Filesystem] Strengthen the check of file permissions in dumpFile
1 parent 50268e6 commit e91d15d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,8 @@ public function dumpFile(string $filename, $content)
691691
throw new IOException(sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename);
692692
}
693693

694-
self::box('chmod', $tmpFile, file_exists($filename) ? fileperms($filename) : 0666 & ~umask());
694+
$perms = @fileperms($filename);
695+
self::box('chmod', $tmpFile, file_exists($filename) && false !== $perms ? $perms : 0666 & ~umask());
695696

696697
$this->rename($tmpFile, $filename, true);
697698
} finally {

src/Symfony/Component/Mime/Tests/AbstractMimeTypeGuesserTestCase.php

+2-1
Origina 7DC3 l file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public function testGuessWithNonReadablePath()
116116
touch($path);
117117
@chmod($path, 0333);
118118

119-
if (str_ends_with(sprintf('%o', fileperms($path)), '0333')) {
119+
$perms = @fileperms($path);
120+
if (false !== $perms && str_ends_with(sprintf('%o', $perms), '0333')) {
120121
$this->expectException(\InvalidArgumentException::class);
121122
$this->getGuesser()->guessMimeType($path);
122123
} else {

0 commit comments

Comments
 (0)
0