Skip to content

Commit

Permalink
fix(studio): Ensure null-termination of layer name read from settings
Browse files Browse the repository at this point in the history
This fixes the string leak when a layer name is changed to a longer one,
but is discarded and reverted to the original shorter one from ZMK Studio.
  • Loading branch information
xingrz committed Sep 17, 2024
1 parent 32d0a4b commit 7a697a5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,14 @@ static int keymap_handle_set(const char *name, size_t len, settings_read_cb read
LOG_WRN("Found layer name for invalid layer ID %d", layer);
}

int err = read_cb(cb_arg, zmk_keymap_layer_names[layer],
int ret = read_cb(cb_arg, zmk_keymap_layer_names[layer],
MIN(len, CONFIG_ZMK_KEYMAP_LAYER_NAME_MAX_LEN - 1));
if (err <= 0) {
LOG_ERR("Failed to handle keymap layer name from settings (err %d)", err);
return err;
if (ret <= 0) {
LOG_ERR("Failed to handle keymap layer name from settings (err %d)", ret);
return ret;
}

zmk_keymap_layer_names[layer][ret] = 0;
} else if (settings_name_steq(name, "l", &next) && next) {
char *endptr;
uint8_t layer = strtoul(next, &endptr, 10);
Expand Down

0 comments on commit 7a697a5

Please sign in to comment.