]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/Regressions/secitem/si-80-empty-data.c
Security-58286.230.21.tar.gz
[apple/security.git] / OSX / sec / Security / Regressions / secitem / si-80-empty-data.c
1 /*
2 * Copyright (c) 2014 Apple Inc. All Rights Reserved.
3 */
4
5 #include <CoreFoundation/CoreFoundation.h>
6 #include <Security/SecItem.h>
7 #include <Security/SecBase.h>
8 #include <utilities/array_size.h>
9 #include <utilities/SecCFWrappers.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12
13 #include "Security_regressions.h"
14
15 /* Test <rdar://problem/16669564>
16 Retrieving attributes and data when item contains no data crashed.
17 */
18
19 static void tests(void)
20 {
21 CFDictionaryRef item = CFDictionaryCreateForCFTypes(NULL,
22 kSecClass, kSecClassGenericPassword,
23 kSecAttrAccount, CFSTR("empty-data-account-test"),
24 kSecAttrService, CFSTR("empty-data-svce-test"),
25 NULL);
26 ok_status(SecItemAdd(item, NULL), "add generic password");
27
28 CFDictionaryRef query = CFDictionaryCreateForCFTypes(NULL,
29 kSecClass, kSecClassGenericPassword,
30 kSecAttrService, CFSTR("empty-data-svce-test"),
31 kSecMatchLimit, kSecMatchLimitAll,
32 kSecReturnData, kCFBooleanTrue,
33 kSecReturnAttributes, kCFBooleanTrue,
34 NULL);
35 CFTypeRef result;
36 ok_status(SecItemCopyMatching(query, &result), "query generic password");
37 ok(isArray(result) && CFArrayGetCount(result) == 1, "return 1-sized array of results");
38 CFDictionaryRef row = CFArrayGetValueAtIndex(result, 0);
39 ok(isDictionary(row), "array row is dictionary");
40 ok(CFDictionaryGetValue(row, kSecValueData) == NULL, "result contains no data");
41 ok(CFEqual(CFDictionaryGetValue(row, kSecAttrService), CFSTR("empty-data-svce-test")), "svce attribute is returned");
42 ok(CFEqual(CFDictionaryGetValue(row, kSecAttrAccount), CFSTR("empty-data-account-test")), "account attribute is returned");
43
44 CFRelease(result);
45 CFRelease(query);
46 query = CFDictionaryCreateForCFTypes(NULL,
47 kSecClass, kSecClassGenericPassword,
48 kSecAttrService, CFSTR("empty-data-svce-test"),
49 NULL);
50 ok_status(SecItemDelete(query), "delete testing item");
51
52 CFRelease(query);
53 CFRelease(item);
54 }
55
56 int si_80_empty_data(int argc, char *const *argv)
57 {
58 plan_tests(8);
59
60 tests();
61
62 return 0;
63 }