Skip to content

ble::AdvertisingDataParser::hasNext() bug #10563

@ijessen

Description

@ijessen

Description

ble::AdvertisingDataParser fails on 31-byte payloads padded with one or two null terminating bytes.

AdvertisingDataParser::hasNext() performs a bounds check in determining if there's more data to process:

if (position >= data.size()) {
    return false;
}

However, AdvertisingDataParser::next() indexes further than this into the data span:


(ble::adv_data_type_t::type) data[position + TYPE_INDEX],
data.subspan(position + VALUE_INDEX, current_length() - (TYPE_SIZE))

As a result, when a full-length legacy advertising payload is padded with one or two null terminating bytes at the end, AdvertisingDataParser::hasNext() returns true even after all data has been consumed, and a subsequent call to AdvertisingDataParser::next() overruns the span when it attempts to read either the data type or value.

One fix is to fix the comparison against data.size() in AdvertisingDataParser::hasNext():

if (position + VALUE_INDEX >= data.size()) {
    return false;
}

Affects v15.2 (0f959db)

Issue request type

[ ] Question
[ ] Enhancement
[X ] Bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions