From b15611eb28cf4e187453cdd5eaf911d4abbf65df Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Fri, 17 Nov 2023 09:40:25 +0100 Subject: [PATCH] Bluetooth: Mesh: Check return value of bt_conn_get_info Coverity-CID: 323094 Fixes #65366 Coverity-CID: 323081 Fixes #65370 Signed-off-by: Pavel Vasilyev --- subsys/bluetooth/mesh/gatt_cli.c | 9 +++++---- subsys/bluetooth/mesh/pb_gatt_srv.c | 14 ++++++++------ subsys/bluetooth/mesh/proxy_srv.c | 14 ++++++++------ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/subsys/bluetooth/mesh/gatt_cli.c b/subsys/bluetooth/mesh/gatt_cli.c index 59407458de2..bff9b567011 100644 --- a/subsys/bluetooth/mesh/gatt_cli.c +++ b/subsys/bluetooth/mesh/gatt_cli.c @@ -176,8 +176,8 @@ static void gatt_connected(struct bt_conn *conn, uint8_t conn_err) struct bt_conn_info info; int err; - bt_conn_get_info(conn, &info); - if (info.role != BT_CONN_ROLE_CENTRAL || + err = bt_conn_get_info(conn, &info); + if (err || info.role != BT_CONN_ROLE_CENTRAL || !server->gatt) { return; } @@ -214,9 +214,10 @@ static void gatt_disconnected(struct bt_conn *conn, uint8_t reason) { struct bt_conn_info info; struct bt_mesh_gatt_server *server = get_server(conn); + int err; - bt_conn_get_info(conn, &info); - if (info.role != BT_CONN_ROLE_CENTRAL || + err = bt_conn_get_info(conn, &info); + if (err || info.role != BT_CONN_ROLE_CENTRAL || !server->gatt) { return; } diff --git a/subsys/bluetooth/mesh/pb_gatt_srv.c b/subsys/bluetooth/mesh/pb_gatt_srv.c index d5ad2f9711d..f6d9298fc78 100644 --- a/subsys/bluetooth/mesh/pb_gatt_srv.c +++ b/subsys/bluetooth/mesh/pb_gatt_srv.c @@ -94,27 +94,29 @@ static ssize_t gatt_recv(struct bt_conn *conn, return bt_mesh_proxy_msg_recv(conn, buf, len); } -static void gatt_connected(struct bt_conn *conn, uint8_t err) +static void gatt_connected(struct bt_conn *conn, uint8_t conn_err) { struct bt_conn_info info; + int err; - bt_conn_get_info(conn, &info); - if (info.role != BT_CONN_ROLE_PERIPHERAL || !service_registered || + err = bt_conn_get_info(conn, &info); + if (err || info.role != BT_CONN_ROLE_PERIPHERAL || !service_registered || bt_mesh_is_provisioned() || info.id != BT_ID_DEFAULT || cli) { return; } cli = bt_mesh_proxy_role_setup(conn, gatt_send, proxy_msg_recv); - LOG_DBG("conn %p err 0x%02x", (void *)conn, err); + LOG_DBG("conn %p err 0x%02x", (void *)conn, conn_err); } static void gatt_disconnected(struct bt_conn *conn, uint8_t reason) { struct bt_conn_info info; + int err; - bt_conn_get_info(conn, &info); - if (info.role != BT_CONN_ROLE_PERIPHERAL || !service_registered || + err = bt_conn_get_info(conn, &info); + if (err || info.role != BT_CONN_ROLE_PERIPHERAL || !service_registered || info.id != BT_ID_DEFAULT || !cli || cli->conn != conn) { return; } diff --git a/subsys/bluetooth/mesh/proxy_srv.c b/subsys/bluetooth/mesh/proxy_srv.c index 2943afdca93..3a2bad0851e 100644 --- a/subsys/bluetooth/mesh/proxy_srv.c +++ b/subsys/bluetooth/mesh/proxy_srv.c @@ -1057,18 +1057,19 @@ static void solicitation_reset(struct bt_mesh_subnet *sub) #endif } -static void gatt_connected(struct bt_conn *conn, uint8_t err) +static void gatt_connected(struct bt_conn *conn, uint8_t conn_err) { struct bt_mesh_proxy_client *client; struct bt_conn_info info; + int err; - bt_conn_get_info(conn, &info); - if (info.role != BT_CONN_ROLE_PERIPHERAL || !service_registered || + err = bt_conn_get_info(conn, &info); + if (err || info.role != BT_CONN_ROLE_PERIPHERAL || !service_registered || info.id != BT_ID_DEFAULT) { return; } - LOG_DBG("conn %p err 0x%02x", (void *)conn, err); + LOG_DBG("conn %p err 0x%02x", (void *)conn, conn_err); client = find_client(conn); @@ -1107,9 +1108,10 @@ static void gatt_disconnected(struct bt_conn *conn, uint8_t reason) { struct bt_conn_info info; struct bt_mesh_proxy_client *client; + int err; - bt_conn_get_info(conn, &info); - if (info.role != BT_CONN_ROLE_PERIPHERAL || info.id != BT_ID_DEFAULT) { + err = bt_conn_get_info(conn, &info); + if (err || info.role != BT_CONN_ROLE_PERIPHERAL || info.id != BT_ID_DEFAULT) { return; }