From 53e1bcaeba428273e95cdb2687a4f3161446344d Mon Sep 17 00:00:00 2001 From: Guancheng Wang <24189100307@stu.xidian.edu.cn> Date: Sat, 19 Sep 2026 05:30:52 +0800 Subject: [PATCH] proxy: guard coap_proxy_get_add_list_entry() against two NULL sessions `coap_proxy_get_add_list_entry(incoming, ongoing, ...)` dereferences `ongoing->context` when `incoming == NULL`. Current in-tree callers always pass exactly one non-NULL session, but the function is a public-ish internal helper and a future caller passing both NULL would dereference NULL immediately. cppcheck flags exactly this (`nullPointer` on `ongoing`). This adds an explicit early `return NULL` when both arguments are NULL - defensive only, no behavior change for existing callers. Signed-off-by: warter666 <121139223+Warterkk@users.noreply.github.com> --- src/coap_proxy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/coap_proxy.c b/src/coap_proxy.c index 36cfa36d..1436bf38 100644 --- a/src/coap_proxy.c +++ b/src/coap_proxy.c @@ -381,6 +381,8 @@ static coap_proxy_entry_t * coap_proxy_get_add_list_entry(coap_session_t *incoming, coap_session_t *ongoing, coap_uri_t uri, coap_proxy_server_list_t *server_list, int allow_add) { + if (!incoming && !ongoing) + return NULL; coap_context_t *context = incoming ? incoming->context : ongoing->context; coap_proxy_entry_t *proxy_list = context->proxy_list; size_t proxy_list_count = context->proxy_list_count;