X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/5c19dc3ae3bd8e40a9c028b0deddd50ff337692c..07691282a056c4efea71e1e505527601e8cc166b:/OSX/libsecurity_pkcs12/lib/pkcs12Utils.cpp diff --git a/OSX/libsecurity_pkcs12/lib/pkcs12Utils.cpp b/OSX/libsecurity_pkcs12/lib/pkcs12Utils.cpp index 7ad4593c..ba1ea6f1 100644 --- a/OSX/libsecurity_pkcs12/lib/pkcs12Utils.cpp +++ b/OSX/libsecurity_pkcs12/lib/pkcs12Utils.cpp @@ -104,7 +104,7 @@ void p12IntToData( } /* CFDataRef <--> CSSM_DATA */ -CFDataRef p12CssmDataToCf( +CFDataRef CF_RETURNS_RETAINED p12CssmDataToCf( const CSSM_DATA &c) { return CFDataCreate(NULL, c.Data, c.Length); @@ -133,14 +133,18 @@ CSSM_DATA_PTR p12StringToUtf8( if(cfStr == NULL) { return NULL; } - CFIndex strLen = CFStringGetLength(cfStr); + + CFIndex strLen = 0; + CFRange range = { 0, CFStringGetLength(cfStr) }; + CFStringGetBytes(cfStr, range, kCFStringEncodingUTF8, 0, FALSE, NULL, 0, &strLen); if(strLen == 0) { return NULL; } + CSSM_DATA_PTR rtn = coder.mallocn(); - coder.allocItem(*rtn, strLen + 1); - if(!CFStringGetCString(cfStr, (char *)rtn->Data,strLen + 1, - kCFStringEncodingUTF8)) { + coder.allocItem(*rtn, strLen); + + if(!CFStringGetBytes(cfStr, range, kCFStringEncodingUTF8, 0, FALSE, (UInt8*)rtn->Data, strLen, &strLen)) { /* not convertible from native Unicode to UTF8 */ return NULL; }