From fda6af5a8a75f68912322a98ceffd2d0cf8f22f8 Mon Sep 17 00:00:00 2001 From: Shawn Carey Date: Wed, 6 Mar 2024 19:36:19 +0000 Subject: [PATCH] advance map iterators with model_map_it_remove when removing items from iterated map (#822) --- lib/ziti-tunnel-cbs/ziti_dns.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/ziti-tunnel-cbs/ziti_dns.c b/lib/ziti-tunnel-cbs/ziti_dns.c index e02e6d97..c9b86d72 100644 --- a/lib/ziti-tunnel-cbs/ziti_dns.c +++ b/lib/ziti-tunnel-cbs/ziti_dns.c @@ -370,22 +370,24 @@ void ziti_dns_deregister_intercept(void *intercept) { dns_entry_t *e = model_map_it_value(it); model_map_remove_key(&e->intercepts, &intercept, sizeof(intercept)); if (model_map_size(&e->intercepts) == 0 && (e->domain == NULL || model_map_size(&e->domain->intercepts) == 0)) { - model_map_remove(&ziti_dns.hostnames, e->name); + it = model_map_it_remove(it); model_map_removel(&ziti_dns.ip_addresses, ip_2_ip4(&e->addr)->addr); ZITI_LOG(DEBUG, "%zu active hostnames mapped to %zu IPs", model_map_size(&ziti_dns.hostnames), model_map_size(&ziti_dns.ip_addresses)); ZITI_LOG(INFO, "DNS mapping %s -> %s is now inactive", e->name, e->ip); + } else { + it = model_map_it_next(it); } - it = model_map_it_next(it); } it = model_map_iterator(&ziti_dns.domains); while (it != NULL) { dns_domain_t *domain = model_map_it_value(it); if (model_map_size(&domain->intercepts) == 0) { - model_map_remove(&ziti_dns.domains, domain->name); + it = model_map_it_remove(it); ZITI_LOG(INFO, "wildcard domain[*%s] is now inactive", domain->name); + } else { + it = model_map_it_next(it); } - it = model_map_it_next(it); } }