Skip to content

fix(niri/workspaces): segfault when setting workspace button markup#5112

Open
jaschiu wants to merge 1 commit into
Alexays:masterfrom
jaschiu:patch-2
Open

fix(niri/workspaces): segfault when setting workspace button markup#5112
jaschiu wants to merge 1 commit into
Alexays:masterfrom
jaschiu:patch-2

Conversation

@jaschiu

@jaschiu jaschiu commented Jun 9, 2026

Copy link
Copy Markdown

Hi, waybar was crashing for me when I was using the niri/workspaces module. My LLM wrote the below description for me and debugged it for me. I am not sure if this fix needs to also be applied to other modules using the same pattern such as sway/workspaces

Problem

Waybar segfaults on startup when niri/workspaces is the only configured module (default options). Right after the first WorkspacesChanged event:

Thread 1 "waybar" received signal SIGSEGV
#0 gtk_label_set_markup ()
#1 waybar::modules::niri::Workspaces::doUpdate () at src/modules/niri/workspaces.cpp:106

Root cause

doUpdate() set the label markup via:

static_cast<Gtk::Label*>(button.get_children()[0])->set_markup(name);

The button's child is a valid GtkLabel, but gtkmm's get_children() returns it wrapped as a generic Gtk::Widget (confirmed: dynamic_cast to Gtk::Label* yields nullptr). The unchecked static_cast then performs an invalid downcast, producing a corrupt pointer whose gobj() is garbage (0x1), so gtk_label_set_markup() dereferences it and crashes.

This is reliably triggered when no other module has instantiated a Gtk::Label yet (so the Gtk::Label wrapper isn't registered), which is exactly the case for a niri/workspaces-only bar. The same idiom exists in sway/workspaces and wayfire/workspaces; it's masked there because typical configs include other label-using modules.

Testing

  • Reproduced the crash on 0.15.0 / current master with a minimal "modules-left": ["niri/workspaces"] config under niri.
  • After the fix: no crash; three workspace buttons render with correct names/labels (niri-workspace-1/2/3).

…on markup

### Problem
Waybar segfaults on startup when `niri/workspaces` is the only configured
module (default options). Right after the first `WorkspacesChanged` event:
 
    Thread 1 "waybar" received signal SIGSEGV
    #0 gtk_label_set_markup ()
    Alexays#1 waybar::modules::niri::Workspaces::doUpdate () at src/modules/niri/workspaces.cpp:106
 
### Root cause
[doUpdate()](cci:1://file:///home/lj/Downloads/Waybar/src/modules/niri/window.cpp:27:0-90:1) set the label markup via:
 
    static_cast<Gtk::Label*>(button.get_children()[0])->set_markup(name);
 
The button's child *is* a valid `GtkLabel`, but gtkmm's `get_children()`
returns it wrapped as a generic `Gtk::Widget` (confirmed: `dynamic_cast`
to `Gtk::Label*` yields `nullptr`). The unchecked `static_cast` then
performs an invalid downcast, producing a corrupt pointer whose `gobj()`
is garbage (`0x1`), so `gtk_label_set_markup()` dereferences it and crashes.
 
This is reliably triggered when no other module has instantiated a
`Gtk::Label` yet (so the `Gtk::Label` wrapper isn't registered), which is
exactly the case for a `niri/workspaces`-only bar. The same idiom exists in
`sway/workspaces` and `wayfire/workspaces`; it's masked there because typical
configs include other label-using modules.

### Testing
- Reproduced the crash on 0.15.0 / current `master` with a minimal
  `"modules-left": ["niri/workspaces"]` config under niri.
- After the fix: no crash; three workspace buttons render with correct
  names/labels (`niri-workspace-1/2/3`).
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