Skip to content

Commit

Permalink
[Filesystem] Safeguard (sym)link calls
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored and nicolas-grekas committed May 20, 2022
1 parent 72a5b35 commit 815412e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ private function isReadable(string $filename): bool
*/
public function symlink($originDir, $targetDir, $copyOnWindows = false)
{
self::assertFunctionExists('symlink');

if ('\\' === \DIRECTORY_SEPARATOR) {
$originDir = strtr($originDir, '/', '\\');
$targetDir = strtr($targetDir, '/', '\\');
Expand Down Expand Up @@ -354,6 +356,8 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
*/
public function hardlink($originFile, $targetFiles)
{
self::assertFunctionExists('link');

if (!$this->exists($originFile)) {
throw new FileNotFoundException(null, 0, null, $originFile);
}
Expand Down Expand Up @@ -737,13 +741,22 @@ private function getSchemeAndHierarchy(string $filename): array
return 2 === \count($components) ? [$components[0], $components[1]] : [null, $components[0]];
}

private static function assertFunctionExists(string $func): void
{
if (!\function_exists($func)) {
throw new IOException(sprintf('Unable to perform filesystem operation because the "%s()" function has been disabled.', $func));
}
}

/**
* @param mixed ...$args
*
* @return mixed
*/
private static function box(callable $func, ...$args)
private static function box(string $func, ...$args)
{
self::assertFunctionExists($func);

self::$lastError = null;
set_error_handler(__CLASS__.'::handleError');
try {
Expand Down

0 comments on commit 815412e

Please sign in to comment.