Skip to content

Use-after-free: Group/AModule may stores const Json::Value& that may reference a temporary (dangling reference) #4969

@Mrpaoo

Description

@Mrpaoo

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions