Skip to content

main: reject --xwayland-count below 1 - #2340

Open
adamsjo95 wants to merge 1 commit into
ValveSoftware:masterfrom
adamsjo95:main-validate-xwayland-count
Open

main: reject --xwayland-count below 1#2340
adamsjo95 wants to merge 1 commit into
ValveSoftware:masterfrom
adamsjo95:main-validate-xwayland-count

Conversation

@adamsjo95

Copy link
Copy Markdown

--xwayland-count 0 and negative values segfault at startup.

The creation loop in wlserver_init() is
for (int i = 0; i < g_nXWaylandCount; i++), so a count below 1 leaves
wlserver.wlr.xwayland_servers empty. main.cpp:1068 then does:

gamescope_xwayland_server_t *base_server = wlserver_get_xwayland_server(0);
setenv("DISPLAY", base_server->get_nested_display_name(), 1);

wlserver_get_xwayland_server() correctly returns NULL for an
out-of-range index, but the return value isn't checked here.

Reproduction

$ gamescope --xwayland-count 0 -- true
Segmentation fault (core dumped)     # exit 139

$ gamescope --xwayland-count -1 -- true
Segmentation fault (core dumped)     # exit 139

Backtrace:

#0  gamescope_xwayland_server_t::get_nested_display_name (this=0x0) at src/wlserver.cpp:3270
#1  main (...) at src/main.cpp:1070

Why validate instead of null-check

wlserver_get_xwayland_server(0) is used unchecked in main.cpp and in
roughly ten places in steamcompmgr.cpp (2573, 4413, 4436, 5582, 5992,
5997, 8783, ...), plus wlserver.cpp 367 and 872. Server 0 is assumed
to exist throughout, so guarding one call site would move the crash
rather than fix it. Rejecting the input at parse time matches the
existing parse_integer() and --backend error handling.

After

$ gamescope --xwayland-count 0 -- true
gamescope: invalid value for --xwayland-count, must be at least 1    # exit 1

Normal operation unaffected. meson test --suite gamescope passes 2/2.
Builds clean with --werror (689/689). Tested on fcc1341.

Independent of #, different file, different
mechanism and no dependency between them.

gamescope assumes at least one Xwayland server exists: wlserver_get_xwayland_server(0) is called without a null check in main() and in approximately 10 places in steamcompmgr.cpp. --xwayland-count 0 or a negative value the creation loop never runs, the server list stays empty, and main() results in NULL.

Reject the value at parse time rather than null-checking a single call site, which would only move the crash to the next unchecked use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant