summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Winstein <208955+keithw@users.noreply.github.com>2024-11-11 21:10:52 -0800
committerGitHub <noreply@github.com>2024-11-12 05:10:52 +0000
commit958d0a72030227bf3133c8b99c7c670bcdbc7636 (patch)
tree626768a14e0bf13fbc9f144f2f38e6fec076705c
parent94c25a93c5ee81939bd1acfee06808f6745883ce (diff)
downloadwabt-958d0a72030227bf3133c8b99c7c670bcdbc7636.tar.gz
wabt-958d0a72030227bf3133c8b99c7c670bcdbc7636.tar.bz2
wabt-958d0a72030227bf3133c8b99c7c670bcdbc7636.zip
wast-parser.cc: Fix a crash from failing (module quote ...) (#2509)
-rw-r--r--src/wast-parser.cc6
-rw-r--r--test/wast2json/test-invalid-quoted-modules.txt8
2 files changed, 12 insertions, 2 deletions
diff --git a/src/wast-parser.cc b/src/wast-parser.cc
index e3606b7c..0868a217 100644
--- a/src/wast-parser.cc
+++ b/src/wast-parser.cc
@@ -3481,7 +3481,7 @@ Result WastParser::ParseModuleCommand(Script* script, CommandPtr* out_command) {
std::unique_ptr<Module> m;
std::unique_ptr<WastLexer> lexer = WastLexer::CreateBufferLexer(
filename, qsm->data.data(), qsm->data.size(), &errors);
- ParseWatModule(lexer.get(), &m, &errors, options_);
+ auto result = ParseWatModule(lexer.get(), &m, &errors, options_);
for (const auto& error : errors) {
if (error.loc.offset == kInvalidOffset) {
Error(qsm->loc, "error in quoted module: %s", error.message.c_str());
@@ -3490,7 +3490,9 @@ Result WastParser::ParseModuleCommand(Script* script, CommandPtr* out_command) {
error.loc.offset, error.message.c_str());
}
}
- *module = std::move(*m.get());
+ if (Succeeded(result)) {
+ *module = std::move(*m.get());
+ }
*out_command = std::move(command);
break;
}
diff --git a/test/wast2json/test-invalid-quoted-modules.txt b/test/wast2json/test-invalid-quoted-modules.txt
new file mode 100644
index 00000000..c72fa89c
--- /dev/null
+++ b/test/wast2json/test-invalid-quoted-modules.txt
@@ -0,0 +1,8 @@
+;;; TOOL: wast2json
+;;; ERROR: 1
+(module quote "invalid")
+(;; STDERR ;;;
+out/test/wast2json/test-invalid-quoted-modules.txt:3:2: error: error in quoted module: @0x100000001: unexpected token "invalid", expected a module field or a module.
+(module quote "invalid")
+ ^^^^^^
+;;; STDERR ;;)