From 01d6efb414c5563f8e1be40973ff724d1e67869a 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 61740127d..dc1fd2271 100644 --- a/Xext/xres.c +++ b/Xext/xres.c @@ -221,12 +221,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++) { @@ -303,7 +304,6 @@ ProcXResQueryClientResources(ClientPtr client) REQUEST(xXResQueryClientResourcesReq); xXResQueryClientResourcesReply rep; int i, num_types; - int *counts; REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq); @@ -316,7 +316,9 @@ ProcXResQueryClientResources(ClientPtr client) return BadValue; } - counts = calloc(lastResourceType + 1, sizeof(int)); + int *counts = calloc(lastResourceType + 1, sizeof(int)); + if (!counts) + return BadAlloc; FindAllClientResources(resClient, ResFindAllRes, counts);