From 9e5fec73f8f8c77c0fd6d552555f2097e7de0091 Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 3 Apr 2020 16:58:12 +0800 Subject: [PATCH] ble_mesh: Fix dereferencing pointer before checking for NULL [Zephyr] The publication context is checked for NULL in bt_mesh_model_publish() however it was dereferenced before that. Move the assignment to ctx.send_rel to the same place where other ctx members are set. --- components/bt/esp_ble_mesh/mesh_core/access.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/access.c b/components/bt/esp_ble_mesh/mesh_core/access.c index 484e70aa4b..eb18d88a91 100644 --- a/components/bt/esp_ble_mesh/mesh_core/access.c +++ b/components/bt/esp_ble_mesh/mesh_core/access.c @@ -1032,9 +1032,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) struct bt_mesh_model_pub *pub = model->pub; struct bt_mesh_app_key *key = NULL; struct net_buf_simple *sdu = NULL; - struct bt_mesh_msg_ctx ctx = { - .send_rel = pub->send_rel, - }; + struct bt_mesh_msg_ctx ctx = {0}; struct bt_mesh_net_tx tx = { .sub = NULL, .ctx = &ctx, @@ -1072,6 +1070,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) } ctx.addr = pub->addr; + ctx.send_rel = pub->send_rel; ctx.send_ttl = pub->ttl; ctx.net_idx = key->net_idx; ctx.app_idx = key->app_idx;