xwayland: protect against alloc failures and NULL pointers

Protecting against NULL pointers and allocation failures.
Printing out a bug warning in those cases.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-05-07 15:09:43 +02:00
parent 25f50e2cc5
commit b31b4c0ae2
4 changed files with 9 additions and 3 deletions

View File

@ -455,7 +455,7 @@ xwl_screen_add_drm_lease_device(struct xwl_screen *xwl_screen, uint32_t id)
{ {
struct wp_drm_lease_device_v1 *lease_device = wl_registry_bind( struct wp_drm_lease_device_v1 *lease_device = wl_registry_bind(
xwl_screen->registry, id, &wp_drm_lease_device_v1_interface, 1); xwl_screen->registry, id, &wp_drm_lease_device_v1_interface, 1);
struct xwl_drm_lease_device *device_data = malloc(sizeof(struct xwl_drm_lease_device)); struct xwl_drm_lease_device *device_data = XNFcallocarray(1, sizeof(struct xwl_drm_lease_device));
device_data->drm_lease_device = lease_device; device_data->drm_lease_device = lease_device;
device_data->xwl_screen = xwl_screen; device_data->xwl_screen = xwl_screen;

View File

@ -3341,6 +3341,7 @@ xwl_pointer_warp_emulator_is_locked(struct xwl_pointer_warp_emulator *warp_emula
static void static void
xwl_pointer_warp_emulator_lock(struct xwl_pointer_warp_emulator *warp_emulator) xwl_pointer_warp_emulator_lock(struct xwl_pointer_warp_emulator *warp_emulator)
{ {
BUG_RETURN(!warp_emulator);
struct xwl_seat *xwl_seat = warp_emulator->xwl_seat; struct xwl_seat *xwl_seat = warp_emulator->xwl_seat;
struct xwl_screen *xwl_screen = xwl_seat->xwl_screen; struct xwl_screen *xwl_screen = xwl_seat->xwl_screen;
struct zwp_pointer_constraints_v1 *pointer_constraints = struct zwp_pointer_constraints_v1 *pointer_constraints =

View File

@ -25,6 +25,8 @@
#include <xwayland-config.h> #include <xwayland-config.h>
#include "os/bug_priv.h"
#include <compint.h> #include <compint.h>
#ifdef XWL_HAS_GLAMOR #ifdef XWL_HAS_GLAMOR
#include <glamor.h> #include <glamor.h>
@ -641,6 +643,8 @@ xwl_present_queue_vblank(ScreenPtr screen,
return BadImplementation; return BadImplementation;
} }
BUG_RETURN_VAL(!xwl_present_window, BadImplementation);
event->vblank.exec_msc = msc; event->vblank.exec_msc = msc;
xorg_list_del(&event->vblank.event_queue); xorg_list_del(&event->vblank.event_queue);

View File

@ -313,7 +313,8 @@ xwl_cursor_warped_to(DeviceIntPtr device,
window = XYToWindow(sprite, x, y); window = XYToWindow(sprite, x, y);
xwl_window = xwl_window_from_window(window); xwl_window = xwl_window_from_window(window);
if (!xwl_window && xwl_seat->focus_window) {
if (!xwl_window && xwl_seat && xwl_seat->focus_window) {
focus = xwl_seat->focus_window->toplevel; focus = xwl_seat->focus_window->toplevel;
/* Warps on non wl_surface backed Windows are only allowed /* Warps on non wl_surface backed Windows are only allowed
@ -525,7 +526,7 @@ registry_global(void *data, struct wl_registry *registry, uint32_t id,
} }
else if (strcmp(interface, wp_drm_lease_device_v1_interface.name) == 0) { else if (strcmp(interface, wp_drm_lease_device_v1_interface.name) == 0) {
if (xwl_screen->screen->root == NULL) { if (xwl_screen->screen->root == NULL) {
struct xwl_queued_drm_lease_device *queued = malloc(sizeof(struct xwl_queued_drm_lease_device)); struct xwl_queued_drm_lease_device *queued = XNFcallocarray(1, sizeof(struct xwl_queued_drm_lease_device));
queued->id = id; queued->id = id;
xorg_list_append(&queued->link, &xwl_screen->queued_drm_lease_devices); xorg_list_append(&queued->link, &xwl_screen->queued_drm_lease_devices);
} else { } else {