You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ry...@apache.org on 2023/07/25 13:02:27 UTC

[mynewt-nimble] branch master updated: host/ble_l2cap_coc: coc_rx.sdus index should not exceed BLE_L2CAP_SDU_BUFF_CNT

This is an automated email from the ASF dual-hosted git repository.

rymek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


The following commit(s) were added to refs/heads/master by this push:
     new dc60f90a3 host/ble_l2cap_coc: coc_rx.sdus index should not exceed BLE_L2CAP_SDU_BUFF_CNT
dc60f90a3 is described below

commit dc60f90a379b92262b2e58fc2e48ae65cd4f45d1
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Tue Jul 25 08:39:41 2023 +0200

    host/ble_l2cap_coc: coc_rx.sdus index should not exceed BLE_L2CAP_SDU_BUFF_CNT
    
    Multiple calls to `ble_l2cap_coc_recv_ready` with
    `BLE_L2CAP_SDU_BUFF_CNT == 1` will lead to assigning coc_rx.sdus outside
    array range - so this will (most likely) overwrite rest of stucture.
    This will lead to either undefined behavior or crash when structure
    members are accessed.
---
 nimble/host/src/ble_l2cap_coc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/nimble/host/src/ble_l2cap_coc.c b/nimble/host/src/ble_l2cap_coc.c
index ae5624ce9..25727ee19 100644
--- a/nimble/host/src/ble_l2cap_coc.c
+++ b/nimble/host/src/ble_l2cap_coc.c
@@ -341,7 +341,12 @@ ble_l2cap_coc_chan_alloc(struct ble_hs_conn *conn, uint16_t psm, uint16_t mtu,
         chan->coc_rx.sdus[i] = NULL;
     }
     chan->coc_rx.current_sdu_idx = 0;
-    chan->coc_rx.next_sdu_alloc_idx = chan->coc_rx.sdus[0] == NULL ? 0 : 1;
+
+    if (BLE_L2CAP_SDU_BUFF_CNT == 1) {
+        chan->coc_rx.next_sdu_alloc_idx = 0;
+    } else {
+        chan->coc_rx.next_sdu_alloc_idx = chan->coc_rx.sdus[0] == NULL ? 0 : 1;
+    }
 
     /* Number of credits should allow to send full SDU with on given
      * L2CAP MTU