diff options
author | Alon Zakai <azakai@google.com> | 2022-12-08 09:03:48 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-08 09:03:48 -0800 |
commit | 2cb5cefb6392619d908ce2ab683815d7e22ac9a5 (patch) | |
tree | 260a30a79fdd9ec04820cb47ca4335afce0473cf /src/wasm/wasm-s-parser.cpp | |
parent | c79548b93a81ccf7609413da1345a7570c51b9ba (diff) | |
download | binaryen-2cb5cefb6392619d908ce2ab683815d7e22ac9a5.tar.gz binaryen-2cb5cefb6392619d908ce2ab683815d7e22ac9a5.tar.bz2 binaryen-2cb5cefb6392619d908ce2ab683815d7e22ac9a5.zip |
Validate ref.as_* argument is a reference (#5330)
Without this we hit an assert with no line number info (or in a no-asserts build,
bad things can happen). With this:
$ bin/wasm-opt -all ~/Downloads/crash.wat --nominal
[parse exception: Invalid ref for ref.as (at 155065:119)]
Fatal: error parsing wasm
(That can only happen for ref.as_non_null, as all the others do not have that
assert - their types do not depend on the child's type, so their finalize does not
error. Still, it is nice to validate earlier for them as well, so this PR handles them
all.)
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index ee9fdde72..507cf3b6c 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2945,7 +2945,11 @@ Expression* SExpressionWasmBuilder::makeArrayCopy(Element& s) { } Expression* SExpressionWasmBuilder::makeRefAs(Element& s, RefAsOp op) { - return Builder(wasm).makeRefAs(op, parseExpression(s[1])); + auto* value = parseExpression(s[1]); + if (!value->type.isRef() && value->type != Type::unreachable) { + throw ParseException("ref.as child must be a ref", s.line, s.col); + } + return Builder(wasm).makeRefAs(op, value); } Expression* SExpressionWasmBuilder::makeStringNew(Element& s, StringNewOp op) { |