From 9ad860741525b89385ea9b8faffc4c6b52f8b973 Mon Sep 17 00:00:00 2001 From: Zebra North Date: Wed, 11 Dec 2024 19:32:54 +0000 Subject: [PATCH] Don't throw if open_basedir is enabled --- src/SDK/Resource/Detectors/Host.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/SDK/Resource/Detectors/Host.php b/src/SDK/Resource/Detectors/Host.php index 3a353cc67..8228ce5a6 100644 --- a/src/SDK/Resource/Detectors/Host.php +++ b/src/SDK/Resource/Detectors/Host.php @@ -53,10 +53,14 @@ private function getLinuxId(): ?string foreach ($paths as $path) { $file = $this->dir . $path; - if (is_file($file) && is_readable($file)) { - $contents = file_get_contents($file); - - return $contents !== false ? trim($contents) : null; + try { + if (is_file($file) && is_readable($file)) { + $contents = file_get_contents($file); + + return $contents !== false ? trim($contents) : null; + } + } catch (ErrorException $ex) { + // This may occur if open_basedir is enabled. } } @@ -66,10 +70,14 @@ private function getLinuxId(): ?string private function getBsdId(): ?string { $file = $this->dir . self::PATH_ETC_HOSTID; - if (is_file($file) && is_readable($file)) { - $contents = file_get_contents($file); + try { + if (is_file($file) && is_readable($file)) { + $contents = file_get_contents($file); - return $contents !== false ? trim($contents) : null; + return $contents !== false ? trim($contents) : null; + } + } catch (ErrorException $ex) { + // This may occur if open_basedir is enabled. } $out = exec('which kenv && kenv -q smbios.system.uuid');