From c45edc0c51b11997b27e8e5a694f5b15d86afe95 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 11 Oct 2025 21:23:18 +0300 Subject: [PATCH] Xext/xselinux: add fast path to ProcSELinuxListSelections() If there's nothing to send, skip over a bunch of code to make a list that won't be used, and hopefully make the code path clearer to both humans and static analyzers, who raise errors as seen in https://gitlab.freedesktop.org/xorg/xserver/-/issues/1817 of dereferencing NULL pointers when count == 0. Signed-off-by: Alan Coopersmith Part-of: --- Xext/xselinux_ext.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Xext/xselinux_ext.c b/Xext/xselinux_ext.c index feaec0ada0..920d7ffd7f 100644 --- a/Xext/xselinux_ext.c +++ b/Xext/xselinux_ext.c @@ -451,8 +451,10 @@ ProcSELinuxListSelections(ClientPtr client) count = 0; for (pSel = CurrentSelections; pSel; pSel = pSel->next) count++; + if (count == 0) + return SELinuxSendItemsToClient(client, NULL, 0, 0); items = calloc(count, sizeof(SELinuxListItemRec)); - if (count && !items) + if (!items) return BadAlloc; /* Fill in the items and calculate size */