From 51b5019fe29f5cff14791de25354c3b9bcd319e8 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 25 Aug 2025 17:25:45 +0200 Subject: [PATCH] Xext: xres: fix XResQueryClientResources request been using the wrong index for retrieving the resource type atom. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/xres.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/Xext/xres.c b/Xext/xres.c index 1026dffb5..faec0ec8c 100644 --- a/Xext/xres.c +++ b/Xext/xres.c @@ -304,12 +304,28 @@ ProcXResQueryClientResources(ClientPtr client) FindAllClientResources(resClient, ResFindAllRes, counts); - int num_types = 0; - for (int i = 0; i <= lastResourceType; i++) { - if (counts[i]) - num_types++; + xXResType *scratch = calloc(lastResourceType + 1, sizeof(xXResType)); + if (!scratch) { + free(counts); + return BadAlloc; } + int num_types = 0; + for (int i = 0; i < num_types; i++) { + if (!(counts[i])) + continue; + + scratch[num_types].resource_type = resourceTypeAtom(i + 1); + scratch[num_types].count = counts[i]; + if (client->swapped) { + swapl(&scratch[num_types].resource_type); + swapl(&scratch[num_types].count); + } + num_types++; + } + + free(counts); + xXResQueryClientResourcesReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, @@ -322,24 +338,6 @@ ProcXResQueryClientResources(ClientPtr client) swapl(&rep.num_types); } - xXResType *scratch = calloc(sizeof(xXResType), num_types); - if (!scratch) { - free(counts); - return BadAlloc; - } - - for (int i = 0; i < num_types; i++) { - scratch[i].resource_type = resourceTypeAtom(i + 1); - scratch[i].count = counts[i]; - - if (client->swapped) { - swapl(&scratch[i].resource_type); - swapl(&scratch[i].count); - } - } - - free(counts); - WriteToClient(client, sizeof(xXResQueryClientResourcesReply), &rep); WriteToClient(client, num_types * sizeof(xXResType), scratch); free(scratch);