Skip to content

Commit

Permalink
[nrf fromtree] bluetooth: mesh: cfg_cli: Check buf len when pulling o…
Browse files Browse the repository at this point in the history
…ut 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]>
  • Loading branch information
PavelVPV authored and HaavardRei committed Dec 3, 2024
1 parent 88ac9d2 commit 752afb3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions subsys/bluetooth/mesh/cfg_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,10 @@ struct bt_mesh_comp_p1_elem *bt_mesh_comp_p1_elem_pull(struct net_buf_simple *bu
elem->nsig = net_buf_simple_pull_u8(buf);
elem->nvnd = net_buf_simple_pull_u8(buf);
for (i = 0; i < elem->nsig + elem->nvnd; i++) {
if (buf->len < elem_size + 1) {
return NULL;
}

header = buf->data[elem_size];
cor_present = COR_PRESENT(header);
fmt = FMT(header);
Expand All @@ -2346,6 +2350,10 @@ struct bt_mesh_comp_p1_elem *bt_mesh_comp_p1_elem_pull(struct net_buf_simple *bu
elem_size += (1 + cor_present) + (fmt + 1) * ext_item_cnt;
}

if (buf->len < elem_size) {
return NULL;
}

net_buf_simple_init_with_data(elem->_buf,
net_buf_simple_pull_mem(buf, elem_size),
elem_size);
Expand All @@ -2372,9 +2380,17 @@ struct bt_mesh_comp_p1_model_item *bt_mesh_comp_p1_item_pull(
item->ext_item_cnt = EXT_ITEM_CNT(header);
item_size = item->ext_item_cnt * (item->format + 1);
if (item->cor_present) {
if (elem->_buf->len < 1) {
return NULL;
}

item->cor_id = net_buf_simple_pull_u8(elem->_buf);
}

if (elem->_buf->len < item_size) {
return NULL;
}

net_buf_simple_init_with_data(item->_buf,
net_buf_simple_pull_mem(elem->_buf, item_size),
item_size);
Expand Down

0 comments on commit 752afb3

Please sign in to comment.