Commit graph

163 commits

Author SHA1 Message Date
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
Todd Carson
0e6561efcf Fix signed length values in _XimGetAttributeID()
The lengths are unsigned according to the specification. Passing
negative values can lead to data corruption.

Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
2020-07-24 21:27:56 +02:00
Alan Coopersmith
2b7598221d Fix spelling/wording issues
Found by using:
    codespell --builtin clear,rare,usage,informal,code,names

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-07-22 15:19:58 -07:00
Samuel Thibault
4385a84c4a Braille: Fix default lookup
cbb59d172 ('Braille: Fix typing quickly') broke the default lookup that
translates Braille keysym patterns to Braille Unicode patterns since it
rightfully clears brl_committing, but then we do not have it any more to
fill brl_committed.

This change saves the committed pattern so we can return it in the
default lookup.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2020-06-04 02:19:13 +02:00
Samuel Thibault
cbb59d1727 Braille: Fix typing quickly
On finishing releasing Braille keys, we should clear the just-commited
pattern, to reset the state to initial state, and avoid having to wait for
0.3s before typing the next pattern.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Tested-by: Jean-Philippe Mengual <jpmengual@hypra.fr>
2019-06-07 23:39:22 +02:00
Alan Coopersmith
003e30a66a Avoid use-after-free in _XimProtoSetIMValues()
Fixes gitlab issue #49

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2019-01-01 14:34:04 -08:00
Alan Coopersmith
336c1e7a50 Replace Xmalloc+strcpy pairs with strdup calls
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2018-12-08 10:06:42 -08:00
Matthieu Herrb
173704243f Remove statement with no effect.
Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
2018-08-21 16:53:40 +02:00
Michal Srb
a9dafdd57c Use flexible array member instead of fake size.
The _XimCacheStruct structure is followed in memory by two strings containing
fname and encoding. The memory was accessed using the last member of the
structure `char fname[1]`. That is a lie, prohibits us from using sizeof and
confuses checkers. Lets declare it properly as a flexible array, so compilers
don't complain about writing past that array. As bonus we can replace the
XOffsetOf with regular sizeof.

Fixes GCC8 error:
  In function 'strcpy',
      inlined from '_XimWriteCachedDefaultTree' at imLcIm.c:479:5,
      inlined from '_XimCreateDefaultTree' at imLcIm.c:616:2,
      inlined from '_XimLocalOpenIM' at imLcIm.c:700:5:
  /usr/include/bits/string_fortified.h:90:10: error: '__builtin_strcpy'
  forming offset 2 is out of the bounds [0, 1] [-Werror=array-bounds]
     return __builtin___strcpy_chk (__dest, __src, __bos (__dest));

Caused by this line seemingly writing past the fname[1] array:
  imLcIm.c:479:  strcpy (m->fname+strlen(name)+1, encoding);

Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-03-23 14:32:05 +10:00
walter harms
9abe838007 no need to check XFree arguments
You can save a bit of code. The is no need to check XFree arguments bring  free_fontdataOM in line with other free function and check for NULL arg

Signed-off-by: harms wharms@bfs.de
2017-08-20 21:41:41 +02:00
walter harms
d02c2466f6 fix more shadow warning
Signed-off-by: walter harms <wharms@bfs.de>
2017-08-14 18:12:35 +02:00
walter harms
916dffadf0 remove argument check for free() adjust one inden
Signed-off-by: walter harms <wharms@bfs.de>
2017-08-14 18:02:40 +02:00
Alan Coopersmith
4359dfabc0 Delete #if 0 hunks of code
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2015-12-18 23:50:26 -08:00
Alan Coopersmith
07a97b3944 Bug 93184: read_EncodingInfo invalid free
Free the correct bits of memory if we run out and need to unwind

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=93184
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2015-12-03 23:21:31 -08:00
Alan Coopersmith
dbcb847a08 Get rid of some extraneous ; at the end of C source lines
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Thomas Klausner <wiz@NetBSD.org>
2015-10-19 13:52:20 -04:00
Alan Coopersmith
26e0d2de29 Replace Xmalloc+memset pairs with Xcalloc calls
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2015-06-04 20:51:17 -07:00
Bhavi Dhingra
f0286b2770 omGeneric.c: Correct the parameter usage of sizeof
Incorrect parameter usage with sizeof. Earlier passed argument FontData
will be 4 bytes always as its a pointer hence the change is needed and
FontDataRec should be used for memset.

Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2015-06-04 19:08:31 -07:00
Peter Hutterer
19a30f17f3 Fix an indentation issue
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2015-05-18 07:56:22 +10:00
Peter Hutterer
013ccece12 Fix potential memory leak
If we hit the depth limit, filename leaks. Move the depth check up before we
allocate filename.
Introduced in 226622349a.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2015-05-18 07:55:17 +10:00
Ran Benita
ddf3b09bb2 compose: fix the description of modifiers in compose sequences
The Compose format has a feature which allows specifying certain
modifiers must (or must not) be present with a given keysym in the
sequence.

The grammar in imLcPrs.c and the Compose man page both do not match what
the code actually does (see the handling of the variables
`modifier_mask` and `modifier` in parseline() in imLcPrs.c, which are
eventually matched as `ev->state & modifier_mask == modifier`).

Also explicitly list the accepted modifier names, since they are
not standard (e.g. "Ctrl" instead of "Control").

Signed-off-by: Ran Benita <ran234@gmail.com>
Signed-off-by: James Cloos <cloos@jhcloos.com>
2015-02-05 17:36:01 -05:00
walter harms
aa8bda0db2 lcDefConv.c: fix use before check
* Do not use variables before checked for NULL.
* remove some superfluid spaces (Mark Kettenis)

Signed-off-by: Harms <wharms@bfs,de>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2014-07-06 10:12:20 -07:00
walter harms
d81fed4614 Remove more redundant null checks before Xfree()
Signed-off-by: Harms <wharms@bfs,de>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2014-06-06 17:24:39 -07:00
walter harms
b3c9f6a17e libX11/lcGenConv.c fix: dereferenced before check
* Do not use variables before checked for NULL.

Signed-off-by: Harms <wharms@bfs,de>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2014-06-06 17:05:55 -07:00
Jon TURNEY
3d69b0a83e Don't try so hard to find a matching font with the given encoding
See http://sourceware.org/bugzilla/show_bug.cgi?id=10948

Currently, if the locale is UTF-8, no CJK fonts are installed, and someone
does XCreateFontSet() with a font name of "*", we end up asking the server
to list the (non-existent) fonts 11 times for each CJK encoding, which can
take a while.

A * wildcard can match multiple components in a XLFD name in XListFonts(),
so there's no need to try adding more than one to get a match.

We do try once with a leading '*-' in case the fontname isn't a full
well-formed XLFD name, maybe even that isn't needed?

(See also http://invisible-island.net/xterm/xterm.faq.html#slow_menus)

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-12-13 22:27:08 -08:00
Alan Coopersmith
0e45f64766 Drop X_LOCALE fallback for OS'es without setlocale()
C89 or bust!   This was documented as being needed for "only Lynx,
Linux-libc5, OS/2" and has never been enabled in modular builds,
since none of those platforms have had anyone step up to add support
since the X11R7 conversion to autotools.

Mostly performed with unifdef -UX_LOCALE, followed by removal of files
left without any purpose, and manual cleanup of remaining references.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-11-22 22:02:17 -08:00
Alan Coopersmith
e9b14d10d0 Bug 68413 - [Bisected]Error in `xterm': realloc(): invalid next size
Pass *new* size to realloc, not old size.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-24 17:27:43 -07:00
Alan Coopersmith
bf3501e039 Remove unnecessary casts of pointers to (char *) in calls to Xfree()
Left one cast behind that is necessary to change from const char *
to char * in src/xlibi18n/lcCharSet.c.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:09 -07:00