From c10baabc897210b5f99f4d95ce3ac37cc59aa736 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 14 Aug 2025 19:10:03 +0200 Subject: [PATCH] xres: ProcXResQueryClients(): use x_rpcbuf_t use x_rpcbuf_t for reply payload assembly and byte-swapping. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/xres.c | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/Xext/xres.c b/Xext/xres.c index e00e3fdcd..9426c1eab 100644 --- a/Xext/xres.c +++ b/Xext/xres.c @@ -205,56 +205,34 @@ ProcXResQueryClients(ClientPtr client) { REQUEST_SIZE_MATCH(xXResQueryClientsReq); - int *current_clients = calloc(currentMaxClients, sizeof(int)); - if (!current_clients) - return BadAlloc; + x_rpcbuf_t rpcbuf = { .swapped = client->swapped, .err_clear = TRUE }; int num_clients = 0; for (int i = 0; i < currentMaxClients; i++) { - if (clients[i]) { - if (XaceHookClientAccess(client, clients[i], DixReadAccess) == Success) { - current_clients[num_clients] = i; - num_clients++; - } + ClientPtr walkClient = clients[i]; + if (walkClient && + (XaceHookClientAccess(client, walkClient, DixReadAccess) == Success)) { + x_rpcbuf_write_CARD32(&rpcbuf, walkClient->clientAsMask); /* resource_base */ + x_rpcbuf_write_CARD32(&rpcbuf, RESOURCE_ID_MASK); /* resource_mask */ + num_clients++; } } xXResQueryClientsReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, - .length = bytes_to_int32(num_clients * sz_xXResClient), + .length = x_rpcbuf_wsize_units(&rpcbuf), .num_clients = num_clients }; + if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); swapl(&rep.num_clients); } - xXResClient *scratch = NULL; - - if (num_clients) { - scratch = calloc(sizeof(xXResClient), num_clients); - if (!scratch) { - free(current_clients); - return BadAlloc; - } - - for (int i = 0; i < num_clients; i++) { - scratch[i].resource_base = clients[current_clients[i]]->clientAsMask; - scratch[i].resource_mask = RESOURCE_ID_MASK; - - if (client->swapped) { - swapl(&scratch[i].resource_base); - swapl(&scratch[i].resource_mask); - } - } - } - WriteToClient(client, sizeof(xXResQueryClientsReply), &rep); - WriteToClient(client, sizeof(xXResClient) * num_clients, scratch); - free(current_clients); - free(scratch); + WriteRpcbufToClient(client, &rpcbuf); return Success; }