Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9647d10

Browse files
committed
[Filesystem] Safeguard (sym)link calls
1 parent 1a7fa5d commit 9647d10

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 11 additions & 0 deletions
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::assertOperationIsAvailable('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::assertOperationIsAvailable('link');
360+
357361
if (!$this->exists($originFile)) {
358362
throw new FileNotFoundException(null, 0, null, $originFile);
359363
}
@@ -737,6 +741,13 @@ private function getSchemeAndHierarchy(string $filename): array
737741
return 2 === \count($components) ? [$components[0], $components[1]] : [null, $components[0]];
738742
}
739743

744+
private static function assertOperationIsAvailable(string $functionName): void
745+
{
746+
if (!\function_exists($functionName)) {
747+
throw new IOException(sprintf('Unable to perform filesystem operation because the %s() function has been disabled.', $functionName));
748+
}
749+
}
750+
740751
/**
741752
* @param mixed ...$args
742753
*

0 commit comments

Comments
 (0)