Skip to content

Commit 9ab5868

Browse files
ThalleyMaureenHelm
authored andcommitted
Bluetooth: OTS: Add len validation in olcp_ind_handler
Verify the length of the indication before we pull from the buffer. Signed-off-by: Emil Gydesen <[email protected]> (cherry picked from commit 044f8aa)
1 parent 5afc636 commit 9ab5868

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

subsys/bluetooth/services/ots/ots_client.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,24 @@ static void olcp_ind_handler(struct bt_conn *conn,
297297
enum bt_gatt_ots_olcp_proc_type op_code;
298298
struct net_buf_simple net_buf;
299299

300+
if (length < sizeof(op_code)) {
301+
LOG_DBG("Invalid indication length: %u", length);
302+
return;
303+
}
304+
300305
net_buf_simple_init_with_data(&net_buf, (void *)data, length);
301306

302307
op_code = net_buf_simple_pull_u8(&net_buf);
303308

304309
LOG_DBG("OLCP indication");
305310

306311
if (op_code == BT_GATT_OTS_OLCP_PROC_RESP) {
312+
if (net_buf.len < (sizeof(uint8_t) + sizeof(uint8_t))) {
313+
LOG_DBG("Invalid indication length for op_code %u: %u", op_code,
314+
net_buf.len);
315+
return;
316+
}
317+
307318
enum bt_gatt_ots_olcp_proc_type req_opcode =
308319
net_buf_simple_pull_u8(&net_buf);
309320
enum bt_gatt_ots_olcp_res_code result_code =
@@ -366,6 +377,11 @@ static void oacp_ind_handler(struct bt_conn *conn,
366377
uint32_t checksum;
367378
struct net_buf_simple net_buf;
368379

380+
if (length < sizeof(op_code)) {
381+
LOG_DBG("Invalid indication length: %u", length);
382+
return;
383+
}
384+
369385
net_buf_simple_init_with_data(&net_buf, (void *)data, length);
370386

371387
op_code = net_buf_simple_pull_u8(&net_buf);

0 commit comments

Comments
 (0)