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

Embr 6517 thena t0q1bf4ua 5769 repeated crashes in ios embrace sdk 6 x with thread sanitizer warning #172

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ class URLSessionDelegateProxy: NSObject {

// check if the originalDelegate responds to the selector
if let originalDelegate = originalDelegate,
originalDelegate.responds(to: selector) {
originalDelegate.responds(to: selector) {
// Add protection against self-delegation
guard !(originalDelegate is URLSessionDelegateProxy) else {
return .doesNotRespond
}

if let delegateAsT = originalDelegate as? T {
return .respondsAndConforms(as: delegateAsT)
} else if let object = originalDelegate as? NSObject {
Expand All @@ -90,6 +95,17 @@ class URLSessionDelegateProxy: NSObject {
// if session delegate also responds to selector, we must call it
if let sessionDelegate = session.delegate,
sessionDelegate.responds(to: selector) {
// Guard that we are not the session.delegate to prevent infinite recursion
guard (sessionDelegate as? URLSessionDelegateProxy) != self,
!(sessionDelegate is URLSessionDelegateProxy) else {
return .doesNotRespond
}

// Avoid forwarding if already swizzled
guard self.swizzledDelegate == nil else {
return .doesNotRespond
}

if let sessionDelegateAsT = sessionDelegate as? T {
return .respondsAndConforms(as: sessionDelegateAsT)
} else if let object = sessionDelegate as? NSObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ struct URLSessionInitWithDelegateSwizzler: URLSessionSwizzler {
return originalImplementation(urlSession, Self.selector, configuration, delegate, queue)
}

// Add protection against re-proxying our own proxy
guard !(proxiedDelegate is URLSessionDelegateProxy) else {
return originalImplementation(urlSession, Self.selector, configuration, delegate, queue)
}

let newDelegate = URLSessionDelegateProxy(originalDelegate: proxiedDelegate, handler: handler)
let session = originalImplementation(urlSession, Self.selector, configuration, newDelegate, queue)

Expand Down
Loading