summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Fourdan <ofourdan@redhat.com>2024-11-27 14:41:45 +0100
committerAlan Coopersmith <alan.coopersmith@oracle.com>2025-02-26 16:46:21 -0800
commitf6592c6f272587456f69aef6e1db6a1aef5731ca (patch)
treeb42378019c454ccf07b49f5c83b4df350191fc26
parent730c9df040546f1a98ab1b974ad2ccd1b4ad4552 (diff)
xkb: Fix buffer overflow in XkbVModMaskText()HEADmaster
The code in XkbVModMaskText() allocates a fixed sized buffer on the stack and copies the virtual mod name. There's actually two issues in the code that can lead to a buffer overflow. First, the bound check mixes pointers and integers using misplaced parenthesis, defeating the bound check. But even though, if the check fails, the data is still copied, so the stack overflow will occur regardless. Change the logic to skip the copy entirely if the bound check fails. (cherry picked from xorg/xserver@11fcda8753e994e15eb915d28cf487660ec8e722) Signed-off-by: Olivier Fourdan <ofourdan@redhat.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Part-of: <https://gitlab.freedesktop.org/xorg/lib/libxkbfile/-/merge_requests/24>
-rw-r--r--src/xkbtext.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/xkbtext.c b/src/xkbtext.c
index 4459ca7..59429b2 100644
--- a/src/xkbtext.c
+++ b/src/xkbtext.c
@@ -190,14 +190,14 @@ XkbVModMaskText(Display * dpy,
len = strlen(tmp) + 1 + (str == buf ? 0 : 1);
if (format == XkbCFile)
len += 4;
- if ((str - (buf + len)) <= BUFFER_SIZE) {
- if (str != buf) {
- if (format == XkbCFile)
- *str++ = '|';
- else
- *str++ = '+';
- len--;
- }
+ if ((str - buf) + len > BUFFER_SIZE)
+ continue; /* Skip */
+ if (str != buf) {
+ if (format == XkbCFile)
+ *str++ = '|';
+ else
+ *str++ = '+';
+ len--;
}
if (format == XkbCFile)
sprintf(str, "%sMask", tmp);