Skip to content

Commit 33453e1

Browse files
Veijo Pesonencarlescufi
authored andcommitted
lwm2m: fails if incorrect registration reply
No need to proceed if registration reply parsing fails. Signed-off-by: Veijo Pesonen <[email protected]>
1 parent bdf161a commit 33453e1

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

subsys/net/lib/lwm2m/lwm2m_rd_client.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ static int do_registration_reply_cb(const struct coap_packet *response,
436436
{
437437
struct coap_option options[2];
438438
uint8_t code;
439-
int ret;
439+
int ret = -EINVAL;
440440

441441
code = coap_header_get_code(response);
442442
LOG_DBG("Registration callback (code:%u.%u)",
@@ -448,8 +448,9 @@ static int do_registration_reply_cb(const struct coap_packet *response,
448448
ret = coap_find_options(response, COAP_OPTION_LOCATION_PATH,
449449
options, 2);
450450
if (ret < 2) {
451-
LOG_ERR("Unexpected endpoint data returned.");
452-
return -EINVAL;
451+
LOG_ERR("Unexpected endpoint data returned. ret = %d", ret);
452+
ret = -EINVAL;
453+
goto fail;
453454
}
454455

455456
/* option[0] should be "rd" */
@@ -459,7 +460,8 @@ static int do_registration_reply_cb(const struct coap_packet *response,
459460
"%u (expected %zu)\n",
460461
options[1].len,
461462
sizeof(client.server_ep));
462-
return -EINVAL;
463+
ret = -EINVAL;
464+
goto fail;
463465
}
464466

465467
/* remember the last reg time */
@@ -478,10 +480,10 @@ static int do_registration_reply_cb(const struct coap_packet *response,
478480
LOG_ERR("Failed with code %u.%u (%s). Not Retrying.",
479481
COAP_RESPONSE_CODE_CLASS(code), COAP_RESPONSE_CODE_DETAIL(code),
480482
code2str(code));
481-
483+
fail:
482484
sm_handle_failure_state(ENGINE_IDLE);
483485

484-
return 0;
486+
return ret;
485487
}
486488

487489
static void do_registration_timeout_cb(struct lwm2m_message *msg)

0 commit comments

Comments
 (0)