Skip to content

Commit

Permalink
restart_advertising_id: Prevent use of illegal ID (qmk#25)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Lenbok authored and sekigon-gonnoc committed Dec 17, 2019
1 parent c6eeb53 commit 122801f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tmk_core/protocol/nrf/sdk12/ble_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion tmk_core/protocol/nrf/sdk15/ble_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 122801f

Please sign in to comment.