Commit graph

693 commits

Author SHA1 Message Date
qneko
289c8ec8cd Merge branch 'master' into 'master'
XGetSubImage: improve efficiency by reducing number of temporary heap allocations

Closes #114

See merge request xorg/lib/libx11!239
2026-04-15 10:21:10 +00:00
Alan Coopersmith
13fd1cbb6f XlibInt.c: use correct type for Win32 in SocketBytesReadable()
Fixes compiler error of:

XlibInt.c: In function 'SocketBytesReadable':
XlibInt.c:1254:50: error: passing argument 3 of 'ioctlsocket' from
 incompatible pointer type [-Wincompatible-pointer-types]
 1254 |     ioctlsocket(ConnectionNumber(dpy), FIONREAD, &bytes);
      |                                                  ^~~~~~
      |                                                  |
      |                                                  int *
In file included from /usr/share/mingw-w64/include/windows.h:92,
                 from /usr/i686-w64-mingw32/include/X11/Xwindows.h:77,
                 from /usr/i686-w64-mingw32/include/X11/Xthreads.h:98:
/usr/share/mingw-w64/include/winsock.h:281:76: note: expected 'u_long *' {aka 'long unsigned int *'} but argument is of type 'int *'
  281 |   WINSOCK_API_LINKAGE int WSAAPI ioctlsocket(SOCKET s,__LONG32 cmd,u_long *argp);
      |                                                                    ~~~~~~~~^~~~

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/299>
2026-03-15 14:52:08 -07:00
Julian Orth
1e511b0cb7 Ignore XkbMapNotify events that don't belong to the core keyboard
Such events can contain values that are incompatible with the core
keyboard map.

Fixes a potentially fatal error when such values are later used in a
XkbGetMap request.

Signed-off-by: Julian Orth <ju.orth@gmail.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/293>
2026-01-22 18:05:14 +00:00
Pierre Le Marre
369c6a8065 xkb: Fix key type level names
Fixed invalid level names count for key types without level names.

Signed-off-by: Pierre Le Marre <dev@wismill.eu>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/292>
2025-10-17 22:51:29 +02:00
Pierre Le Marre
ff409a48f9 xkb: Fix default key types
Before this commit, using xkbcomp to compile a keymap that omits the key
type `ALPHABETIC` leads to either a wrong serialization (`-xkb` output)
or a server error such as:

    X Error of failed request:  BadValue (integer parameter out of range for operation)
      Major opcode of failed request:  135 (XKEYBOARD)
      Minor opcode of failed request:  9 (XkbSetMap)
      Value in failed request:  0x8010202
      Serial number of failed request:  55
      Current serial number in output stream:  60

Indeed, there is an error in the default key maps: the second field of
`XkbKTMapEntryRec` if a level index, not a modifier mask. While it worked
*by chance* for `ShiftMask` (e.g. the `TWO_LEVEL` type), it does not work
for `LockMask` (e.g. the `ALPHABETIC` type).

Fixed by using the correct level indices.

It probably went unnoticed for so long because xkbcomp and libxkbcommon
< 1.12 always use all the key types, while libxkbcommon ≥ 1.12 does not
serialize unused key types. The latter case may result in a keymap that
omits `ALPHABETIC`, e.g. with keyboard layouts with 4+ levels which use
alternative key types such as `FOUR_LEVEL_ALPHABETIC`.

Signed-off-by: Pierre Le Marre <dev@wismill.eu>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/292>
2025-10-17 22:50:57 +02:00
Alan Coopersmith
7b9a1dba6f Drop vestiges of OS/2 support
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/291>
2025-09-29 17:54:40 +00:00
Alan Coopersmith
06516f8c51 xkb: fix include of config.h and drop unused DEBUG check
I can find nowhere in the source history where there was DEBUG code
that needed to include <stdio.h>, but the include of config.h should
never have been inside the DEBUG ifdef.

Resolves warnings from gcc 15 in 32-bit builds on Solaris of:
../../src/config.h:306:9: warning: "_FILE_OFFSET_BITS" redefined

Fixes: 7eee605e ("Conditionally include config.h in Xlib source")
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/290>
2025-09-23 16:33:37 -07:00
Alan Coopersmith
503e5aa44a xcb_io: fix build with configure --disable-xthreads
Closes: #232
Fixes: da97120f ("xcb: Clarify the XInitThreads error message")

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/289>
2025-09-01 13:08:21 -07:00
Keith Packard
622de26180 Avoid memory leak in XKeysymToString
Instead of calling malloc each time this function is invoked, use
the Quark database to ensure the return value lasts forever while not
leaking memory.

Signed-off-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Peter Harris <pharris2@rocketsoftware.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/282>
2025-08-09 20:01:49 +00:00
Alan Coopersmith
8b77c86a06 Strip trailing whitespace from source files
Performed with: `git ls-files | xargs perl -i -p -e 's{[ \t]+$}{}'`

`git diff -w` & `git diff -b` show no diffs from this change

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/287>
2025-08-02 18:38:26 -07:00
Weng Xuetian
7f8305c779 imDefIc: Clear fabricated state on unfocus.
When unsetting focus, the event filter is removed. This means a pending
fabricated event may not yet be sent to filter.

All the fabricated event state should be cleared and the pending sync
reply sent back as if the state is unfabricated.

Fix #235

Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/283>
2025-05-24 13:46:13 -07:00
Olivier Fourdan
5f8077b257 xkb: Fix buffer overflow in XkbChangeTypesOfKey()
If XkbChangeTypesOfKey() is called with nGroups == 0, it will resize the
key syms to 0 but leave the key actions unchanged.

If later, the same function is called with a non-zero value for nGroups,
this will cause a buffer overflow because the key actions are of the wrong
size.

To avoid the issue, make sure to resize both the key syms and key actions
when nGroups is 0.

(cherry picked from xorg/xserver@0e4ed94952)

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/libx11/-/merge_requests/279>
2025-02-26 17:26:10 -08:00
Alan Coopersmith
865fd56aeb xkb: always set *mask_rtrn in XkbVirtualModsToReal
Resolves warning from Oracle Parfait static analyser:

Error: Uninitialised memory
   Uninitialised memory variable [uninitialised-mem-var] (CWE 457):
      Possible access to uninitialised memory referenced by variable 'mask'
        at line 721 of xkb/XKBMisc.c in function 'XkbUpdateKeyTypeVirtualMods'.
        Path in callee avoiding write at line 720
          mask allocated at line 718

(cherry picked from xorg/xserver@a6574033f4)

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/279>
2025-02-26 17:26:02 -08:00
Alan Coopersmith
88d1a84ca3 XkbChangeTypesOfKey: verify newTypesIn is not null before using it
Based on xorg/xserver@97c9e6a713

Fixes: 8ba0ca32 ("Janitor: ansification, make distcheck, compiler warnings.")
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/279>
2025-02-26 17:26:00 -08:00
Siddhesh Poyarekar
48a1335cab xkb: Allocate size_syms correctly when width of a type increases
The current code seems to skip syms with width less than
type->num_levels when calculating the total size for the new
size_syms. This leads to less space being allocated than necessary
during the next phase, which is to copy over the syms to the new
location. This results in an overflow leading to a crash.

(cherry picked from xorg/xserver@42ae2e8199)

Signed-off-by: Siddhesh Poyarekar <siddhesh.poyarekar@gmail.com>
Signed-off-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/libx11/-/merge_requests/279>
2025-02-26 17:25:52 -08:00
Daniel Stone
158be3ebd7 XKB: Fix size_syms calculation bug
Apparently it needed to be nSyms*15/10, not *12/10; make it match the
other allocation code.

(cherry picked from xorg/xserver@f292de2ef1)

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/279>
2025-02-26 17:25:46 -08:00
Alan Coopersmith
d6e1ca046a XkbFreeKeyboard: set xkb->geom to NULL after freeing it
Because XkbFreeGeometry takes a pointer to the geometry structure,
and not the overall xkb structure like the other XkbFree*() calls,
the caller is responsible for clearing the xkb->geom pointer to
ensure it is not used after free.

Based on xorg/xserver@629798c73a

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/279>
2025-02-26 17:25:46 -08:00
qkot
1bc80e8f86 XGetSubImage: improve efficiency by reducing number of temporary allocations 2025-02-21 22:12:47 +00:00
Alan Coopersmith
61175323a8 cmsColNm: remove obsolete comment about FirstCmp being public
It was made a static function in May 14, 1991 by rws in
commit "make FirstCmp static" for X11R5

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/276>
2024-12-30 10:29:37 -08:00
Pierre Le Marre
7c75a06645 Fix misuse of UCSConvertCase in XConvertCase
There are two issues with the use of `UCSConvertCase` in `XConvertCase`:

- Some Latin-1 keysyms do not map within Latin-1, e.g. `ssharp`.
  Only Latin-1 keysyms have the same value as the Unicode code point of
  their corresponding character. So `UCSConvertCase` does not work for
  some Latin-1 keysyms as it returns Unicode code points outside Latin-1
  that do not match their corresponding keysyms values.
- Some Unicode keysyms should map to Latin-1 keysyms (<0x100). But the
  Unicode keysym mask 0x01000000 is applied blindly to the result of
  `UCSConvertCase`, resulting in invalid Unicode keysyms (0x010000nn)
  while they should be Latin-1 keysyms.

Example with ß/ẞ:

```c
KeySym lower, upper;

XConvertCase(XK_ssharp, &lower, &upper);
// Expected: lower == XK_ssharp, upper == U1E9E
// Got:      lower == XK_ssharp, upper == 0x1E9E

XConvertCase(U1E9E, &lower, &upper);
// Expected: lower == XK_ssharp, upper == U1E9E
// Got:      lower == 0x10000df, upper == U1E9E
```

Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/274>
2024-12-14 07:26:34 +01:00
Alan Coopersmith
5a7d94e07f xkb: avoid undefined behavior due to left shift overflow
Closes: #225
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/273>
2024-11-16 21:11:07 +00:00
Alan Coopersmith
1ef3c6f010 XIM_SET_PAD: add do ... while (0) to avoid -Wextra-semi-stmt warnings
Clears 8 warnings from clang of the form:

imDefIc.c:366:29: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
        XIM_SET_PAD(&buf_s[2], len);            /* pad */
                                   ^

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/272>
2024-11-10 16:04:08 -08:00
Alan Coopersmith
22ded6890e Xrm.c: remove unneccessary ; after {}
Clears 2 clang warnings:

Xrm.c:1186:51: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
            while (is_space(bits = next_char(c, str))) {};
                                                         ^
Xrm.c:1191:48: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
                while (is_space(bits = next_char(c, str))) {};
                                                             ^

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/272>
2024-11-10 16:04:03 -08:00
Alan Coopersmith
b7f59114ab DL_APPEND/DL_DELETE: remove trailing semicolon from definitions
Clears 2 clang warnings:

XlibInt.c:672:26: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
    DL_APPEND(*head, add);
                         ^
XlibInt.c:694:36: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
            DL_DELETE(*head, event);
                                   ^

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/272>
2024-11-10 15:39:49 -08:00
Alan Coopersmith
da431b8f7f xcb_io.c: add do ... while (0) to avoid -Wextra-semi-stmt warnings
Clears 10 warnings from clang of the form:

xcb_io.c:177:56: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
                                         xcb_xlib_unknown_req_in_deq);
                                                                     ^

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/272>
2024-11-10 15:39:43 -08:00
Alan Coopersmith
a53c45d69e CI_GET_*_INFO_*: add do ... while (0) to avoid -Wextra-semi-stmt warnings
Clears 24 warnings from clang of the form:

TextExt16.c:63:34: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
        CI_GET_DEFAULT_INFO_1D (fs, def);
                                        ^

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/272>
2024-11-10 15:23:52 -08:00
Alan Coopersmith
6891228821 RETURN: add do ... while (0) to avoid -Wextra-semi-stmt warnings
Clears 5 warnings from clang of the form:

RdBitF.c:141:32: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
            RETURN (BitmapFileInvalid);
                                      ^

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/272>
2024-11-10 13:11:12 -08:00
Alan Coopersmith
38c642c8eb poly.h: add do ... while (0) to avoid -Wextra-semi-stmt warnings
Clears 3 warnings from clang of the form:

PolyReg.c:224:67: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
            BRESINITPGONSTRUCT(dy, top->x, bottom->x, pETEs->bres);
                                                                  ^

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/272>
2024-11-10 13:08:31 -08:00
Alan Coopersmith
906bf4a86d PutCommandResource: add do ... while (0) to avoid -Wextra-semi-stmt warnings
Clears 4 warnings from clang of the form:

ParseCmd.c:158:43: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
                    PutCommandResource(options[i].value);
                                                        ^

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/272>
2024-11-10 12:37:53 -08:00
Alan Coopersmith
c0768ab687 GetFunc: add do ... while (0) to avoid -Wextra-semi-stmt warnings
Clears 4 warnings from clang of the form:

CrGlCur.c:140:64: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
    GetFunc (TryShapeCursorFunc, "XcursorTryShapeCursor", func);
                                                               ^

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/272>
2024-11-10 12:35:44 -08:00
Alan Coopersmith
68e6caad8f _XkbCheckPendingRefresh: add do ... while (0) to avoid -Wextra-semi-stmt
Clears 6 warnings from clang of the form:

XKBBind.c:74:48: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
    _XkbCheckPendingRefresh(dpy, dpy->xkb_info);
                                               ^

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/272>
2024-11-10 11:48:41 -08:00
Alan Coopersmith
5e22c4b3d5 set_toupper: add do { ... } while (0) to avoid -Wextra-semi-stmt warnings
Clears 4 warnings from clang of the form:

lcUtil.c:53:18: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
        set_toupper(ch1);
                        ^

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/272>
2024-11-10 11:06:28 -08:00
Julien Cristau
8703ecf105 ximcp: hide internal functions
commit 13e9ac4d45 "ximcp: Unmark to fabricate key events with XKeyEvent
serial" added new _XimFabricateSerial / _XimUnfabricateSerial /
_XimIsFabricatedSerial functions; they don't need to be exported by
libX11.

Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/271>
2024-11-04 17:24:11 +00:00
Alan Coopersmith
df1f1a47f9 _XGetRequest: Set data field to 0 when initializing new requests
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/268>
2024-10-12 10:00:04 -07:00
Alan Coopersmith
1f01aafa6d _XlcDefaultMapModifiers: remove conversions between size_t & int
Avoids build failures with gcc 14.2 when MALLOC_0_RETURNS_NULL is defined:

lcWrap.c: In function ‘_XlcDefaultMapModifiers’:
lcWrap.c:149:9: warning: ‘strcpy’ writing between 4294967296 and
 9223372036854775806 bytes into a region of size 1 [-Wstringop-overflow=]
  149 |         strcpy(mods, prog_mods);
      |         ^~~~~~~~~~~~~~~~~~~~~~~
../../include/X11/Xlibint.h:457:24: note: destination object of size 1
 allocated by ‘malloc’
  457 | # define Xmalloc(size) malloc((size_t)((size) == 0 ? 1 : (size)))
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lcWrap.c:147:12: note: in expansion of macro ‘Xmalloc’
  147 |     mods = Xmalloc(i);
      |            ^~~~~~~
lcWrap.c:149:9: error: ‘__builtin_memcpy’ forming offset [1, 4294967295]
 is out of the bounds [0, 1] [-Werror=array-bounds=]
  149 |         strcpy(mods, prog_mods);
      |         ^~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/267>
2024-09-29 10:04:04 -07:00
Alan Coopersmith
86e71472bc SetFontPath: if ndirs is 0, skip work to make a list of directories
Clears warning from gcc 14.1:

SetFPath.c: In function ‘XSetFontPath’:
../include/X11/Xlibint.h:463:24: warning: argument 1 value is zero
 [-Walloc-zero]
  463 | # define Xmalloc(size) malloc((size_t)(size))
      |                        ^~~~~~~~~~~~~~~~~~~~~~
SetFPath.c:61:18: note: in expansion of macro ‘Xmalloc’
   61 |         if ((p = Xmalloc (nbytes))) {
      |                  ^~~~~~~

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/266>
2024-08-31 10:49:16 -07:00
Olivier Fourdan
19b2f5c2d0 Fix indentation
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/264>
2024-08-09 11:15:44 +02:00
Olivier Fourdan
f3d6ebac35 Close xcb connection after freeing display structure
Commit 1472048b7 to fix a colormap threading issue added a display
lock/unlock and a call to SyncHandle() to _XcmsFreeClientCmaps().

When running synchronized, that means calling XSync().

_XcmsFreeClientCmaps() is called from _XFreeDisplayStructure() via
XCloseDisplay() after the xcb connection is closed.

So when running synchronized, we may end up calling XSync() after the
xcb connection to the display is closed, which will generate a spurious
XIO error:

  | #0 in _XDefaultIOError () at /lib64/libX11.so.6
  | #1 in _XIOError () at /lib64/libX11.so.6
  | #2 in _XReply () at /lib64/libX11.so.6
  | #3 in XSync () at /lib64/libX11.so.6
  | #4 in _XSyncFunction () at /lib64/libX11.so.6
  | 8#5 in _XFreeDisplayStructure () at /lib64/libX11.so.6
  | 8#6 in XCloseDisplay () at /lib64/libX11.so.6

To avoid that issue, closed the xcb connection to the display last.

v2: And same in OutOfMemory() as well (José Expósito)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: José Expósito <jexposit@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/264>
2024-08-09 11:15:37 +02:00
Alan Coopersmith
39d57cbeda xlibi18n/lcFile.c: avoid use of possibly-NULL pointer with strcpy
Fixes gcc warnings:
lcFile.c: In function ‘_XlcLocaleLibDirName’:
lcFile.c:708:5: warning: use of possibly-NULL ‘last_dir_name’ where
 non-null expected [CWE-690] [-Wanalyzer-possible-null-argument]
  708 |     strcpy (last_dir_name, dir_name);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/258>
2024-07-13 10:14:02 -07:00
Alan Coopersmith
8abcaba1a7 Revert "unifdef __vax__"
This reverts commit 4ce3962b70.
Requested by NetBSD which still has a supported VAX port.

Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/257>
2024-07-06 09:37:50 -07:00
Olivier Fourdan
751fbc59c3 Fix deadlock in XRebindKeysym()
Xlib is now built with threading support enabled from the constructor
by default.

XRebindKeysym() acquires the display lock, then calls:

| XRebindKeysym()
|  LockDisplay()
|  ComputeMaskFromKeytrans()
|    -> XkbKeysymToModifiers()
|        -> _XkbLoadDpy()
|            -> XkbGetMap()
|                -> XkbGetUpdatedMap()
|                   LockDisplay()

And the dead lock:

| Xlib ERROR: XKBGetMap.c line 575 thread 1fc6e580: locking display already
| locked at KeyBind.c line 937

To avoid the issue, call ComputeMaskFromKeytrans() from outside the display
lock.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Closes: https://gitlab.freedesktop.org/xorg/lib/libx11/-/issues/216
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/256>
2024-06-24 08:58:11 +02:00
Olivier Fourdan
1472048b7a Make colormap private interfaces thread safe.
Protect access to the dpy structure by a display lock, so that these can
be called outside of a global display lock.

That allows the XCMS colormap functions to be thread safe without having
the whole functions within a display lock, to avoid deadlocks.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
See-also: https://gitlab.freedesktop.org/xorg/lib/libx11/-/issues/215
See-also: https://gitlab.freedesktop.org/xorg/lib/libx11/-/issues/94
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/254>
2024-06-15 00:10:17 +00:00
Olivier Fourdan
739fce4c12 Revert "Protect colormap add/removal with display lock"
That commit 99a2cf1aa was moving the calls to the _Xcms*CmapRec*()
family of functions within a display lock to make the XCMS colormap
functions thread safe.

Unfortunately, that causes a deadlock in XCopyColormapAndFree(), because
_XcmsCopyCmapRecAndFree() calls CmapRecForColormap() which calls
XGetVisualInfo() which also tries to acquire the display lock.

So, instead of moving the entire functions within the display lock,
let's try to make the functions themselves thread safe in the following
commit, and revert this change which causes a deadlock.

This reverts commit 99a2cf1aa0.

Fixes: https://gitlab.freedesktop.org/xorg/lib/libx11/-/issues/215
See-also: https://gitlab.freedesktop.org/xorg/lib/libx11/-/issues/94
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/254>
2024-06-15 00:10:17 +00:00
Olivier Fourdan
5dfedaf4aa Revert "Fix XTS regression in XCopyColormapAndFree"
This change was to fix the next change that we are to revert as well.

This reverts commit 68c72a7341.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/254>
2024-06-15 00:10:17 +00:00
Alan Coopersmith
c099d0105f Avoid buffer overflow in _XimLookupMBText & _XimLookupUTF8Text
Reported-by: u32i <u32i@proton.me>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/251>
2024-06-07 18:12:29 +00:00
José Expósito
af1312d287 XKBMAlloc: Check that needed is >= 0 in XkbResizeKeyActions
Passing a negative value in `needed` to the `XkbResizeKeyActions()`
function can create a `newActs` array of an unespected size.
Check the value and return if it is invalid.

This error has been found by a static analysis tool. This is the report:

    Error: OVERRUN (CWE-119):
    libX11-1.8.7/src/xkb/XKBMAlloc.c:811: cond_const:
      Checking "xkb->server->size_acts == 0" implies that
      "xkb->server->size_acts" is 0 on the true branch.
    libX11-1.8.7/src/xkb/XKBMAlloc.c:811: buffer_alloc:
      "calloc" allocates 8 bytes dictated by parameters
      "(size_t)((xkb->server->size_acts == 0) ? 1 : xkb->server->size_acts)"
      and "8UL".
    libX11-1.8.7/src/xkb/XKBMAlloc.c:811: var_assign:
      Assigning: "newActs" = "calloc((size_t)((xkb->server->size_acts == 0) ? 1 : xkb->server->size_acts), 8UL)".
    libX11-1.8.7/src/xkb/XKBMAlloc.c:815: assignment:
      Assigning: "nActs" = "1".
    libX11-1.8.7/src/xkb/XKBMAlloc.c:829: cond_at_least:
      Checking "nCopy > 0" implies that "nCopy" is at least 1 on the
      true branch.
    libX11-1.8.7/src/xkb/XKBMAlloc.c:830: overrun-buffer-arg:
      Overrunning buffer pointed to by "&newActs[nActs]" of 8 bytes by
      passing it to a function which accesses it at byte offset 15
      using argument "nCopy * 8UL" (which evaluates to 8).
    #  828|
    #  829|           if (nCopy > 0)
    #  830|->             memcpy(&newActs[nActs], XkbKeyActionsPtr(xkb, i),
    #  831|                      nCopy * sizeof(XkbAction));
    #  832|           if (nCopy < nKeyActs)

Signed-off-by: José Expósito <jexposit@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/250>
2024-05-07 08:54:50 +00:00
Takao Fujiwara
898746f9b1 ximcp: Unmark fabricated with serial 0 and Xic commit_info
GTK2 XIM resets the XKeyEvent serial to 0 even if _XimCommitRecv()
sets the serial so now checks if the events are sent with
Xic->private.proto.commit_info.

Closes: !246
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/246>
2024-04-26 01:29:34 +09:00
Takao Fujiwara
5a1e62d77b Accept anon windows in XFilterEvent to update XIM state
When input focuses are switched quickly with shortcut keys in a Java
window, the focus is sometimes lost and the Window=0 is assigned in
XFilterEvent() but the XKeyEvent was forwarded by a XIM serer(IBus)
with XIM_FORWARD_EVENT -> XNextEvent() -> XFilterEvent() and the event
needs to be forwarded to the XIM XKeyEvent press and release filters
to update the XIM state with Window=0 likes _XimPendingFilter() and
_XimUnfabricateSerial().

Closes: #205, #206
Fixes: 024d229f ("ximcp: Unmark to fabricate key events with XKeyEvent serial")
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/246>
2024-04-26 01:29:26 +09:00
Takao Fujiwara
5a14178c7c ximcp: Add fabricated_time in XimProtoPrivate for timeout
When users type keys quickly, some applications using Steam or Java
do not call XNextEvent() for a key event but _XimFilterKeypress()
and _XimFilterKeyrelease() expect to receive the key events
forwarded by input methods.

Now fabricated_time Time value is added to XimProtoPrivate to check
the timeout value.

Closes: #205
Fixes: 024d229f ("ximcp: Unmark to fabricate key events with XKeyEvent serial")
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/246>
2024-04-26 00:49:14 +09:00
Takao Fujiwara
13e9ac4d45 ximcp: Unmark to fabricate key events with XKeyEvent serial
_XimProtoKeypressFilter() and _XimProtoKeyreleaseFilter() can
receive XKeyEvent from both the typing on the keyboard and the
callback of XIM_FORWARD_EVENT.

If the filter functions unmark to fabricate XKeyEvent from the typing
on the keyboard during receiving XKeyEvent from the callback of
XIM_FORWARD_EVENT with typing keys very quickly likes an bar code
scanner (or evemu-play), XIM server cannot receive some key events and
it causes the key typing order to get scrambled.

Now XIM client saves the serial in XKeyEvent and the filter functions
unmark to fabricate XKeyEvent from the callback of XIM_FORWARD_EVENT
only.

This and 024d229f are same patches but the regression issues will be
fixed by the later patches.

Closes: #198
Fixes: 024d229f ("ximcp: Unmark to fabricate key events with XKeyEvent serial")
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/246>
2024-04-12 10:21:41 +09:00