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 2ec626f

Browse filesBrowse files
committed
bug #46407 [Filesystem] Safeguard (sym)link calls (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- [Filesystem] Safeguard (sym)link calls | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #46402 | License | MIT | Doc PR | N/A This PR let's link and symlink operations fail if the corresponding PHP functions are unavailable, e.g. because they have been disabled. Without the patch, the user receives a cryptic `TypeError` in such cases. I'm not really sure, if I can write tests for this scenario because we cannot disable those functions at runtime, can we? Commits ------- c15028f [Filesystem] Safeguard (sym)link calls
2 parents c6a2331 + c15028f commit 2ec626f
Copy full SHA for 2ec626f

File tree

1 file changed

+14
-1
lines changed
Filter options

1 file changed

+14
-1
lines changed

‎src/Symfony/Component/Filesystem/Filesystem.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Filesystem.php
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ private function isReadable(string $filename): bool
318318
*/
319319
public function symlink($originDir, $targetDir, $copyOnWindows = false)
320320
{
321+
self::assertFunctionExists('symlink');
322+
321323
if ('\\' === \DIRECTORY_SEPARATOR) {
322324
$originDir = strtr($originDir, '/', '\\');
323325
$targetDir = strtr($targetDir, '/', '\\');
@@ -354,6 +356,8 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
354356
*/
355357
public function hardlink($originFile, $targetFiles)
356358
{
359+
self::assertFunctionExists('link');
360+
357361
if (!$this->exists($originFile)) {
358362
throw new FileNotFoundException(null, 0, null, $originFile);
359363
}
@@ -737,13 +741,22 @@ private function getSchemeAndHierarchy(string $filename): array
737741
return 2 === \count($components) ? [$components[0], $components[1]] : [null, $components[0]];
738742
}
739743

744+
private static function assertFunctionExists(string $func): void
745+
{
746+
if (!\function_exists($func)) {
747+
throw new IOException(sprintf('Unable to perform filesystem operation because the "%s()" function has been disabled.', $func));
748+
}
749+
}
750+
740751
/**
741752
* @param mixed ...$args
742753
*
743754
* @return mixed
744755
*/
745-
private static function box(callable $func, ...$args)
756+
private static function box(string $func, ...$args)
746757
{
758+
self::assertFunctionExists($func);
759+
747760
self::$lastError = null;
748761
set_error_handler(__CLASS__.'::handleError');
749762
try {

0 commit comments

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