From bbcb50de8d60158067913e27908f43593c8c23c4 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 3 Jan 2018 17:55:30 -0800 Subject: Validation fixes for #1317 (#1347) * add get_global/set_global validation * validate get_local index * update builds * fix tests --- src/wasm/wasm-validator.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index df88a5f32..26b8c66b6 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -228,6 +228,8 @@ public: void visitCallIndirect(CallIndirect *curr); void visitGetLocal(GetLocal* curr); void visitSetLocal(SetLocal *curr); + void visitGetGlobal(GetGlobal* curr); + void visitSetGlobal(SetGlobal *curr); void visitLoad(Load *curr); void visitStore(Store *curr); void visitAtomicRMW(AtomicRMW *curr); @@ -470,6 +472,7 @@ void FunctionValidator::visitCallIndirect(CallIndirect *curr) { } void FunctionValidator::visitGetLocal(GetLocal* curr) { + shouldBeTrue(curr->index < getFunction()->getNumLocals(), curr, "get_local index must be small enough"); shouldBeTrue(isConcreteWasmType(curr->type), curr, "get_local must have a valid type - check what you provided when you constructed the node"); } @@ -483,6 +486,19 @@ void FunctionValidator::visitSetLocal(SetLocal *curr) { } } +void FunctionValidator::visitGetGlobal(GetGlobal* curr) { + if (!info.validateGlobally) return; + shouldBeTrue(getModule()->getGlobalOrNull(curr->name) || getModule()->getImportOrNull(curr->name), curr, "get_global name must be valid"); +} + +void FunctionValidator::visitSetGlobal(SetGlobal *curr) { + if (!info.validateGlobally) return; + auto* global = getModule()->getGlobalOrNull(curr->name); + shouldBeTrue(global, curr, "set_global name must be valid (and not an import; imports can't be modified)"); + shouldBeTrue(global->mutable_, curr, "set_global global must be mutable"); + shouldBeEqualOrFirstIsUnreachable(curr->value->type, global->type, curr, "set_global value must have right type"); +} + void FunctionValidator::visitLoad(Load *curr) { if (curr->isAtomic) shouldBeTrue(info.features & Feature::Atomics, curr, "Atomic operation (atomics are disabled)"); shouldBeFalse(curr->isAtomic && !getModule()->memory.shared, curr, "Atomic operation with non-shared memory"); -- cgit v1.2.3