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

Bug: Out of bounds read in ydotool type #275

Open
AstroSnail opened this issue Jan 29, 2025 · 0 comments
Open

Bug: Out of bounds read in ydotool type #275

AstroSnail opened this issue Jan 29, 2025 · 0 comments

Comments

@AstroSnail
Copy link

AstroSnail commented Jan 29, 2025

When ydotool type is asked to type unicode characters, sometimes strange keypresses are generated.

For example, on my computer, asking ydotool to type "Å" causes it to press the Numpad 0/Insert key:

[erry@soon:~]$ ydotool type Å
^[[2~

This is because inside Client/tool_type.c, the loop that reads characters and transforms them into keycodes doesn't correctly handle non-ASCII characters. Specifically:

The result is that any time a byte greater than 127 is read, the array is indexed out of bounds.

On my system, "Å" is encoded in UTF-8 as the sequence 0xC3 0x85, which ydotool type uses to index the array out of bounds in two separate cases, and one of the out-of-bounds reads produces 0x73250052. As the function takes the lower 16 significant bits of the value as the keycode (and the most significant bit is unset, so it is not considered uppercase), this results in pressing keycode 0x0052 (decimal 82), which corresponds to Numpad 0 (if Num Lock is off, this is the same as Insert).

I'm disappointed that ydotool does not support typing unicode characters, but I'm ready to admit that, at this stage, supporting them will involve a lot of work. Therefore I think the easiest fix would be to add an extra check before calling type_char that ensures the byte is within the range of 0 to 127.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant