wayland/src
David Benjamin 50ea9c5b1c connection: avoid calling memcpy on NULL, 0
Due to what is arguably a mistake in the C language specification,
passing NULL to memcpy and friends is undefined behavior (UB) even when
the count is 0. C additionally mistakenly leaves NULL + 0 and NULL -
NULL undefined. (C++ fixes this mistake.) These are very problematic
because (NULL, 0) is a natural representation of the empty slice.

Some details:
https://github.com/llvm/llvm-project/issues/49459
https://www.imperialviolet.org/2016/06/26/nonnull.html

Unfortunately, despite how clearly this is a mistake, glibc headers and
GCC now try to exploit this specification mistake and will miscompile
code, so C projects need to workaround this. In particular, UBSan from
Clang will flag this as a bug (although Clang itself has the good sense
to never lean on this bug). We've run into a few UBSan errors in
Chromium stemming from Wayland's memcpy calls. Add runtime guards as
needed to avoid these cases.

Note: Chromium's copy of wayland has
https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/188
applied. It is possible the ring_buffer_copy UB cases are only reachable
with that MR applied, I'm not sure. But it seemed simplest to just add
the fix to wayland as-is. Then when/if that MR lands, it will pick this
up.

Signed-off-by: David Benjamin <davidben@google.com>
2023-11-08 08:41:16 -05:00
..
.gitignore ignore: Add *.dtd.embed 2016-03-10 22:24:20 -08:00
connection.c connection: avoid calling memcpy on NULL, 0 2023-11-08 08:41:16 -05:00
embed.py build: replace assembly embedding with Python script 2021-05-10 22:08:45 +00:00
event-loop.c event-loop: optimize timer check logic 2023-05-03 19:21:17 +00:00
meson.build build: override wayland-scanner dep 2023-05-09 09:56:18 +00:00
scanner.c scanner: Fix undefined behavior around qsort 2023-01-03 11:05:35 +00:00
wayland-client-core.h client: Add method to get display for a given proxy 2023-08-07 13:38:01 +00:00
wayland-client.c client: Add method to get display for a given proxy 2023-08-07 13:38:01 +00:00
wayland-client.h doc: Formalize file comment in wayland-client.h, wayland-server.h 2016-05-11 11:03:27 -07:00
wayland-os.c tests: manually wrap libc functions 2023-06-27 13:31:50 +02:00
wayland-os.h shm: Add mmap+memmove fallback if mremap() does not exist 2021-09-10 11:35:54 +00:00
wayland-private.h util: Limit size of wl_map 2022-05-16 14:39:21 +00:00
wayland-server-core.h wayland-server: Add method to get global name 2023-02-11 12:19:56 +00:00
wayland-server-private.h Move wl_priv_signal to wayland-server-private.h 2019-11-06 08:24:14 -06:00
wayland-server.c debug: Replace "@<id>" with "#<id>" in logs 2023-06-27 14:08:25 -07:00
wayland-server.h wayland-server: Finally remove deprecated struct wl_buffer definition 2018-07-25 12:08:16 -05:00
wayland-shm.c shm: fix segfault when accessing destroyed pool resource 2023-02-27 21:00:10 +00:00
wayland-util.c util: set errno when hitting WL_MAP_MAX_OBJECTS 2022-06-28 11:59:26 +02:00
wayland-util.h util: simplify wl_fixed_to_double() 2023-05-09 09:33:06 +00:00
wayland-version.h.in src: Update boilerplate from MIT X11 license to MIT Expat license 2015-06-12 15:31:24 -07:00