From 713729544370bb688af02512901a7f947738ca55 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 21 Sep 2013 21:52:29 +0200 Subject: [PATCH] Fix potential crash in case auth token request fails. Previously, the NSError generated by beginAuthWithCallbackURL:... if auth token or secret are missing sets the NSURLResponse object as NSLocalizedDescriptionKey. According to the docs, the object associated with NSLocalizedDescriptionKey must be a string. In particular, if you called -[NSError localizedDescription] on the object, a "unrecongnized selector 'length' sent to instance NSError" error occurred. This commit sets a string containing a generic error message including HTTP status code as NSLocalizedDescriptionKey. --- Classes/FlickrKit/FlickrKit.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Classes/FlickrKit/FlickrKit.m b/Classes/FlickrKit/FlickrKit.m index e492a02..35a9f89 100644 --- a/Classes/FlickrKit/FlickrKit.m +++ b/Classes/FlickrKit/FlickrKit.m @@ -211,8 +211,12 @@ - (FKDUNetworkOperation *) beginAuthWithCallbackURL:(NSURL *)url permission:(FKP NSString *oat = params[@"oauth_token"]; NSString *oats = params[@"oauth_token_secret"]; if (!oat || !oats) { - - NSDictionary *userInfo = @{NSLocalizedDescriptionKey: response}; + NSInteger statusCode = -1; + if ([response isKindOfClass:[NSHTTPURLResponse class]]) { + statusCode = ((NSHTTPURLResponse*)response).statusCode; + } + NSString* errorDescription = [NSString stringWithFormat:@"Unexpected response from server: %d", statusCode]; + NSDictionary *userInfo = @{NSLocalizedDescriptionKey: errorDescription}; NSError *error = [NSError errorWithDomain:FKFlickrKitErrorDomain code:FKErrorAuthenticating userInfo:userInfo]; if (completion) { completion(nil, error);