Skip to content

Fix ScanEntry prefix matching for any=False #3036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions shared-module/_bleio/ScanEntry.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ bool bleio_scanentry_data_matches(const uint8_t* data, size_t len, const uint8_t
if (prefixes_length == 0) {
return true;
}
if (len == 0) {
// Prefixes exist, but no data.
return false;
}
size_t i = 0;
while(i < prefixes_length) {
uint8_t prefix_length = prefixes[i];
i += 1;
size_t j = 0;
bool prefix_matched = false;
while (j < len) {
uint8_t structure_length = data[j];
j += 1;
Expand All @@ -71,13 +76,18 @@ bool bleio_scanentry_data_matches(const uint8_t* data, size_t len, const uint8_t
if (any) {
return true;
}
} else if (!any) {
return false;
prefix_matched = true;
break;
}
j += structure_length;
}
// If all (!any), the current prefix must have matched at least one field.
if (!prefix_matched && !any) {
return false;
}
i += prefix_length;
}
// All prefixes matched some field (if !any), or none did (if any).
return !any;
}

Expand Down