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 /Source/SPKeychain.m | |
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
Diffstat (limited to 'Source/SPKeychain.m')
-rw-r--r-- | Source/SPKeychain.m | 27 |
1 files changed, 22 insertions, 5 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; |