From c5fbd3a5ad14f14a9726942750e0cb95c1e08066 Mon Sep 17 00:00:00 2001 From: Nassim 'Nass' Eddequiouaq Date: Wed, 8 Mar 2017 18:54:09 +0100 Subject: [PATCH] Fix type conversion for labels added to search queries on macOS Signed-off-by: Nassim 'Nass' Eddequiouaq --- osxkeychain/osxkeychain_darwin.c | 6 +++++- osxkeychain/osxkeychain_darwin_test.go | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/osxkeychain/osxkeychain_darwin.c b/osxkeychain/osxkeychain_darwin.c index 5b420d0..f84d61e 100644 --- a/osxkeychain/osxkeychain_darwin.c +++ b/osxkeychain/osxkeychain_darwin.c @@ -135,16 +135,20 @@ char * CFStringToCharArr(CFStringRef aString) { } char *keychain_list(char *credsLabel, char *** paths, char *** accts, unsigned int *list_l) { + CFStringRef credsLabelCF = CFStringCreateWithCString(NULL, credsLabel, kCFStringEncodingUTF8); CFMutableDictionaryRef query = CFDictionaryCreateMutable (NULL, 1, NULL, NULL); CFDictionaryAddValue(query, kSecClass, kSecClassInternetPassword); CFDictionaryAddValue(query, kSecReturnAttributes, kCFBooleanTrue); CFDictionaryAddValue(query, kSecMatchLimit, kSecMatchLimitAll); - CFDictionaryAddValue(query, kSecAttrLabel, CFSTR(credsLabel)); + CFDictionaryAddValue(query, kSecAttrLabel, credsLabelCF); //Use this query dictionary CFTypeRef result= NULL; OSStatus status = SecItemCopyMatching( query, &result); + + CFRelease(credsLabelCF); + //Ran a search and store the results in result if (status) { return get_error(status); diff --git a/osxkeychain/osxkeychain_darwin_test.go b/osxkeychain/osxkeychain_darwin_test.go index bbfe1ff..9cfb108 100644 --- a/osxkeychain/osxkeychain_darwin_test.go +++ b/osxkeychain/osxkeychain_darwin_test.go @@ -7,13 +7,13 @@ import ( func TestOSXKeychainHelper(t *testing.T) { creds := &credentials.Credentials{ - Label: credentials.CredsLabel, + Label: credentials.CredsLabel, ServerURL: "https://foobar.docker.io:2376/v1", Username: "foobar", Secret: "foobarbaz", } creds1 := &credentials.Credentials{ - Label: credentials.CredsLabel, + Label: credentials.CredsLabel, ServerURL: "https://foobar.docker.io:2376/v2", Username: "foobarbaz", Secret: "foobar",