Commit graph

1769 commits

Author SHA1 Message Date
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
4935050168 _XCreateMutex/_XFreeMutex: remove trailing semicolon from definitions
Makes them match the style of the other macros here and clears
up 5 clang warnings of the form:

Context.c:194:27: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
        _XCreateMutex(&db->linfo);
                                 ^

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:33:01 -08:00
Alan Coopersmith
41c4aa408c OneDataCard32: add do ... while (0) to avoid -Wextra-semi-stmt warnings
Clears 13 warnings from clang of the form:

Backgnd.c:44:72: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
    OneDataCard32 (dpy, NEXTPTR(req,xChangeWindowAttributesReq), pixel);
                                                                       ^

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:52:19 -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
563ddd4ff5 BufAlloc: add do { ... } while (0) to avoid -Wextra-semi-stmt warnings
Clears 46 warnings from clang of the form:

XKB.c:207:69: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
        BufAlloc(char *, out, (((size * 2) + (unsigned) 3) / 4) * 4);
                                                                    ^

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:46:43 -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
Alan Coopersmith
4cb567d9a0 Data: add do ... while (0) to avoid -Wextra-semi-stmt warnings
Clears 38 warnings from clang of the form:

cmsLkCol.c:155:35: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
    Data (dpy, colorname, (long)n);
                                  ^

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

cmsCmap.c:194:34: warning: empty expression statement has no effect;
 remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
            DeqAsyncHandler(dpy, &async);
                                        ^

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/272>
2024-11-10 10:25:56 -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
41bc1a9dbe ximcp: don't leak window if XGetAtomName() fails
Found by Oracle Parfait 13.3 static analyzer:
   X Resource Leak [X-resource-leak]:
      Leaked X Resource window
        at line 306 of imDefIm.c in function '_XimPreConnectionIM'.
          window initialized at line 300 with XCreateSimpleWindow

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/269>
2024-10-26 11:02:42 -07: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
f2ebbce6d0 _XimStrConversionCallback: use size_t to calculate size to malloc
Avoids build failures with gcc 14.2 when MALLOC_0_RETURNS_NULL is defined:

imCallbk.c:346:9: error: ‘memcpy’ offset 10 is out of the bounds [0, 1]
 [-Werror=array-bounds=]
  346 |         memcpy(&buf[p],&cbrec.text->string.mbs,length_in_bytes);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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:24:23 -07:00
Alan Coopersmith
75c5bdee81 _XimEncodingNegotiation: swap order of arguments to calloc
Avoids build failures with gcc 14.2 when MALLOC_0_RETURNS_NULL is defined:

imDefIm.c: In function ‘_XimEncodingNegotiation’:
imDefIm.c:1739:15: error: ‘memcpy’ offset 8 is out of the bounds [0, 1]
 [-Werror=array-bounds=]
 1739 |         (void)memcpy((char *)&buf_s[2], name_ptr, name_len);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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:40 -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
ed9fb5535e
libX11 1.8.10
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2024-07-28 10:37:55 -07:00
Kelly Roadkill
92014b3963 Revert "nls: add compose seq's for symbols absent from Cyrillic layouts to ru_RU"
Testing by multilingual typists revealed that the
proposed sequences are too complex for everyday
use. It seems that the inherent problems with
JCUKEN can only be fixed with better kbd layouts.

This reverts commit 174df0b8b6.

Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/261>
2024-07-23 08:12:01 +05:00
Kelly Roadkill
be137dffa6 nls: add compose sequences for hryvnia currency
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/259>
2024-07-20 16:33:10 +00: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
Kelly Roadkill
bc8c908ae8 nls: delete compose sequence with anomalous post-fixed cedilla
The only sequence with post-fixed cedilla in the
whole en_US.UTF-8 was introduced in cf040016 with
the merge of GTK+ compose sequences 12 years ago.
It goes against the established patterns.

Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/255>
2024-06-18 14:49:50 +05: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
jmcwilliams403
0af3328dc3 NLS: Add 6 Multi_key sequences for Ezh
Ezh is a Latin-Script letter belonging to several Uralic, Caucasian,
and West-African languages. It is present on some Finnish keyboards,
but users of many other layouts cannot presently type it. This commit
adds Multi_key sequences for both Capital and lowercase Ezh, as well
as Multi_key + dead_caron sequences for Ezh with a caron, which is
used in Laz and Skolt Sámi.

Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/221>
2024-06-02 18:22:55 +00:00
Kelly Roadkill
174df0b8b6 nls: add compose seq's for symbols absent from Cyrillic layouts to ru_RU
JCUKEN (ЙЦУКЕН) - the default and de-facto standard layout for most Cyrillic scripts - lacks a number of ASCII symbols from QWERTY counterpart, forcing users to switch back-and-forth between layouts to type them.
This adds sequences for them to the ru_RU compose map in an intuitive and consistent manner.

Fixes #200 for ru_RU (but other Cyrillic layouts might benefit too)

Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/238>
2024-06-02 18:20:36 +00:00
Mohamed Akram
763f3f938c nls: add Arabic hamza compose sequences
These sequences are intended for use in the ara(mac-phonetic) and
my(phonetic) layouts. They are based on the following layouts listed in
the CLDR:

- https://github.com/unicode-org/cldr/blob/release-43/keyboards/osx/ar-t-k0-osx-qwerty.xml
- https://github.com/unicode-org/cldr/blob/release-43/keyboards/osx/ms-t-k0-osx.xml

The sequences are listed in the `<transforms>` section, and are
reproduced below:

```
<transforms type="simple">
	<transform from="ء\u{64E}" to="آ"/> <!--  ءَ → آ -->
	<transform from="ء\u{650}" to="إ"/> <!--  ءِ → إ -->
	<transform from="ء " to="ء"/>
	<transform from="ء\u{A0}" to="ء"/>
	<transform from="ء!" to="إ"/>
	<transform from="ء١" to="إ"/>
	<transform from="ءا" to="أ"/>
	<transform from="ءس" to="ئ"/>
	<transform from="ءو" to="ؤ"/>
	<transform from="ءي" to="ئ"/>
	<transform from="ءى" to="ئ"/>
</transforms>
```

We limit ourselves to the sequences that strictly combine a character
and a hamza, and generate that character with a hamza on it, following
the behavior in sequences of other dead keys. Additional sequences,
potentially for other layouts as well, could be added later on as
necessary.

Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/218>
2024-05-24 18:18:43 +04:00
José Expósito
97fb5bda3d Fix buffer overrun in parse_omit_name
When `num_fields == 12`, if the last character of the pattern is '-',
the `buf` array is overrun.

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

    Error: OVERRUN (CWE-119):
    libX11-1.8.7/modules/om/generic/omGeneric.c:691: cond_at_most:
      Checking "length > 255" implies that "length" may be up to 255 on
      the false branch.
    libX11-1.8.7/modules/om/generic/omGeneric.c:695: alias:
      Assigning: "last" = "buf + length - 1". "last" may now point to as
      high as byte 254 of "buf" (which consists of 256 bytes).
    libX11-1.8.7/modules/om/generic/omGeneric.c:718: ptr_incr:
      Incrementing "last". "last" may now point to as high as byte 255
      of "buf" (which consists of 256 bytes).
    libX11-1.8.7/modules/om/generic/omGeneric.c:720: ptr_incr:
      Incrementing "last". "last" may now point to as high as byte 256
      of "buf" (which consists of 256 bytes).
    libX11-1.8.7/modules/om/generic/omGeneric.c:720: overrun-local:
      Overrunning array of 256 bytes at byte offset 256 by
      dereferencing pointer "++last".
    #  718|               *++last = '*';
    #  719|
    #  720|->         *++last = '-';
    #  721|           break;
    #  722|       case 13:

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
José Expósito
f67a87dad4 Fix memory leak in _XimProtoSetIMValues
This error has been found by a static analysis tool. This is the report:

    Error: RESOURCE_LEAK (CWE-772):
    libX11-1.8.7/modules/im/ximcp/imDefIm.c:1316: alloc_fn:
      Storage is returned from allocation function "calloc".
    libX11-1.8.7/modules/im/ximcp/imDefIm.c:1316: var_assign:
      Assigning: "tmp" = storage returned from
      "calloc((size_t)((buf_size + data_len == 0) ? 1 : (buf_size + data_len)), 1UL)".
    libX11-1.8.7/modules/im/ximcp/imDefIm.c:1319: noescape:
      Resource "tmp" is not freed or pointed-to in "memcpy".
    libX11-1.8.7/modules/im/ximcp/imDefIm.c:1320: var_assign:
      Assigning: "buf" = "tmp".
    libX11-1.8.7/modules/im/ximcp/imDefIm.c:1302: var_assign:
      Assigning: "data" = "buf".
    libX11-1.8.7/modules/im/ximcp/imDefIm.c:1303: noescape:
      Resource "data" is not freed or pointed-to in
      "_XimEncodeIMATTRIBUTE".
    libX11-1.8.7/modules/im/ximcp/imDefIm.c:1333: leaked_storage:
      Variable "data" going out of scope leaks the storage it points to.
    libX11-1.8.7/modules/im/ximcp/imDefIm.c:1333: leaked_storage:
      Variable "buf" going out of scope leaks the storage it points to.
    libX11-1.8.7/modules/im/ximcp/imDefIm.c:1333: leaked_storage:
      Variable "tmp" going out of scope leaks the storage it points to.
    # 1331|
    # 1332|       if (!total)
    # 1333|->         return (char *)NULL;
    # 1334|
    # 1335|       buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];

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
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
José Expósito
836a8f2cf5 Fix use of uninitialized variable in _XimEncodeICATTRIBUTE
In the `res->resource_size == XimType_NEST` code path, if
`res->xrm_name != pre_quark` and `res->xrm_name != sts_quark`, `len` can
be used uninitialized.

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

    Error: UNINIT (CWE-457):
    libX11-1.8.7/modules/im/ximcp/imRmAttr.c:1106: var_decl:
      Declaring variable "len" without initializer.
    libX11-1.8.7/modules/im/ximcp/imRmAttr.c:1179: uninit_use:
      Using uninitialized value "len".
    # 1177|           }
    # 1178|
    # 1179|->         if (len == 0) {
    # 1180|               continue;
    # 1181|           } else if (len < 0) {

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
José Expósito
eaad761e24 Fix use of uninitialized variable in _XimExtension
`_XimRead()` is being called with `reply` as target buffer instead of
using `preply`, accessing uninitialized memory a few lines later.

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

    Error: UNINIT (CWE-457):
    libX11-1.8.7/modules/im/ximcp/imExten.c:468: alloc_fn:
      Calling "malloc" which returns uninitialized memory.
    libX11-1.8.7/modules/im/ximcp/imExten.c:468: assign:
      Assigning: "preply" = "malloc((size_t)((buf_size == 0) ? 1 : buf_size))",
      which points to uninitialized data.
    libX11-1.8.7/modules/im/ximcp/imExten.c:479: uninit_use:
      Using uninitialized value "*((CARD8 *)preply)".
    #  477|           return False;
    #  478|       buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
    #  479|->     if (*((CARD8 *)preply) == XIM_ERROR) {
    #  480|           _XimProcError(im, 0, (XPointer)&buf_s[3]);
    #  481|               if(reply != preply)

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
José Expósito
4f5541193d Fix use of uninitialized variable in _XimTriggerNotify
`_XimRead()` is being called with `reply` as target buffer instead of
using `preply`, accessing uninitialized memory a few lines later.

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

    Error: UNINIT (CWE-457):
    libX11-1.8.7/modules/im/ximcp/imDefLkup.c:561: alloc_fn:
      Calling "malloc" which returns uninitialized memory.
    libX11-1.8.7/modules/im/ximcp/imDefLkup.c:561: assign:
      Assigning: "preply" = "malloc((size_t)((len == 0) ? 1 : len))",
      which points to uninitialized data.
    libX11-1.8.7/modules/im/ximcp/imDefLkup.c:573: uninit_use:
      Using uninitialized value "*((CARD8 *)preply)".
    #  571|       }
    #  572|       buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
    #  573|->     if (*((CARD8 *)preply) == XIM_ERROR) {
    #  574|           _XimProcError(im, 0, (XPointer)&buf_s[3]);
    #  575|           if(reply != preply)

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
90b8fc65da imDefIm: Add LIBX11_ENABLE_FABRICATED_ORDER env
If an XIM application does not return the XKeyEvent from XNextEvent()
to XFilterEvent(), a timeout is reached and the behavior is fallen
back to the previous one with a warning messsage and we can ask
the application to send the XKeyEvent to XFilterEvent() but also
libX11 provides LIBX11_ENABLE_FABRICATED_ORDER environment variable.
If the application runs with LIBX11_ENABLE_FABRICATED_ORDER=0, the
previous behavior is available until the application is fixed.

Closes: !246
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/246>
2024-04-26 01:29:39 +09: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
1181abd6ff imDefLkup: Mark and unmark fabricated with serial 0
GTK2 applications with GTK_IM_MODULE=xim sets the serial number 0
to the XKeyEvent and the previous _XimFabricateSerial() logic did
not work for the applications.
Now the API marks to fabricate with the serial 0.

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-12 10:50:33 +09:00
Takao Fujiwara
c779007265 imDefLkup: Commit first info in XimCommitInfo
Xic.private.proto.commit_info can receive multiple XimCommitInfo
when typing keys very quickly like an bar code scanner (or evemu-play)
and the first info in XimCommitInfo should be committed to keep
the typing key order.

This and 041b5291 are same patches but the regression issues will be
fixed by the later patches.

Closes: #198
Fixes: 041b5291 ("imDefLkup: Commit first info in XimCommitInfo")
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/246>
2024-04-12 10:21:43 +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
Alan Coopersmith
a465588218
libX11 1.8.9
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2024-04-05 15:50:06 -07:00