Skip to content

Commit 54e5364

Browse files
EListenXhyson710
authored andcommitted
bluetooth: Fix null pointer dereference before null check issues.
bug: v/81520 In `spp_find_connection_by_sdp_param` and `spp_connect_with_uuid`, the pointer `spp_conn` was dereferenced before the NULL check. This patch ensures the pointer is validated before access to avoid potential crashes. Signed-off-by: v-yichenxi <[email protected]>
1 parent 49a0c0f commit 54e5364

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

service/stacks/zephyr/sal_spp_interface.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static sal_spp_connection_t* spp_find_connection_by_sdp_param(struct bt_conn* co
219219

220220
spp_conn = bt_list_node(node);
221221
spp_client = spp_conn->spp_client;
222-
if ((spp_conn && (spp_conn->conn == conn)) && (spp_client && (&spp_client->sdp_discover == param))) {
222+
if ((spp_conn->conn == conn) && (spp_client && (&spp_client->sdp_discover == param))) {
223223
return spp_conn;
224224
}
225225
}
@@ -771,7 +771,7 @@ static void sdp_disconnected_cb(struct bt_conn* conn, const struct bt_sdp_discov
771771

772772
static bt_status_t spp_connect_with_uuid(sal_spp_connection_t* spp_conn, bt_uuid_t* uuid)
773773
{
774-
sal_spp_client_t* spp_client = spp_conn->spp_client;
774+
sal_spp_client_t* spp_client;
775775
int err;
776776
bt_uuid_t uuid_128;
777777

@@ -780,6 +780,12 @@ static bt_status_t spp_connect_with_uuid(sal_spp_connection_t* spp_conn, bt_uuid
780780
return BT_STATUS_PARM_INVALID;
781781
}
782782

783+
spp_client = spp_conn->spp_client;
784+
if (!spp_client) {
785+
BT_LOGE("SPP client not found for conn");
786+
return BT_STATUS_PARM_INVALID;
787+
}
788+
783789
sys_memcpy_swap(uuid_128.val.u128, uuid->val.u128, sizeof(uuid->val.u128));
784790

785791
err = bt_uuid_create((struct bt_uuid*)&spp_client->uuid_128, uuid_128.val.u128, BT_UUID_SIZE_128);

0 commit comments

Comments
 (0)