Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes null-character termination in ucis_add() #22351

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions quantum/process_keycode/process_ucis.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ bool process_ucis(uint16_t keycode, keyrecord_t *record) {
case KC_ENTER:
ucis_finish();
return false;
default:
return false;
}
}
}
Expand Down
21 changes: 15 additions & 6 deletions quantum/unicode/ucis.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ static char keycode_to_char(uint16_t keycode) {

bool ucis_add(uint16_t keycode) {
char c = keycode_to_char(keycode);
if (c) {
input[count++] = c;
return true;
if (count < UCIS_MAX_INPUT_LENGTH - 1) {
if (c) {
input[count++] = c;
input[count] = 0;
return true;
}
}
return false;
}

bool ucis_remove_last(void) {
if (count) {
input[count] = 0;
count--;
return true;
}
Expand All @@ -72,17 +76,22 @@ void ucis_finish(void) {
}
}

for (uint8_t j = 0; j <= count; j++) {
tap_code(KC_BACKSPACE);
}

if (found) {
for (uint8_t j = 0; j <= count; j++) {
tap_code(KC_BACKSPACE);
}
register_ucis(i);
}

active = false;
}

void ucis_cancel(void) {
for (uint8_t i = 0; i <= count; i++) {
tap_code(KC_BACKSPACE);
}

count = 0;
active = false;
}
Expand Down
Loading