diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 3 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 985a38be5..ac68cbe56 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1505,6 +1505,9 @@ void WasmBinaryBuilder::processFunctions() { auto index = exportIndexes[curr]; switch (curr->kind) { case ExternalKind::Function: { + if (index >= wasm.functions.size()) { + throwError("bad function export index"); + } curr->value = getFunctionIndexName(index); break; } diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index fe622f54a..eca4c7493 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -580,6 +580,7 @@ void SExpressionWasmBuilder::parseFunction(Element& s, bool preParseImport) { } if (importModule.is()) { // this is an import, actually + if (!importBase.size()) throw ParseException("module but no base for import"); if (!preParseImport) throw ParseException("!preParseImport in func"); auto im = make_unique<Function>(); im->name = name; @@ -1571,6 +1572,7 @@ void SExpressionWasmBuilder::parseImport(Element& s) { auto module = s[i++]->str(); if (!s[i]->isStr()) throw ParseException("no name for import"); auto base = s[i++]->str(); + if (!module.size() || !base.size()) throw ParseException("imports must have module and base"); // parse internals Element& inner = newStyle ? *s[3] : s; Index j = newStyle ? newStyleInner : i; @@ -1694,6 +1696,7 @@ void SExpressionWasmBuilder::parseGlobal(Element& s, bool preParseImport) { } if (importModule.is()) { // this is an import, actually + if (!importBase.size()) throw ParseException("module but no base for import"); if (!preParseImport) throw ParseException("!preParseImport in global"); auto im = make_unique<Global>(); im->name = global->name; |