Commit graph

1506 commits

Author SHA1 Message Date
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
Alex Richardson
1c845834a3 Fix cross-compilation from macOS
We can't use `LC_CTYPE=C sed` there since /usr/bin/sed is not compatible
with the expressions in nls/ (`sed: RE error: illegal byte sequence`).
To fix this use $(SED) instead which autotools will set to a GNU
version of sed (usually /usr/local/bin/gsed) on macOS.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-06-15 08:47:31 +01:00
Lev Korol
401f58f8ba nls: Add en_IL locale
Signed-off-by: Lev Korol <epicatsupercell@gmail.com>
2021-06-12 23:11:36 +00:00
Alan Coopersmith
f906fe8e97
libX11 1.7.2
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2021-06-05 09:36:54 -07:00
Tobias Stoeckmann
51b73ac0ac Protect against overly long strings
Checking against upper limit of USHRT_MAX must happen before truncating
size_t to int. On 64 bit systems with strings larger than 2 GB this
could otherwise lead to negative ints or ints smaller than USHRT_MAX.

In XParseColor this could lead to out of boundary access with strings
starting with a # (color sequence). A modulo 12 operation is performed
to validate the string length, but with an overflown length, the for
loop would eventually read behind terminating '\0' character.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2021-05-31 18:39:15 +02:00
Matthieu Herrb
ab2f59530b Check for NULL strings before getting their lengths
Problem reported by Karsten Trulsen

Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
2021-05-30 16:33:48 +02:00
Matthieu Herrb
a8216e8653 include <limits.h> always, not if HAVE_CONFIG_H is set.
via Matthew Green from the NetBSD project

Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
2021-05-22 17:36:37 +02:00
Matthieu Herrb
6953a586df Version 1.7.1
Release notes in README.md, version bump in configure.ac
2021-05-18 15:27:58 +02:00
Matthieu Herrb
8d2e02ae65 Reject string longer than USHRT_MAX before sending them on the wire
The X protocol uses CARD16 values to represent the length so
this would overflow.

CVE-2021-31535

Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
2021-05-18 13:57:49 +02:00
Gaurav Ujjwal
838ea5a5a0 Fix out-of-bound access in KeySymToUcs4()
Array `keysym_to_unicode_590_5fe` is only valid for range  [0x590, 0x5fe] but current lower-bound is checked against 0x589.

So invalid values from 0x58a to 0x58f are being allowed by current check.

If any of these invalid value is passed as `keysym`,    `keysym - 0x590` would underflow.

Signed-off-by: Gaurav Ujjwal <gujjwal00@gmail.com>
2021-05-09 11:30:09 +05:30
Christopher Chavez
32491b02c7 Xlib.h: spelling fix in comment 2021-05-03 19:08:03 +00:00
Benno Schulenberg
5faa8dc0b3 nls: adjust three comments about the APL compose sequences
Commit 0bbc0d5e60 (from eight years ago) removed the lines that two
of these comments referred to.  Without those lines, the comments don't
make sense any more.  Reword and shorten them.

Also reword a comment about two sequences that don't work.

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2021-01-12 00:32:09 +00:00
Benno Schulenberg
b126bfd7fe nls: allow composing all breved letters also with a lowercase "u"
The letters ă and ŭ can already be composed with "u a" and "u u", but
ĕ, ğ, ĭ, and ŏ can be composed only with an uppercase U.  Emancipate
the latter four and understand also a lowercase "u" to mean 'breve'.

(Yesterday I needed ğ and was annoyed that "u g" did not work.)

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2021-01-12 00:32:09 +00:00
Walter Harms
78027fdb7a fix same roff code
Signed-off-by: Walter Harms <wharms@bfs.de>
2020-11-28 21:05:33 +01:00
Walter Harms
4f15cfc645 Fix some roff code add see also
Signed-off-by: Walter Harms <wharms@bfs.de>
2020-11-28 20:56:35 +01:00
Walter Harms
daa106927f fix broken nroff coding for code comments
the comments /* */ are code as /\(**  */ that does not work.
the coding in other X11 man pages is /\&* */ so we do the same here.
2020-11-28 17:49:25 +01:00
Walter Harms
7bdeae239b FIX: warning: macro `hN' not defined
Signed-off-by: Walter Harms <wharms@bfs.de>
2020-11-27 22:43:21 +01:00
Walter Harms
b7ec67d3ea FIX: warning: macro `IN' not defined
just remove an other dead macro use.
2020-11-27 22:26:15 +01:00
Walter Harms
7ca3ceb917 fix warning: macro `s' not defined
this is caused by bad nroff coding, fix some more issues on the fly
2020-11-27 21:58:04 +01:00
Walter Harms
14fb4e5356 FIX: warning: macro `hN' not defined
this was found by checking man pages with
 groff -t -mandoc -Z  -wmac -Tutf8 $FILE >/dev/null

In most cases .hN could be replaced with .BR

Signed-off-by: Walter Harms <wharms@bfs.de>
2020-11-27 20:04:22 +01:00
Walter Harms
cb03da4447 FIX: warning: macro `Pn' not defined
The missing macro is found via:
roff -t -mandoc -Z  -wmac -Tutf8 XAnyEvent.man >/dev/null

To fix the problem the macro is replaced with .RB.

Signed-off-by: Walter Harms <wharms@bfs.de>
2020-11-27 19:00:00 +01:00
Benno Schulenberg
cc9f8878f2 nls: add 'C.utf8' as an alias for 'en_US.UTF-8'
The normal form is 'C.UTF-8', but 'C.utf8' has been seen in the wild.

Fixes #102.

Reported-by: Tomas Korbar

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2020-11-25 17:06:38 +01:00
Keith Packard
ca8115186f Version 1.7.0
Release notes in README.md, version bump in configure.ac

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-11-19 11:31:09 -08:00
Keith Packard
325ac177fb Update libX11 .so version to 6.4.0
There have been API additions since the previous release, so the
.so version needs to change.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-11-18 22:53:18 +00: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
Alan Coopersmith
7d70e30221 XimProto.h: wrap XIM_HEADER_SIZE definition in parens
Resolves parfait warning of potential macro misinterpretation if
expanded in the midst of other arithmetic operations with higher
precedence.

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
Peter Hutterer
960e2e0cfa gitlab CI: add a basic build test
Using Arch as base distribution here because we can expect our dependencies to
be up-to-date. We rely on the Arch for our dependencies rather than building
those from git (notably: xorg-macros, xtrans and libxcb).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-11-16 23:28:15 +00:00
Frediano Ziglio
dbb55e1a5e Fix poll_for_response race condition
In poll_for_response is it possible that event replies are skipped
and a more up to date message reply is returned.
This will cause next poll_for_event call to fail aborting the program.

This was proved using some slow ssh tunnel or using some program
to slow down server replies (I used a combination of xtrace and strace).

How the race happens:
- program enters into poll_for_response;
- poll_for_event is called but the server didn't still send the reply;
- pending_requests is not NULL because we send a request (see call
  to  append_pending_request in _XSend);
- xcb_poll_for_reply64 is called from poll_for_response;
- xcb_poll_for_reply64 will read from server, at this point
  server reply with an event (say sequence N) and the reply to our
  last request (say sequence N+1);
- xcb_poll_for_reply64 returns the reply for the request we asked;
- last_request_read is set to N+1 sequence in poll_for_response;
- poll_for_response returns the response to the request;
- poll_for_event is called (for instance from another poll_for_response);
- event with sequence N is retrieved;
- the N sequence is widen, however, as the "new" number computed from
  last_request_read is less than N the number is widened to N + 2^32
  (assuming last_request_read is still contained in 32 bit);
- poll_for_event enters the nested if statement as req is NULL;
- we compare the widen N (which now does not fit into 32 bit) with
  request (which fits into 32 bit) hitting the throw_thread_fail_assert.

To avoid the race condition and to avoid the sequence to go back
I check again for new events after getting the response and
return this last event if present saving the reply to return it
later.

To test the race and the fix it's helpful to add a delay (I used a
"usleep(5000)") before calling xcb_poll_for_reply64.

Original patch written by Frediano Ziglio, see
https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/34

Reworked primarily for readability by Peter Hutterer, see
https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/53

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-11-16 00:02:37 +00:00
Keith Packard
30ccef3a48 Avoid recursing through _XError due to sequence adjustment
This patch is based on research done by Dmitry Osipenko to uncover the
cause of a large class of Xlib lockups.

_XError must unlock and re-lock the display around the call to the
user error handler function. When re-locking the display, two
functions are called to ensure that the display is ready to generate a request:

    _XIDHandler(dpy);
    _XSeqSyncFunction(dpy);

The first ensures that there is at least one XID available to use
(possibly calling _xcb_generate_id to do so). The second makes sure a
reply is received at least every 65535 requests to keep sequence
numbers in sync (possibly generating a GetInputFocus request and
synchronously awaiting the reply).

If the second of these does generate a GetInputFocus request and wait
for the reply, then a pending error will cause recursion into _XError,
which deadlocks the display.

One seemingly easy fix is to have _XError avoid those calls by
invoking InternalLockDisplay instead of LockDisplay. That function
does everything that LockDisplay does *except* call those final two
functions which may end up receiving an error.

However, that doesn't protect the system from applications which call
some legal Xlib function from within their error handler. Any Xlib
function which cannot generate protocol or wait for events is valid,
including many which invoke LockDisplay.

What we need to do is make LockDisplay skip these two function calls
precisely when it is called from within the _XError context for the
same display.

This patch accomplishes this by creating a list of threads in the
display which are in _XError, and then having LockDisplay check the
current thread against those list elements.

Inspired-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
Tested-by: Dmitry Osipenko <digetx@gmail.com>
Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
2020-11-15 10:09:16 -08:00
Benno Schulenberg
c9c4d6efbf nls: improve the comments for the Serbian compose sequences
Also put an extra space before the lone combining characters
so they have some room to breathe.

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2020-11-13 17:01:02 +00:00
Benno Schulenberg
3497dae3d9 nls: remove mistaken Serbian compose sequences with combining diacritics
Combining characters are not dead keys -- they have an immediate effect
and combine with the preceding character.  So they cannot be used in
compose sequences.

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2020-11-13 17:01:02 +00:00
Benno Schulenberg
5cd60398b7 nls: rename the obsolete sr_CS locale to sr_RS
Fixes #107, for the most part.

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2020-11-13 17:01:02 +00:00
Keith Packard
7cf1729590 Don't attempt to unload locale context data
Most locale context users call _XlcCurrentLC, which returns a pointer
which never needs to be passed to _XCloseLC, meaning it has unbounded
lifetime, so that locale data can never be freed.

Remove all reference counting and just leave all locales that were
ever used in memory.

Signed-off-by: Keith Packard <keithp@keithp.com>
Acked-by: Martin Peres <martin.peres@mupuf.org>
2020-11-09 08:47:35 -08:00
Jacek Caban
87a8fd8051 Don't cache last lcd in _XlcCurrentLC.
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=55678
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=68538
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=69088

The way it's currently cached is not thread safe. As long as locale doesn't change, the same object is reused anyway.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
Acked-by: Martin Peres <martin.peres@mupuf.org>
2020-11-09 08:47:35 -08:00
Keith Packard
7a38c09b82 Don't cache converters in _Xlcmbtowc and Xlcwctomb
These functions were caching encoding conversion functions in static
variables which is not thread safe. Let the conversion loader do its
job and cache locale to converters there. It's less efficient, but
it's also (now) thread safe.

Signed-off-by: Keith Packard <keithp@keithp.com>
Acked-by: Martin Peres <martin.peres@mupuf.org>
2020-11-09 08:47:35 -08:00
Jacek Caban
b52ba5c209 Make conv_list thread safe.
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=55678
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=68538
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=69088
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
Acked-by: Martin Peres <martin.peres@mupuf.org>
2020-11-09 08:47:35 -08:00
Antti Savolainen
8b5ce3a9b1 Added DOWNWARD ARROW support 2020-11-08 01:32:21 +00:00
Antti Savolainen
7138826dcc Added support for UPWARDS ARROW and ALMOST EQUAL TO
Signed-off-by: Antti Savolainen <antti.savo@gmail.com>
2020-11-08 01:32:21 +00:00
Jonathan Belsewir
56d59299f7 Add less and greater to characters that are difficult to access on some keyboards 2020-11-05 22:57:50 +00:00
Benno Schulenberg
5caf45f8d3 nls: Allow all letters with a caron to be composed also with v.
It was strange that the accented letters Ž and ž can be composed with
sequences that start with "v" ("v Z" and "v z"), but not Č and č and
Š and š (and other letters with a caron).  For these letters, compose
sequences that start with a "c" had to be used, which was frustrating
because it is hard to remember that "c" stands for "caron", AND the
graphically more obvious "v" is right next to it.

(Unfortunately, the sequence "v l" is already taken for vertical line.
Maybe the compose sequences for vertical line could be reduced to just
"V L" and "L V"?)

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2020-11-05 22:55:07 +00:00
Benno Schulenberg
62de4ac902 nls: vertically align the target column of aliases
Also improve the grammar of the initial comment.

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2020-11-01 20:32:08 +01:00
Benno Schulenberg
f5b26a16ef nls: remove some twenty aliases that have been obsolete for fifteen years
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2020-11-01 20:18:30 +01:00
Benno Schulenberg
3e61f3b496 nls: remove country-specific aliases for two constructed languages
These artificial languages are meant to be international and are
thus not specific to any country.  If one would want to support
aliases like ia_FR or ia_CH, then one would also have to support
ia_AU, ia_DE, ia_ES, et cetera, et cetera.  That would be silly.

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2020-11-01 19:56:22 +01:00
Benno Schulenberg
3f9c43adde nls: remove four aliases where the name is identical to the definition
They were found with:

    while read one two; do
        if [[ $one == $two: ]]; then echo $two; fi;
    done  <nls/locale.alias.pre

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2020-11-01 19:55:57 +01:00
Carlos Garnacho
9f9c536581 Add XSetIOErrorExitHandler() function
This function complements XSetIOErrorHandler(), allowing to override
the default behavior that trusts on I/O errors never coming back
(i.e. exit()ing the process).

This is meant as a mechanism for Wayland compositors (that are too
a X11 client + compositing manager) to unfasten seatbelts and jump
through the car window. It might get lucky and land on a stack of
pillows.

In consequence, some functions labeled as _X_NORETURN can as a
matter of fact return. So those hints were removed.

Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2020-10-15 11:14:53 +02:00
Carlos Garnacho
4cb758019e Prepare for _XIOError() possibly returning
Ensure current state is cut short on _XIOError(), possible reentrancy
should be skipped through the XlibDisplayIOError flag checks.

Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2020-10-15 11:14:41 +02:00
Ross Burton
a37986f7a7 cpprules.in: squash whitespace in generated files
CPP is used to generate files, but as cpp reads files from the build host the
output has a number of blank lines at the beginning which varies depending on
what GCC and friends is used.

Pathalogical example:

 $ cpp -undef -traditional /dev/null
 # 1 "/dev/null"
 # 1 "<built-in>"
 # 1 "<command-line>"
 # 31 "<command-line>"
 # 1 "/usr/include/stdc-predef.h" 1 3 4

 # 17 "/usr/include/stdc-predef.h" 3 4

 [ 40 blank line ]

 # 32 "<command-line>" 2
 # 1 "/dev/null"

So depending on the content of stdc-predef.h and what other headers CPP will
load, the amount of whitespace in the generates files varies. This can result in
differences in reproducible environments, and file conflicts in multilib
environments.

As whitespace is irrelevant to these machine-readable files, extend the sed to
just delete blank lines.
2020-10-10 21:35:04 +00:00
Carmina16
16192ce2a7 Adding ia and ie locales 2020-10-10 14:32:51 -07:00
Alan Coopersmith
caa71668af Use __builtin_popcountl if available to replace Ones() in GetImage.c
If the compiler knows of a better algorithm for counting the number of
bits set in a word for the target CPU, let it use that, instead of the
classic algorithm optimized for PDP-6.

Based on libXext commit 490a25e6f8a4d2482af4364c700b68ad11a4d10b

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-09-28 16:16:07 -07:00