fix(mdns): Fix use after free reported by coverity

Fixes CID 467739: Use after free in mdns.c, mdns_service_remove_for_host
We should look only for one match in the service list, since if we
assume there could be aliases, we might free one and reference the
other.
This commit is contained in:
David Cermak
2024-08-27 15:26:25 +02:00
parent 11846c7d00
commit 25b3d5fd7b

View File

@ -6398,22 +6398,14 @@ esp_err_t mdns_service_remove_for_host(const char *instance, const char *service
if (_mdns_service_match(a->service, service, proto, hostname)) {
if (_mdns_server->services != a) {
b->next = a->next;
_mdns_send_bye(&a, 1, false);
_mdns_remove_scheduled_service_packets(a->service);
_mdns_free_service(a->service);
free(a);
a = b->next;
continue;
} else {
_mdns_server->services = a->next;
}
_mdns_send_bye(&a, 1, false);
_mdns_remove_scheduled_service_packets(a->service);
_mdns_free_service(a->service);
free(a);
a = _mdns_server->services;
b = a;
continue;
}
break;
}
b = a;
a = a->next;