Files
xserver/dix
Alex Richardson f9f705bf3c dix/privates.c: 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 DevPrivateKey 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 `XVnc` on a CHERI-RISC-V system. With this commit I can
successfully connect to the XVnc instance running inside a QEMU with a
VNC viewer on my host.

This also changes the check whether the allocation was moved to use
uintptr_t instead of a pointer since according to the C standard:
"The value of a pointer becomes indeterminate when the object it
points to (or just past) reaches the end of its lifetime." Casting to an
integer type avoids this undefined behaviour.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-10-08 09:59:11 +00:00
..
2020-07-05 13:07:33 -07:00
2015-07-08 16:41:29 -04:00
2020-07-05 13:07:33 -07:00
2021-05-30 13:26:42 +03:00
2021-06-07 17:28:05 +02:00
2014-11-12 10:25:00 +10:00
2020-07-05 13:07:33 -07:00
2021-05-30 13:26:42 +03:00
2017-10-30 13:45:20 -04:00
2021-05-30 13:26:42 +03:00
2019-10-30 16:17:04 +00:00
2015-04-21 16:57:07 -07:00
2019-10-30 16:17:04 +00:00
2020-07-31 14:51:23 +00:00
2020-07-05 13:07:33 -07:00
2020-07-05 13:07:33 -07:00
2013-07-23 23:56:58 +01:00
2020-07-05 13:07:33 -07:00
2014-11-12 10:25:00 +10:00
2021-09-06 21:19:46 +00:00
2020-07-05 13:07:33 -07:00