Permalink
Browse files

Fix a potential exception password data can't be pared correctly.

  • Loading branch information...
1 parent 3a6d43c commit 3281505c3dd15d47da1e6dbf4701e40ca3b93234 Michael Gorbach committed Nov 27, 2010
Showing with 5 additions and 2 deletions.
  1. +5 −2 MFSecurity.m
View
7 MFSecurity.m
@@ -70,22 +70,25 @@
int port = [[[fs parameters] objectForKey:kNetFSPortParameter] intValue];
NSString *hostName = [[fs parameters] objectForKey:kNetFSHostParameter];
SecProtocolType protocol = [[[fs parameters] objectForKey:kNetFSProtocolParameter] intValue];
+ NSString *passwordToReturn = nil;
if (userName && hostName && port && protocol) {
OSStatus error = SecKeychainFindInternetPassword(NULL,[hostName lengthOfBytesUsingEncoding: NSUTF8StringEncoding],[hostName UTF8String],0,NULL,[userName lengthOfBytesUsingEncoding: NSUTF8StringEncoding],[userName UTF8String],0,NULL,port,protocol,(SecAuthenticationType)NULL,&passwordLength,&passwordData,itemRef);
if (error == noErr) {
// MFLogS(self, @"Successfully found internet password for fs %@", fs);
NSString *password = [NSString stringWithCString:passwordData encoding:NSUTF8StringEncoding];
SecKeychainItemFreeContent(NULL, passwordData);
- return [NSDictionary dictionaryWithObject: password forKey: kNetFSPasswordParameter];
+ if (password) {
+ passwordToReturn = password;
+ }
} else {
// MFLogS(self, @"Error searching for internet password fs %@ error %d", fs, error);
}
} else {
// MFLogS(self, @"No network info to search for fs %@", fs);
}
- return nil;
+ return passwordToReturn ? [NSDictionary dictionaryWithObject:passwordToReturn forKey:kNetFSPasswordParameter] : nil;
}
NSDictionary *getGenericSecretsForFilesystem(MFFilesystem* fs) {

0 comments on commit 3281505

Please sign in to comment.