]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_transform/lib/SecCustomTransform.cpp
Security-59754.60.13.tar.gz
[apple/security.git] / OSX / libsecurity_transform / lib / SecCustomTransform.cpp
index e8a243e8ed58af686b7c43010513b23b7b0faeb4..4d29a3d0ca25ea078e9dba31c0136c015ba87cf9 100644 (file)
 #include "Utilities.h"
 #include "misc.h"
 
-static const CFStringRef kSecCustom = CFSTR("CustomTransform");
+const CFStringRef kSecCustom = CFSTR("CustomTransform");
 const CFStringRef kSecTransformPreviousErrorKey = CFSTR("PreviousError");
 const CFStringRef kSecTransformAbortOriginatorKey = CFSTR("Originating Transform");
 const CFStringRef kSecTransformActionCanExecute = CFSTR("CanExecute");
-const CFStringRef kSecCustomTransformWhatIsRequired = CFSTR("WhatIsRequired");
-const CFStringRef kSecCustomTransformAttributesToExternalize = CFSTR("AttributesToExternalize");
 const CFStringRef kSecTransformActionStartingExecution = CFSTR("ExecuteStarting");
 const CFStringRef kSecTransformActionProcessData = CFSTR("TransformProcessData");
 const CFStringRef kSecTransformActionAttributeNotification = CFSTR("GenericAttributeSetNotification");
@@ -305,14 +303,14 @@ public:
 };
 
 
-static SecTransformActionBlock default_can_run = ^{ return (CFTypeRef)NULL; };
-static SecTransformActionBlock default_execute_starting = default_can_run;
-static SecTransformActionBlock default_finalize = default_execute_starting;
-static SecTransformActionBlock default_externalize_data = default_finalize;
+static const SecTransformActionBlock default_can_run = ^{ return (CFTypeRef)NULL; };
+static const SecTransformActionBlock default_execute_starting = default_can_run;
+static const SecTransformActionBlock default_finalize = default_execute_starting;
+static const SecTransformActionBlock default_externalize_data = default_finalize;
 
-static SecTransformDataBlock default_process_data = ^(CFTypeRef value) { return value; };
+static const SecTransformDataBlock default_process_data = ^(CFTypeRef value) { return value; };
 //static SecTransformDataBlock default_validate = ^(CFTypeRef value) { return (CFTypeRef)NULL; };
-static SecTransformAttributeActionBlock default_generic_attribute_set_notification = 
+static const SecTransformAttributeActionBlock default_generic_attribute_set_notification =
        ^(SecTransformAttributeRef ah, CFTypeRef value) { return value; };
 
 static SecTransformAttributeActionBlock default_generic_attribute_validation = 
@@ -569,12 +567,15 @@ CustomTransformFactory::CustomTransformFactory(CFStringRef uniqueName, SecTransf
     RegisterTransform(this, kSecCustom);
 }
 
-CFTypeRef CustomTransformFactory::Make() 
+// clang cannot possibly reason about the way in which we turn Transforms into CFRefs, and it just looks like a leak
+#ifndef __clang_analyzer__
+CFTypeRef CustomTransformFactory::Make() CF_RETURNS_RETAINED
 {
        CustomTransform *ct = new CustomTransform(this->GetTypename(), createFuncPtr);
        ct->Create();
        return ct->get_ref();
 }
+#endif
 
 #pragma mark MISC
 
@@ -592,12 +593,12 @@ extern "C" {
                                                                                                                          null_allowed ? CFSTR(" either") : CFSTR(""),
                                                                                                                          expected_type_name,
                                                                                                                          null_allowed ? CFSTR(" or a NULL") : CFSTR(""));
-                               CFRelease(value_type_name);
+                               CFReleaseNull(value_type_name);
                        } else {
                                error = CreateSecTransformErrorRef(kSecTransformErrorInvalidType, "%@ received NULL value, expected a %@",
                                                                                                   attr, expected_type_name);
                        }
-                       CFRelease(expected_type_name);
+                       CFReleaseNull(expected_type_name);
                        
                        return error;
                };
@@ -623,6 +624,8 @@ extern "C" {
        }
 }
 
+// clang cannot reason about this business of creating an object for the side-effects of doing so
+#ifndef __clang_analyzer__
 Boolean SecTransformRegister(CFStringRef uniqueName, SecTransformCreateFP createFP, CFErrorRef *caller_error) 
 {
        CFErrorRef error = NULL;
@@ -642,6 +645,7 @@ Boolean SecTransformRegister(CFStringRef uniqueName, SecTransformCreateFP create
                return TRUE;
        }
 }
+#endif
 
 SecTransformRef SecTransformCreate(CFStringRef name, CFErrorRef *error) 
 {
@@ -752,12 +756,15 @@ void CustomTransform::AttributeChanged(SecTransformAttributeRef ah, CFTypeRef va
        if (vr) {
                        if (CFGetTypeID(vr) == CFErrorGetTypeID()) {
                                        SendAttribute(AbortAH, vr);
-                                       CFRelease(vr);
+                                       CFReleaseNull(vr);
                        } else {
-                                       CFErrorRef e = CreateSecTransformErrorRef(kSecTransformErrorInvalidType, "Invalid return type from a validate action, expected a CFErrorRef got a %@ (%@)", CFCopyTypeIDDescription(CFGetTypeID(vr)), vr);
+                    CFStringRef idDescription = CFCopyTypeIDDescription(CFGetTypeID(vr));
+                                       CFErrorRef e = CreateSecTransformErrorRef(kSecTransformErrorInvalidType, "Invalid return type from a validate action, expected a CFErrorRef got a %@ (%@)", idDescription, vr);
                                        SendAttribute(AbortAH, e);
-                                       CFRelease(vr);
-                                       // XXX: this causes a core dump -- I think AbortAH doesn't take it's own reference!!   CFRelease(e);
+                                       CFReleaseNull(vr);
+                    CFReleaseNull(e);
+                    CFReleaseNull(idDescription);
+                                       // XXX: this causes a core dump -- I think AbortAH doesn't take it's own reference!!   CFReleaseNull(e);
                        }
                        return;
        }
@@ -781,7 +788,7 @@ void CustomTransform::AttributeChanged(SecTransformAttributeRef ah, CFTypeRef va
 
                 if (output != value && output != NULL)
                 {
-                    CFRelease(output);
+                    CFReleaseNull(output);
                 }
                        }
                } 
@@ -840,7 +847,7 @@ CFTypeRef CustomTransform::rebind_data_action(CFStringRef action,
         char *utf8_message = utf8(msg);
         syslog(LOG_ERR, "%s", utf8_message);
         free(utf8_message);
-        CFRelease(msg);
+        CFReleaseNull(msg);
        }
        return result;
 }
@@ -1024,7 +1031,7 @@ CFDictionaryRef CustomTransform::GetCustomExternalData()
        if (CFGetTypeID(result) == CFErrorGetTypeID())
        {
                // Ouch!  we should deal with this
-               CFRelease(result);
+               CFReleaseNull(result);
                return NULL;
        }
        
@@ -1033,7 +1040,7 @@ CFDictionaryRef CustomTransform::GetCustomExternalData()
                return (CFDictionaryRef)result;
        }
        
-       CFRelease(result);
+       CFReleaseNull(result);
        result = NULL;
        return (CFDictionaryRef)result;
 }
@@ -1055,9 +1062,9 @@ CFErrorRef SecTransformSetAttributeAction(SecTransformImplementationRef ref,
 {
        if (NULL == ref)
        {
-                CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput, 
+        CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
                        "SecTransformSetAttributeNotificationAction called with a NULL SecTransformImplementationRef ref");
-                       
+        CFAutorelease(result);
                return result;
        }
        
@@ -1070,9 +1077,9 @@ CFErrorRef SecTransformSetDataAction(SecTransformImplementationRef ref,
 {
        if (NULL == ref)
        {
-                CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput, 
+        CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
                        "SecTransformSetAttributeNotificationAction called with a NULL SecTransformImplementationRef ref");
-                       
+        CFAutorelease(result);
                return result;
        }
        
@@ -1085,9 +1092,9 @@ CFErrorRef SecTransformSetTransformAction(SecTransformImplementationRef ref,
 {
        if (NULL == ref)
        {
-                CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput, 
+        CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
                        "SecTransformSetAttributeNotificationAction called with a NULL SecTransformImplementationRef ref");
-                       
+        CFAutorelease(result);
                return result;
        }
        
@@ -1102,7 +1109,7 @@ CFTypeRef SecTranformCustomGetAttribute(SecTransformImplementationRef ref,
        {
         CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput, 
                                                        "SecTransformCustomGetAttribute called with a NULL SecTransformImplementationRef ref");
-        
+        CFAutorelease(result);
                return result;
        }
        
@@ -1116,9 +1123,9 @@ CFTypeRef SecTransformCustomSetAttribute(SecTransformImplementationRef ref,
 {
        if (NULL == ref)
        {
-                CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput, 
+        CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
                        "SecTransformCustomSetAttribute called with a NULL SecTransformImplementationRef ref");
-                       
+        CFAutorelease(result);
                return result;
        }
        
@@ -1132,9 +1139,9 @@ CFTypeRef SecTransformPushbackAttribute(SecTransformImplementationRef ref,
 {
        if (NULL == ref)
        {
-                CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput, 
+        CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
                        "SecTransformPushbackAttribute called with a NULL SecTransformImplementationRef ref");
-                       
+        CFAutorelease(result);
                return (CFTypeRef)result;
        }