Skip to content

Commit

Permalink
Fix for GTMSessionFetcherService: do not use session delegate if it's…
Browse files Browse the repository at this point in the history
… not an instance of GTMSessionFetcherSessionDelegateDispatcher class (so, self-protected from the session delegate swizzling)
  • Loading branch information
gelosi committed Oct 24, 2018
1 parent 0ab03f2 commit 8a98220
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Source/GTMSessionFetcherService.m
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,19 @@ - (void)startFetcher:(GTMSessionFetcher *)fetcher {
}

// Internal utility. Returns a fetcher's delegate if it's a dispatcher, or nil if the fetcher
// is its own delegate and has no dispatcher.
// is its either own delegate and has no dispatcher or swizzled alien.
- (GTMSessionFetcherSessionDelegateDispatcher *)delegateDispatcherForFetcher:(GTMSessionFetcher *)fetcher {
GTMSessionCheckNotSynchronized(self);

NSURLSession *fetcherSession = fetcher.session;
if (fetcherSession) {
id<NSURLSessionDelegate> fetcherDelegate = fetcherSession.delegate;
BOOL hasDispatcher = (fetcherDelegate != nil && fetcherDelegate != fetcher);
if (hasDispatcher) {
BOOL maybeHasDispatcher = (fetcherDelegate != nil && fetcherDelegate != fetcher);
GTMSESSION_ASSERT_DEBUG([fetcherDelegate isKindOfClass:[GTMSessionFetcherSessionDelegateDispatcher class]],
@"Fetcher delegate class: %@", [fetcherDelegate class]);

if (maybeHasDispatcher && [fetcherDelegate isKindOfClass:GTMSessionFetcherSessionDelegateDispatcher.class]) {
return (GTMSessionFetcherSessionDelegateDispatcher *)fetcherDelegate;
}
}
Expand Down

0 comments on commit 8a98220

Please sign in to comment.