From 122801f713bdc95163659eed12082f8b1ac607c7 Mon Sep 17 00:00:00 2001 From: Len Trigg Date: Wed, 18 Dec 2019 01:28:28 +1300 Subject: [PATCH] restart_advertising_id: Prevent use of illegal ID (#25) * Fix crash when given an ID one greater than permitted. * For split keyboards, ID 0 is reserved for slave, so make ADV_ID0 a no-op. --- tmk_core/protocol/nrf/sdk12/ble_master.c | 2 +- tmk_core/protocol/nrf/sdk15/ble_master.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tmk_core/protocol/nrf/sdk12/ble_master.c b/tmk_core/protocol/nrf/sdk12/ble_master.c index 787390169ba8..669b7ace501d 100644 --- a/tmk_core/protocol/nrf/sdk12/ble_master.c +++ b/tmk_core/protocol/nrf/sdk12/ble_master.c @@ -1380,7 +1380,7 @@ void restart_advertising_id(uint8_t id) { m_whitelist_peer_cnt = (sizeof(m_whitelist_peers) / sizeof(pm_peer_id_t)); peer_list_get(m_whitelist_peers, &m_whitelist_peer_cnt); - if (id > m_whitelist_peer_cnt) { + if (id >= m_whitelist_peer_cnt) { return; } m_whitelist_peer_cnt = 1; diff --git a/tmk_core/protocol/nrf/sdk15/ble_master.c b/tmk_core/protocol/nrf/sdk15/ble_master.c index 840e70f1bc9c..79a5a931798b 100644 --- a/tmk_core/protocol/nrf/sdk15/ble_master.c +++ b/tmk_core/protocol/nrf/sdk15/ble_master.c @@ -1305,10 +1305,13 @@ void restart_advertising_id(uint8_t id) { m_whitelist_peer_cnt = (sizeof(m_whitelist_peers) / sizeof(pm_peer_id_t)); peer_list_get(m_whitelist_peers, &m_whitelist_peer_cnt); - if (id > m_whitelist_peer_cnt) { + if (id >= m_whitelist_peer_cnt) { return; } #ifdef NRF_SEPARATE_KEYBOARD_MASTER + if (id == 0) { + return; + } m_whitelist_peer_cnt = 2; m_whitelist_peers[1] = m_whitelist_peers[id]; #else