]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_transform/lib/Transform.cpp
Security-58286.260.20.tar.gz
[apple/security.git] / OSX / libsecurity_transform / lib / Transform.cpp
index 9046c3ce161829cad1e9cbcc2b39f2df264104af..a9d1fc7c878c576aac690006b2fa74f15c1f4c2f 100644 (file)
@@ -265,7 +265,12 @@ bool Transform::HasNoOutboundConnections()
 {
        // make an array big enough to hold all of the attributes
        CFIndex numAttributes = CFSetGetCount(mAttributes);
 {
        // make an array big enough to hold all of the attributes
        CFIndex numAttributes = CFSetGetCount(mAttributes);
-       transform_attribute* attributes[numAttributes];
+       transform_attribute **attributes = (transform_attribute**)malloc(numAttributes*sizeof(transform_attribute));
+       
+       if (attributes == NULL) {
+               // No more memory, we assume it's orphaned
+               return true;
+       }
        
        TAGetAll(attributes);
        
        
        TAGetAll(attributes);
        
@@ -275,10 +280,13 @@ bool Transform::HasNoOutboundConnections()
        {
                if (attributes[i]->connections && CFArrayGetCount(attributes[i]->connections) != 0)
                {
        {
                if (attributes[i]->connections && CFArrayGetCount(attributes[i]->connections) != 0)
                {
+                       free(attributes);
                        return false;
                }
        }
        
                        return false;
                }
        }
        
+       free(attributes);
+       
        return true;
 }
 
        return true;
 }
 
@@ -288,7 +296,12 @@ bool Transform::HasNoInboundConnections()
 {
        // make an array big enough to hold all of the attributes
        CFIndex numAttributes = CFSetGetCount(mAttributes);
 {
        // make an array big enough to hold all of the attributes
        CFIndex numAttributes = CFSetGetCount(mAttributes);
-       transform_attribute* attributes[numAttributes];
+       transform_attribute **attributes = (transform_attribute**)malloc(numAttributes*sizeof(transform_attribute));
+       
+       if (attributes == NULL) {
+               // No more memory, we assume it's orphaned
+               return true;
+       }
        
        TAGetAll(attributes);
        
        
        TAGetAll(attributes);
        
@@ -298,10 +311,13 @@ bool Transform::HasNoInboundConnections()
        {
                if (attributes[i]->has_incoming_connection)
                {
        {
                if (attributes[i]->has_incoming_connection)
                {
+                       free(attributes);
                        return false;
                }
        }
        
                        return false;
                }
        }
        
+       free(attributes);
+       
        return true;
 }
 
        return true;
 }
 
@@ -413,8 +429,14 @@ void Transform::FinalizePhase2()
 void Transform::FinalizeForClang()
 {
        CFIndex numAttributes = CFSetGetCount(mAttributes);
 void Transform::FinalizeForClang()
 {
        CFIndex numAttributes = CFSetGetCount(mAttributes);
-       SecTransformAttributeRef handles[numAttributes];
-       CFSetGetValues(mAttributes, (const void**)&handles);
+       SecTransformAttributeRef *handles = (const void**)malloc(numAttributes*sizeof(SecTransformAttributeRef));
+       
+       if (handles == NULL) {
+               syslog(LOG_ERR, "Unable to allocate SecTransformAttributeRef handles in FinalizeForClang");
+               return;
+       }
+    
+       CFSetGetValues(mAttributes, handles);
        
        for(CFIndex i = 0; i < numAttributes; ++i) {
                SecTransformAttributeRef ah = handles[i];
        
        for(CFIndex i = 0; i < numAttributes; ++i) {
                SecTransformAttributeRef ah = handles[i];
@@ -431,7 +453,7 @@ void Transform::FinalizeForClang()
                }
                dispatch_release(ta->q);
        }
                }
                dispatch_release(ta->q);
        }
-       
+    
        // We might be finalizing a transform as it is being activated, make sure that is complete before we do the rest
     dispatch_group_notify(mActivationPending, mDispatchQueue, ^{
         if (mActivationQueue != NULL) {
        // We might be finalizing a transform as it is being activated, make sure that is complete before we do the rest
     dispatch_group_notify(mActivationPending, mDispatchQueue, ^{
         if (mActivationQueue != NULL) {
@@ -446,6 +468,8 @@ void Transform::FinalizeForClang()
         });
         dispatch_release(mDispatchQueue);
     });
         });
         dispatch_release(mDispatchQueue);
     });
+       
+       free(handles);
 }
 
 void Transform::Finalize()
 }
 
 void Transform::Finalize()
@@ -1598,9 +1622,17 @@ CFDictionaryRef Transform::GetAHDictForSaveState(SecTransformStringOrAttributeRe
 CFDictionaryRef Transform::CopyState()
 {
        CFIndex i, j, cnt = CFSetGetCount(mAttributes);
 CFDictionaryRef Transform::CopyState()
 {
        CFIndex i, j, cnt = CFSetGetCount(mAttributes);
-       transform_attribute *attrs[cnt];
-       CFStringRef names[cnt];
-       CFDictionaryRef values[cnt];
+       transform_attribute **attrs = (transform_attribute**)malloc(cnt*sizeof(transform_attribute));
+       CFStringRef *names = (CFStringRef*)malloc(cnt*sizeof(CFStringRef));
+       CFDictionaryRef *values = (CFDictionaryRef*)malloc(sizeof(CFDictionaryRef) * cnt);
+    
+    if (attrs == NULL || names == NULL || values == NULL) {
+        free(attrs);
+        free(names);
+               free(values);
+        return NULL;
+    }
+
        TAGetAll(attrs);
        for(i = j = 0; i < cnt; ++i)
        {
        TAGetAll(attrs);
        for(i = j = 0; i < cnt; ++i)
        {
@@ -1613,7 +1645,9 @@ CFDictionaryRef Transform::CopyState()
        }
        
        CFDictionaryRef result = CFDictionaryCreate(NULL, (const void**)&names, (const void**)&values, j, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
        }
        
        CFDictionaryRef result = CFDictionaryCreate(NULL, (const void**)&names, (const void**)&values, j, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
-       
+    
+    free(names);
+    
        for(i = j = 0; i < cnt; ++i)
        {
                transform_attribute *ta = attrs[i];
        for(i = j = 0; i < cnt; ++i)
        {
                transform_attribute *ta = attrs[i];
@@ -1623,6 +1657,8 @@ CFDictionaryRef Transform::CopyState()
                }
        }
        
                }
        }
        
+    free(attrs);
+       free(values);
        return result;
 }
 
        return result;
 }
 
@@ -1783,7 +1819,12 @@ CFErrorRef Transform::ProcessExternalize(CFMutableArrayRef transforms, CFMutable
        
        // now walk the attribute list
        CFIndex numAttributes = CFSetGetCount(mAttributes);
        
        // now walk the attribute list
        CFIndex numAttributes = CFSetGetCount(mAttributes);
-       transform_attribute *attributes[numAttributes];
+       transform_attribute **attributes = (transform_attribute**)malloc(numAttributes*sizeof(transform_attribute));
+       
+       if (attributes == NULL) {
+               return GetNoMemoryErrorAndRetain();
+       }
+       
        TAGetAll(attributes);
        
        CFIndex i;
        TAGetAll(attributes);
        
        CFIndex i;
@@ -1819,5 +1860,7 @@ CFErrorRef Transform::ProcessExternalize(CFMutableArrayRef transforms, CFMutable
                }
        }
        
                }
        }
        
+       free(attributes);
+       
        return NULL;
 }
        return NULL;
 }