From 7eefde36c3d2d955cee46fb5d3f9fbfc00928dc9 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 1 Dec 2020 16:44:30 +0100 Subject: [PATCH] net: lwm2m: Fix msg find based on pending/reply The message should only be returned if the requested pending/reply pointer is not NULL. Otherwise it could get an incorrect match (for instance if specific pending pointer is searched for and reply is NULL the function could return any message that doesn't expect a reply (and thus has its reply pointer set to NULL). Signed-off-by: Robert Lubos --- subsys/net/lib/lwm2m/lwm2m_engine.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 2b9f6efb2f0..b4f3d625edd 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -869,11 +869,13 @@ static struct lwm2m_message *find_msg(struct coap_pending *pending, } for (i = 0; i < CONFIG_LWM2M_ENGINE_MAX_MESSAGES; i++) { - if (messages[i].ctx && messages[i].pending == pending) { + if (pending != NULL && messages[i].ctx && + messages[i].pending == pending) { return &messages[i]; } - if (messages[i].ctx && messages[i].reply == reply) { + if (reply != NULL && messages[i].ctx && + messages[i].reply == reply) { return &messages[i]; } }