diff options
author | rowanbeentje <rowan@beent.je> | 2009-08-11 22:48:35 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-08-11 22:48:35 +0000 |
commit | 8db453b2c23e84e16c492f0a0856463bb866c620 (patch) | |
tree | 83f62a8318d0d82bd79b9ceb94bad4794a3e5828 | |
parent | 9c4f6b6fd05acc7e10ac50ddf66eb25f5cf9344f (diff) | |
download | sequelpro-8db453b2c23e84e16c492f0a0856463bb866c620.tar.gz sequelpro-8db453b2c23e84e16c492f0a0856463bb866c620.tar.bz2 sequelpro-8db453b2c23e84e16c492f0a0856463bb866c620.zip |
- Merge in r1191 from SP0.9.6 branch, fixing a crasher for blank passwords by checking a keychain item is present before trying to load it
- Also make keychain checks more robust when supplying nil values as some of the parameters
-rw-r--r-- | Source/SPKeychain.m | 27 | ||||
-rw-r--r-- | Source/TableDocument.m | 9 |
2 files changed, 28 insertions, 8 deletions
diff --git a/Source/SPKeychain.m b/Source/SPKeychain.m index 9aea5248..0929317d 100644 --- a/Source/SPKeychain.m +++ b/Source/SPKeychain.m @@ -48,7 +48,12 @@ SecAccessRef passwordAccessRef; SecKeychainAttribute attributes[4]; SecKeychainAttributeList attList; - + + // Check supplied variables and replaces nils with empty strings + if (!name) name = @""; + if (!account) account = @""; + if (!label) label = @""; + // Check if password already exists before adding if (![self passwordExistsForName:name account:account]) { @@ -109,7 +114,11 @@ UInt32 passwordLength; SecKeychainItemRef itemRef; NSString *password = @""; - + + // Check supplied variables and replaces nils with empty strings + if (!name) name = @""; + if (!account) account = @""; + status = SecKeychainFindGenericPassword( NULL, // default keychain strlen([name UTF8String]), // length of service name (bytes) @@ -142,6 +151,10 @@ OSStatus status; SecKeychainItemRef itemRef = nil; + // Check supplied variables and replaces nils with empty strings + if (!name) name = @""; + if (!account) account = @""; + // Check if password already exists before deleting if ([self passwordExistsForName:name account:account]) { status = SecKeychainFindGenericPassword( @@ -177,7 +190,11 @@ int numberOfItemsFound = 0; SecKeychainAttributeList list; SecKeychainAttribute attributes[2]; - + + // Check supplied variables and replaces nils with empty strings + if (!name) name = @""; + if (!account) account = @""; + attributes[0].tag = kSecAccountItemAttr; attributes[0].data = (void *)[account UTF8String]; // Account name attributes[0].length = strlen([account UTF8String]); // Length of account name (bytes) @@ -209,7 +226,7 @@ NSString *keychainItemName; keychainItemName = [NSString stringWithFormat:@"Sequel Pro : %@ (%i)", - theName, + theName?theName:@"", [theID intValue]]; return keychainItemName; @@ -238,7 +255,7 @@ NSString *sshKeychainItemName; sshKeychainItemName = [NSString stringWithFormat:@"Sequel Pro SSHTunnel : %@ (%i)", - theName, + theName?theName:@"", [theID intValue]]; return sshKeychainItemName; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index a7c0d176..c36a2e35 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -2426,11 +2426,14 @@ * Invoked when the current connection needs a password from the Keychain. */ - (NSString *)keychainPasswordForConnection:(MCPConnection *)connection -{ - SPKeychain *keychain = [[SPKeychain alloc] init]; +{ + // If no keychain item is available, return an empty password + if (![connectionController connectionKeychainItemName]) return @""; + + // Otherwise, pull the password from the keychain using the details from this connection + SPKeychain *keychain = [[SPKeychain alloc] init]; NSString *password = [keychain getPasswordForName:[connectionController connectionKeychainItemName] account:[connectionController connectionKeychainItemAccount]]; - [keychain release]; return password; |