From 880c0b87b4caab6ec3358c35beb29c864807343d Mon Sep 17 00:00:00 2001 From: Jash Date: Tue, 17 Nov 2026 10:02:24 +0530 Subject: [PATCH] fix: zone view shows the error page for a zone that is not found refs #6561 --- tests/php/test_zone_view_missing_zone.php | 62 +++++++++++++++++++++++ web/skins/classic/views/zone.php | 5 ++ 2 files changed, 67 insertions(+) create mode 100644 tests/php/test_zone_view_missing_zone.php diff --git a/tests/php/test_zone_view_missing_zone.php b/tests/php/test_zone_view_missing_zone.php new file mode 100644 index 0000000000..c3e2f830dc --- /dev/null +++ b/tests/php/test_zone_view_missing_zone.php @@ -0,0 +1,62 @@ + '7', 'zid' => $zid); + $view = 'zone'; + $warnings = array(); + set_error_handler(function($no, $str) use (&$warnings) { $warnings[] = $str; return true; }); + try { + require __DIR__.'/../../web/skins/classic/views/zone.php'; + } catch (Throwable $e) { + $warnings[] = $e->getMessage(); + } + restore_error_handler(); + return array($view, $warnings); + } + + list($view, $warnings) = run_view('99'); + check('zone that is not found shows the error view', $view, 'error'); + check('zone that is not found raises no warnings', $warnings, array()); + + echo "\n$passed passed, $failed failed\n"; + exit($failed ? 1 : 0); +} diff --git a/web/skins/classic/views/zone.php b/web/skins/classic/views/zone.php index 172a5fad04..28a12376e7 100644 --- a/web/skins/classic/views/zone.php +++ b/web/skins/classic/views/zone.php @@ -62,6 +62,11 @@ $maxY = 100; if ( !isset($zone) ) { if ( $zid > 0 ) { $zone = dbFetchOne('SELECT * FROM Zones WHERE MonitorId=? AND Id=?', NULL, array($monitor->Id(), $zid)); + if (!$zone) { + // A stale link to a deleted zone, or a zone of another monitor. + $view = 'error'; + return; + } } else { $zone = array( 'Id' => 0,