Skip to content

Commit f1be8af

Browse files
ubiedafabiobaltieri
authored andcommitted
bluetooth: Guard gatt_prepare_write against calls while disconnected
Fixes #84752. Signed-off-by: Luis Ubieda <luisf@croxel.com>
1 parent 6d5dd34 commit f1be8af

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

subsys/bluetooth/host/gatt.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5261,10 +5261,18 @@ static int gatt_prepare_write(struct bt_conn *conn,
52615261
struct bt_gatt_write_params *params)
52625262
{
52635263
uint16_t len, req_len;
5264+
uint16_t mtu = bt_att_get_mtu(conn);
52645265

52655266
req_len = sizeof(struct bt_att_prepare_write_req);
52665267

5267-
len = bt_att_get_mtu(conn) - req_len - 1;
5268+
/** MTU size is bigger than the ATT_PREPARE_WRITE_REQ header (5 bytes),
5269+
* unless there's no connection.
5270+
*/
5271+
if (mtu == 0) {
5272+
return -ENOTCONN;
5273+
}
5274+
5275+
len = mtu - req_len - 1;
52685276
len = MIN(params->length, len);
52695277
len += req_len;
52705278

0 commit comments

Comments
 (0)