[NSString1 isEqualToString: NSString2] and [NSString UTF8String] crashes when it contains special characters ("_", "-", " ' ") only on iOS 15.5 or later

A framework is used in iOS application. In framework network change status is observed and callback code segment is something like this:

NSString *initialAPName = nil;

NSString* getSSID() {
    __block NSString *ssid = nil;
    dispatch_semaphore_t sem = dispatch_semaphore_create(0);
    [NEHotspotNetwork fetchCurrentWithCompletionHandler:^(NEHotspotNetwork * _Nullable currentNetwork) {
      if( currentNetwork != nil) {
        ssid = [currentNetwork SSID];
      } 
      dispatch_semaphore_signal(sem);
    }];
    dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC));
    dispatch_semaphore_wait(sem, timeout);

    return ssid;
}

static void onNotifyCallback(CFNotificationCenterRef center, void *observer, CFStringRef name,
                                            const void *object, CFDictionaryRef userInfo)
{
    NSString *apName = getSSID();

    if([apName isEqualToString:initialAPName]) { //Crashes here
        initialAPName = apName;
    }
}

Using of [NSString UTF8String] also crashes. The crash occurs only when apName contains special characters like (_, -, ') and it only occurs in iOS 15.5 or later.

I think it’s safe to assume that -isEqualToString: and -UTF8String work correctly — they are extremely well-used methods — and that there’s something wonky with your string.

With regards the code you posted, that’s being compiled into a framework, right? Is that compiled with ARC? Or with MRR?

Also, please run a test app that uses this code outside of Xcode, trigger the crash, and then post a full crash report. For advice on how to do that, see Posting a Crash Report.


Finally, your use a Dispatch semaphore for turning an asynchronous call into a synchronous one is worrisome for multiple reasons. While it’s probably not causing this specific issue, I encourage you to explore alternatives.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Yes. The problem is not with -isEqualToString: and -UTF8String. Can you please remove the post? There is no way from me to remove this.

Can you please remove the post? There is no way from me to remove this.

Right. We typically don’t remove threads here on DevForums (unless they contain something actively toxic).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[NSString1 isEqualToString: NSString2] and [NSString UTF8String] crashes when it contains special characters ("_", "-", " ' ") only on iOS 15.5 or later
 
 
Q