Skip to content

Commit

Permalink
mgmt: mcumgt: smp: Fix not checking returned status
Browse files Browse the repository at this point in the history
Fixes not checking if a zcbor operation was successful.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
  • Loading branch information
nordicjm authored and carlescufi committed Jul 10, 2023
1 parent d98656f commit c9a4764
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions subsys/mgmt/mcumgr/smp/src/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,18 @@ static int smp_handle_single_payload(struct smp_streamer *cbuf, const struct smp
}

if (handler_fn) {
bool ok;

*handler_found = true;
zcbor_map_start_encode(cbuf->writer->zs,
CONFIG_MCUMGR_SMP_CBOR_MAX_MAIN_MAP_ENTRIES);
ok = zcbor_map_start_encode(cbuf->writer->zs,
CONFIG_MCUMGR_SMP_CBOR_MAX_MAIN_MAP_ENTRIES);

MGMT_CTXT_SET_RC_RSN(cbuf, NULL);

if (!ok) {
return MGMT_ERR_EMSGSIZE;
}

#if defined(CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS)
cmd_recv.group = req_hdr->nh_group;
cmd_recv.id = req_hdr->nh_id;
Expand All @@ -248,8 +254,8 @@ static int smp_handle_single_payload(struct smp_streamer *cbuf, const struct smp
if (status == MGMT_CB_ERROR_RC) {
rc = ret_rc;
} else {
bool ok = smp_add_cmd_ret(cbuf->writer->zs, ret_group,
(uint16_t)ret_rc);
ok = smp_add_cmd_ret(cbuf->writer->zs, ret_group,
(uint16_t)ret_rc);

rc = (ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE);
}
Expand Down

0 comments on commit c9a4764

Please sign in to comment.