Skip to content

Commit

Permalink
Fix undefined behavior in MethodInvoker (#46188)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
Riley Berton authored and facebook-github-bot committed Aug 23, 2024
1 parent 8d3c4fb commit 09e8844
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ MethodCallResult MethodInvoker::invoke(
auto env = Environment::current();
auto argCount = signature_.size() - 2;
JniLocalScope scope(env, static_cast<int>(argCount));
jvalue args[argCount];
std::vector<jvalue> argsStorage(
argCount + 1); // ensure we have at least 1 element
jvalue* args = argsStorage.data();
std::transform(
signature_.begin() + 2,
signature_.end(),
Expand Down

0 comments on commit 09e8844

Please sign in to comment.