-
Notifications
You must be signed in to change notification settings - Fork 125
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
Fix numeric keysym parsing #357
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good fixes!
I left some comments. Also, do you mind splitting the Fix parsing of numeric keysyms
commit such that each fix is in its own commit? It will be easier to bisect etc. this way.
@@ -656,11 +656,25 @@ ExprResolveKeySym(struct xkb_context *ctx, const ExprDef *expr, | |||
if (!ExprResolveInteger(ctx, expr, &val)) | |||
return false; | |||
|
|||
if (val < 0 || val >= 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it regressed in 2e4933c compared to xkbcomp...
@bluetech Commit split! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two nitpicks but this LGTM. though my eyes glaze over every time i look at the actual parser code :)
Rebased. I added the constant I also added much more test related to keysyms, to reflect the current implementation. |
Keysyms are 32-bit integers with the 3 most significant bits always set to zero. See: Appendix A “KEYSYM Encoding” of the X Window System Protocol at https://www.x.org/releases/current/doc/xproto/x11protocol.html#keysym_encoding. Add a new constants XKB_KEYSYM_MIN and XKB_KEYSYM_MAX to make the interval of valid keysyms more obvious in the code.
When parsing hexadecimal keysym using `xkb_keysym_from_name`, the result is limited by `parse_keysym_hex` to 0xffffffff, but the maximum keysym is XKB_MAX_KEYSYM, i.e. 0x1fffffff. Fixed by adding an upper bound.
In `parser.y`, a numeric keysym is parsed by formatting it in its hexadecimal form then parsed as a keysym name. This is convoluted. Fixed by checking directly the upper bound.
`ExprResolveKeySym` in `expr.c` does not parse non-digit numeric keysyms. Fixed by checking upper bound; also add warning messages.
- Add a keymap test with decimal and hexadecimal keysyms. - Reorganize code in `test/keysym.c` by parsing type: name, Unicode and hexadecimal. - Add more tests for edge cases. In particular: - test decimal format (currently not supported); - test the Unicode and hexadecimal ranges more thoroughly; - test with wrong case without the XKB_KEYSYM_CASE_INSENSITIVE flag; - test surrounding spaces. - Document the tests.
While working on #332, I realized that numeric keysyms parsing has some issues. Let’s deal with it in this separate PR.
This PR fixes some edges cases and improve tests.