From 38d62bcc0884d084c5f4c1162e2736057817c33b Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 5 Mar 2025 15:17:33 +0100 Subject: [PATCH] dix: CreateColormap() pass in ClientPtr instead of client index The function actually operates on ClientRec, so we can pass it in directly, so it doesn't need to fetch it from clients[] array itself. Signed-off-by: Enrico Weigelt, metux IT consult --- dix/colormap.c | 34 ++++++++++++++++++++-------------- dix/colormap_priv.h | 4 ++-- dix/dispatch.c | 4 ++-- hw/xfree86/common/xf86DGA.c | 2 +- hw/xnest/Color.c | 4 ++-- hw/xwin/wincmap.c | 12 ++++++------ mi/micmap.c | 4 ++-- render/picture.c | 4 ++-- 8 files changed, 37 insertions(+), 31 deletions(-) diff --git a/dix/colormap.c b/dix/colormap.c index ab1dba79d..c94810dce 100644 --- a/dix/colormap.c +++ b/dix/colormap.c @@ -55,6 +55,7 @@ SOFTWARE. #include "dix/colormap_priv.h" #include "dix/dix_priv.h" #include "os/osdep.h" +#include "os/bug_priv.h" #include "misc.h" #include "dix.h" @@ -240,8 +241,8 @@ typedef struct _colorResource { * \param alloc 1 iff all entries are allocated writable */ int -CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, - ColormapPtr *ppcmap, int alloc, int client) +dixCreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, + ColormapPtr *ppcmap, int alloc, ClientPtr pClient) { int class, size; unsigned long sizebytes; @@ -250,9 +251,14 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, int i; Pixel *ppix, **pptr; + if (!pClient) + return BadMatch; + + const int clientIndex = pClient->index; + class = pVisual->class; if (!(class & DynamicClass) && (alloc != AllocNone) && - (client != SERVER_ID)) + (pClient != serverClient)) return BadMatch; size = pVisual->ColormapEntries; @@ -309,10 +315,10 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, free(pmap); return BadAlloc; } - pmap->clientPixelsRed[client] = ppix; + pmap->clientPixelsRed[clientIndex] = ppix; for (i = 0; i < size; i++) ppix[i] = i; - pmap->numPixelsRed[client] = size; + pmap->numPixelsRed[clientIndex] = size; } if ((class | DynamicClass) == DirectColor) { @@ -347,14 +353,14 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, pmap->freeGreen = 0; ppix = xallocarray(size, sizeof(Pixel)); if (!ppix) { - free(pmap->clientPixelsRed[client]); + free(pmap->clientPixelsRed[clientIndex]); free(pmap); return BadAlloc; } - pmap->clientPixelsGreen[client] = ppix; + pmap->clientPixelsGreen[clientIndex] = ppix; for (i = 0; i < size; i++) ppix[i] = i; - pmap->numPixelsGreen[client] = size; + pmap->numPixelsGreen[clientIndex] = size; size = pmap->freeBlue; for (pent = &pmap->blue[size - 1]; pent >= pmap->blue; pent--) @@ -362,15 +368,15 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, pmap->freeBlue = 0; ppix = xallocarray(size, sizeof(Pixel)); if (!ppix) { - free(pmap->clientPixelsGreen[client]); - free(pmap->clientPixelsRed[client]); + free(pmap->clientPixelsGreen[clientIndex]); + free(pmap->clientPixelsRed[clientIndex]); free(pmap); return BadAlloc; } - pmap->clientPixelsBlue[client] = ppix; + pmap->clientPixelsBlue[clientIndex] = ppix; for (i = 0; i < size; i++) ppix[i] = i; - pmap->numPixelsBlue[client] = size; + pmap->numPixelsBlue[clientIndex] = size; } } pmap->flags |= CM_BeingCreated; @@ -381,7 +387,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, /* * Security creation/labeling check */ - i = XaceHookResourceAccess(clients[client], mid, X11_RESTYPE_COLORMAP, + i = XaceHookResourceAccess(pClient, mid, X11_RESTYPE_COLORMAP, pmap, X11_RESTYPE_NONE, NULL, DixCreateAccess); if (i != Success) { FreeResource(mid, X11_RESTYPE_NONE); @@ -547,7 +553,7 @@ CopyColormapAndFree(Colormap mid, ColormapPtr pSrc, int client) size = pVisual->ColormapEntries; /* If the create returns non-0, it failed */ - result = CreateColormap(mid, pScreen, pVisual, &pmap, alloc, client); + result = dixCreateColormap(mid, pScreen, pVisual, &pmap, alloc, clients[client]); if (result != Success) return result; if (alloc == AllocAll) { diff --git a/dix/colormap_priv.h b/dix/colormap_priv.h index 382f5aff5..176dd1347 100644 --- a/dix/colormap_priv.h +++ b/dix/colormap_priv.h @@ -21,8 +21,8 @@ typedef struct _CMEntry *EntryPtr; -int CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, - ColormapPtr *ppcmap, int alloc, int client); +int dixCreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, + ColormapPtr *ppcmap, int alloc, ClientPtr client); /* should only be called via resource type's destructor */ int FreeColormap(void *pmap, XID mid); diff --git a/dix/dispatch.c b/dix/dispatch.c index a5867d2d2..5f1c77026 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -2446,8 +2446,8 @@ ProcCreateColormap(ClientPtr client) i < pScreen->numVisuals; i++, pVisual++) { if (pVisual->vid != stuff->visual) continue; - return CreateColormap(mid, pScreen, pVisual, &pmap, - (int) stuff->alloc, client->index); + return dixCreateColormap(mid, pScreen, pVisual, &pmap, + (int) stuff->alloc, client); } client->errorValue = stuff->visual; return BadMatch; diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c index 59353b33a..7ec15de6f 100644 --- a/hw/xfree86/common/xf86DGA.c +++ b/hw/xfree86/common/xf86DGA.c @@ -709,7 +709,7 @@ DGACreateColormap(int index, ClientPtr client, int id, int mode, int alloc) LEGAL_NEW_RESOURCE(id, client); - return CreateColormap(id, pScreen, pVisual, &pmap, alloc, client->index); + return dixCreateColormap(id, pScreen, pVisual, &pmap, alloc, client); } /* Called by the extension to install a colormap on DGA active screens */ diff --git a/hw/xnest/Color.c b/hw/xnest/Color.c index b8460b974..ecf337df1 100644 --- a/hw/xnest/Color.c +++ b/hw/xnest/Color.c @@ -469,9 +469,9 @@ xnestCreateDefaultColormap(ScreenPtr pScreen) for (pVisual = pScreen->visuals; pVisual->vid != pScreen->rootVisual; pVisual++); - if (CreateColormap(pScreen->defColormap, pScreen, pVisual, &pCmap, + if (dixCreateColormap(pScreen->defColormap, pScreen, pVisual, &pCmap, (pVisual->class & DynamicClass) ? AllocNone : AllocAll, - 0) + serverClient) != Success) return FALSE; diff --git a/hw/xwin/wincmap.c b/hw/xwin/wincmap.c index 7b279f490..679b4d34c 100644 --- a/hw/xwin/wincmap.c +++ b/hw/xwin/wincmap.c @@ -520,12 +520,12 @@ winCreateDefColormap(ScreenPtr pScreen) #endif /* Allocate an X colormap, owned by client 0 */ - if (CreateColormap(pScreen->defColormap, - pScreen, - pVisual, - &pcmap, - (pVisual->class & DynamicClass) ? AllocNone : AllocAll, - 0) != Success) { + if (dixCreateColormap(pScreen->defColormap, + pScreen, + pVisual, + &pcmap, + (pVisual->class & DynamicClass) ? AllocNone : AllocAll, + serverClient) != Success) { ErrorF("winCreateDefColormap - CreateColormap failed\n"); return FALSE; } diff --git a/mi/micmap.c b/mi/micmap.c index 655151035..134fe7a33 100644 --- a/mi/micmap.c +++ b/mi/micmap.c @@ -261,8 +261,8 @@ miCreateDefColormap(ScreenPtr pScreen) else alloctype = AllocAll; - if (CreateColormap(pScreen->defColormap, pScreen, pVisual, &cmap, - alloctype, 0) != Success) + if (dixCreateColormap(pScreen->defColormap, pScreen, pVisual, &cmap, + alloctype, serverClient) != Success) return FALSE; if (pScreen->rootDepth > 1) { diff --git a/render/picture.c b/render/picture.c index ac5bbc8c3..f0a2aee43 100644 --- a/render/picture.c +++ b/render/picture.c @@ -421,8 +421,8 @@ PictureInitIndexedFormat(ScreenPtr pScreen, PictFormatPtr format) if (pVisual == NULL) return FALSE; - if (CreateColormap(FakeClientID(0), pScreen, pVisual, - &format->index.pColormap, AllocNone, 0) + if (dixCreateColormap(FakeClientID(0), pScreen, pVisual, + &format->index.pColormap, AllocNone, serverClient) != Success) return FALSE; }