From e3db58f013dddf98ffd7ffeb93f7fe3bdca68577 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 2 Oct 2020 20:51:40 +0200 Subject: [PATCH] net/gcoap: Avoid endless loop on error The NULL case can not regularly be reached (because regularly gcoap_register_listener sets thel link_encoder to a default one), but if it is (eg. because an application unsets its link_encoder to hide a resource set at runtime), the existing `continue` is a good idea (skip over this entry) but erroneously created an endless loop by skipping the advancement step. --- sys/net/application_layer/gcoap/gcoap.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index 7dcb442da8..f745f519b0 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -887,7 +887,7 @@ int gcoap_get_resource_list(void *buf, size_t maxlen, uint8_t cf) ctx.flags = COAP_LINK_FLAG_INIT_RESLIST; /* write payload */ - while (listener) { + for (; listener != NULL; listener = listener->next) { if (!listener->link_encoder) { continue; } @@ -912,8 +912,6 @@ int gcoap_get_resource_list(void *buf, size_t maxlen, uint8_t cf) break; } } - - listener = listener->next; } return (int)pos;