From 0b11b36bf215a351050280ab0b329ceda7a9dccf Mon Sep 17 00:00:00 2001 From: Ludwig Krispenz Date: Mon, 13 Jun 2016 09:51:17 +0200 Subject: [PATCH] v2 - avoid crash in topology plugin when host list contains host with no hostname ticket #5928 prevent a crash when dereferncing a NULL hostnam, log an error to help debugging fix an incorrect order of statement when freeing a host list Reviewed-By: Thierry Bordaz --- daemons/ipa-slapi-plugins/topology/topology_cfg.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/daemons/ipa-slapi-plugins/topology/topology_cfg.c b/daemons/ipa-slapi-plugins/topology/topology_cfg.c index 3ca61a8ea..23b8eddfb 100644 --- a/daemons/ipa-slapi-plugins/topology/topology_cfg.c +++ b/daemons/ipa-slapi-plugins/topology/topology_cfg.c @@ -452,6 +452,15 @@ ipa_topo_cfg_host_find(TopoReplica *tconf, char *findhost, int lock) if (lock) slapi_lock_mutex(tconf->repl_lock); for (host=tconf->hosts;host;host=host->next) { + if (host->hostname == NULL) { + /* this check is done to avoid a crash, + * for which the root cause is not yet known. + * Avoid the crash and log an error + */ + slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM, + "ipa_topo_cfg_host_find: found a NULL hostname in host list\n"); + continue; + } if (!strcasecmp(host->hostname,findhost)) { break; } @@ -849,8 +858,8 @@ ipa_topo_cfg_replica_free(TopoReplica *tconf) while (host) { host_next = host->next; slapi_ch_free_string(&host->hostname); - host = host_next; slapi_ch_free((void **)&host); + host = host_next; } slapi_ch_free((void **)&tconf); }