Commit Graph

2473 Commits

Author SHA1 Message Date
Daniel Stone
0d3e47abdc ci: Use appropriate concurrency level
The appropriate concurrency level is not necessarily the number of
available CPUs; limit it to what the runners tell us we should be using.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-08-04 18:20:27 +01:00
Daniel Stone
71ff5fe0af ci: Add release builds
Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-08-04 18:20:26 +01:00
Daniel Stone
705154a09d ci: Use consistent YAML indendation
Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-08-04 18:16:59 +01:00
Daniel Stone
e4deb4dc66 ci: Only run ci-fairy on MRs
This requires adding rules to all the jobs, as it's all or nothing.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-08-04 18:16:59 +01:00
Daniel Stone
c4865c774b ci: Add ARMv7 build
Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-08-04 18:16:59 +01:00
Daniel Stone
33767673bc ci: Add AArch64 build
Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-08-04 18:16:55 +01:00
Daniel Stone
b88e1d40b0 ci: Parameterise and template build
This will make it a lot easier to add other variants later.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-08-03 21:22:15 +01:00
Daniel Stone
7940bbb735 ci: Add comments, rename build stages
No non-cosmetic changes, just making things more accessible.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-08-03 21:10:51 +01:00
Simon Ser
2aa0a83d36 connection: print array size
This makes it easier to understand how an xdg_toplevel is configured for
instance.

Signed-off-by: Simon Ser <contact@emersion.fr>
2021-07-31 16:54:57 +00:00
Manuel Stoeckl
2f05ceeb4d connection, client: Avoid locale-dependent float printing
Specifically, in the log formed when WAYLAND_DEBUG is set, this commit
ensures that floating point numbers are formatted using '.' instead of
the locale-specific decimal separator. As the debug logs are not
otherwise localized for end-users, and may be parsed by scripts, it is
better to have consistent output here.

The 24.8 fixed point numbers are now represented with 8 digits after
the decimal, since this is both exact and simpler to compute.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2021-07-31 16:49:54 +00:00
Fergus Dall
91d98b622f os-wrappers-test: Make syscall intercepts work with sanitizers
Sanitizers need to intercept syscalls in the compiler run-time library, as
do these tests. We try to make this work by using dlsym(RTLD_NEXT) to find
the next definition in the chain, but here this approach won't work because
the compiler run-time library is linked into the same elf object as the test
interceptors are.

The sanitizer library supports this by giving the intercept functions a
prefix and making them only weakly alias the real names, so our interceptors
can call the sanitizers interceptors explicitly, which will then use dlsym
to call the real function.

By making our declarations of the sanitizer interceptor function weak we can
handle any combination of intercepts (including none, if there is no
sanitizer). If our declaration is resolves to a NULL pointer, we just use
dlsym.

Signed-off-by: Fergus Dall <sidereal@google.com>
2021-07-22 22:27:45 +00:00
Fergus Dall
e5c3ac9bcd connection-test: Pad out strings with null bytes
The connection_demarshal test writes a 10 byte string into a wayland message,
but doesn't pad it out to a four byte boundary. This leads to the last 32-bit
word of the message being partially uninitialized, which triggers an msan
violation when the message is written to the socket.

Signed-off-by: Fergus Dall <sidereal@google.com>
2021-07-22 22:27:45 +00:00
Fergus Dall
f6b78b76b2 server: Fix undefined behavior in wl_socket_init_for_display_name
This function constructs a socket path in sun_path using snprintf, which
returns the amount of space that would have been used if the buffer was
large enough. It then checks if this is larger then the actual buffer size
and, if so, returns ENAMETOOLONG. This is correct.

However, after calling snprintf and before checking that the length isn't too
long, it tries to compute a pointer to the part of the path that matches the
input name. It does this by adding the computed path length to the pointer to
the start of the path buffer, which will take it to one-past the null
terminator, and then walking backwards. If the path fits in the buffer, this
will take it at most one-past-the-end of the allocation, which is allowed, but
if the path is longer then the buffer then the pointer addition is undefined behavior.

Fix this by moving the display name computation past the check that the path
length is not too long.

This is detected by the test socket_path_overflow_server_create under ubsan.

Signed-off-by: Fergus Dall <sidereal@google.com>
2021-07-21 11:42:42 +00:00
Fergus Dall
80164ef300 util: Avoid undefined behaviour in for_each_helper
for_each_helper tries to calculate a one-past-the-end pointer for its
wl_array input. This is fine when the array has one or more entries, but we
initialize arrays by setting wl_array.data to NULL. Pointer arithmetic is
only defined when both the pointer operand and the result point to the same
allocation, or one-past-the-end of that allocation. As NULL points to no
allocation, no pointer arithmetic can be performed on it, not even adding 0,
even if the result is never dereferenced.

This is caught by clang's ubsan from version 10.

Many tests already hit this case, but I added an explicit test for iterating
over an empty wl_map.

Signed-off-by: Fergus Dall <sidereal@google.com>
2021-07-21 11:42:42 +00:00
Manuel Stoeckl
ada25fbd52 client: print discarded events in debug log
Before this patch, setting WAYLAND_DEBUG=1 or WAYLAND_DEBUG=client made
a program log all requests sent and events that it processes. However,
some events received are not processed. This can happen when a Wayland
server sends an event to an object that does not exist, or was recently
destroyed by the client program (either before the event was decoded,
or after being decoded but before being dispatched.)

This commit prints all discarded messages in the debug log, producing
lines like:

[1234567.890] discarded [unknown]@42.[event 0](0 fd, 12 byte)
[1234567.890] discarded wl_callback@3.done(34567)
[1234567.890] discarded [zombie]@13.[event 1](3 fd, 8 byte)

The first indicates an event to an object that does not exist; the
second, an event to an object that was deleted after decoding, but
before dispatch; the third, an event to an object that left a
'zombie' marker behind to indicate which events have associated
file descriptors.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2021-07-20 09:20:38 +00:00
Pekka Paalanen
13ccd1c4db wayland-util: avoid memcpy(NULL) in wl_array_copy()
The problem was found running Weston, with both Weston and Wayland built
with ASan:

../../git/wayland/src/wayland-util.c:150:2: runtime error: null pointer passed as argument 1, which is declared to never be null
../../git/wayland/src/wayland-util.c:150:2: runtime error: null pointer passed as argument 2, which is declared to never be null

This turns out to be caused by copying an empty array into an empty
array.

That seems to be completely valid thing to do, and wl_array_init()
initializes the pointers to NULL and size to zero. Copying initialized
arrays must always be valid.

The error are caused by calling memcpy() with NULL pointers. It doesn't
explode, because also the size is zero.

Fix the problem by calling memcpy() only if size is not zero. This
should keep things like copying an empty array into a non-empty array
work.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-07-14 07:21:40 +00:00
Simon Ser
8899310fc8 shm: document wl_shm_buffer
The main motivation is to make it clear when a wl_shm_buffer is
destroyed.

Signed-off-by: Simon Ser <contact@emersion.fr>
2021-07-13 15:52:31 +02:00
James Legg
b7153f2273 tests: Test wayland-scanner with a description in an entry
This previously would have caused a memory leak and incorrect
comments.

Signed-off-by: James Legg <lankyleggy@gmail.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-07-07 12:11:42 +00:00
James Legg
51d336ec14 scanner: Use descriptions in entries
entry may have a description according to the DTD. This is used in
some protocols including xdg-shell.

Fixes the code comment on an enum declaration using the description of
the last enum that had one, adds the descriptions to the comments on
enumerators, and avoids leaking the previously missing descriptions.

Fixes #208

Signed-off-by: James Legg <lankyleggy@gmail.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-07-07 12:11:42 +00:00
Simon Ser
767765d584 protocol: clarify wl_seat.name description
Define the expected properties of the seat name.

Signed-off-by: Simon Ser <contact@emersion.fr>
2021-07-06 11:57:39 +00:00
Pekka Paalanen
92038fa394 CI: turn on ASan and UBSan
I just noticed that libwayland test suite is ASan and UBSan clean, so
let's turn that on in CI to avoid regressing.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-07-01 16:28:08 +03:00
Simon Ser
817fdb9009 shm: add safety assertions
Catch any API mis-use with an assert. This should abort when the
user calls unreferences the pool more times than it's referenced.

Also change the refcount check to explicitly check for positive
counts. That makes the condition more readable.

Signed-off-by: Simon Ser <contact@emersion.fr>
2021-06-29 11:17:44 +02:00
Fergus Dall
ccc9612e82 connection: Handle non-nullable strings in wl_connection_demarshal
Currently a null string passed into a non-nullable argument of a message
will decode succesfully, probably resulting in the handler function
crashing. Instead treat it the same way we do non-nullable objects and ids.

Signed-off-by: Fergus Dall <sidereal@google.com>
2021-06-22 20:15:39 +10:00
Fergus Dall
4f53613e70 connection-test: Encode size in message headers correctly
In these tests, message sizes are inconsistently encoded in either the upper
or lower 16 bits of the second word of the message. Resolve this in favour
of using the upper 16 bits, as this is how messages are supposed to be
encoded, even though that aspect of message decoding isn't being tested
here.

Signed-off-by: Fergus Dall <sidereal@google.com>
2021-06-22 20:15:32 +10:00
Simon Ser
3e897faa29 protocol: allow immediate wl_buffer.destroy if not re-used
Allow wl_buffer objects to be destroyed without having to wait for
wl_buffer.release if the underlying storage isn't going to be
re-used.

The main motivation for this is to avoid glitches when a client is
torn down. When a client disconnects, all of its objects are destroyed
in arbitrary order. However some compositors will still need to
access the destroyed buffer's underlying storage afterwards, e.g. for
visual effects (fade-out) or for atomic layout updates (wait for other
clients to commit a new buffer before hiding the buffer).

It's still incorrect for clients to destroy a wl_buffer and mutate
the underlying storage without waiting for wl_buffer.release.

Signed-off-by: Simon Ser <contact@emersion.fr>
Closes: https://gitlab.freedesktop.org/wayland/wayland/-/issues/185
2021-06-11 14:05:27 +00:00
Simon Ser
ba0c63dee8 shm: remove wl_shm_buffer.pool NULL checks
wl_shm_buffer.pool is never set to NULL. The only time it's set is
in shm_pool_create_buffer, and the pool is guaranteed to be non-NULL
there.

Signed-off-by: Simon Ser <contact@emersion.fr>
2021-06-10 14:33:32 +00:00
Tobias Stoeckmann
abcf1048e2 cursor: fix crash with weird input files
If a cursor file contains multiple images for the same size, this
typically indicates an animation. The compositor weston uses
wl_cursor_frame_and_duration to figure out at which time a specific image
should be shown.

The total delay is the sum of all image delays. But if all images have a
delay of 0, the total delay is 0 as well. The code does not check for this
special condition and triggers a floating point exception by eventually
performing a modulo operation with 0.

This, of course, could also happen if the sum of all image delays
triggers an unsigned int overflow. But since a comment in the code
already indicates that it does not try to "fix" handling of weird files,
I would argue that it's "okay" if that happens. At least the program
won't crash.

Proof of Concept:

install -D ~/.icons/poc/cursors
base64 -d > ~/.icons/poc/cursors/left_ptr << EOF
WGN1chAAAAAAAAEAAgAAAAIA/f8BAAAAKAAAAAIA/f8BAAAAKAAAACQAAAACAP3/AQAAAAEAAAAB
AAAAAQAAAAEAAAABAAAAAAAAAAAAAAA=
EOF
cat > /tmp/weston.ini << EOF
[shell]
cursor-theme=poc
EOF
weston -c /tmp/weston.ini

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2021-06-02 13:46:33 +00:00
Simon Ser
f8bea2450d protocol: drop reference to wl_drm
Change the wl_drm reference to linux-dmabuf. wl_drm is a legacy,
private Mesa protocol that shouldn't be used by regular clients.

Signed-off-by: Simon Ser <contact@emersion.fr>
2021-05-27 10:48:40 +02:00
Simon Ser
f452e41264 build: replace assembly embedding with Python script
This allows Meson to properly track dependencies and re-build the scanner when
editing the dtd. We also stop depending on GNU as' .incbin and make the
embedding less obscure.

Signed-off-by: Simon Ser <contact@emersion.fr>
2021-05-10 22:08:45 +00:00
Marius Vlad
e475decf1d src: Add missing new lines to log messages
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-05-07 11:07:54 +03:00
Nick Diego Yamane
208fc99e66 Document serial param usage in wl_pointer.set_cursor
Serial is supposed to contain the latest wl_pointer.enter value received
by clients but it was not even mentioned in the docs, so add it to avoid
misinterpretations.

Signed-off-by: Nick Diego Yamane <nickdiego@igalia.com>
2021-05-04 15:26:48 +00:00
Tobias Stoeckmann
ed55438366 cursor: fix CVE-2013-2003
The libXcursor fix for CVE-2013-2003 has never been imported into
wayland, leaving it vulnerable to it.

Changing the argument type to an unsigned type is an effective merge of
Ilja Van Sprundel's commit in libXcursor.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2021-05-02 21:35:23 +02:00
Alexander Dunaev
0aebb5b94d cursor: add one more directory to XCURSORPATH
The user may install cursor themes manually, and the desktop environment
may provide a special directory for storing them.  For instance, GTK puts
those themes into ~/.local/share/icons, and many Linux distributions suggest
using that directory for user-specific themes.  However, users of
libwayland-cursor cannot load these themes using the API provided by the
library because the latter does not look into that directory.

This patch adds ~/.local/share/icons to the search path, so user-specific
themes can be loaded through the API provided by libwayland-cursor.

Signed-off-by: Alexander Dunaev <adunaev@igalia.com>
Reviewed-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Reviewed-by: Simon Ser <contact@emersion.fr>
2021-04-27 11:16:17 +00:00
James Hilliard
88f1605a82 build: add option to disable tests
When building for a product, tests are not needed.

Besides, one test requires a C++ compiler, which is not always
available.

So, add an option to configure to disable building tests altogether.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2021-04-16 03:45:06 -06:00
James Hilliard
4c21053123 meson: only require cpp for tests
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2021-04-16 03:04:56 -06:00
Alex Richardson
34306efeb2 Change wl_os_dupfd_cloexec minfd to be int
The fcntl() argument is defined to be an int and not a long. This does not
matter on most architectures since the value is passed in registers, but
it causes issues on big-endian architectures that pass variadic arguments
on the stack.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Reviewed-by: Simon Ser <contact@emersion.fr>
2021-04-15 07:34:53 +00:00
Alex Richardson
e881934927 os-wrappers-test.c: Correctly forward arguments to fcntl
We can't just unconditionally read the optional arguments (and also read
it as a void* despite actually being an int).
While this happens to work on most architectures because the first few
variadic arguments are passed in registers, this is non-portable and
causes a crash on architectures that set bounds on variadic function
arguments (for example CHERI-enabled architectures). It could also cause
problems on big-endian architectures that pass variadic arguments on the
stack rather than in registers.

For CHERI-MIPS, reading sizeof(void*) causes a read of 16 bytes from the
bounded varargs capability. This always crashes since even calls with the
optional argument only have 4 bytes available.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Reviewed-by: Simon Ser <contact@emersion.fr>
2021-04-15 07:34:53 +00:00
Michael Weiss
e4659ffbf5
meson: Only require expat when building wayland-scanner
This code is only required for building wayland-scanner so it should be
scoped accordingly. libxml-2.0 will only be required if both "scanner"
and "dtd_validation" are set to true.

Signed-off-by: Michael Weiss <dev.primeos@gmail.com>
2021-04-02 20:55:15 +02:00
Jonas Ådahl
d224e6ccf3 ci: Use ci-fairy to check for Signed-off-by
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2021-03-26 17:24:47 +01:00
Alex Richardson
1349d3d15b Use MAP_FAILED instead of (void *) -1
While MAP_FAILED is generally defined to that value, we should not be
relying on implementation details of system headers.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Reviewed-by: Simon Ser <contact@emersion.fr>
2021-03-22 14:05:11 +00:00
Simon Ser
3bda3d1b47 build: drop autotools
Meson now replaces autotools.

Signed-off-by: Simon Ser <contact@emersion.fr>
2021-03-05 09:15:04 +00:00
Vlad Zahorodnii
2b22160fb6 server: add wl_display getter for wl_global
This can be useful if the compositor wants to call wl_global_destroy() with some
delay but it doesn't have the wl_display object associated with the global,
which is needed to get access to the event loop.

Signed-off-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
2021-03-05 09:12:33 +00:00
Simon Ser
727c7903b2 client: assert queue display matches proxy
In wl_proxy_set_queue, passing a wl_event_queue from a completely
unrelated wl_display could lead to object IDs mismatches.

Add an assertion to catch this case. It's always a user bug if this
happens.

Signed-off-by: Simon Ser <contact@emersion.fr>
2021-02-25 23:49:00 +01:00
sheepwall
70f1c83fd9 server: remove duplicate include
Signed-off-by: August Svensson <a.sve@live.se>
2021-02-22 19:09:08 +01:00
Tadeo Kondrak
ddf21afa6e protocol: Specify wl_callback::done to be a destructor event
It's the only destructor event in the core protocol, and destructor
events were previously unannotated.

Signed-off-by: Tadeo Kondrak <me@tadeo.ca>
2021-01-27 17:49:10 +00:00
Tadeo Kondrak
efab39642e protocol: Add type attribute to events
This allows specifying events to be destructors, which is useful for
non-C language bindings. It is unused in wayland-scanner.

Signed-off-by: Tadeo Kondrak <me@tadeo.ca>
2021-01-27 17:49:10 +00:00
Simon Ser
f1cc5d0c37 build: re-open master for regular development 2021-01-27 18:45:57 +01:00
Simon Ser
e60398b175 build: bump to version 1.19.0 for the official release 2021-01-27 17:48:01 +01:00
Simon Ser
0344e08ce0 build: bump to 1.18.93 for the RC1 release 2021-01-20 22:35:34 +01:00
Simon Ser
db8b64ca5e protocol: sync wl_shm.format with libdrm 2.4.104
This adds 4 new formats.

Signed-off-by: Simon Ser <contact@emersion.fr>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
Acked-by: Daniel Stone <daniels@collabora.com>
2021-01-19 17:16:54 +01:00