From 2849662aa80d8b761dd42659bae6c459d22fdb91 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 21 Nov 2017 21:19:29 +0200 Subject: [PATCH] Bluetooth: Mesh: Fix dereferencing mod->pub too early The bt_mesh_model_publish() is supposed to return a "not supported" error if the publish context doesn't exist. Fixing the premature dereferencing also fixes coverity warnings. Signed-off-by: Johan Hedberg --- subsys/bluetooth/host/mesh/access.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/host/mesh/access.c b/subsys/bluetooth/host/mesh/access.c index 9ba3cbac0fa..6096641b759 100644 --- a/subsys/bluetooth/host/mesh/access.c +++ b/subsys/bluetooth/host/mesh/access.c @@ -608,14 +608,11 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) struct bt_mesh_model_pub *pub = model->pub; struct bt_mesh_app_key *key; struct bt_mesh_msg_ctx ctx = { - .addr = pub->addr, - .send_ttl = pub->ttl, }; struct bt_mesh_net_tx tx = { .ctx = &ctx, .src = model->elem->addr, .xmit = bt_mesh_net_transmit_get(), - .friend_cred = model->pub->cred, }; int err; @@ -647,9 +644,12 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) net_buf_simple_init(sdu, 0); net_buf_simple_add_mem(sdu, pub->msg->data, pub->msg->len); + ctx.addr = pub->addr; + ctx.send_ttl = pub->ttl; ctx.net_idx = key->net_idx; ctx.app_idx = key->app_idx; + tx.friend_cred = pub->cred; tx.sub = bt_mesh_subnet_get(ctx.net_idx), pub->count = BT_MESH_PUB_TRANSMIT_COUNT(pub->retransmit);