Skip to content

fix(linux): guard XRandR NULL returns to avoid a SEGV during display setup - #5644

Open
sresarehumantoo wants to merge 1 commit into
LizardByte:masterfrom
sresarehumantoo:fix/x11-randr-null-deref
Open

fix(linux): guard XRandR NULL returns to avoid a SEGV during display setup#5644
sresarehumantoo wants to merge 1 commit into
LizardByte:masterfrom
sresarehumantoo:fix/x11-randr-null-deref

Conversation

@sresarehumantoo

Copy link
Copy Markdown

Description

XRRGetScreenResources and XRRGetCrtcInfo return NULL on a transient X error. There are three call sites in src/platform/linux/x11grab.cpp that dereference without checking:

  • screenr -> noutput at line 516 (x11_attr_t::init) and line 945 (x11_display_names)
  • crt_info -> width at line 537

Trigger: RandR config still settling, ex: a second CRTC comes up as a multi-display session starts. Result is a process-wide SEGV.
What I saw: sunshine SEGVs on session start with two displays, succeeds on retry. Found and fixed in my own tree in July; running on my test bench (vdi-test, Debian 13 (trixie)) since.

Verified on Ubuntu 22.04 WSL2 that it builds clean against master (393/393). Unit tests show no new failures (MouseHIDTest and EncoderTest fail identically before and after the patch in that environment, because it has no /dev/uinput; 0 failed tests either way).

Screenshot

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

See our AI usage policy.

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

…setup

XRRGetScreenResources and XRRGetCrtcInfo both return NULL on a transient X
error, which happens while the RandR configuration is still settling (for
example when a second CRTC is being brought up as a multi-display session
starts). Three call sites dereference the result without checking it, so the
whole process dies instead of reporting a failure the caller can retry.

Check all three: both x11_attr_t::init() and x11_display_names() bail out the
way the adjacent xdisplay failures already do, and the CRTC lookup falls
through to the existing "record the entire virtual desktop" path.

Observed on a two-display session that raced CRTC bring-up, where sunshine
would SEGV on session start and succeed on retry.
@sonarqubecloud

sonarqubecloud Bot commented Sep 8, 2026

Copy link
Copy Markdown

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