mirror of
https://gitlab.freedesktop.org/xorg/xserver.git
synced 2026-05-09 07:18:05 +02:00
Xext/xres: fix undefined behavior in ConstructClientIdValue
The CARD32 *value pointer was computed as (ptr + sizeof(rep)) BEFORE the NULL check for ptr. If AddFragment returns NULL, this performs pointer arithmetic on a null pointer, which is undefined behavior per C11 section 6.5.6 paragraph 8. With aggressive compiler optimizations (e.g., GCC -O2 with LTO), the compiler could reason that since ptr was used in arithmetic, it must be non-NULL, and optimize away the NULL check entirely. This would then cause a write to an invalid address on OOM. Co-Authored-by: Claude Code <noreply@anthropic.com> Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2181>
This commit is contained in:
parent
d2d4fb35e7
commit
598994a856
1 changed files with 3 additions and 1 deletions
|
|
@ -490,12 +490,14 @@ ConstructClientIdValue(ClientPtr sendClient, ClientPtr client, CARD32 mask,
|
|||
if (pid != -1) {
|
||||
void *ptr = AddFragment(&ctx->response,
|
||||
sizeof(rep) + sizeof(CARD32));
|
||||
CARD32 *value = (void*) ((char*) ptr + sizeof(rep));
|
||||
CARD32 *value;
|
||||
|
||||
if (!ptr) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
value = (void*) ((char*) ptr + sizeof(rep));
|
||||
|
||||
rep.spec.mask = X_XResLocalClientPIDMask;
|
||||
rep.length = 4;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue