From 815412ee8971209bd4c1eecd5f4f481eacd44bf5 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 19 May 2022 13:09:40 +0200 Subject: [PATCH] [Filesystem] Safeguard (sym)link calls --- Filesystem.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Filesystem.php b/Filesystem.php index 5c9bbd12b..fd1dbf39b 100644 --- a/Filesystem.php +++ b/Filesystem.php @@ -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, '/', '\\'); @@ -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); } @@ -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 {