Skip to content

Commit

Permalink
Merge branch 'bugfix/ble_check_adv_data_v5.2' into 'release/v5.2'
Browse files Browse the repository at this point in the history
fix(bt/bluedroid): Fix ble adv data check to avoid memory overflow(backport v5.2)

See merge request espressif/esp-idf!28405
  • Loading branch information
Isl2017 committed Jan 22, 2024
2 parents 15341d5 + 09475c7 commit 0c5d2c2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion components/bt/host/bluedroid/stack/btm/btm_ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2090,15 +2090,23 @@ UINT8 *BTM_CheckAdvData( UINT8 *p_adv, UINT8 type, UINT8 *p_length)

STREAM_TO_UINT8(length, p);

while ( length && (p - p_adv <= BTM_BLE_CACHE_ADV_DATA_MAX)) {
while ( length && (p - p_adv < BTM_BLE_CACHE_ADV_DATA_MAX)) {
STREAM_TO_UINT8(adv_type, p);

if ( adv_type == type ) {
/* length doesn't include itself */
*p_length = length - 1; /* minus the length of type */
return p;
}

p += length - 1; /* skip the length of data */

/* Break loop if advertising data is in an incorrect format,
as it may lead to memory overflow */
if (p >= p_adv + BTM_BLE_CACHE_ADV_DATA_MAX) {
break;
}

STREAM_TO_UINT8(length, p);
}

Expand Down

0 comments on commit 0c5d2c2

Please sign in to comment.