Skip to content

Commit

Permalink
nrf_rpc: fix error handling
Browse files Browse the repository at this point in the history
Commit fixes null dereference when error handling
is triggered but group does not exist.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
  • Loading branch information
alxelax committed Oct 29, 2024
1 parent 4baac51 commit 47fdbee
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions nrf_rpc/nrf_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ struct internal_pool_data {
static struct nrf_rpc_cmd_ctx cmd_ctx_pool[CONFIG_NRF_RPC_CMD_CTX_POOL_SIZE];

static struct nrf_rpc_os_event groups_init_event;
static struct nrf_rpc_os_event error_event;

/* Number of groups */
static uint8_t group_count;
Expand Down Expand Up @@ -362,16 +363,16 @@ static void internal_tx_handler(void)
{
struct internal_pool_data copy = internal_data;

nrf_rpc_os_event_set(&copy.group->data->decode_done_event);

if (copy.type == NRF_RPC_INITIALIZATION) {
nrf_rpc_os_event_set(&copy.group->data->decode_done_event);
if (group_init_send(copy.group)) {
NRF_RPC_ERR("Failed to send group init packet for group id: %d strid: %s",
copy.group->data->src_group_id, copy.group->strid);
}
}

if (copy.type == NRF_RPC_ERROR) {
nrf_rpc_os_event_set(&error_event);
nrf_rpc_err(copy.err, NRF_RPC_ERR_SRC_RECV, copy.group, copy.hdr_id, copy.hdr_type);
}
}
Expand Down Expand Up @@ -807,7 +808,7 @@ static void receive_handler(const struct nrf_rpc_tr *transport, const uint8_t *p
internal_data.hdr_id = hdr.id;
internal_data.hdr_type = hdr.type;
nrf_rpc_os_thread_pool_send((const uint8_t *)&internal_data, sizeof(internal_data));
nrf_rpc_os_event_wait(&group->data->decode_done_event, NRF_RPC_OS_WAIT_FOREVER);
nrf_rpc_os_event_wait(&error_event, NRF_RPC_OS_WAIT_FOREVER);
}
}

Expand Down Expand Up @@ -1082,6 +1083,11 @@ int nrf_rpc_init(nrf_rpc_err_handler_t err_handler)
return err;
}

err = nrf_rpc_os_event_init(&error_event);
if (err < 0) {
return err;
}

for (i = 0; i < CONFIG_NRF_RPC_CMD_CTX_POOL_SIZE; i++) {
cmd_ctx_pool[i].id = i;
err = nrf_rpc_os_msg_init(&cmd_ctx_pool[i].recv_msg);
Expand Down

0 comments on commit 47fdbee

Please sign in to comment.