From 449b317cd7f612638d7e418927e7787790abfd21 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 4 Oct 2025 17:19:05 -0700 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 #1817 of dereferencing NULL pointers when count == 0. Signed-off-by: Alan Coopersmith Part-of: (cherry picked from commit d34243606c8d7a01108827ad1ca3216bf81a119d) --- 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 2ae8c6431..699a20d0f 100644 --- a/Xext/xselinux_ext.c +++ b/Xext/xselinux_ext.c @@ -455,8 +455,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 */