diff --git a/CHANGELOG.md b/CHANGELOG.md index 7beca0ae8..d5888530c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 20.10.4 + +### Bugfixes + +*Macros* + +If a service / host is not in a service/host group, then the HOSTGROUPNAME/ +SERVICEGROUPNAME macros can lead to segfault. This patch fixes this issue. + ## 20.10.3 ### Bugfixes diff --git a/CMakeLists.txt b/CMakeLists.txt index aeac0ed08..fe1d7aaf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ link_directories(${json11_LIB_DIRS}) # Version. set(CENTREON_ENGINE_MAJOR 20) set(CENTREON_ENGINE_MINOR 10) -set(CENTREON_ENGINE_PATCH 3) +set(CENTREON_ENGINE_PATCH 4) if (CENTREON_ENGINE_PRERELEASE) set(CENTREON_ENGINE_VERSION "${CENTREON_ENGINE_MAJOR}.${CENTREON_ENGINE_MINOR}.${CENTREON_ENGINE_PATCH}-${CENTREON_ENGINE_PRERELEASE}") else () diff --git a/src/macros/grab_host.cc b/src/macros/grab_host.cc index fb61da6ce..5e11d39aa 100755 --- a/src/macros/grab_host.cc +++ b/src/macros/grab_host.cc @@ -33,12 +33,6 @@ using namespace com::centreon::engine; using namespace com::centreon::engine::macros; using namespace com::centreon::engine::logging; -/************************************** - * * - * Local Functions * - * * - **************************************/ - /** * Generate total services macros. * @@ -141,10 +135,13 @@ static std::string get_host_group_names(host& hst, nagios_macros* mac) { */ static std::string get_host_group_name(host& hst, nagios_macros* mac) { (void)mac; - logger(dbg_notifications, more) << "on macro juste avant host group "; - std::string buf{hst.get_parent_groups().front()->get_group_name()}; - logger(dbg_notifications, more) << "on macro after host group " << buf; - return buf; + + // Find all hostgroups this host is associated with. + auto it = hst.get_parent_groups().begin(); + if (it == hst.get_parent_groups().end()) + return ""; + else + return (*it)->get_group_name(); } /** diff --git a/src/macros/grab_service.cc b/src/macros/grab_service.cc index 99b0008c6..1c215abc8 100644 --- a/src/macros/grab_service.cc +++ b/src/macros/grab_service.cc @@ -93,9 +93,11 @@ static std::string get_service_group_name(service& svc, nagios_macros* mac) { (void)mac; // Find all servicegroups this service is associated with. - std::string buf{svc.get_parent_groups().front()->get_group_name()}; - logger(dbg_notifications, more) << "on grab service service name :" << buf; - return buf; + auto it = svc.get_parent_groups().begin(); + if (it == svc.get_parent_groups().end()) + return ""; + else + return (*it)->get_group_name(); } /** @@ -234,7 +236,11 @@ struct grab_service_redirection { true}}, // Is volatile. {MACRO_SERVICEISVOLATILE, - {&get_member_as_string, true}}, + {&get_member_as_string, + true}}, // Attempt. {MACRO_SERVICEATTEMPT, {&get_member_as_string