]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_pkcs12/lib/pkcs12Utils.cpp
Security-58286.260.20.tar.gz
[apple/security.git] / OSX / libsecurity_pkcs12 / lib / pkcs12Utils.cpp
index 7ad4593c298ef3c2d966556d6ecd16d4735e3e97..ba1ea6f1ebee07dfa75b1909516f64cd0e9bd60f 100644 (file)
@@ -104,7 +104,7 @@ void p12IntToData(
 }
 
 /* CFDataRef <--> CSSM_DATA */
 }
 
 /* CFDataRef <--> CSSM_DATA */
-CFDataRef p12CssmDataToCf(
+CFDataRef CF_RETURNS_RETAINED p12CssmDataToCf(
        const CSSM_DATA &c)
 {
        return CFDataCreate(NULL, c.Data, c.Length);
        const CSSM_DATA &c)
 {
        return CFDataCreate(NULL, c.Data, c.Length);
@@ -133,14 +133,18 @@ CSSM_DATA_PTR p12StringToUtf8(
        if(cfStr == NULL) {
                return NULL;
        }
        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;
        }
        if(strLen == 0) {
                return NULL;
        }
+
        CSSM_DATA_PTR rtn = coder.mallocn<CSSM_DATA>();
        CSSM_DATA_PTR rtn = coder.mallocn<CSSM_DATA>();
-       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;
        }
                /* not convertible from native Unicode to UTF8 */
                return NULL;
        }