Skip to content

Fix use-after-free crash in UI callbacks on rebase#1048

Open
xusheng6 wants to merge 1 commit intodevfrom
test_1039-fix-ui-callback-use-after-free
Open

Fix use-after-free crash in UI callbacks on rebase#1048
xusheng6 wants to merge 1 commit intodevfrom
test_1039-fix-ui-callback-use-after-free

Conversation

@xusheng6
Copy link
Copy Markdown
Member

@xusheng6 xusheng6 commented Apr 6, 2026

Summary

  • Unregister UI callbacks from the DebuggerController in ~DebuggerUI() before deleting them, preventing a use-after-free crash when the controller processes a rebase after the UI is destroyed.
  • SetDebuggerUICallbacks now accepts nullptr to clear the callbacks. The existing null check in RebaseToAddress() ensures any rebase attempt after UI destruction safely returns false.

Test plan

  • Launch a debug target, then close the binary view tab before the launch completes. Verify no crash occurs when the target eventually stops and triggers a rebase.
  • Normal debugging workflow (launch, hit breakpoints, rebase) still works correctly with UI open.

Fixes #1039

🤖 Generated with Claude Code

ui/ui.cpp Outdated
frame->navigate(m_controller->GetData(), address, true, true);
}

openDebuggerSideBar(frame);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the purpose of this? Seems like a behavior change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change introduced earlier: #1032. The reason that I wanted it to no longer focus the debugger sidebar is that if the user is using sidekick to automate the debugger, this will cause the sidekick sidebar to lose focus.

I think I made some git mistake so that it gets wiped out unexpectedly. I will add it back

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I force-pushed to rebase it on top of dev. dev now already has the change

When the user closes a binary view tab while a debug session is still
running (e.g., during a slow launch), the DebuggerUI is destroyed but
the DebuggerController persists via reference counting. If the controller
subsequently processes a target stop and calls RebaseToAddress(), it
invokes NotifyRebaseBinaryView() through the now-dangling UI callback
pointer, causing a SIGSEGV.

Fix by unregistering the UI callbacks from the controller in the
DebuggerUI destructor before deleting them. SetDebuggerUICallbacks now
accepts nullptr to clear the callbacks. The existing null check in
RebaseToAddress() ensures that any rebase attempt after UI destruction
safely returns false instead of crashing.

Fixes #1039

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@xusheng6 xusheng6 force-pushed the test_1039-fix-ui-callback-use-after-free branch from 361e0b2 to 3fecca8 Compare April 7, 2026 03:22
Copy link
Copy Markdown
Member

@plafosse plafosse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks good now.

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.

BinaryNinjaDebugger::DebuggerUICallbacks::NotifyRebaseBinaryView

2 participants