Skip to content

Commit

Permalink
Remove uses of implicit conversion of ScopedTypeRef in iOS code in /c…
Browse files Browse the repository at this point in the history
…rypto

Implicit unwrapping of a scoper to its underlying pointer is dangerous
and that capability is being removed. This converts uses of implicit
conversion to be explicit so that implicit unwrapping can be removed.
This also may perform other cleanup and modernization.

Bug: 1495439
Change-Id: I8dd640b2126e40349e13855c41600d9211862996
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5002755
Commit-Queue: David Benjamin <davidben@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Reviewed-by: David Benjamin <davidben@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1219496}
  • Loading branch information
Avi Drissman authored and Chromium LUCI CQ committed Nov 3, 2023
1 parent 96ceadf commit 64adc11
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions crypto/apple_keychain_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
// Set the service name.
CFDictionarySetValue(
query, kSecAttrService,
StringWithBytesAndLength(serviceName, serviceNameLength));
StringWithBytesAndLength(serviceName, serviceNameLength).get());

// Set the account name.
CFDictionarySetValue(
query, kSecAttrAccount,
StringWithBytesAndLength(accountName, accountNameLength));
StringWithBytesAndLength(accountName, accountNameLength).get());

// Use the proper search constants, return only the data of the first match.
CFDictionarySetValue(query, kSecMatchLimit, kSecMatchLimitOne);
Expand Down Expand Up @@ -89,12 +89,12 @@
// Set the service name.
CFDictionarySetValue(
keychain_data, kSecAttrService,
StringWithBytesAndLength(serviceName, serviceNameLength));
StringWithBytesAndLength(serviceName, serviceNameLength).get());

// Set the account name.
CFDictionarySetValue(
keychain_data, kSecAttrAccount,
StringWithBytesAndLength(accountName, accountNameLength));
StringWithBytesAndLength(accountName, accountNameLength).get());

return base::apple::ScopedCFTypeRef<CFDictionaryRef>(keychain_data);
}
Expand Down Expand Up @@ -124,21 +124,21 @@
MakeGenericPasswordQuery(serviceNameLength, serviceName,
accountNameLength, accountName);
// Check that there is not already a password.
OSStatus status = SecItemCopyMatching(query, /*result=*/nullptr);
OSStatus status = SecItemCopyMatching(query.get(), /*result=*/nullptr);
if (status == errSecItemNotFound) {
// A new entry must be created.
base::apple::ScopedCFTypeRef<CFDictionaryRef> keychain_data =
MakeKeychainData(serviceNameLength, serviceName, accountNameLength,
accountName, passwordLength, passwordData,
kKeychainActionCreate);
status = SecItemAdd(keychain_data, /*result=*/nullptr);
status = SecItemAdd(keychain_data.get(), /*result=*/nullptr);
} else if (status == noErr) {
// The entry must be updated.
base::apple::ScopedCFTypeRef<CFDictionaryRef> keychain_data =
MakeKeychainData(serviceNameLength, serviceName, accountNameLength,
accountName, passwordLength, passwordData,
kKeychainActionUpdate);
status = SecItemUpdate(query, keychain_data);
status = SecItemUpdate(query.get(), keychain_data.get());
}

return status;
Expand All @@ -160,7 +160,7 @@

// Get the keychain item containing the password.
base::apple::ScopedCFTypeRef<CFTypeRef> result;
OSStatus status = SecItemCopyMatching(query, result.InitializeInto());
OSStatus status = SecItemCopyMatching(query.get(), result.InitializeInto());

if (status != noErr) {
if (passwordData) {
Expand All @@ -171,7 +171,7 @@
}

if (passwordData) {
CFDataRef data = base::apple::CFCast<CFDataRef>(result);
CFDataRef data = base::apple::CFCast<CFDataRef>(result.get());
NSUInteger length = CFDataGetLength(data);
*passwordData = malloc(length * sizeof(UInt8));
CFDataGetBytes(data, CFRangeMake(0, length), (UInt8*)*passwordData);
Expand Down

0 comments on commit 64adc11

Please sign in to comment.