From 142729468537437fe8ecd320197500328f1fda87 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Wed, 18 Mar 2026 16:03:35 +0100 Subject: [PATCH 1/2] xwayland: Validate command line options separately The design document hw/xfree86/doc/ddxDesign.xml states that: | AddScreen() should only fail because of programming errors or | failure to allocate resources (like memory). | All configuration problems should be detected BEFORE this point. Different command line options errors are detected in xwl_screen_init() and can cause AddScreen() to fail, which is not compliant with the specification. Move all command line checks out of xwl_screen_init() in a separate function that will take care of verifying the command line options and bail out with meaningful error messages. Signed-off-by: Olivier Fourdan --- hw/xwayland/xwayland-screen.c | 81 +++++++++++++++++++++++++---------- hw/xwayland/xwayland-screen.h | 2 + hw/xwayland/xwayland.c | 4 ++ 3 files changed, 64 insertions(+), 23 deletions(-) diff --git a/hw/xwayland/xwayland-screen.c b/hw/xwayland/xwayland-screen.c index 44e4a8055..778627a91 100644 --- a/hw/xwayland/xwayland-screen.c +++ b/hw/xwayland/xwayland-screen.c @@ -864,6 +864,63 @@ xwl_screen_update_global_surface_scale(struct xwl_screen *xwl_screen) return (xwl_screen->global_surface_scale != old_scale); } +Bool +xwl_screen_validate_options(int argc, char **argv) +{ + int i; + int width, height; + Bool use_fixed_size = FALSE; + Bool fullscreen = FALSE; + Bool decorate = FALSE; + Bool host_grab = FALSE; + Bool rootless = FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-geometry") == 0) { + sscanf(argv[i + 1], "%ix%i", &width, &height); + if (width == 0 || height == 0) { + ErrorF("Invalid argument, '-geometry %s'\n", argv[i + 1]); + return FALSE; + } + use_fixed_size = TRUE; + } + else if (strcmp(argv[i], "-fullscreen") == 0) { + fullscreen = TRUE; + } + else if (strcmp(argv[i], "-decorate") == 0) { + decorate = TRUE; + } + else if (strcmp(argv[i], "-host-grab") == 0) { + host_grab = TRUE; + } + else if (strcmp(argv[i], "-rootless") == 0) { + rootless = TRUE; + } + } + + if (rootless && use_fixed_size) { + ErrorF("Invalid argument, cannot set '-geometry' with '-rootless'\n"); + return FALSE; + } + + if (fullscreen && rootless) { + ErrorF("Invalid argument, cannot set '-fullscreen' with '-rootless'\n"); + return FALSE; + } + + if (fullscreen && decorate) { + ErrorF("Invalid argument, cannot use '-decorate' with '-fullscreen'\n"); + return FALSE; + } + + if (host_grab && rootless) { + ErrorF("Invalid argument, cannot use '-host-grab' with '-rootless'\n"); + return FALSE; + } + + return TRUE; +} + Bool xwl_screen_init(ScreenPtr pScreen, int argc, char **argv) { @@ -934,7 +991,7 @@ xwl_screen_init(ScreenPtr pScreen, int argc, char **argv) else if (strncmp(argv[i + 1], "off", 3) == 0) xwl_screen->glamor = XWL_GLAMOR_NONE; else - ErrorF("Xwayland glamor: unknown rendering API selected\n"); + ErrorF("glamor: ignoring unknown rendering API selected\n"); } #endif else if (strcmp(argv[i], "-force-xrandr-emulation") == 0) { @@ -942,10 +999,6 @@ xwl_screen_init(ScreenPtr pScreen, int argc, char **argv) } else if (strcmp(argv[i], "-geometry") == 0) { sscanf(argv[i + 1], "%ix%i", &xwl_width, &xwl_height); - if (xwl_width == 0 || xwl_height == 0) { - ErrorF("invalid argument for -geometry %s\n", argv[i + 1]); - return FALSE; - } use_fixed_size = 1; } else if (strcmp(argv[i], "-fullscreen") == 0) { @@ -986,9 +1039,6 @@ xwl_screen_init(ScreenPtr pScreen, int argc, char **argv) use_fixed_size = 1; xwl_screen->width = xwl_width; xwl_screen->height = xwl_height; - } else if (use_fixed_size) { - ErrorF("error, cannot set a geometry when running rootless\n"); - return FALSE; } xwl_screen->display = wl_display_connect(NULL); @@ -1039,26 +1089,11 @@ xwl_screen_init(ScreenPtr pScreen, int argc, char **argv) ®istry_listener, xwl_screen); xwl_screen_roundtrip(xwl_screen); - if (xwl_screen->fullscreen && xwl_screen->rootless) { - ErrorF("error, cannot set fullscreen when running rootless\n"); - return FALSE; - } - - if (xwl_screen->fullscreen && xwl_screen->decorate) { - ErrorF("error, cannot use the decorate option when running fullscreen\n"); - return FALSE; - } - if (xwl_screen->fullscreen && !xwl_screen_has_viewport_support(xwl_screen)) { ErrorF("missing viewport support in the compositor, ignoring fullscreen\n"); xwl_screen->fullscreen = FALSE; } - if (xwl_screen->host_grab && xwl_screen->rootless) { - ErrorF("error, cannot use host grab when running rootless\n"); - return FALSE; - } - if (!xwl_screen->rootless && !xwl_screen->xdg_wm_base) { ErrorF("missing XDG-WM-Base protocol\n"); return FALSE; diff --git a/hw/xwayland/xwayland-screen.h b/hw/xwayland/xwayland-screen.h index ffbaa09e7..a8b6bc121 100644 --- a/hw/xwayland/xwayland-screen.h +++ b/hw/xwayland/xwayland-screen.h @@ -173,6 +173,7 @@ int xwl_screen_get_width(struct xwl_screen *xwl_screen); int xwl_screen_get_height(struct xwl_screen *xwl_screen); Bool xwl_close_screen(ScreenPtr screen); +Bool xwl_screen_verify_command_line(int argc, char **argv); Bool xwl_screen_init(ScreenPtr pScreen, int argc, char **argv); void xwl_sync_events (struct xwl_screen *xwl_screen); void xwl_screen_roundtrip (struct xwl_screen *xwl_screen); @@ -183,5 +184,6 @@ int xwl_screen_get_next_output_serial(struct xwl_screen * xwl_screen); void xwl_screen_lost_focus(struct xwl_screen *xwl_screen); Bool xwl_screen_update_global_surface_scale(struct xwl_screen *xwl_screen); Bool xwl_screen_should_use_fractional_scale(struct xwl_screen *xwl_screen); +Bool xwl_screen_validate_options(int argc, char **argv); #endif /* XWAYLAND_SCREEN_H */ diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c index 91c94681b..de1b0b836 100644 --- a/hw/xwayland/xwayland.c +++ b/hw/xwayland/xwayland.c @@ -434,6 +434,10 @@ InitOutput(ScreenInfo * screen_info, int argc, char **argv) wl_log_set_handler_client(xwl_log_handler); + if (!xwl_screen_validate_options(argc, argv)) { + FatalError("Invalid command line arguments\n"); + } + if (AddScreen(xwl_screen_init, argc, argv) == -1) { FatalError("Couldn't add screen\n"); } From b723eb5085a8a5312923f401fa3064a5e39a11bf Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Tue, 26 Nov 2024 10:34:59 +0100 Subject: [PATCH 2/2] xwayland: Refuse to start with indirect GLX enabled Xwayland does not support indirect GLX contexts and enabling them will crash the xserver. Refuse to start if indirect GLX contexts are enabled on the command line. Signed-off-by: Olivier Fourdan --- hw/xwayland/xwayland-screen.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/xwayland/xwayland-screen.c b/hw/xwayland/xwayland-screen.c index 778627a91..2864e7c3d 100644 --- a/hw/xwayland/xwayland-screen.c +++ b/hw/xwayland/xwayland-screen.c @@ -896,6 +896,10 @@ xwl_screen_validate_options(int argc, char **argv) else if (strcmp(argv[i], "-rootless") == 0) { rootless = TRUE; } + else if (strcmp(argv[i], "+iglx") == 0) { + ErrorF("Invalid argument, '+iglx' (indirect GLX context) is not supported\n"); + return FALSE; + } } if (rootless && use_fixed_size) {