fix(vm): validate arg count before OpCall #904
+30
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
See OSS-Fuzz finding #903. The expression
$env(''matches' '? :now().UTC(g).d)//caused:The expression bypasses compile-time type checking due to
$env(...)being treated as an unknown type. Also the ternary operator deferring evaluation. Then at runtimeUTC()is called with an argument - even though it takes none. When theOpCallhandler accessesfnType.In(0)without checking its length, an index out of bounds panic happens, although recovered by the VM.Changes
Added argument count validation in VM before attempting to call functions. Including a regression test.
Further comments
Functions that return no values are already caught by the checker at compile time, so the
out[0]access afterfn.Call()remains safe.Regression from #889.
Nice edge case catched by the fuzzer.