From 7b5cbb50788799be5dadd0136bb3a17339da4eb5 Mon Sep 17 00:00:00 2001 From: John Spaetzel Date: Thu, 14 Nov 2024 21:42:53 -0800 Subject: [PATCH] guard against possible false value from file_get_contents in Host.php (#1430) --- src/SDK/Resource/Detectors/Host.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/SDK/Resource/Detectors/Host.php b/src/SDK/Resource/Detectors/Host.php index 7d74f6991..3a353cc67 100644 --- a/src/SDK/Resource/Detectors/Host.php +++ b/src/SDK/Resource/Detectors/Host.php @@ -54,7 +54,9 @@ private function getLinuxId(): ?string foreach ($paths as $path) { $file = $this->dir . $path; if (is_file($file) && is_readable($file)) { - return trim(file_get_contents($file)); + $contents = file_get_contents($file); + + return $contents !== false ? trim($contents) : null; } } @@ -65,7 +67,9 @@ private function getBsdId(): ?string { $file = $this->dir . self::PATH_ETC_HOSTID; if (is_file($file) && is_readable($file)) { - return trim(file_get_contents($file)); + $contents = file_get_contents($file); + + return $contents !== false ? trim($contents) : null; } $out = exec('which kenv && kenv -q smbios.system.uuid');