#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");
};
-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 =
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
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;
};
}
}
+// 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;
return TRUE;
}
}
+#endif
SecTransformRef SecTransformCreate(CFStringRef name, CFErrorRef *error)
{
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;
}
if (output != value && output != NULL)
{
- CFRelease(output);
+ CFReleaseNull(output);
}
}
}
char *utf8_message = utf8(msg);
syslog(LOG_ERR, "%s", utf8_message);
free(utf8_message);
- CFRelease(msg);
+ CFReleaseNull(msg);
}
return result;
}
if (CFGetTypeID(result) == CFErrorGetTypeID())
{
// Ouch! we should deal with this
- CFRelease(result);
+ CFReleaseNull(result);
return NULL;
}
return (CFDictionaryRef)result;
}
- CFRelease(result);
+ CFReleaseNull(result);
result = NULL;
return (CFDictionaryRef)result;
}
{
if (NULL == ref)
{
- CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
+ CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
"SecTransformSetAttributeNotificationAction called with a NULL SecTransformImplementationRef ref");
-
+ CFAutorelease(result);
return result;
}
{
if (NULL == ref)
{
- CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
+ CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
"SecTransformSetAttributeNotificationAction called with a NULL SecTransformImplementationRef ref");
-
+ CFAutorelease(result);
return result;
}
{
if (NULL == ref)
{
- CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
+ CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
"SecTransformSetAttributeNotificationAction called with a NULL SecTransformImplementationRef ref");
-
+ CFAutorelease(result);
return result;
}
{
CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
"SecTransformCustomGetAttribute called with a NULL SecTransformImplementationRef ref");
-
+ CFAutorelease(result);
return result;
}
{
if (NULL == ref)
{
- CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
+ CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
"SecTransformCustomSetAttribute called with a NULL SecTransformImplementationRef ref");
-
+ CFAutorelease(result);
return result;
}
{
if (NULL == ref)
{
- CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
+ CFErrorRef result = CreateSecTransformErrorRef(kSecTransformErrorInvalidInput,
"SecTransformPushbackAttribute called with a NULL SecTransformImplementationRef ref");
-
+ CFAutorelease(result);
return (CFTypeRef)result;
}