summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/emscripten-optimizer/istring.h4
-rw-r--r--src/emscripten-optimizer/simple_ast.h1
-rw-r--r--src/wasm/wasm-binary.cpp3
-rw-r--r--src/wasm/wasm-s-parser.cpp3
4 files changed, 11 insertions, 0 deletions
diff --git a/src/emscripten-optimizer/istring.h b/src/emscripten-optimizer/istring.h
index 5a7d05162..5c3b094c3 100644
--- a/src/emscripten-optimizer/istring.h
+++ b/src/emscripten-optimizer/istring.h
@@ -149,6 +149,10 @@ struct IString {
bool startsWith(const char *prefix) const {
return stripPrefix(prefix) != nullptr;
}
+
+ size_t size() const {
+ return str ? strlen(str) : 0;
+ }
};
} // namespace cashew
diff --git a/src/emscripten-optimizer/simple_ast.h b/src/emscripten-optimizer/simple_ast.h
index de8122ba1..f38377e70 100644
--- a/src/emscripten-optimizer/simple_ast.h
+++ b/src/emscripten-optimizer/simple_ast.h
@@ -561,6 +561,7 @@ struct JSPrinter {
void printAst() {
print(ast);
+ ensure(1);
buffer[used] = 0;
}
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;