From 51246e91d7709ea1083039be88b9076bec7b3c44 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 4 Sep 2009 11:07:42 +0000 Subject: =?UTF-8?q?=E2=80=A2=20the=20in=20r1313=20introduced=20method=20[N?= =?UTF-8?q?SString=20stringWithCString:encoding:]=20must=20be=20a=20\0=20t?= =?UTF-8?q?erminated=20cString=20-=20fixed=20that=20and=20replaced=20the?= =?UTF-8?q?=20deprecated=20method=20[NSString=20stringWithCString:length]?= =?UTF-8?q?=20again?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPKeychain.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Source/SPKeychain.m') diff --git a/Source/SPKeychain.m b/Source/SPKeychain.m index 4a62c310..e808d3ea 100644 --- a/Source/SPKeychain.m +++ b/Source/SPKeychain.m @@ -129,6 +129,7 @@ NULL, // default keychain strlen([name UTF8String]), // length of service name (bytes) [name UTF8String], // service name + strlen([account UTF8String]), // length of account name (bytes) [account UTF8String], // account name &passwordLength, // length of password @@ -137,9 +138,13 @@ ); if (status == noErr) { - password = [NSString stringWithCString:passwordData length:passwordLength]; - // password = [NSString stringWithCString:passwordData encoding:NSUTF8StringEncoding]; - + // Create a \0 terminated cString out of passwordData + char passwordBuf[passwordLength + 1]; + strncpy(passwordBuf, passwordData, (size_t)passwordLength); + passwordBuf[passwordLength] = '\0'; + + password = [NSString stringWithCString:passwordBuf encoding:NSUTF8StringEncoding]; + // Free the data allocated by SecKeychainFindGenericPassword: SecKeychainItemFreeContent( NULL, // No attribute data to release -- cgit v1.2.3