summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2022-12-02 16:29:49 -0600
committerGitHub <noreply@github.com>2022-12-02 14:29:49 -0800
commit6658a66e6330f25105f0dca7241e520cffb8c3eb (patch)
tree2d49e0759b5b34ba93fe133da081f113403f7a9b
parent49f89749862749e4571983cac971ffb798d30c99 (diff)
downloadbinaryen-6658a66e6330f25105f0dca7241e520cffb8c3eb.tar.gz
binaryen-6658a66e6330f25105f0dca7241e520cffb8c3eb.tar.bz2
binaryen-6658a66e6330f25105f0dca7241e520cffb8c3eb.zip
[NFC] Do not read past the end of a string_view (#5317)
wasm-s-parser.cpp was detecting the end of type strings by looking for null characters, but those null characters would be past the end of the relevant string_view. Bring that code in line with similar code by checking the length of the string_view instead. Fixes an assertion failure in MSVC debug mode. Fixes #5312.
-rw-r--r--src/wasm/wasm-s-parser.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index ab6230442..7bdbc69c6 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -1151,18 +1151,18 @@ Type SExpressionWasmBuilder::stringToType(std::string_view str,
bool prefix) {
if (str.size() >= 3) {
if (str[0] == 'i') {
- if (str[1] == '3' && str[2] == '2' && (prefix || str[3] == 0)) {
+ if (str[1] == '3' && str[2] == '2' && (prefix || str.size() == 3)) {
return Type::i32;
}
- if (str[1] == '6' && str[2] == '4' && (prefix || str[3] == 0)) {
+ if (str[1] == '6' && str[2] == '4' && (prefix || str.size() == 3)) {
return Type::i64;
}
}
if (str[0] == 'f') {
- if (str[1] == '3' && str[2] == '2' && (prefix || str[3] == 0)) {
+ if (str[1] == '3' && str[2] == '2' && (prefix || str.size() == 3)) {
return Type::f32;
}
- if (str[1] == '6' && str[2] == '4' && (prefix || str[3] == 0)) {
+ if (str[1] == '6' && str[2] == '4' && (prefix || str.size() == 3)) {
return Type::f64;
}
}
@@ -1170,7 +1170,7 @@ Type SExpressionWasmBuilder::stringToType(std::string_view str,
if (str.size() >= 4) {
if (str[0] == 'v') {
if (str[1] == '1' && str[2] == '2' && str[3] == '8' &&
- (prefix || str[4] == 0)) {
+ (prefix || str.size() == 4)) {
return Type::v128;
}
}