Skip to content

Commit

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

See merge request espressif/esp-idf!28408
  • Loading branch information
Isl2017 committed Jan 22, 2024
2 parents 753bed3 + 6d55e5e commit 9186e0e
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
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 9186e0e

Please sign in to comment.