From 605d56eb8d206db921de89e059b9c94f0779f205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Sun, 9 Feb 2020 18:26:12 +0100 Subject: [PATCH] coap_free_endpoint: fix segfault with incorrect -A argument `coap-server(1)` segfaults when invoked as: $ coap-server -A '2001:db8::1' Feb 09 18:28:49 WARN coap_socket_bind_udp: bind: Address not available Segmentation fault In this case, the `ep->context->endpoint` is NULL but `coap_free_endpoint` still attempts to access it. To prevent this invocation from causing a segmentation fault, check if `ep->context->endpoint` is NULL before accessing it. --- src/coap_session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coap_session.c b/src/coap_session.c index 084ed792..b5873a6c 100644 --- a/src/coap_session.c +++ b/src/coap_session.c @@ -1129,7 +1129,7 @@ coap_free_endpoint(coap_endpoint_t *ep) { coap_socket_close(&ep->sock); } - if (ep->context) { + if (ep->context && ep->context->endpoint) { LL_DELETE(ep->context->endpoint, ep); } coap_mfree_endpoint(ep);