summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2022-07-26 17:38:28 +0100
committerGitHub <noreply@github.com>2022-07-26 17:38:28 +0100
commitc982d6c5e3f5b113322beabb8a51c3153cab3d54 (patch)
treec0e7152710ee7e0c9e11d155b35bef0697ec6e83
parent61da9286a16fd2ad056316685e6d465801cdb4cd (diff)
Avoid OOB in dynamic_keymap_reset (#17695)
-rw-r--r--quantum/dynamic_keymap.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c
index e80dd6d534..01be9806e4 100644
--- a/quantum/dynamic_keymap.c
+++ b/quantum/dynamic_keymap.c
@@ -149,18 +149,25 @@ void dynamic_keymap_set_encoder(uint8_t layer, uint8_t encoder_id, bool clockwis
void dynamic_keymap_reset(void) {
// Reset the keymaps in EEPROM to what is in flash.
- // All keyboards using dynamic keymaps should define a layout
- // for the same number of layers as DYNAMIC_KEYMAP_LAYER_COUNT.
for (int layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) {
for (int row = 0; row < MATRIX_ROWS; row++) {
for (int column = 0; column < MATRIX_COLS; column++) {
- dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column]));
+ if (layer < keymap_layer_count()) {
+ dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column]));
+ } else {
+ dynamic_keymap_set_keycode(layer, row, column, KC_TRANSPARENT);
+ }
}
}
#ifdef ENCODER_MAP_ENABLE
for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) {
- dynamic_keymap_set_encoder(layer, encoder, true, pgm_read_word(&encoder_map[layer][encoder][0]));
- dynamic_keymap_set_encoder(layer, encoder, false, pgm_read_word(&encoder_map[layer][encoder][1]));
+ if (layer < encodermap_layer_count()) {
+ dynamic_keymap_set_encoder(layer, encoder, true, pgm_read_word(&encoder_map[layer][encoder][0]));
+ dynamic_keymap_set_encoder(layer, encoder, false, pgm_read_word(&encoder_map[layer][encoder][1]));
+ } else {
+ dynamic_keymap_set_encoder(layer, encoder, true, KC_TRANSPARENT);
+ dynamic_keymap_set_encoder(layer, encoder, false, KC_TRANSPARENT);
+ }
}
#endif // ENCODER_MAP_ENABLE
}