From 946eb68ff336208441c46be1774d623c4b59f4e7 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 16 Jul 2025 05:18:20 +0200 Subject: [PATCH] xkb: ProcXGetDeviceKeyMapping(): use x_rpcbuf_t Using x_rpcbuf_t for payload assembly and byte swapping. Signed-off-by: Enrico Weigelt, metux IT consult --- Xi/getkmap.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/Xi/getkmap.c b/Xi/getkmap.c index 5b47a1f5fe..1515fc91e2 100644 --- a/Xi/getkmap.c +++ b/Xi/getkmap.c @@ -52,9 +52,13 @@ SOFTWARE. #include -#include "inputstr.h" /* DeviceIntPtr */ #include #include + +#include "dix/dix_priv.h" +#include "dix/rpcbuf_priv.h" + +#include "inputstr.h" /* DeviceIntPtr */ #include "exglobals.h" #include "swaprep.h" #include "xkbsrv.h" @@ -101,27 +105,36 @@ ProcXGetDeviceKeyMapping(ClientPtr client) if (!syms) return BadAlloc; + const size_t mapWidth = syms->mapWidth; + const size_t numKeySyms = (mapWidth * stuff->count); + + x_rpcbuf_t rpcbuf = { .swapped = client->swapped, .err_clear = TRUE }; + x_rpcbuf_write_CARD32s( + &rpcbuf, + &syms->map[mapWidth * (stuff->firstKeyCode - syms->minKeyCode)], + numKeySyms); + + free(syms->map); + free(syms); + + if (rpcbuf.error) + return BadAlloc; + xGetDeviceKeyMappingReply rep = { .repType = X_Reply, .RepType = X_GetDeviceKeyMapping, .sequenceNumber = client->sequence, - .keySymsPerKeyCode = syms->mapWidth, - .length = (syms->mapWidth * stuff->count) /* KeySyms are 4 bytes */ + .keySymsPerKeyCode = mapWidth, + .length = numKeySyms /* KeySyms are 4 bytes */ }; if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); } - WriteToClient(client, sizeof(xGetDeviceKeyMappingReply), &rep); - client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write; - WriteSwappedDataToClient(client, - syms->mapWidth * stuff->count * sizeof(KeySym), - &syms->map[syms->mapWidth * (stuff->firstKeyCode - - syms->minKeyCode)]); - free(syms->map); - free(syms); + WriteToClient(client, sizeof(xGetDeviceKeyMappingReply), &rep); + WriteRpcbufToClient(client, &rpcbuf); return Success; }