From 4114d88e5457da33cc4641c041be3b55c2c33469 Mon Sep 17 00:00:00 2001 From: James Lin Date: Thu, 16 Aug 2018 15:33:17 -0700 Subject: [PATCH] Fix potential null pointer dereference in FlutterDartProject If `FlutterDartProject` found an `FLTLibraryPath` entry in an iOS application's `Info.plist`, it assumed that values that were valid filesystem paths were paths to bundles. If the attempt to retrieve the `NSBundle` fails, `FlutterDartProject` ignored the failure and then would assign `nil` to a C++ `std::string`, resulting in a null pointer dereference. Add some failure checks to prevent this. --- .../ios/framework/Source/FlutterDartProject.mm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index d2073fabc2e3d..a89c61acfccb7 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -73,8 +73,10 @@ NSString* libraryName = [mainBundle objectForInfoDictionaryKey:@"FLTLibraryPath"]; NSString* libraryPath = [mainBundle pathForResource:libraryName ofType:@""]; if (libraryPath.length > 0) { - settings.application_library_path = - [NSBundle bundleWithPath:libraryPath].executablePath.UTF8String; + NSString* executablePath = [NSBundle bundleWithPath:libraryPath].executablePath; + if (executablePath.length > 0) { + settings.application_library_path = executablePath.UTF8String; + } } } @@ -84,8 +86,11 @@ NSString* applicationFrameworkPath = [mainBundle pathForResource:@"Frameworks/App.framework" ofType:@""]; if (applicationFrameworkPath.length > 0) { - settings.application_library_path = - [NSBundle bundleWithPath:applicationFrameworkPath].executablePath.UTF8String; + NSString* executablePath = + [NSBundle bundleWithPath:applicationFrameworkPath].executablePath; + if (executablePath.length > 0) { + settings.application_library_path = executablePath.UTF8String; + } } } }