From 62e164909d3f41caa1dd5507b3b0f2e43e11b1e1 Mon Sep 17 00:00:00 2001 From: mtb0x1 <39337159+mtb0x1@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:11:17 +0200 Subject: [PATCH 1/3] fix null dereference --- src/wasm/wasm-validator.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 0bdc186584a..4c56902db17 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -606,9 +606,13 @@ struct FunctionValidator : public WalkerPass> { 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; From e7cdbf929a322c7fb76136c57643e165cb72d402 Mon Sep 17 00:00:00 2001 From: mtb0x1 Date: Sun, 25 Aug 2024 20:16:32 +0200 Subject: [PATCH 2/3] regression test case --- test/lit/validation/function-missing.wast | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/lit/validation/function-missing.wast diff --git a/test/lit/validation/function-missing.wast b/test/lit/validation/function-missing.wast new file mode 100644 index 00000000000..dbbc45c45ad --- /dev/null +++ b/test/lit/validation/function-missing.wast @@ -0,0 +1,12 @@ +;; Test that we validate functions declaration and usage for globals. + +;; RUN: not wasm-opt %s -all 2>&1 | filecheck %s + +(module + ;; CHECK: function not defined + (global (mut i32)(block)) + + ;; CHECK: function not defined + (global (mut i32)(return_call 0)) + (func $0(return_call 0)(return_call 0)) +) \ No newline at end of file From d638947004f12c535e212e0cd0717db42a1f34f2 Mon Sep 17 00:00:00 2001 From: mtb Date: Mon, 26 Aug 2024 22:20:21 +0200 Subject: [PATCH 3/3] lint test case Co-authored-by: Alon Zakai --- test/lit/validation/function-missing.wast | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/lit/validation/function-missing.wast b/test/lit/validation/function-missing.wast index dbbc45c45ad..5510644a7ea 100644 --- a/test/lit/validation/function-missing.wast +++ b/test/lit/validation/function-missing.wast @@ -3,10 +3,12 @@ ;; RUN: not wasm-opt %s -all 2>&1 | filecheck %s (module - ;; CHECK: function not defined - (global (mut i32)(block)) + ;; CHECK: function not defined + (global (mut i32) (block)) - ;; CHECK: function not defined - (global (mut i32)(return_call 0)) - (func $0(return_call 0)(return_call 0)) + ;; CHECK: function not defined + (global (mut i32) (return_call 0)) + + (func $0 + ) ) \ No newline at end of file