Compare commits

...

4 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult 9c124ae78a Xi: exevents: extra asserts on NULL pointers
Even though shouldn't be practically hit, better have some asserts,
giving us an idea of the point of cause, instead of segfaulting,
just in case.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-05-15 14:09:46 +02:00
Enrico Weigelt, metux IT consult 35fed10d19 Xi: xibarriers: protect add_master_func() from allocation failure
Try to gracefully handle OOM situation, at not hard crashing.

| ../Xi/xibarriers.c: In function ‘add_master_func’:
| ../Xi/xibarriers.c:729:19: warning: dereference of NULL ‘pbd’ [CWE-476] [-Wanalyzer-null-dereference]
|  729 |     pbd->deviceid = *deviceid;
|       |     ~~~~~~~~~~~~~~^~~~~~~~~~~

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-05-15 14:09:40 +02:00
Enrico Weigelt, metux IT consult 675a30f550 Xi: exevents: NULL protection in ‘DeviceEventSuppressForWindow()
Protect against `inputMasks` could be NULL.

| ../Xi/exevents.c: In function ‘DeviceEventSuppressForWindow’:
| ../Xi/exevents.c:3246:32: warning: dereference of NULL ‘inputMasks’ [CWE-476] [-Wanalyzer-null-dereference]
|  3246 |         FreeResource(inputMasks->inputClients->resource, X11_RESTYPE_NONE);
|       |                      ~~~~~~~~~~^~~~~~~~~~~~~~

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-05-15 14:09:35 +02:00
Enrico Weigelt, metux IT consult f6f3411c06 Xi: fix double-free warning in FreePointerBarrierClient()
| ../Xi/xibarriers.c: In function ‘FreePointerBarrierClient’:
| ../Xi/xibarriers.c:127:9: warning: double-‘free’ of ‘pbd’ [CWE-415] [-Wanalyzer-double-free]
|   127 |         free(pbd);
|       |         ^~~~~~~~~

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-05-15 14:09:31 +02:00
2 changed files with 20 additions and 6 deletions

View File

@ -491,6 +491,7 @@ DeepCopyKeyboardClasses(DeviceIntPtr from, DeviceIntPtr to)
if (!k->xkb_sli) if (!k->xkb_sli)
continue; continue;
if (k->xkb_sli->flags & XkbSLI_IsDefault) { if (k->xkb_sli->flags & XkbSLI_IsDefault) {
assert(to->key);
k->xkb_sli->names = to->key->xkbInfo->desc->names->indicators; k->xkb_sli->names = to->key->xkbInfo->desc->names->indicators;
k->xkb_sli->maps = to->key->xkbInfo->desc->indicators->maps; k->xkb_sli->maps = to->key->xkbInfo->desc->indicators->maps;
} }
@ -1044,6 +1045,7 @@ TouchClientWantsOwnershipEvents(ClientPtr client, DeviceIntPtr dev,
{ {
InputClients *iclient; InputClients *iclient;
assert(wOtherInputMasks(win));
nt_list_for_each_entry(iclient, wOtherInputMasks(win)->inputClients, next) { nt_list_for_each_entry(iclient, wOtherInputMasks(win)->inputClients, next) {
if (rClient(iclient) != client) if (rClient(iclient) != client)
continue; continue;
@ -1389,6 +1391,8 @@ RetrieveTouchDeliveryData(DeviceIntPtr dev, TouchPointInfoPtr ti,
else else
evtype = GetXI2Type(ev->any.type); evtype = GetXI2Type(ev->any.type);
assert(iclients);
assert(wOtherInputMasks(*win));
nt_list_for_each_entry(iclients, nt_list_for_each_entry(iclients,
wOtherInputMasks(*win)->inputClients, next) wOtherInputMasks(*win)->inputClients, next)
if (xi2mask_isset(iclients->xi2mask, dev, evtype)) if (xi2mask_isset(iclients->xi2mask, dev, evtype))
@ -1403,6 +1407,7 @@ RetrieveTouchDeliveryData(DeviceIntPtr dev, TouchPointInfoPtr ti,
int xi_type = GetXIType(TouchGetPointerEventType(ev)); int xi_type = GetXIType(TouchGetPointerEventType(ev));
Mask xi_filter = event_get_filter_from_type(dev, xi_type); Mask xi_filter = event_get_filter_from_type(dev, xi_type);
assert(wOtherInputMasks(*win));
nt_list_for_each_entry(iclients, nt_list_for_each_entry(iclients,
wOtherInputMasks(*win)->inputClients, next) wOtherInputMasks(*win)->inputClients, next)
if (iclients->mask[dev->id] & xi_filter) if (iclients->mask[dev->id] & xi_filter)
@ -2292,6 +2297,7 @@ RetrieveGestureDeliveryData(DeviceIntPtr dev, InternalEvent *ev, GestureListener
listener->type == GESTURE_LISTENER_REGULAR */ listener->type == GESTURE_LISTENER_REGULAR */
evtype = GetXI2Type(ev->any.type); evtype = GetXI2Type(ev->any.type);
assert(wOtherInputMasks(*win));
nt_list_for_each_entry(iclients, wOtherInputMasks(*win)->inputClients, next) nt_list_for_each_entry(iclients, wOtherInputMasks(*win)->inputClients, next)
if (xi2mask_isset(iclients->xi2mask, dev, evtype)) if (xi2mask_isset(iclients->xi2mask, dev, evtype))
break; break;
@ -2681,6 +2687,7 @@ SelectForWindow(DeviceIntPtr dev, WindowPtr pWin, ClientPtr client,
return BadAccess; return BadAccess;
} }
} }
assert(wOtherInputMasks(pWin));
for (others = wOtherInputMasks(pWin)->inputClients; others; for (others = wOtherInputMasks(pWin)->inputClients; others;
others = others->next) { others = others->next) {
if (SameClient(others, client)) { if (SameClient(others, client)) {
@ -3242,8 +3249,11 @@ DeviceEventSuppressForWindow(WindowPtr pWin, ClientPtr client, Mask mask,
inputMasks->dontPropagateMask[maskndx] = mask; inputMasks->dontPropagateMask[maskndx] = mask;
} }
RecalculateDeviceDeliverableEvents(pWin); RecalculateDeviceDeliverableEvents(pWin);
if (ShouldFreeInputMasks(pWin, FALSE)) if (ShouldFreeInputMasks(pWin, FALSE)) {
BUG_RETURN_VAL(!inputMasks, BadImplementation);
BUG_RETURN_VAL(!inputMasks->inputClients, BadImplementation);
FreeResource(inputMasks->inputClients->resource, X11_RESTYPE_NONE); FreeResource(inputMasks->inputClients->resource, X11_RESTYPE_NONE);
}
return Success; return Success;
} }
@ -3337,6 +3347,7 @@ XISetEventMask(DeviceIntPtr dev, WindowPtr win, ClientPtr client,
if (len && !others) { if (len && !others) {
if (AddExtensionClient(win, client, 0, 0) != Success) if (AddExtensionClient(win, client, 0, 0) != Success)
return BadAlloc; return BadAlloc;
assert(wOtherInputMasks(win));
others = wOtherInputMasks(win)->inputClients; others = wOtherInputMasks(win)->inputClients;
} }
@ -3346,6 +3357,7 @@ XISetEventMask(DeviceIntPtr dev, WindowPtr win, ClientPtr client,
} }
if (len) { if (len) {
assert(others);
xi2mask_set_one_mask(others->xi2mask, dev->id, mask, len); xi2mask_set_one_mask(others->xi2mask, dev->id, mask, len);
} }

View File

@ -124,8 +124,10 @@ static void FreePointerBarrierClient(struct PointerBarrierClient *c)
{ {
struct PointerBarrierDevice *pbd = NULL, *tmp = NULL; struct PointerBarrierDevice *pbd = NULL, *tmp = NULL;
xorg_list_for_each_entry_safe(pbd, tmp, &c->per_device, entry) { if (!xorg_list_is_empty(&c->per_device)) {
free(pbd); xorg_list_for_each_entry_safe(pbd, tmp, &c->per_device, entry) {
free(pbd);
}
} }
free(c); free(c);
} }
@ -721,14 +723,14 @@ static void add_master_func(void *res, XID id, void *devid)
{ {
struct PointerBarrier *b; struct PointerBarrier *b;
struct PointerBarrierClient *barrier; struct PointerBarrierClient *barrier;
struct PointerBarrierDevice *pbd;
int *deviceid = devid; int *deviceid = devid;
b = res; b = res;
barrier = container_of(b, struct PointerBarrierClient, barrier); barrier = container_of(b, struct PointerBarrierClient, barrier);
struct PointerBarrierDevice *pbd = AllocBarrierDevice();
pbd = AllocBarrierDevice(); if (!pbd)
return;
pbd->deviceid = *deviceid; pbd->deviceid = *deviceid;
input_lock(); input_lock();