Skip to content

Commit 09e8844

Browse files
Riley Bertonfacebook-github-bot
authored andcommitted
Fix undefined behavior in MethodInvoker (facebook#46188)
Summary: Pull Request resolved: facebook#46188 UBSAN identified undefined behavior when argCount == 0 (defining a variable array of zero length). Plus variable arrays in C++ are a clang extension. [ChangeLog]: [General] [Fixed] - Undefined behavior fix in MethodInvoker Reviewed By: nlutsenko Differential Revision: D61725776 fbshipit-source-id: 3729080eae8e78b65a558305f68782ae99edbc0a
1 parent 8d3c4fb commit 09e8844

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/react-native/ReactAndroid/src/main/jni/react/jni/MethodInvoker.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ MethodCallResult MethodInvoker::invoke(
229229
auto env = Environment::current();
230230
auto argCount = signature_.size() - 2;
231231
JniLocalScope scope(env, static_cast<int>(argCount));
232-
jvalue args[argCount];
232+
std::vector<jvalue> argsStorage(
233+
argCount + 1); // ensure we have at least 1 element
234+
jvalue* args = argsStorage.data();
233235
std::transform(
234236
signature_.begin() + 2,
235237
signature_.end(),

0 commit comments

Comments
 (0)