Skip to content

Commit

Permalink
Button: invoke on_click at the end. (#807)
Browse files Browse the repository at this point in the history
Some users might destroy `this`, which would result in UAF.

In the future, we should consider alternatives like posting a task to
the main loop, or rely on users for this.

Fixed:#804
  • Loading branch information
ArthurSonzogni committed Dec 26, 2024
1 parent 6c38bbd commit 84c8908
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ftxui/component/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ class ButtonBase : public ComponentBase, public ButtonOption {
}

void OnClick() {
on_click();
animation_background_ = 0.5F; // NOLINT
animation_foreground_ = 0.5F; // NOLINT
SetAnimationTarget(1.F); // NOLINT

// TODO(arthursonzogni): Consider posting the task to the main loop, instead
// of invoking it immediately.
on_click(); // May delete this.
}

bool OnEvent(Event event) override {
Expand All @@ -110,7 +113,7 @@ class ButtonBase : public ComponentBase, public ButtonOption {
}

if (event == Event::Return) {
OnClick();
OnClick(); // May delete this.
return true;
}
return false;
Expand All @@ -127,7 +130,7 @@ class ButtonBase : public ComponentBase, public ButtonOption {
if (event.mouse().button == Mouse::Left &&
event.mouse().motion == Mouse::Pressed) {
TakeFocus();
OnClick();
OnClick(); // May delete this.
return true;
}

Expand Down

0 comments on commit 84c8908

Please sign in to comment.