Skip to content
Closed
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
13 changes: 11 additions & 2 deletions FirebasePerformance/Sources/Instrumentation/FPRNetworkTrace.m
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,17 @@ - (void)didCompleteRequestWithResponse:(NSURLResponse *)response error:(NSError
self.responseCode = (int32_t)HTTPResponse.statusCode;
}
self.responseError = error;
// Safely copy MIMEType to prevent use after free
NSString *mime = [response.MIMEType copy];
// Defensive access to MIMEType
NSString *mime = nil;
@try {
// Safely copy MIMEType to prevent use after free
mime = [response.MIMEType copy];
} @catch (NSException *exception) {
FPRLogWarning(@"MIMETypeException",
@"Exception while accessing MIMEType for URL %@: %@. Trace will continue "
@"without MIMEType.",
self.URLRequest.URL, exception);
}
Comment on lines +254 to +264
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe a crash like this can be handled. Only NSExceptions can be handled and there isn't one being raised here. This crash is coming at a lower level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would wrapping the 2 lines I already contributed in a if (response) for example would be a better solution? (of course keeping tabs if the crash ever shows up again)

Copy link
Member

Choose a reason for hiding this comment

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

No, because in order for the getMIMEType method to appear in the stack trace, the response is non-nil. Because if the response was nil, the MIMEType call would be a no-op.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok got it, I'm a bit out of ideas maybe I can do a bit more research and try a better solution for this

Thanks Nick

self.responseContentType = (mime.length ? mime : nil);
[self checkpointState:FPRNetworkTraceCheckpointStateResponseCompleted];

Expand Down
Loading