diff options
author | Ben Smith <binjimin@gmail.com> | 2017-10-06 16:40:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-06 16:40:58 -0700 |
commit | dac347ecb3a33eb67f62cd9061c58a1b4a2b549b (patch) | |
tree | 259725305853c39d0b22cbe18fc5c12856d9ca2f /src/wast-parser.cc | |
parent | 518e48c8bbe8167b8925eed9c263f943c7c806e6 (diff) | |
download | wabt-dac347ecb3a33eb67f62cd9061c58a1b4a2b549b.tar.gz wabt-dac347ecb3a33eb67f62cd9061c58a1b4a2b549b.tar.bz2 wabt-dac347ecb3a33eb67f62cd9061c58a1b4a2b549b.zip |
Fix some fuzzer-found regressions (#647)
* Assertion/hang when parsing an invalid value type list
* Assertion parsing an invalid module field
* Assertion when two start sections are specified, and one of them has a
named function
Diffstat (limited to 'src/wast-parser.cc')
-rw-r--r-- | src/wast-parser.cc | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/wast-parser.cc b/src/wast-parser.cc index eaa4a31e..2c16c7e6 100644 --- a/src/wast-parser.cc +++ b/src/wast-parser.cc @@ -439,8 +439,10 @@ Result WastParser::ErrorExpected(const std::vector<std::string>& expected, Result WastParser::ErrorIfLpar(const std::vector<std::string>& expected, const char* example) { - if (Match(TokenType::Lpar)) + if (Match(TokenType::Lpar)) { + GetToken(); return ErrorExpected(expected, example); + } return Result::Ok; } @@ -554,7 +556,6 @@ Result WastParser::ParseValueTypeList(TypeVector* out_type_list) { while (PeekMatch(TokenType::ValueType)) out_type_list->push_back(Consume().type()); - CHECK_RESULT(ErrorIfLpar({"i32", "i64", "f32", "f64"})); return Result::Ok; } @@ -708,7 +709,7 @@ Result WastParser::ParseScript(std::unique_ptr<Script>* out_script) { Result WastParser::ParseModuleFieldList(Module* module) { WABT_TRACE(ParseModuleFieldList); - while (PeekMatch(TokenType::Lpar)) { + while (IsModuleField(PeekPair())) { if (Failed(ParseModuleField(module))) { CHECK_RESULT(Synchronize(IsModuleField)); } @@ -772,7 +773,7 @@ Result WastParser::ParseExceptModuleField(Module* module) { auto field = MakeUnique<ExceptionModuleField>(GetLocation()); EXPECT(Except); ParseBindVarOpt(&field->except.name); - ParseValueTypeList(&field->except.sig); + CHECK_RESULT(ParseValueTypeList(&field->except.sig)); EXPECT(Rpar); module->AppendField(std::move(field)); return Result::Ok; @@ -947,7 +948,7 @@ Result WastParser::ParseImportModuleField(Module* module) { Consume(); ParseBindVarOpt(&name); auto import = MakeUnique<ExceptionImport>(name); - ParseValueTypeList(&import->except.sig); + CHECK_RESULT(ParseValueTypeList(&import->except.sig)); EXPECT(Rpar); field = MakeUnique<ImportModuleField>(std::move(import), loc); break; @@ -1155,7 +1156,7 @@ Result WastParser::ParseBoundValueTypeList(TokenType token, bindings->emplace(name, Binding(loc, types->size())); types->push_back(type); } else { - ParseValueTypeList(types); + CHECK_RESULT(ParseValueTypeList(types)); } EXPECT(Rpar); } @@ -1165,7 +1166,7 @@ Result WastParser::ParseBoundValueTypeList(TokenType token, Result WastParser::ParseResultList(TypeVector* result_types) { WABT_TRACE(ParseResultList); while (MatchLpar(TokenType::Result)) { - ParseValueTypeList(result_types); + CHECK_RESULT(ParseValueTypeList(result_types)); EXPECT(Rpar); } return Result::Ok; |