Skip to content

Commit

Permalink
bug #54471 [Filesystem] Strengthen the check of file permissions in `…
Browse files Browse the repository at this point in the history
…dumpFile` (alexandre-daubois)

This PR was merged into the 5.4 branch.

Discussion
----------

[Filesystem] Strengthen the check of file permissions in `dumpFile`

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #54444
| License       | MIT

`fileperms()` can fail and return `false`, I think we should strengthen the checks on its return value when using it to avoid undesirable behavior.

Commits
-------

0c17a4e327 [Filesystem] Strengthen the check of file permissions in `dumpFile`
  • Loading branch information
nicolas-grekas committed Apr 4, 2024
2 parents 4303603 + 6dc5233 commit db9c7b1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public function dumpFile(string $filename, $content)
throw new IOException(sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename);
}

self::box('chmod', $tmpFile, file_exists($filename) ? fileperms($filename) : 0666 & ~umask());
self::box('chmod', $tmpFile, @fileperms($filename) ?: 0666 & ~umask());

$this->rename($tmpFile, $filename, true);
} finally {
Expand Down

0 comments on commit db9c7b1

Please sign in to comment.