diff options
author | mtb <mtb0x10x1@gmail.com> | 2024-08-26 23:13:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-26 14:13:39 -0700 |
commit | 50181145e39304785ccedcd84be9cb7cc428b1f2 (patch) | |
tree | fae4b293735ed04727d16247f01b9fa9e88dae32 /src/wasm/wasm-validator.cpp | |
parent | b7af8dac2fe457d47d6b29cabb8327457341bffe (diff) | |
download | binaryen-50181145e39304785ccedcd84be9cb7cc428b1f2.tar.gz binaryen-50181145e39304785ccedcd84be9cb7cc428b1f2.tar.bz2 binaryen-50181145e39304785ccedcd84be9cb7cc428b1f2.zip |
Fix null dereference in FunctionValidator (#6849)
visitBlock() and validateCallParamsAndResult() both assumed they were
running inside a function, but might be called on global code too. Calls
and blocks are invalid in global positions, so we should error there, but
must do so properly without a null deref.
Fixes #6847
Fixes #6848
Diffstat (limited to 'src/wasm/wasm-validator.cpp')
-rw-r--r-- | src/wasm/wasm-validator.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 4881ea7ac..f77eeefe7 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -606,9 +606,13 @@ private: Type(Type::unreachable), printable, "return_call* should have unreachable type"); + auto* func = getFunction(); + if (!shouldBeTrue(!!func, curr, "function not defined")) { + return; + } shouldBeSubType( sig.results, - getFunction()->getResults(), + func->getResults(), printable, "return_call* callee return type must match caller return type"); } else { @@ -696,7 +700,12 @@ void FunctionValidator::visitBlock(Block* curr) { } breakTypes.erase(iter); } - switch (getFunction()->profile) { + + auto* func = getFunction(); + if (!shouldBeTrue(!!func, curr, "function not defined")) { + return; + } + switch (func->profile) { case IRProfile::Normal: validateNormalBlockElements(curr); break; |