Skip to content

Commit 8576b04

Browse files
authored
Cordio BLE: Fix integer overflows (#388)
1 parent cda8a9d commit 8576b04

File tree

2 files changed

+15
-0
lines changed
  • connectivity/FEATURE_BLE
    • libraries/cordio_stack/wsf/sources/port/baremetal
    • source/cordio/stack_adaptation

2 files changed

+15
-0
lines changed

connectivity/FEATURE_BLE/libraries/cordio_stack/wsf/sources/port/baremetal/wsf_msg.c

+9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ typedef struct wsfMsg_tag
5353
/*************************************************************************************************/
5454
void *WsfMsgDataAlloc(uint16_t len, uint8_t tailroom)
5555
{
56+
/* check for overflow */
57+
if (len > UINT16_MAX - tailroom) {
58+
return NULL;
59+
}
5660
return WsfMsgAlloc(len + tailroom);
5761
}
5862

@@ -69,6 +73,11 @@ void *WsfMsgAlloc(uint16_t len)
6973
{
7074
wsfMsg_t *pMsg;
7175

76+
/* check for overflow */
77+
if (len > UINT16_MAX - sizeof(wsfMsg_t)) {
78+
return NULL;
79+
}
80+
7281
pMsg = WsfBufAlloc(len + sizeof(wsfMsg_t));
7382

7483
/* hide header */

connectivity/FEATURE_BLE/source/cordio/stack_adaptation/hci_tr.c

+6
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ void hciTrSerialRxIncoming(uint8_t *pBuf, uint8_t len)
204204
}
205205

206206
/* allocate data buffer to hold entire packet */
207+
/* check that the length doesn't overflow */
208+
if (hdrLen > UINT16_MAX - dataLen)
209+
{
210+
stateRx = HCI_RX_STATE_IDLE;
211+
return;
212+
}
207213
if (pktIndRx == HCI_ACL_TYPE)
208214
{
209215
pPktRx = (uint8_t*)WsfMsgDataAlloc(hdrLen + dataLen, 0);

0 commit comments

Comments
 (0)