Index: src/wasm/module-decoder.cc |
diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc |
index 8794fe64351ca17add7c44f5fa149f82796b0a82..857d1302ce59945075117129b111fe079aebcef4 100644 |
--- a/src/wasm/module-decoder.cc |
+++ b/src/wasm/module-decoder.cc |
@@ -910,6 +910,25 @@ class ModuleDecoder : public Decoder { |
switch (opcode) { |
case kExprGetGlobal: { |
GlobalIndexOperand operand(this, pc() - 1); |
+ if (module->globals.size() <= operand.index) { |
+ printf("error\n"); |
titzer
2016/11/09 13:26:43
stray printfs remaining here
ahaas
2016/11/09 14:21:16
Removed.
|
+ error("global index is out of bounds"); |
+ expr.kind = WasmInitExpr::kNone; |
+ expr.val.i32_const = 0; |
+ break; |
+ } |
+ WasmGlobal* global = &module->globals[operand.index]; |
+ if (!global || global->mutability || !global->imported) { |
titzer
2016/11/09 13:26:43
I don't think that !global can ever be true.
ahaas
2016/11/09 14:21:16
Removed.
|
+ printf("error\n"); |
+ error( |
+ "only immutable imported globals can be used in initializer " |
+ "expressions"); |
+ expr.kind = WasmInitExpr::kNone; |
+ expr.val.i32_const = 0; |
+ break; |
+ } else { |
+ printf("passed\n"); |
+ } |
expr.kind = WasmInitExpr::kGlobalIndex; |
expr.val.global_index = operand.index; |
len = operand.length; |