Search code examples
objective-cxcodecrash-reports

How to understand this crash?


Crash report:

0   ??? 0x0 + 0 
1   TestPrj -[AppListReader addInstalledApps:] (AppListReader.m:186) + 77516    
2   TestPrj -[AppListReader getAppsInstalled] (AppListReader.m:161) + 77320 
3   TestPrj -[DetectAppsInstalledService activate:] (DetectAppsInstalledService.m:48) + 197612  
4   TestPrj -[BusinessManager handleBG] (BusinessManager.m:762) + 116672    
5   TestPrj -[BusinessManager activate:] (BusinessManager.m:208) + 106236   
6   TestPrj -[AppDelegate launchViewController:] (AppDelegate.m:338) + 32564    
7   TestPrj -[AppDelegate application:didFinishLaunchingWithOptions:] (AppDelegate.m:153) + 27396   
8   UIKit   <redacted> + 316    
9   UIKit   <redacted> + 1564   
10  UIKit   <redacted> + 772    
11  UIKit   <redacted> + 3316   
12  UIKit   <redacted> + 104    
13  UIKit   <redacted> + 672    
14  GraphicsServices    <redacted> + 676    
15  GraphicsServices    <redacted> + 48 
16  CoreFoundation  <redacted> + 56 
17  CoreFoundation  <redacted> + 444    
18  CoreFoundation  <redacted> + 1620   
19  CoreFoundation  CFRunLoopRunSpecific + 452  
20  UIKit   <redacted> + 784    
21  UIKit   UIApplicationMain + 1156    
22  TestPrj main (main.m:21) + 23548    
23  libdyld.dylib   <redacted> + 4

Line 186 is:

NSMutableArray *allObjetcsArr = [self getInstalled];

This is implementation:

-(NSMutableArray *)getInstalled
{
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:@"ApplicationType",@"Any", [self defaultReturnAttributes] ,@"ReturnAttributes",nil];

    MobileInstallationLookup = dlsym(RTLD_DEFAULT, "MobileInstallationLookup");
    NSDictionary *apps = (__bridge NSDictionary *)((__bridge void*)MobileInstallationLookup(options));

    NSMutableArray *allObjetcsArr = [[NSMutableArray alloc]initWithArray:[apps allValues]];

    return allObjetcsArr;
}

Crash is received via BugSense and I am not able to reproduce it. I think it is related to MobileInstallationLookup framework (which is private api) but I am not sure.

It is not clear for me, why

-(NSMutableArray *)getInstalled

Is not present in stack trace, only ??? 0x0 + 0


Solution

  • My money is on these lines:

    MobileInstallationLookup = dlsym(RTLD_DEFAULT, "MobileInstallationLookup");
    NSDictionary *apps = (__bridge NSDictionary *)((__bridge void*)MobileInstallationLookup(options));
    
    • MobileInstallationLookup is obviously a global, but it's not clear why; for example if it's global they why is it being re-assigned in this method and why does the variable start with a capital letter (which is unconventional)?
    • There is no check to ensure that dlsym() succeeded, and dereferencing a null pointer would cause the crash you are getting.