keychainAPI.m revision 033a07e5fca459ed184369cfee7c90d82367a93a
1// RUN: %clang_cc1 -analyze -analyzer-checker=experimental.osx.KeychainAPI %s -verify
2
3// Fake typedefs.
4typedef unsigned int OSStatus;
5typedef unsigned int SecKeychainAttributeList;
6typedef unsigned int SecKeychainItemRef;
7typedef unsigned int SecItemClass;
8typedef unsigned int UInt32;
9typedef unsigned int CFTypeRef;
10typedef unsigned int UInt16;
11typedef unsigned int SecProtocolType;
12typedef unsigned int SecAuthenticationType;
13enum {
14  noErr                      = 0,
15  GenericError               = 1
16};
17
18// Functions that allocate data.
19OSStatus SecKeychainItemCopyContent (
20    SecKeychainItemRef itemRef,
21    SecItemClass *itemClass,
22    SecKeychainAttributeList *attrList,
23    UInt32 *length,
24    void **outData
25);
26OSStatus SecKeychainFindGenericPassword (
27    CFTypeRef keychainOrArray,
28    UInt32 serviceNameLength,
29    const char *serviceName,
30    UInt32 accountNameLength,
31    const char *accountName,
32    UInt32 *passwordLength,
33    void **passwordData,
34    SecKeychainItemRef *itemRef
35);
36OSStatus SecKeychainFindInternetPassword (
37    CFTypeRef keychainOrArray,
38    UInt32 serverNameLength,
39    const char *serverName,
40    UInt32 securityDomainLength,
41    const char *securityDomain,
42    UInt32 accountNameLength,
43    const char *accountName,
44    UInt32 pathLength,
45    const char *path,
46    UInt16 port,
47    SecProtocolType protocol,
48    SecAuthenticationType authenticationType,
49    UInt32 *passwordLength,
50    void **passwordData,
51    SecKeychainItemRef *itemRef
52);
53
54// Function which frees data.
55OSStatus SecKeychainItemFreeContent (
56    SecKeychainAttributeList *attrList,
57    void *data
58);
59
60int foo () {
61  unsigned int *ptr = 0;
62  OSStatus st = 0;
63
64  UInt32 length;
65  void *outData;
66
67  st = SecKeychainItemCopyContent(2, ptr, ptr, &length, &outData);
68  if (st == noErr)
69    SecKeychainItemFreeContent(ptr, outData);
70
71  return 0;
72}
73