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

Fix numeric keysym parsing #357

Merged
merged 7 commits into from
Jul 14, 2023
Merged

Conversation

wismill
Copy link
Member

@wismill wismill commented Jul 3, 2023

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.

@wismill wismill mentioned this pull request Jul 3, 2023
@wismill wismill added the compile-keymap Indicates a need for improvements or additions to keymap compilation label Jul 3, 2023
@wismill wismill added this to the 1.6.0 milestone Jul 3, 2023
@wismill wismill marked this pull request as ready for review July 3, 2023 11:16
Copy link
Member

@bluetech bluetech left a 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.

include/xkbcommon/xkbcommon-keysyms.h Outdated Show resolved Hide resolved
src/keysym.c Outdated Show resolved Hide resolved
@@ -656,11 +656,25 @@ ExprResolveKeySym(struct xkb_context *ctx, const ExprDef *expr,
if (!ExprResolveInteger(ctx, expr, &val))
return false;

if (val < 0 || val >= 10)
Copy link
Member

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...

test/keysym.c Outdated Show resolved Hide resolved
@wismill
Copy link
Member Author

wismill commented Jul 3, 2023

@bluetech Commit split!

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Contributor

@whot whot left a 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 :)

include/xkbcommon/xkbcommon.h Outdated Show resolved Hide resolved
test/keysym.c Outdated Show resolved Hide resolved
@wismill
Copy link
Member Author

wismill commented Jul 4, 2023

Rebased.

I added the constant XKB_KEYSYM_MIN. xkb_keysym_t is unsigned, but we do need to check min keysym in parser. Then we have the couple min/max.

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.
@wismill wismill merged commit a4c0852 into xkbcommon:master Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compile-keymap Indicates a need for improvements or additions to keymap compilation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants