Commit graph

189 commits

Author SHA1 Message Date
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
Aaron Muir Hamilton
ba15d51bfe ximcp/imRm.c: allow XNArea with OnTheSpot
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/270>
2025-01-10 10:45:00 -05: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
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
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
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
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
Peter Hutterer
52a191ee09 Revert "ximcp: Unmark to fabricate key events with XKeyEvent serial"
This commit causes a regression, see #205, #206, #207, #208.

This reverts commit 024d229fdf.
2024-04-05 13:18:48 +10:00
Peter Hutterer
3ea9f4f769 Revert "imDefLkup: Commit first info in XimCommitInfo"
This commit causes a regression, see #205, #206, #207, #208.

This reverts commit 041b5291f0.
2024-04-05 13:17:07 +10:00
Alan Coopersmith
4400a68b3a unifdef Lynx
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2024-02-20 17:05:50 -08:00
Takao Fujiwara
041b5291f0
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.

Fixes: #198
2024-01-31 20:27:57 +09:00
Takao Fujiwara
024d229fdf
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.

Fixes: #198
2024-01-31 20:26:40 +09:00
Walter Harms
0a951047f6 _XimProtoIMFree:no need to check arg for Xfree()
Xfree() will happily ignore NULL, no need to check
2024-01-08 17:18:19 +01:00
Walter Harms
dce614623e _XimEncodeString:no need to check arg for Xfree()
Xfree() will happily ignore NULL, no need to check
2024-01-08 17:01:44 +01:00
Walter Harms
4f78b61580 Fix XCreateIC() memory leak (Part 2)
Direct leak of 12 byte(s) in 2 object(s) allocated from:
    #0 0x7f4f25c3f7a7 in strdup (/usr/lib64/libasan.so.6+0x5c7a7)
    #1 0x7f4f252ce6a1 in _XimEncodeString libX11-1.8.3/modules/im/ximcp/imRm.c:818
    #2 0x7f4f252ce6a1 in _XimEncodeString libX11-1.8.3/modules/im/ximcp/imRm.c:807
    #3 0x7f4f252d2f0f in _XimSetICValueData libX11-1.8.3/modules/im/ximcp/imRm.c:2912
    #4 0x7f4f252b536a in _XimLocalCreateIC libX11-1.8.3/modules/im/ximcp/imLcIc.c:176
    #5

 0x7f4f251f0105 in XCreateIC libX11-1.8.3/src/xlibi18n/ICWrap.c:251

detected and fix by Patrick Lerda <patrick9876@free.fr>
applied with adjustment, do changes when OOM (unlikely but good practise)
2024-01-08 16:50:52 +01:00
Walter Harms
ed0b97e480 _XimLocalDestroyIC:fix possible mem leak
Adapted:
Fix XCreateIC() memory leak by Patrick Lerda <patrick9876@free.fr> Part 1
2024-01-08 16:21:02 +01:00
Walter Harms
07978634b8 _XimLocalCreateIC: get rid of bzero 2024-01-08 15:16:11 +01:00
Walter Harms
59c9a89e25 _XimLocalCreateIC: minor cleanup
minor cleanup, no code change
2024-01-08 15:09:49 +01:00
Walter Harms
e5b14e59a1 _XimLocalCreateIC:no need to check arg for Xfree()
Xfree() will happily ignore NULL, no need to check
2024-01-08 13:35:28 +01:00
Walter Harms
e6310b5212 _XimLocalDestroyIC: no need to check arg for Xfree()
Xfree() will happily ignore NULL, no need to check
2024-01-08 13:06:03 +01:00
Jeremy Huddleston Sequoia
496d9bfeed
ximcp: Address warning found by UBSan when growing an empty tree
imLcPrs.c:681:52: runtime error: applying zero offset to null pointer

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
2022-12-10 23:15:47 -08:00
Alan Coopersmith
a04b84f0f7 Copyright & license cleanup 2022-11-03 20:31:31 +00:00
Thomas E. Dickey
1d11822601
fix a memory leak in XRegisterIMInstantiateCallback
Analysis:

    _XimRegisterIMInstantiateCallback() opens an XIM and closes it using
    the internal function pointers, but the internal close function does
    not free the pointer to the XIM (this would be done in XCloseIM()).

Report/patch:

    Date: Mon, 03 Oct 2022 18:47:32 +0800
    From: Po Lu <luangruo@yahoo.com>
    To: xorg-devel@lists.x.org
    Subject: Re: Yet another leak in Xlib

    For reference, here's how I'm calling XRegisterIMInstantiateCallback:

    XSetLocaleModifiers ("");
    XRegisterIMInstantiateCallback (compositor.display,
                                    XrmGetDatabase (compositor.display),
                                    (char *) compositor.resource_name,
                                    (char *) compositor.app_name,
                                    IMInstantiateCallback, NULL);

    and XMODIFIERS is:

        @im=ibus

Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2022-10-04 19:03:48 -04:00
Kirill Chibisov
62c3337d89 ximcp/imRm.c: allow XNSpotLocation with OnTheSpot 2022-09-08 22:50:30 +00:00
Benno Schulenberg
623b77d4f3 imDefLkup: verify that a pointer isn't NULL before using it
It is possible for _XimICOfXICID() to return NULL, so it is necessary
to check this isn't actually the case before dereferencing the pointer.
All other callers of _XimICOfXICID() do this check too.

(The check itself is ugly, but it follows the style of the code in the
rest of the module.)

Fixes issue #45.

Reported-by: Bhavi Dhingra

Original-patch-by: Bhavi Dhingra

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2022-02-14 11:47:46 +01:00
Benno Schulenberg
402b843fa7 remove a commented-out code fragment, and remove a stray blank line
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2022-01-26 17:21:31 +01:00
Matthieu Herrb
8382253010 Avoid NULL pointer deref. Fixes issue #47.
Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
2021-12-03 02:56:43 +00:00
Alex Richardson
d01d233741 Avoid undefined behaviour after realloc()
Adding the offset between the realloc result and the old allocation to
update pointers into the new allocation is undefined behaviour: the
old pointers are no longer valid after realloc() according to the C
standard. While this works on almost all architectures and compilers,
it causes  problems on architectures that track pointer bounds (e.g.
CHERI or Arm's Morello): the value_list pointers will still have the
bounds of the previous allocation and therefore any dereference will
result in a run-time trap.

I found this due to a crash (dereferencing an invalid capability) while
trying to run `xev` over SSH on a CHERI-RISC-V system. With these two
realloc changes, and https://gitlab.freedesktop.org/xorg/proto/xorgproto/-/merge_requests/41
I am able to succesfully run `xev` compiled for CHERI-RISC-V.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-06-16 13:38:01 +01:00
Alan Coopersmith
103e2e1151 Don't leave dangling pointers in Free functions
While these are mostly called during teardown of larger structures
that are about to themselves be freed, there's no guarantee that
will always be the case, so try to be safer here.

[ This bug was found by the Parfait 4.0 bug checking tool.
  http://labs.oracle.com/pls/apex/f?p=labs:49:::::P49_PROJECT_ID:13 ]

v2: Deduplicate & simplify pointer clearing in _XFreeEventCookies
    as suggested by @keithp

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-11-18 14:27:59 -08:00
Keith Packard
a3c0b5dbd6 Copy locale modifiers when creating XimInstCallback [v2]
Locale modifiers may be freed whenever XSetLocaleModifiers gets
called, even if the locale hasn't changed. This means that we cannot
save a pointer to those modifiers in the XimInstCallback record and
must, instead, make a copy of them instead.

This fixes a problem uncovered when running wish under libasan as
follows (on current Debian unstable):

	$ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6 wish

Reported-by: Vittorio Zecca <zeccav@gmail.com>
Signed-off-by: Keith Packard <keithp@keithp.com>

v2:
	Remove incorrect 'else' token found by @alanc
2020-11-17 14:42:25 -08:00
Alan Coopersmith
54925250ad i18n: use memcpy instead of strncpy on unterminated char arrays
Avoids gcc warnings that we're using strncpy wrong to copy a known-length
set of characters without a terminating '\0' to a buffer whose length we
are checking separately.  (Should also be imperceptibly faster since we
no longer check if each byte is '\0' when we already know it won't be.)

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-08-28 20:29:27 +00:00
Matthieu Herrb
acdaaadcb3 Fix an integer overflow in init_om()
CVE-2020-14363

This can lead to a double free later, as reported by Jayden Rivers.

Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
2020-08-19 12:46:57 +02:00
Niclas Zeising
d15c24c8b4 Fix input clients connecting to server
Fix a bug where some input clients can't connect to the input server.
This fixes #117.

FreeBSD bugzilla reference:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=248549

Signed-off-by: Niclas Zeising <zeising@daemonic.se>
2020-08-17 02:21:40 +00:00
Yichao Yu
93fce3f4e7
Fix size calculation in _XimAttributeToValue.
The check here guards the read below.
For `XimType_XIMStyles`, these are `num` of `CARD32` and for `XimType_XIMHotKeyTriggers`
these are `num` of `XIMTRIGGERKEY` ref[1] which is defined as 3 x `CARD32`.
(There are data after the `XIMTRIGGERKEY` according to the spec but they are not read by this
function and doesn't need to be checked.)

The old code here used the native datatype size instead of the wire protocol size causing
the check to always fail.

Also fix the size calculation for the header (size). It is 2 x CARD16 for both types
despite the unused `CARD16` for `XimType_XIMStyles`.

[1] https://www.x.org/releases/X11R7.6/doc/libX11/specs/XIM/xim.html#Input_Method_Styles

This fixes a regression caused by 388b303c62 in 1.6.10.

Fix #116
2020-08-02 13:43:58 -04:00
Matthieu Herrb
1703b9f343 Change the data_len parameter of _XimAttributeToValue() to CARD16
It's coming from a length in the protocol (unsigned) and passed
to functions that expect unsigned int parameters (_XCopyToArg()
and memcpy()).

Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
Reviewed-by: Todd Carson <toc@daybefore.net>
2020-07-24 21:28:38 +02:00
Todd Carson
1a566c9e00 Zero out buffers in functions
It looks like uninitialized stack or heap memory can leak
out via padding bytes.

Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
2020-07-24 21:28:31 +02:00
Todd Carson
2fcfcc49f3 Fix more unchecked lengths
Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
2020-07-24 21:28:25 +02:00
Todd Carson
388b303c62 fix integer overflows in _XimAttributeToValue()
Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
2020-07-24 21:28:21 +02:00