summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai (kripken) <alonzakai@gmail.com>2017-05-29 13:56:25 -0700
committerAlon Zakai <alonzakai@gmail.com>2017-06-01 13:17:44 -0700
commit989c5295deebe71e4bf80e6cc5ae4f334134f9ea (patch)
tree1f11f5d945175cfa5d9eddb65b93952bd0a8ef14
parent7438fbd5cb4d882584f405ae37e726fd14928f4d (diff)
downloadbinaryen-989c5295deebe71e4bf80e6cc5ae4f334134f9ea.tar.gz
binaryen-989c5295deebe71e4bf80e6cc5ae4f334134f9ea.tar.bz2
binaryen-989c5295deebe71e4bf80e6cc5ae4f334134f9ea.zip
handle duplicate imports and globals in s-expr parsing
-rw-r--r--src/wasm/wasm-s-parser.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 614b30bdd..10d4c3f17 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -576,6 +576,7 @@ void SExpressionWasmBuilder::parseFunction(Element& s, bool preParseImport) {
im->base = importBase;
im->kind = ExternalKind::Function;
im->functionType = wasm.getFunctionType(type)->name;
+ if (wasm.getImportOrNull(im->name)) throw ParseException("duplicate import", s.line, s.col);
wasm.addImport(im.release());
if (currFunction) throw ParseException("import module inside function dec");
assert(!currFunction);
@@ -1431,6 +1432,7 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) {
im->module = importModule;
im->base = importBase;
im->name = importModule;
+ if (wasm.getImportOrNull(im->name)) throw ParseException("duplicate import", s.line, s.col);
wasm.addImport(im.release());
i++;
} else {
@@ -1653,6 +1655,7 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
wasm.memory.max = atoi(inner[j++]->c_str());
}
}
+ if (wasm.getImportOrNull(im->name)) throw ParseException("duplicate import", s.line, s.col);
wasm.addImport(im.release());
}
@@ -1707,6 +1710,7 @@ void SExpressionWasmBuilder::parseGlobal(Element& s, bool preParseImport) {
im->base = importBase;
im->kind = ExternalKind::Global;
im->globalType = type;
+ if (wasm.getImportOrNull(im->name)) throw ParseException("duplicate import", s.line, s.col);
wasm.addImport(im.release());
return;
}
@@ -1719,6 +1723,7 @@ void SExpressionWasmBuilder::parseGlobal(Element& s, bool preParseImport) {
}
global->mutable_ = mutable_;
if (i != s.size()) throw ParseException("extra import elements");
+ if (wasm.getGlobalOrNull(global->name)) throw ParseException("duplicate import", s.line, s.col);
wasm.addGlobal(global.release());
}
@@ -1753,6 +1758,7 @@ void SExpressionWasmBuilder::parseTable(Element& s, bool preParseImport) {
im->module = importModule;
im->base = importBase;
im->name = importModule;
+ if (wasm.getImportOrNull(im->name)) throw ParseException("duplicate import", s.line, s.col);
wasm.addImport(im.release());
i++;
} else {