Skip to content

Commit 7310fc7

Browse files
PavelVPVjukkar
authored andcommitted
[nrf fromtree] bluetooth: mesh: cfg_cli: Check buf len when pulling out data
This commit checks that config client doesn't pull out data outside of the buffer. Fixes #80012 Signed-off-by: Pavel Vasilyev <[email protected]> (cherry picked from commit e2a0faf) Signed-off-by: Håvard Reierstad <[email protected]> (cherry picked from commit d8de6ce)
1 parent 5b8badb commit 7310fc7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

subsys/bluetooth/mesh/cfg_cli.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,10 @@ struct bt_mesh_comp_p1_elem *bt_mesh_comp_p1_elem_pull(struct net_buf_simple *bu
23322332
elem->nsig = net_buf_simple_pull_u8(buf);
23332333
elem->nvnd = net_buf_simple_pull_u8(buf);
23342334
for (i = 0; i < elem->nsig + elem->nvnd; i++) {
2335+
if (buf->len < elem_size + 1) {
2336+
return NULL;
2337+
}
2338+
23352339
header = buf->data[elem_size];
23362340
cor_present = COR_PRESENT(header);
23372341
fmt = FMT(header);
@@ -2346,6 +2350,10 @@ struct bt_mesh_comp_p1_elem *bt_mesh_comp_p1_elem_pull(struct net_buf_simple *bu
23462350
elem_size += (1 + cor_present) + (fmt + 1) * ext_item_cnt;
23472351
}
23482352

2353+
if (buf->len < elem_size) {
2354+
return NULL;
2355+
}
2356+
23492357
net_buf_simple_init_with_data(elem->_buf,
23502358
net_buf_simple_pull_mem(buf, elem_size),
23512359
elem_size);
@@ -2372,9 +2380,17 @@ struct bt_mesh_comp_p1_model_item *bt_mesh_comp_p1_item_pull(
23722380
item->ext_item_cnt = EXT_ITEM_CNT(header);
23732381
item_size = item->ext_item_cnt * (item->format + 1);
23742382
if (item->cor_present) {
2383+
if (elem->_buf->len < 1) {
2384+
return NULL;
2385+
}
2386+
23752387
item->cor_id = net_buf_simple_pull_u8(elem->_buf);
23762388
}
23772389

2390+
if (elem->_buf->len < item_size) {
2391+
return NULL;
2392+
}
2393+
23782394
net_buf_simple_init_with_data(item->_buf,
23792395
net_buf_simple_pull_mem(elem->_buf, item_size),
23802396
item_size);

0 commit comments

Comments
 (0)