Skip to content

Commit d487cfc

Browse files
author
Donatien Garnier
authored
Merge pull request ARMmbed#54 from paul-szczepanek-arm/fix-whitelist
Whitelist: fix not updating size of array
2 parents 5d8570b + b2f97cc commit d487cfc

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

features/FEATURE_BLE/ble/generic/SecurityDb.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -584,28 +584,32 @@ class SecurityDb {
584584
WhitelistDbCb_t cb,
585585
::Gap::Whitelist_t *whitelist
586586
) {
587-
for (size_t i = 0; i < get_entry_count() && i < whitelist->capacity; i++) {
587+
for (size_t i = 0; i < get_entry_count() && whitelist->size < whitelist->capacity; i++) {
588588
entry_handle_t db_handle = get_entry_handle_by_index(i);
589589
SecurityDistributionFlags_t* flags = get_distribution_flags(db_handle);
590590

591591
if (!flags) {
592592
continue;
593593
}
594594

595+
SecurityEntryIdentity_t* identity = read_in_entry_peer_identity(db_handle);
596+
if (!identity) {
597+
continue;
598+
}
599+
600+
memcpy(
601+
whitelist->addresses[whitelist->size].address,
602+
identity->identity_address.data(),
603+
sizeof(BLEProtocol::AddressBytes_t)
604+
);
605+
595606
if (flags->peer_address_is_public) {
596-
whitelist->addresses[i].type = BLEProtocol::AddressType::PUBLIC;
607+
whitelist->addresses[whitelist->size].type = BLEProtocol::AddressType::PUBLIC;
597608
} else {
598-
whitelist->addresses[i].type = BLEProtocol::AddressType::RANDOM_STATIC;
609+
whitelist->addresses[whitelist->size].type = BLEProtocol::AddressType::RANDOM_STATIC;
599610
}
600611

601-
SecurityEntryIdentity_t* identity = read_in_entry_peer_identity(db_handle);
602-
if (identity) {
603-
memcpy(
604-
whitelist->addresses[i].address,
605-
identity->identity_address.data(),
606-
sizeof(BLEProtocol::AddressBytes_t)
607-
);
608-
}
612+
whitelist->size++;
609613
}
610614

611615
cb(whitelist);

features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ ble_error_t GenericSecurityManager::purgeAllBondingState(void) {
142142
ble_error_t GenericSecurityManager::generateWhitelistFromBondTable(Gap::Whitelist_t *whitelist) const {
143143
if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
144144
if (eventHandler) {
145+
if (!whitelist) {
146+
return BLE_ERROR_INVALID_PARAM;
147+
}
145148
_db->generate_whitelist_from_bond_table(
146149
mbed::callback(eventHandler, &::SecurityManager::EventHandler::whitelistFromBondTable),
147150
whitelist

0 commit comments

Comments
 (0)