-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Fix a potential use-after-free in StopInfoBreakpoint. #163471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b060e19
Fix a potential use-after-free in StopInfoBreakpoint.
jimingham 5e144df
I had done this as a subclass, but decided not to.
jimingham 2925924
formatting
jimingham 7de870c
Store a BreakpointSP per BreakpointLocation, rather than manually ref…
jimingham 8f765e4
formatting
jimingham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
4 changes: 4 additions & 0 deletions
4
lldb/test/API/functionalities/breakpoint/callback_deletes_breakpoints/Makefile
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| C_SOURCES := main.c | ||
| CFLAGS_EXTRAS := -std=c99 | ||
|
|
||
| include Makefile.rules |
67 changes: 67 additions & 0 deletions
67
...functionalities/breakpoint/callback_deletes_breakpoints/TestCallbackDeletesBreakpoints.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| """ | ||
| Make sure that deleting breakpoints in another breakpoint | ||
| callback doesn't cause problems. | ||
| """ | ||
|
|
||
|
|
||
| import lldb | ||
| import lldbsuite.test.lldbutil as lldbutil | ||
| from lldbsuite.test.lldbtest import * | ||
|
|
||
|
|
||
| class TestBreakpointDeletionInCallback(TestBase): | ||
| NO_DEBUG_INFO_TESTCASE = True | ||
|
|
||
| def test_breakpoint_deletion_in_callback(self): | ||
| self.build() | ||
| self.main_source_file = lldb.SBFileSpec("main.c") | ||
| self.delete_others_test() | ||
|
|
||
| def delete_others_test(self): | ||
| """You might use the test implementation in several ways, say so here.""" | ||
|
|
||
| # This function starts a process, "a.out" by default, sets a source | ||
| # breakpoint, runs to it, and returns the thread, process & target. | ||
| # It optionally takes an SBLaunchOption argument if you want to pass | ||
| # arguments or environment variables. | ||
| (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( | ||
| self, "Set a breakpoint here", self.main_source_file | ||
| ) | ||
|
|
||
| # Now set a breakpoint on "I did something" several times | ||
| # | ||
| bkpt_numbers = [] | ||
| for idx in range(0, 5): | ||
| bkpt_numbers.append( | ||
| lldbutil.run_break_set_by_source_regexp(self, "// Deletable location") | ||
| ) | ||
|
|
||
| # And add commands to the third one to delete two others: | ||
| deleter = target.FindBreakpointByID(bkpt_numbers[2]) | ||
| self.assertTrue(deleter.IsValid(), "Deleter is a good breakpoint") | ||
| commands = lldb.SBStringList() | ||
| deleted_ids = [bkpt_numbers[0], bkpt_numbers[3]] | ||
| for idx in deleted_ids: | ||
| commands.AppendString(f"break delete {idx}") | ||
|
|
||
| deleter.SetCommandLineCommands(commands) | ||
|
|
||
| thread_list = lldbutil.continue_to_breakpoint(process, deleter) | ||
| self.assertEqual(len(thread_list), 1) | ||
| stop_data = thread.stop_reason_data | ||
| # There are 5 breakpoints so 10 break_id, break_loc_id. | ||
| self.assertEqual(len(stop_data), 10) | ||
| # We should have been able to get break ID's and locations for all the | ||
| # breakpoints that we originally hit, but some won't be around anymore: | ||
| for idx in range(0, 5): | ||
| bkpt_id = stop_data[idx * 2] | ||
| print(f"{idx}: {bkpt_id}") | ||
| self.assertIn(bkpt_id, bkpt_numbers, "Found breakpoints are right") | ||
| loc_id = stop_data[idx * 2 + 1] | ||
| self.assertEqual(loc_id, 1, "All breakpoints have one location") | ||
| bkpt = target.FindBreakpointByID(bkpt_id) | ||
| if bkpt_id in deleted_ids: | ||
| # Looking these up should be an error: | ||
| self.assertFalse(bkpt.IsValid(), "Deleted breakpoints are deleted") | ||
| else: | ||
| self.assertTrue(bkpt.IsValid(), "The rest are still valid") |
12 changes: 12 additions & 0 deletions
12
lldb/test/API/functionalities/breakpoint/callback_deletes_breakpoints/main.c
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #include <stdio.h> | ||
|
|
||
| int do_something(int input) { | ||
| return input % 5; // Deletable location | ||
| } | ||
|
|
||
| int main() { | ||
| printf("Set a breakpoint here.\n"); | ||
| do_something(100); | ||
| do_something(200); | ||
| return 0; | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need our own refcount? The shared pointer already maintains a ref count. Why can't we use that? This seems like a recipe for leaks if we don't remember to keep the two in sync.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ref count was to handle the case where this BreakpointLocationCollection has two locations from the same breakpoint. If you remove one of the locations, you still nee to keep the breakpoint alive for the second location. The other way to do this would be to have the {breakpoint id, breakpoint location id} be the key and add BreakpointSP's for each location's breakpoint.
This way seemedd simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Off-line Jonas expressed a preference for holding a BreakpointSP per location to simplify the code. So I pushed a change to do that.