Merge pull request #10698 from ymartin-ovh/pr-10687

Fix nullptr dereference on `{child_,parent_}service` navigation
This commit is contained in:
Yonas Habteab 2026-01-30 16:49:19 +01:00 committed by GitHub
commit 36b41dbe11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 24 deletions

View file

@ -52,11 +52,13 @@ class Comment : ConfigObject < CommentNameComposer
} }
}}} }}}
navigate {{{ navigate {{{
if (GetServiceName().IsEmpty()) if (!GetServiceName().IsEmpty()) {
return nullptr; Host::Ptr host = Host::GetByName(GetHostName());
if (host)
return host->GetServiceByShortName(GetServiceName());
}
Host::Ptr host = Host::GetByName(GetHostName()); return nullptr;
return host->GetServiceByShortName(GetServiceName());
}}} }}}
}; };

View file

@ -44,11 +44,13 @@ class Dependency : CustomVarObject < DependencyNameComposer
} }
}}} }}}
navigate {{{ navigate {{{
if (GetChildServiceName().IsEmpty()) if (!GetChildServiceName().IsEmpty()) {
return nullptr; Host::Ptr host = Host::GetByName(GetChildHostName());
if (host)
return host->GetServiceByShortName(GetChildServiceName());
}
Host::Ptr host = Host::GetByName(GetChildHostName()); return nullptr;
return host->GetServiceByShortName(GetChildServiceName());
}}} }}}
}; };
@ -71,11 +73,13 @@ class Dependency : CustomVarObject < DependencyNameComposer
} }
}}} }}}
navigate {{{ navigate {{{
if (GetParentServiceName().IsEmpty()) if (!GetParentServiceName().IsEmpty()) {
return nullptr; Host::Ptr host = Host::GetByName(GetParentHostName());
if (host)
return host->GetServiceByShortName(GetParentServiceName());
}
Host::Ptr host = Host::GetByName(GetParentHostName()); return nullptr;
return host->GetServiceByShortName(GetParentServiceName());
}}} }}}
}; };

View file

@ -43,11 +43,13 @@ class Downtime : ConfigObject < DowntimeNameComposer
} }
}}} }}}
navigate {{{ navigate {{{
if (GetServiceName().IsEmpty()) if (!GetServiceName().IsEmpty()) {
return nullptr; Host::Ptr host = Host::GetByName(GetHostName());
if (host)
return host->GetServiceByShortName(GetServiceName());
}
Host::Ptr host = Host::GetByName(GetHostName()); return nullptr;
return host->GetServiceByShortName(GetServiceName());
}}} }}}
}; };

View file

@ -69,11 +69,13 @@ class Notification : CustomVarObject < NotificationNameComposer
} }
}}} }}}
navigate {{{ navigate {{{
if (GetServiceName().IsEmpty()) if (!GetServiceName().IsEmpty()) {
return nullptr; Host::Ptr host = Host::GetByName(GetHostName());
if (host)
return host->GetServiceByShortName(GetServiceName());
}
Host::Ptr host = Host::GetByName(GetHostName()); return nullptr;
return host->GetServiceByShortName(GetServiceName());
}}} }}}
}; };

View file

@ -44,11 +44,13 @@ class ScheduledDowntime : CustomVarObject < ScheduledDowntimeNameComposer
} }
}}} }}}
navigate {{{ navigate {{{
if (GetServiceName().IsEmpty()) if (!GetServiceName().IsEmpty()) {
return nullptr; Host::Ptr host = Host::GetByName(GetHostName());
if (host)
return host->GetServiceByShortName(GetServiceName());
}
Host::Ptr host = Host::GetByName(GetHostName()); return nullptr;
return host->GetServiceByShortName(GetServiceName());
}}} }}}
}; };