Platform
- OS (kernel): 6.19.10-arch1-1
- Compiler: gcc 15.2.1 (20260209)
- jsoncpp: 1.9.6-3
Waybar version
Description
While debugging a scrolling issue mentioned in #4862, I noticed a likely lifetime bug in group creation.
At src/bar.cpp:544 there is code :
auto group_config = config[ref];
if (group_config["modules"].isNull()) {
spdlog::warn("Group definition '{}' has not been found, group will be hidden", ref);
}
auto* group_module = new waybar::Group(id_name, class_name, group_config, vertical);
group_config is a local Json::Value (a copy). I know in documentation of jsoncpp,operator[] return the reference,but i dont know why it is still value-copy ,The Group constructor takes const Json::Value& and forwards it to AModule. AModule stores it as a reference member (const Json::Value& config_). This means config_ may end up referencing the stack object group_config, which is destroyed at the end of the block, leaving a dangling reference (use-after-free / undefined behavior). Later, scroll handling code (e.g. AModule::handleScroll -> AModule::getScrollDir(GdkEventScroll* e)) may access config_ and crash.
As I see it, the current fix for this bug only disables the event handler for Group. So I'm raising a question here.
Platform
Waybar version
make build-debugin Makefile of repoDescription
While debugging a scrolling issue mentioned in #4862, I noticed a likely lifetime bug in group creation.
At
src/bar.cpp:544there is code :group_configis a localJson::Value(a copy). I know in documentation of jsoncpp,operator[] return the reference,but i dont know why it is still value-copy ,The Group constructor takesconst Json::Value&and forwards it to AModule. AModule stores it as a reference member(const Json::Value& config_).This means config_ may end up referencing the stack object group_config, which is destroyed at the end of the block, leaving a dangling reference (use-after-free / undefined behavior). Later, scroll handling code (e.g.AModule::handleScroll -> AModule::getScrollDir(GdkEventScroll* e))may access config_ and crash.As I see it, the current fix for this bug only disables the event handler for Group. So I'm raising a question here.