-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
host/ble_l2cap_coc: coc_rx.sdus index should not exceed BLE_L2CAP_SDU_BUFF_CNT #1567
host/ble_l2cap_coc: coc_rx.sdus index should not exceed BLE_L2CAP_SDU_BUFF_CNT #1567
Conversation
@jrotkiewicz PTAL. AFAIK if mynewt-nimble/nimble/host/src/ble_l2cap_coc.c Lines 606 to 610 in ef0fb14
But maybe I'm missing something :) I'm sure of a crash though |
This was caught while testing #845 |
8bd97d9
to
875192a
Compare
As discussed offline, |
nimble/host/src/ble_l2cap_coc.c
Outdated
@@ -341,7 +341,8 @@ 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; | |||
chan->coc_rx.next_sdu_alloc_idx = chan->coc_rx.sdus[0] == NULL || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
technically it is ok, but lets try to make it look nicer using if () Ok ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ble_l2cap_coc_chan_alloc
can be called with *sdu_rx = NULL
- in that case, with previous fix, we would set next_sdu_alloc_idx = 1
where it should be 0. Fixed this with simple if case for BLE_L2CAP_SDU_BUFF_CNT == 1
…_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.
875192a
to
e563f14
Compare
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Multiple calls to
ble_l2cap_coc_recv_ready
withBLE_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.