From 050a0195deb23310c826075425b60eb3485c8d8d Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Mon, 18 Nov 2024 21:55:09 -0300 Subject: [PATCH] fix: consider open_basedir Signed-off-by: Vitor Mattos --- src/OperatingSystem.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/OperatingSystem.php b/src/OperatingSystem.php index 83b3760..ee77a0b 100644 --- a/src/OperatingSystem.php +++ b/src/OperatingSystem.php @@ -77,7 +77,11 @@ public function getLinuxDistribution(): string private function getFromEtcRelease(): string { $file = $this->rootFolder . '/etc/*-release'; - foreach (glob($file) as $path) { + $filesFound = glob($file); + if (!$filesFound) { + return ''; + } + foreach ($filesFound as $path) { $content = file_get_contents($path); preg_match('/^ID=(?.*)$/m', $content, $matches); if (isset($matches['version'])) { @@ -102,10 +106,12 @@ public function getFromLsbRelease(): string private function isDebian(): string { - if (file_exists($this->rootFolder . '/etc/debian_version')) { - return 'Debian'; + if ($this->isInOpenBasedir($this->rootFolder . '/etc/debian_version')) { + if (file_exists($this->rootFolder . '/etc/debian_version')) { + return 'Debian'; + } } - if (!$this->runSafe('type apt 2>/dev/null >/dev/null &')) { + if (!$this->runSafe('type apt')) { return ''; } return 'Debian'; @@ -113,7 +119,7 @@ private function isDebian(): string private function isAlpine(): string { - if (!$this->runSafe('type apk 2>/dev/null >/dev/null &')) { + if (!$this->runSafe('type apk')) { return ''; } return 'Alpine'; @@ -121,7 +127,15 @@ private function isAlpine(): string private function runSafe(string $command): string { - $output = shell_exec($command . ' 2>/dev/null >/dev/null &'); + $output = shell_exec($command . ' 2>/dev/null'); return (string) $output; } + + private function isInOpenBasedir(string $path): bool { + $openBasedir = ini_get('open_basedir'); + if (empty($openBasedir) || strpos($openBasedir, $path) !== false) { + return true; + } + return false; + } }