From a46077cfc967501a64b4574612cfe07b034e4a15 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 15 May 2025 17:14:55 +0200 Subject: [PATCH] dix: add dixPropertyCreate() This function shall be used for creating an entirely new property structure from given data. Signed-off-by: Enrico Weigelt, metux IT consult --- dix/property.c | 22 +++++++--------------- dix/property_list.c | 26 ++++++++++++++++++++++++++ dix/property_priv.h | 14 ++++++++++++++ 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/dix/property.c b/dix/property.c index 2fb4dc624..d0bd18f35 100644 --- a/dix/property.c +++ b/dix/property.c @@ -325,11 +325,9 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, { PropertyPtr pProp; PropertyRec savedProp; - int sizeInBytes, totalSize, rc; + int rc; Mask access_mode; - sizeInBytes = format >> 3; - totalSize = len * sizeInBytes; access_mode = (mode == PropModeReplace) ? DixWriteAccess : DixBlendAccess; /* first see if property already exists */ @@ -338,20 +336,11 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, if (rc == BadMatch) { /* just add to list */ if (!MakeWindowOptional(pWin)) return BadAlloc; - pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY); + + pProp = dixPropertyCreate(type, property, format, len, value); if (!pProp) return BadAlloc; - if (totalSize) { - if (!(pProp->data = calloc(1, totalSize))) { - dixPropertyFree(pProp); - return BadAlloc; - } - memcpy(pProp->data, value, totalSize); - } - pProp->propertyName = property; - pProp->type = type; - pProp->format = format; - pProp->size = len; + rc = XaceHookPropertyAccess(pClient, pWin, &pProp, DixCreateAccess | DixWriteAccess); if (rc != Success) { @@ -363,6 +352,9 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, pWin->properties = pProp; } else if (rc == Success) { + const int sizeInBytes = format >> 3; + const int totalSize = len * sizeInBytes; + /* To append or prepend to a property the request format and type must match those of the already defined property. The existing format and type are irrelevant when using the mode diff --git a/dix/property_list.c b/dix/property_list.c index 59ddfe5bc..9a7a2fc8b 100644 --- a/dix/property_list.c +++ b/dix/property_list.c @@ -15,3 +15,29 @@ void dixPropertyFree(PropertyPtr pr) dixFreeObjectWithPrivates(pr, PRIVATE_PROPERTY); } } + +PropertyPtr dixPropertyCreate(Atom type, Atom name, int format, size_t len, + const void *value) +{ + const int totalSize = (format >> 3) * len; + + void *data = calloc(1, totalSize); + if (!data) + return NULL; + + PropertyPtr pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY); + if (!pProp) { + free(data); + return NULL; + } + + memcpy(data, value, totalSize); + + pProp->data = data; + pProp->propertyName = name; + pProp->format = format; + pProp->size = len; + pProp->type = type; + + return pProp; +} diff --git a/dix/property_priv.h b/dix/property_priv.h index 8528ad669..dad4a07a7 100644 --- a/dix/property_priv.h +++ b/dix/property_priv.h @@ -109,4 +109,18 @@ void DeleteAllWindowProperties(WindowPtr pWin); */ void dixPropertyFree(PropertyPtr pProp); +/* + * Create and fill a new property structure from given data. The `value` + * is malloc()ed and copied over. + * + * @param type AtomID of the property type + * @param name AtomID of the property name + * @param format the property format (8/16/32 bits) + * @param len length in units defined by format + * @param value pointer to the (raw) property data) + * @return pointer to newly created property structure (NULL on allocation failure) + */ +PropertyPtr dixPropertyCreate(Atom type, Atom name, int format, + size_t len, const void *value); + #endif /* _XSERVER_PROPERTY_PRIV_H */