Skip to content

Commit b7a3a2f

Browse files
authored
Merge pull request Expensify#91076 from software-mansion-labs/war-in/fix-uaf-crash
2 parents a7cf976 + 33f2bbd commit b7a3a2f

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

patches/react-native/details.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@
265265
- Upstream PR/issue: [facebook/react-native#51835](https://github.com/facebook/react-native/pull/51835)
266266
- E/App issue: [#59953](https://github.com/Expensify/App/issues/59953)
267267
268+
### [react-native+0.83.1+036+fix-turbomodule-event-emitter-uaf.patch](react-native+0.83.1+036+fix-turbomodule-event-emitter-uaf.patch)
269+
270+
- Reason: Fixes an Android use-after-free crash in `JavaTurboModule::configureEventEmitterCallback`. The event-emitter callback lambda captured `this` by reference (`[&]`), so when the C++ TurboModule was deallocated (e.g. on screen unmount) a background thread invoking the callback would dereference freed memory via `eventEmitterMap_[name]` and crash with `SIGSEGV`. The fix copies the `shared_ptr` map by value into the lambda and replaces `operator[]` with `find()` + null-check, which both keeps the map alive for the callback's lifetime and avoids inserting empty entries on missing keys.
271+
- Upstream PR/issue: [facebook/react-native#55398](https://github.com/facebook/react-native/pull/55398)
272+
- E/App issue: [#90623](https://github.com/Expensify/App/issues/90623)
273+
268274
### [react-native+0.83.1+036+rounded-inline-code-background.patch](react-native+0.83.1+036+rounded-inline-code-background.patch)
269275
270276
- Reason: Draws inline code block background with rounded corners on iOS when `borderTopLeftRadius` is set.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
diff --git a/node_modules/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp b/node_modules/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp
2+
index 5c9b464..5766844 100644
3+
--- a/node_modules/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp
4+
+++ b/node_modules/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp
5+
@@ -982,12 +982,17 @@ void JavaTurboModule::configureEventEmitterCallback() {
6+
FACEBOOK_JNI_THROW_PENDING_EXCEPTION();
7+
}
8+
9+
- auto callback = JCxxCallbackImpl::newObjectCxxArgs([&](folly::dynamic args) {
10+
- auto eventName = args.at(0).asString();
11+
- auto& eventEmitter = static_cast<AsyncEventEmitter<folly::dynamic>&>(
12+
- *eventEmitterMap_[eventName].get());
13+
- eventEmitter.emit(args.size() > 1 ? std::move(args).at(1) : nullptr);
14+
- });
15+
+ auto emitterMap = eventEmitterMap_;
16+
+ auto callback =
17+
+ JCxxCallbackImpl::newObjectCxxArgs([emitterMap](folly::dynamic args) {
18+
+ auto eventName = args.at(0).asString();
19+
+ auto it = emitterMap.find(eventName);
20+
+ if (it != emitterMap.end() && it->second) {
21+
+ auto& eventEmitter =
22+
+ static_cast<AsyncEventEmitter<folly::dynamic>&>(*it->second);
23+
+ eventEmitter.emit(args.size() > 1 ? std::move(args).at(1) : nullptr);
24+
+ }
25+
+ });
26+
27+
jvalue args[1];
28+
args[0].l = callback.release();

0 commit comments

Comments
 (0)