Skip to content

fix(screen): harden Wayland screen capture cleanup - #125

Open
Ed-web-d wants to merge 1 commit into
FedeDP:masterfrom
Ed-web-d:fix/wayland-screen-cleanup
Open

Ed-web-d wants to merge 1 commit into
FedeDP:masterfrom
Ed-web-d:fix/wayland-screen-cleanup

Conversation

@Ed-web-d

Copy link
Copy Markdown

Summary

Fix a SIGSEGV in the Wayland screen plugin when the compositor does not
support wlr-screencopy-unstable-v1 (GNOME Wayland).

Root cause

get_frame_brightness() calls fetch_wl_display() before initializing
display.outputs. When the Wayland connect fails, it jumps to err and
wl_cleanup() walks the uninitialized wl_list, crashing clightd.
wl_cleanup() also dereferences output->frame, output->buffer and
output->wl_output unconditionally.

Reproduction

On GNOME Wayland:

busctl --system call org.clightd.clightd /org/clightd/clightd/Screen \
  org.clightd.clightd.Screen GetEmittedBrightness "ss" "" ""

Before: clightd exits with SIGSEGV (get_frame_brightness in the stack).
After: the call returns
Compositor does not support 'wlr-screencopy-unstable-v1' protocol
and clightd keeps running.

Changes

  • Initialize display.outputs before fetch_wl_display().
  • Guard frame, buffer and wl_output in wl_cleanup(); free frame.
  • Reject NULL/zero-sized frames in rgb_frame_brightness().

Testing

Built with -DENABLE_GAMMA=ON -DENABLE_DPMS=ON -DENABLE_SCREEN=ON on
Fedora 45 (GCC 16) against libmodule 5.0.2; tested on MacBookPro12,1
(GNOME Wayland). X11 path is unaffected.

The Wayland screen plugin calls wl_cleanup() from the error path before
display.outputs is initialized.  On GNOME Wayland (no wlr-screencopy
support) fetch_wl_display() fails and wl_cleanup() walks an uninitialized
list, crashing clightd with SIGSEGV.

Initialize the list before fetching the display and make cleanup tolerate
partially initialized outputs (frame, buffer, wl_output).  Also reject
invalid frame geometry in rgb_frame_brightness() instead of dividing by
zero.
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