Skip to content

Commit 7f3cc25

Browse files
RSNarafacebook-github-bot
authored andcommitted
Prevent Nullptr segfault in TurboModule init path
Summary: During the TurboModule init path, the TurboModuleManager asks the application to create the TurboModule object, given its class. If the application is unable to create the TurboModule object, what should we do? 0. **What we do now:** Continue executing TurboModule init path. 1. Silently return nil early. 2. Silently return nil early, and RCTLogError. If we Continue executing the TurobModule init path, we'll run into a segfault, because we'll call objc_setAssociatedObject(nil, ...). This diff prevents that segfault, by doing a silent return of nil. Changelog: [iOS][Fixed] - Prevent Nullptr segfault in TurboModule init path Reviewed By: fkgozali Differential Revision: D35942323 fbshipit-source-id: 7755800379c4bc733502314f3af3f401e9b04872
1 parent 36c4e42 commit 7f3cc25

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm

+13
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,19 @@ - (TurboModuleHolder *)_getOrCreateTurboModuleHolder:(const char *)moduleName
521521
std::lock_guard<std::mutex> delegateGuard(_turboModuleManagerDelegateMutex);
522522
module = [_delegate getModuleInstanceFromClass:moduleClass];
523523
}
524+
525+
/**
526+
* If the application is unable to create the TurboModule object from its class:
527+
* abort TurboModule creation, and early return nil.
528+
*/
529+
if (!module) {
530+
RCTLogWarn(
531+
@"TurboModuleManager delegate %@ returned nil TurboModule object for module with name=\"%s\" and class=%@",
532+
NSStringFromClass([_delegate class]),
533+
moduleName,
534+
NSStringFromClass(moduleClass));
535+
return nil;
536+
}
524537
} else {
525538
module = [moduleClass new];
526539
}

0 commit comments

Comments
 (0)