-
Notifications
You must be signed in to change notification settings - Fork 123
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
Disallow producing NULL with escape sequences & prevent overflow #374
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.
Great catches, thanks.
@@ -0,0 +1,9 @@ | |||
xkb_keymap { | |||
// The following include statement has an octal escape sequence that | |||
// must be ignored. Else it would insert a NULL character and thus |
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.
NULL -> NUL
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.
Actually, the character name is NULL. NUL
is the ASCII abreviation. I prefer the name, but if you prefer the abbreviation then I suggest we use \NUL
instead.
dd68f0f
to
cd8698a
Compare
Is there a reason to prevent it? |
Well, I wonder if some strings are exposed and where. They might be exposed by some of the log entries, currently unescaped. They could be exposed by functions like Just thinking out loud here; we should deal with it in a dedicated issue if relevant. |
I have thought about this topic before. My assumption is that xkbcommon, being a huge custom parser written in C in the 90s, is not safe from malicious input. So the question is whether there is a threat model in which xkbcommon is fed untrusted keymaps. In the cases I know and could think of, xkb keymap input comes trusted sources, like a compositor, X server, Of course this is no excuse to make xkbcommon full of holes, and we even have a rudimentary fuzzer, but it does make me weigh compatibility more than malicious input. |
NULL usually terminates the strings; allowing to produce it via escape sequences may lead to undefined behaviour. - Make NULL escape sequences (e.g. `\0` and `\x0`) invalid. - Add corresponding test. - Introduce the new message: XKB_WARNING_INVALID_ESCAPE_SEQUENCE.
The octal parser accepts the range `\1..\777`. The result is cast to `char` which will silently overflow. This commit prevents overlow and will treat `\400..\777` as invalid escape sequences.
It is easier to debug when the message actually displays the offending escape sequence.
cd8698a
to
ed491a9
Compare
@bluetech let’s continue this discussion in private. It is far too serious a topic. |
Rebased & improved commit message. Will merge when CI is successful. |
NULL usually terminates the strings; allowing to produce it via escape sequences may lead to undefined behaviour.
\0
and\x0
) invalid\400
,\777
)Fixes #363