Skip to content

Commit 246feab

Browse files
hermabembolivar-nordic
authored andcommitted
[nrf fromtree] Bluetooth: Host: Clean up buffer user data in case of error
`bt_l2cap_chan_send_cb()` overwrote the buffer user data for internal use. In the case where sending fails, this would be visible for the caller. If the caller relied on the buffer user data to be unchanged, this could cause unexpected behavior. L2CAP tx metadata was also not freed in the error case. Signed-off-by: Herman Berget <[email protected]> Signed-off-by: Herman Berget <[email protected]> (cherry picked from commit a3758a3)
1 parent 15cd94d commit 246feab

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

subsys/bluetooth/host/l2cap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,6 +2952,7 @@ int bt_l2cap_chan_send_cb(struct bt_l2cap_chan *chan, struct net_buf *buf, bt_co
29522952
{
29532953
struct bt_l2cap_le_chan *le_chan = BT_L2CAP_LE_CHAN(chan);
29542954
struct l2cap_tx_meta_data *data;
2955+
void *old_user_data = l2cap_tx_meta_data(buf);
29552956
int err;
29562957

29572958
if (!buf) {
@@ -3003,7 +3004,11 @@ int bt_l2cap_chan_send_cb(struct bt_l2cap_chan *chan, struct net_buf *buf, bt_co
30033004
net_buf_put(&le_chan->tx_queue, buf);
30043005
return l2cap_tx_meta_data(buf)->sent;
30053006
}
3007+
30063008
BT_ERR("failed to send message %d", err);
3009+
3010+
l2cap_tx_meta_data(buf) = old_user_data;
3011+
free_tx_meta_data(data);
30073012
}
30083013

30093014
return err;

0 commit comments

Comments
 (0)