Skip to content

Commit 1c8e82f

Browse files
authored
Merge pull request #4010 from wmathurin/fix/safe-dict-nil-key-crash
Add nil key guards to SFSDKSafeMutableDictionary
2 parents d6ec210 + 82dc4ce commit 1c8e82f

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

libs/SalesforceSDKCommon/SalesforceSDKCommon/Classes/Util/SFSDKSafeMutableDictionary.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
#import "SFSDKSafeMutableDictionary.h"
26+
#import "SFLogger.h"
2627

2728
@interface SFSDKSafeMutableDictionary()
2829

@@ -89,6 +90,10 @@ - (NSDictionary *)dictionary {
8990
#pragma Mark - Mutating Methods
9091

9192
- (void)setObject:(id)object forKey:(id<NSCopying>)aKey {
93+
if (aKey == nil) {
94+
[SFLogger w:[self class] format:@"Attempted to set object with nil key in safe dictionary"];
95+
return;
96+
}
9297
dispatch_barrier_async(self.queue, ^{
9398
self.backingDictionary[aKey] = object;
9499
});
@@ -99,6 +104,10 @@ - (void)setObject:(id)object forKeyedSubscript:(id<NSCopying>)aKey {
99104
}
100105

101106
- (void)removeObject:(id<NSCopying>)aKey {
107+
if (aKey == nil) {
108+
[SFLogger w:[self class] format:@"Attempted to remove nil key from safe dictionary"];
109+
return;
110+
}
102111
dispatch_barrier_async(self.queue, ^{
103112
[self.backingDictionary removeObjectForKey:aKey];
104113
});

0 commit comments

Comments
 (0)