summaryrefslogtreecommitdiff
path: root/src/wast-parser.cc
diff options
context:
space:
mode:
authorBen Smith <binjimin@gmail.com>2017-10-14 00:12:28 -0700
committerGitHub <noreply@github.com>2017-10-14 00:12:28 -0700
commitcf5df451ee53beccefec11e0be9e4de5cf4d69a3 (patch)
tree7088d43cb21177ee1dfd1d93dfaf08569845a442 /src/wast-parser.cc
parent0d59f1e96ab81d882f390cb424b2ae41534726b4 (diff)
downloadwabt-cf5df451ee53beccefec11e0be9e4de5cf4d69a3.tar.gz
wabt-cf5df451ee53beccefec11e0be9e4de5cf4d69a3.tar.bz2
wabt-cf5df451ee53beccefec11e0be9e4de5cf4d69a3.zip
Validate utf-8 encoding in text format (#653)
Diffstat (limited to 'src/wast-parser.cc')
-rw-r--r--src/wast-parser.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/wast-parser.cc b/src/wast-parser.cc
index 2c16c7e6..fffdcf5e 100644
--- a/src/wast-parser.cc
+++ b/src/wast-parser.cc
@@ -21,6 +21,7 @@
#include "src/cast.h"
#include "src/error-handler.h"
#include "src/make-unique.h"
+#include "src/utf8.h"
#include "src/wast-parser-lexer-shared.h"
#define WABT_TRACING 0
@@ -564,7 +565,11 @@ Result WastParser::ParseQuotedText(std::string* text) {
if (!PeekMatch(TokenType::Text))
return ErrorExpected({"a quoted string"}, "\"foo\"");
- RemoveEscapes(Consume().text(), std::back_inserter(*text));
+ Token token = Consume();
+ RemoveEscapes(token.text(), std::back_inserter(*text));
+ if (!IsValidUtf8(text->data(), text->length())) {
+ Error(token.loc, "quoted string has an invalid utf-8 encoding");
+ }
return Result::Ok;
}