fix(niri/workspaces): segfault when setting workspace button markup#5112
Open
jaschiu wants to merge 1 commit into
Open
fix(niri/workspaces): segfault when setting workspace button markup#5112jaschiu wants to merge 1 commit into
jaschiu wants to merge 1 commit into
Conversation
…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`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, waybar was crashing for me when I was using the
niri/workspacesmodule. 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 assway/workspacesProblem
Waybar segfaults on startup when
niri/workspacesis the only configured module (default options). Right after the firstWorkspacesChangedevent:Root cause
doUpdate()set the label markup via:The button's child is a valid
GtkLabel, but gtkmm'sget_children()returns it wrapped as a genericGtk::Widget(confirmed:dynamic_casttoGtk::Label*yieldsnullptr). The uncheckedstatic_castthen performs an invalid downcast, producing a corrupt pointer whosegobj()is garbage (0x1), sogtk_label_set_markup()dereferences it and crashes.This is reliably triggered when no other module has instantiated a
Gtk::Labelyet (so theGtk::Labelwrapper isn't registered), which is exactly the case for aniri/workspaces-only bar. The same idiom exists insway/workspacesandwayfire/workspaces; it's masked there because typical configs include other label-using modules.Testing
masterwith a minimal"modules-left": ["niri/workspaces"]config under niri.niri-workspace-1/2/3).