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 <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2020-12-01 16:44:30 +01:00 committed by Anas Nashif
commit 7eefde36c3

View file

@ -869,11 +869,13 @@ static struct lwm2m_message *find_msg(struct coap_pending *pending,
} }
for (i = 0; i < CONFIG_LWM2M_ENGINE_MAX_MESSAGES; i++) { 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]; return &messages[i];
} }
if (messages[i].ctx && messages[i].reply == reply) { if (reply != NULL && messages[i].ctx &&
messages[i].reply == reply) {
return &messages[i]; return &messages[i];
} }
} }