Skip to content
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

fix: avoid call to possibly crashing mach_thread_deallocate #3364

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

- Add thread id and name to span data (#3359)

### Improvements
### Fixes

- Stop sending empty thread names (#3361)
- Work around edge case with a thread info kernel call sometimes returning invalid data, leading to a crash (#3364)

## 8.14.2

Expand Down
3 changes: 3 additions & 0 deletions Sources/Sentry/SentryBacktrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace profiling {
} else {
current = getFrameAddress(&machineContext);
}

// Even if this bounds check passes, the frame pointer address could still be invalid if the
// thread was suspended in an inconsistent state. The best we can do is to detect these
// situations at symbolication time on the server and filter them out -- there's not an easy
Expand All @@ -76,6 +77,7 @@ namespace profiling {
if (UNLIKELY(!isValidFrame(current, bounds))) {
return 0;
}

bool reachedEndOfStack = false;
while (depth < maxDepth) {
const auto frame = reinterpret_cast<StackFrame *>(current);
Expand All @@ -92,6 +94,7 @@ namespace profiling {
break;
}
}

if (LIKELY(reachedEndOfStackPtr != nullptr)) {
*reachedEndOfStackPtr = reachedEndOfStack;
}
Expand Down
5 changes: 2 additions & 3 deletions Sources/Sentry/SentryThreadHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ namespace profiling {
std::unique_ptr<ThreadHandle>
ThreadHandle::current() noexcept
{
const auto port = mach_thread_self();
SENTRY_PROF_LOG_KERN_RETURN(mach_port_deallocate(mach_task_self(), port));
return std::make_unique<ThreadHandle>(port);
const auto thread = pthread_mach_thread_np(pthread_self());
return std::make_unique<ThreadHandle>(thread);
}

std::vector<std::unique_ptr<ThreadHandle>>
Expand Down