From f1670b0456e51e28a4e642a05a15cfb6de4e7856 Mon Sep 17 00:00:00 2001 From: Yannick Martin Date: Fri, 16 Jan 2026 18:14:46 +0100 Subject: [PATCH] Fix(#10687): address null pointer dereference on navigate (cherry picked from commit 1f7c38c792313c5e01dc41a5410645ef8fc6d1f3) --- lib/icinga/comment.ti | 10 ++++++---- lib/icinga/dependency.ti | 20 ++++++++++++-------- lib/icinga/downtime.ti | 10 ++++++---- lib/icinga/notification.ti | 10 ++++++---- lib/icinga/scheduleddowntime.ti | 10 ++++++---- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/lib/icinga/comment.ti b/lib/icinga/comment.ti index 8fbb2da17d0..2863f5608c2 100644 --- a/lib/icinga/comment.ti +++ b/lib/icinga/comment.ti @@ -52,11 +52,13 @@ class Comment : ConfigObject < CommentNameComposer } }}} navigate {{{ - if (GetServiceName().IsEmpty()) - return nullptr; + if (!GetServiceName().IsEmpty()) { + Host::Ptr host = Host::GetByName(GetHostName()); + if (host) + return host->GetServiceByShortName(GetServiceName()); + } - Host::Ptr host = Host::GetByName(GetHostName()); - return host->GetServiceByShortName(GetServiceName()); + return nullptr; }}} }; diff --git a/lib/icinga/dependency.ti b/lib/icinga/dependency.ti index 6d6249d9f83..6cd85742bdb 100644 --- a/lib/icinga/dependency.ti +++ b/lib/icinga/dependency.ti @@ -44,11 +44,13 @@ class Dependency : CustomVarObject < DependencyNameComposer } }}} navigate {{{ - if (GetChildServiceName().IsEmpty()) - return nullptr; + if (!GetChildServiceName().IsEmpty()) { + Host::Ptr host = Host::GetByName(GetChildHostName()); + if (host) + return host->GetServiceByShortName(GetChildServiceName()); + } - Host::Ptr host = Host::GetByName(GetChildHostName()); - return host->GetServiceByShortName(GetChildServiceName()); + return nullptr; }}} }; @@ -71,11 +73,13 @@ class Dependency : CustomVarObject < DependencyNameComposer } }}} navigate {{{ - if (GetParentServiceName().IsEmpty()) - return nullptr; + if (!GetParentServiceName().IsEmpty()) { + Host::Ptr host = Host::GetByName(GetParentHostName()); + if (host) + return host->GetServiceByShortName(GetParentServiceName()); + } - Host::Ptr host = Host::GetByName(GetParentHostName()); - return host->GetServiceByShortName(GetParentServiceName()); + return nullptr; }}} }; diff --git a/lib/icinga/downtime.ti b/lib/icinga/downtime.ti index b1530abe114..2193732db53 100644 --- a/lib/icinga/downtime.ti +++ b/lib/icinga/downtime.ti @@ -43,11 +43,13 @@ class Downtime : ConfigObject < DowntimeNameComposer } }}} navigate {{{ - if (GetServiceName().IsEmpty()) - return nullptr; + if (!GetServiceName().IsEmpty()) { + Host::Ptr host = Host::GetByName(GetHostName()); + if (host) + return host->GetServiceByShortName(GetServiceName()); + } - Host::Ptr host = Host::GetByName(GetHostName()); - return host->GetServiceByShortName(GetServiceName()); + return nullptr; }}} }; diff --git a/lib/icinga/notification.ti b/lib/icinga/notification.ti index e8c4418cdb1..7ee3d88fb69 100644 --- a/lib/icinga/notification.ti +++ b/lib/icinga/notification.ti @@ -69,11 +69,13 @@ class Notification : CustomVarObject < NotificationNameComposer } }}} navigate {{{ - if (GetServiceName().IsEmpty()) - return nullptr; + if (!GetServiceName().IsEmpty()) { + Host::Ptr host = Host::GetByName(GetHostName()); + if (host) + return host->GetServiceByShortName(GetServiceName()); + } - Host::Ptr host = Host::GetByName(GetHostName()); - return host->GetServiceByShortName(GetServiceName()); + return nullptr; }}} }; diff --git a/lib/icinga/scheduleddowntime.ti b/lib/icinga/scheduleddowntime.ti index c44228b1c84..15b7b59d4c8 100644 --- a/lib/icinga/scheduleddowntime.ti +++ b/lib/icinga/scheduleddowntime.ti @@ -44,11 +44,13 @@ class ScheduledDowntime : CustomVarObject < ScheduledDowntimeNameComposer } }}} navigate {{{ - if (GetServiceName().IsEmpty()) - return nullptr; + if (!GetServiceName().IsEmpty()) { + Host::Ptr host = Host::GetByName(GetHostName()); + if (host) + return host->GetServiceByShortName(GetServiceName()); + } - Host::Ptr host = Host::GetByName(GetHostName()); - return host->GetServiceByShortName(GetServiceName()); + return nullptr; }}} };