Skip to content

Commit fc18aaa

Browse files
PavelVPVm-alperen-sener
authored andcommitted
[nrf fromtree] bluetooth: mesh: proxy_msg: check that att mtu is big enough
This commit checks that ATT MTU value returned by `bt_gatt_get_mtu` is greater or equal to 3 to prevent integer overflow. Fixes #84693 Coverity-CID: 487743 Signed-off-by: Pavel Vasilyev <[email protected]> (cherry picked from commit 038173a)
1 parent 87820cb commit fc18aaa

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

subsys/bluetooth/mesh/proxy_msg.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,20 @@ int bt_mesh_proxy_msg_send(struct bt_conn *conn, uint8_t type,
176176
bt_gatt_complete_func_t end, void *user_data)
177177
{
178178
int err;
179+
uint16_t att_mtu = bt_gatt_get_mtu(conn);
179180
uint16_t mtu;
180181
struct bt_mesh_proxy_role *role = &roles[bt_conn_index(conn)];
181182

182183
LOG_DBG("conn %p type 0x%02x len %u: %s", (void *)conn, type, msg->len,
183184
bt_hex(msg->data, msg->len));
184185

185186
/* ATT_MTU - OpCode (1 byte) - Handle (2 bytes) */
186-
mtu = bt_gatt_get_mtu(conn) - 3;
187+
if (att_mtu < 3) {
188+
LOG_WRN("Invalid ATT MTU: %d", att_mtu);
189+
return -EINVAL;
190+
}
191+
192+
mtu = att_mtu - 3;
187193
if (mtu > msg->len) {
188194
net_buf_simple_push_u8(msg, PDU_HDR(SAR_COMPLETE, type));
189195
return role->cb.send(conn, msg->data, msg->len, end, user_data);

0 commit comments

Comments
 (0)