From 09847016b8816b5fbf37aeb5af93cd553f76b8ac Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 18 Jan 2024 14:40:35 +0100 Subject: [locations/statistics] More type safety, array key checks --- modules-available/statistics/pages/machine.inc.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'modules-available/statistics/pages/machine.inc.php') diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php index fe82797d..1d46b523 100644 --- a/modules-available/statistics/pages/machine.inc.php +++ b/modules-available/statistics/pages/machine.inc.php @@ -229,18 +229,20 @@ class SubPage } // BIOS update check if (!empty($client['bios']['BIOS Revision']) || !empty($client['bios']['Release Date'])) { - if (preg_match('#^(\d{1,2})/(\d{1,2})/(\d{4})#', $client['bios']['Release Date'], $out)) { + if (preg_match('#^(\d{1,2})/(\d{1,2})/(\d{4})#', $client['bios']['Release Date'] ?? '', $out)) { $client['bios']['Release Date'] = $out[2] . '.' . $out[1] . '.' . $out[3]; } $mainboard = ($client['mainboard']['Manufacturer'] ?? '') . '##' . ($client['mainboard']['Product Name'] ?? ''); $system = ($client['system']['Manufacturer'] ?? '') . '##' . ($client['system']['Product Name'] ?? ''); - $ret = self::checkBios($mainboard, $system, $client['bios']['Release Date'], $client['bios']['BIOS Revision']); + $ret = self::checkBios($mainboard, $system, + $client['bios']['Release Date'] ?? null, + $client['bios']['BIOS Revision'] ?? null); if ($ret === false) { // Not loaded, use AJAX $params = [ 'mainboard' => $mainboard, 'system' => $system, - 'date' => $client['bios']['Release Date'], - 'revision' => $client['bios']['BIOS Revision'], + 'date' => $client['bios']['Release Date'] ?? null, + 'revision' => $client['bios']['BIOS Revision'] ?? null, ]; $client['biosurl'] = '?do=statistics&action=bios&' . http_build_query($params); } elseif (!isset($ret['status']) || $ret['status'] !== 0) { @@ -677,7 +679,7 @@ class SubPage die(Render::parse('machine-bios-update', $reply)); } - private static function checkBios($mainboard, $system, $date, $revision, $json = null) + private static function checkBios(string $mainboard, string $system, ?string $date, ?string $revision, $json = null) { if ($json === null) { if (!file_exists(self::BIOS_CACHE) || filemtime(self::BIOS_CACHE) + 3600 < time()) @@ -694,10 +696,10 @@ class SubPage return ['status' => 0]; } $key = $match['match']; - if ($key === 'revision') { + if ($key === 'revision' && $revision !== null) { $cmp = function ($item) { $s = explode('.', $item); return $s[0] * 0x10000 + $s[1]; }; $reference = $cmp($revision); - } elseif ($key === 'date') { + } elseif ($key === 'date' && $date !== null) { $cmp = function ($item) { $s = explode('.', $item); return $s[2] * 10000 + $s[1] * 100 + $s[0]; }; $reference = $cmp($date); } else { -- cgit v1.2.3-55-g7522