Skip to content

Commit

Permalink
Prevent Nullptr segfault in TurboModule init path
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Apr 26, 2022
1 parent 36c4e42 commit 7f3cc25
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,19 @@ - (TurboModuleHolder *)_getOrCreateTurboModuleHolder:(const char *)moduleName
std::lock_guard<std::mutex> delegateGuard(_turboModuleManagerDelegateMutex);
module = [_delegate getModuleInstanceFromClass:moduleClass];
}

/**
* If the application is unable to create the TurboModule object from its class:
* abort TurboModule creation, and early return nil.
*/
if (!module) {
RCTLogWarn(
@"TurboModuleManager delegate %@ returned nil TurboModule object for module with name=\"%s\" and class=%@",
NSStringFromClass([_delegate class]),
moduleName,
NSStringFromClass(moduleClass));
return nil;
}
} else {
module = [moduleClass new];
}
Expand Down

0 comments on commit 7f3cc25

Please sign in to comment.