From ab150e8b525b824b6047d5c66c9491d6cf6fb721 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 24 Feb 2025 13:49:22 +0100 Subject: [PATCH] xext: xres: protect from allocation failure Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/xres.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Xext/xres.c b/Xext/xres.c index 61f16b583..1f3d0a7f8 100644 --- a/Xext/xres.c +++ b/Xext/xres.c @@ -220,12 +220,13 @@ ProcXResQueryClients(ClientPtr client) { /* REQUEST(xXResQueryClientsReq); */ xXResQueryClientsReply rep; - int *current_clients; int i, num_clients; REQUEST_SIZE_MATCH(xXResQueryClientsReq); - current_clients = calloc(currentMaxClients, sizeof(int)); + int *current_clients = calloc(currentMaxClients, sizeof(int)); + if (!current_clients) + return BadAlloc; num_clients = 0; for (i = 0; i < currentMaxClients; i++) { @@ -300,7 +301,6 @@ ProcXResQueryClientResources(ClientPtr client) REQUEST(xXResQueryClientResourcesReq); xXResQueryClientResourcesReply rep; int i, clientID, num_types; - int *counts; REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq); @@ -311,7 +311,9 @@ ProcXResQueryClientResources(ClientPtr client) return BadValue; } - counts = calloc(lastResourceType + 1, sizeof(int)); + int *counts = calloc(lastResourceType + 1, sizeof(int)); + if (!counts) + return BadAlloc; FindAllClientResources(clients[clientID], ResFindAllRes, counts);