-
-
Notifications
You must be signed in to change notification settings - Fork 387
fix(macos): Don't overwrite exception value with notable addresses for AppKit _crashOnException crashes #7734
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
base: main
Are you sure you want to change the base?
Changes from all commits
e5e1005
0d8b3f7
97c61a2
8b035c3
934059d
0645819
1b6d1db
779f3e5
cba7a89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -460,7 +460,10 @@ - (SentryDebugMeta *)debugMetaFromBinaryImageDictionary:(NSDictionary *)sourceIm | |
| exception = [[SentryException alloc] initWithValue:@"Unknown Exception" type:exceptionType]; | ||
| } | ||
|
|
||
| [self enhanceValueFromNotableAddresses:exception]; | ||
| // AppKit's _crashOnException: produces garbage notable addresses; skip enhancement for those. | ||
| if (![self isMachExceptionFromAppKitCrashOnException]) { | ||
| [self enhanceValueFromNotableAddresses:exception]; | ||
| } | ||
|
|
||
| NSArray<NSString *> *crashInfoMessages = [self crashInfoMessagesFromBinaryImages]; | ||
|
|
||
|
|
@@ -518,6 +521,36 @@ - (SentryException *)parseNSException | |
| return [[SentryException alloc] initWithValue:reason type:type]; | ||
| } | ||
|
|
||
| /// EXC_BREAKPOINT with a top frame in AppKit indicates @c _crashOnException:. | ||
| - (BOOL)isMachExceptionFromAppKitCrashOnException | ||
| { | ||
| if ([self.threads count] == 0 || self.crashedThreadIndex >= [self.threads count]) { | ||
| return NO; | ||
| } | ||
|
|
||
| NSString *exceptionType = self.exceptionContext[@"type"]; | ||
| if (![exceptionType isEqualToString:@"mach"] && ![exceptionType isEqualToString:@"signal"]) { | ||
| return NO; | ||
| } | ||
|
|
||
| if (![self.exceptionContext[@"mach"][@"exception_name"] isEqualToString:@"EXC_BREAKPOINT"]) { | ||
| return NO; | ||
| } | ||
|
|
||
| // Only check top frames; AppKit is always deeper in the stack on macOS main-thread crashes. | ||
| NSArray *frames = [self rawStackTraceForThreadIndex:self.crashedThreadIndex]; | ||
| NSUInteger limit = MIN(frames.count, 3u); | ||
| for (NSUInteger i = 0; i < limit; i++) { | ||
| uintptr_t addr = (uintptr_t)[frames[i][@"instruction_addr"] unsignedLongLongValue]; | ||
| NSDictionary *image = [self binaryImageForAddress:addr]; | ||
| if (image != nil && [image[@"name"] rangeOfString:@"AppKit"].location != NSNotFound) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, will check if we have better heuristics for this so we only filter out unusual messages. |
||
| return YES; | ||
| } | ||
| } | ||
|
|
||
| return NO; | ||
| } | ||
|
|
||
| - (void)enhanceValueFromNotableAddresses:(SentryException *)exception | ||
| { | ||
| // Gatekeeper fixes https://github.com/getsentry/sentry-cocoa/issues/231 | ||
|
|
||
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.
Nil image name falsely matches AppKit substring check
Low Severity
If
image[@"name"]is nil,[nil rangeOfString:@"AppKit"]returns a zero-filledNSRangewithlocation = 0. SinceNSNotFoundisNSIntegerMax, the comparison.location != NSNotFoundevaluates toYES, causing a binary image with no name to be falsely identified as AppKit. This would makeisMachExceptionFromAppKitCrashOnExceptionreturnYESincorrectly, suppressing the notable address enhancement for crashes that aren't_crashOnException:.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.
I don't think there are images with no names, but we should cover ourselves just in case