From fce8ed15630a4969be7c9761b9b7d3cef0530cc6 Mon Sep 17 00:00:00 2001 From: Diego <96022404+dzfrias@users.noreply.github.com> Date: Thu, 4 Jul 2024 08:40:36 -0700 Subject: [PATCH] LibWasm: Validate potentially empty `else` branch in `if` instruction --- Userland/Libraries/LibWasm/AbstractMachine/Validator.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Validator.cpp b/Userland/Libraries/LibWasm/AbstractMachine/Validator.cpp index faa9ae9873e..325bd0dda5c 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Validator.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/Validator.cpp @@ -1939,6 +1939,13 @@ VALIDATE_INSTRUCTION(structured_end) auto& last_frame = m_frames.last(); + // If this is true, then the `if` had no else. In that case, validate that the + // empty else block produces the correct type. + if (last_frame.kind == FrameKind::If) { + bool is_constant = false; + TRY(validate(Instruction(Instructions::structured_else), stack, is_constant)); + } + auto& results = last_frame.type.results(); for (size_t i = 1; i <= results.size(); ++i) TRY(stack.take(results[results.size() - i]));