Skip to content

Commit

Permalink
Merge branch 'bugfix/ble_check_adv_data' into 'master'
Browse files Browse the repository at this point in the history
fix(bt/bluedroid): Fix ble adv data check to avoid memory overflow

See merge request espressif/esp-idf!28245
  • Loading branch information
esp-zhp committed Jan 5, 2024
2 parents dbe1df8 + c66fc14 commit 0b8e6c6
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 0b8e6c6

Please sign in to comment.