diff options
author | JF Bastien <jfb@chromium.org> | 2016-01-10 10:49:59 -0800 |
---|---|---|
committer | JF Bastien <jfb@chromium.org> | 2016-01-10 17:40:15 -0800 |
commit | e3c38c14e7dd9c115da960daafd109d2687f1a08 (patch) | |
tree | c8e892eed8ad9dc0a5e071b9e8af775733dedc03 /src/s2wasm.h | |
parent | 75a562190a9f4588c8ffb19b8304f76c15a850c6 (diff) | |
download | binaryen-e3c38c14e7dd9c115da960daafd109d2687f1a08.tar.gz binaryen-e3c38c14e7dd9c115da960daafd109d2687f1a08.tar.bz2 binaryen-e3c38c14e7dd9c115da960daafd109d2687f1a08.zip |
Add Travis builds with sanitizers
This triggers 5 independent build / test runs:
- clang, no sanitizer;
- clang, UB sanitizer;
- clang, address sanitizer (disabled for now);
- clang, thread sanitizer (disabled for now);
- GCC.
Enabling UBSan led to these changes:
- Fix a bunch of undefined behavior throughout the code base.
- Fix some tests that relied on that undefined behavior.
- Make some of the tests easier to debug by printing their command line.
- Add ubsan blacklist to work around libstdc++ bug.
- Example testcase also needs sanitizer because libsupport.a uses it.
Diffstat (limited to 'src/s2wasm.h')
-rw-r--r-- | src/s2wasm.h | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index bd3f12e73..d1836b274 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -159,16 +159,23 @@ private: return cashew::IString(str.c_str(), false); } - int32_t getInt() { - int32_t ret = 0; + uint32_t getInt() { + uint32_t ret = 0; bool neg = false; if (*s == '-') { neg = true; s++; } while (isdigit(*s)) { + uint32_t digit = *s - '0'; + if (ret > std::numeric_limits<uint32_t>::max() / 10) { + abort_on("overflow"); + } ret *= 10; - ret += (*s - '0'); + if (ret > std::numeric_limits<uint32_t>::max() - digit) { + abort_on("overflow"); + } + ret += digit; s++; } if (neg) ret = -ret; @@ -197,16 +204,23 @@ private: } } - int64_t getInt64() { - int64_t ret = 0; + uint64_t getInt64() { + uint64_t ret = 0; bool neg = false; if (*s == '-') { neg = true; s++; } while (isdigit(*s)) { + uint64_t digit = *s - '0'; + if (ret > std::numeric_limits<uint64_t>::max() / 10) { + abort_on("overflow"); + } ret *= 10; - ret += (*s - '0'); + if (ret > std::numeric_limits<uint64_t>::max() - digit) { + abort_on("overflow"); + } + ret += digit; s++; } if (neg) ret = -ret; @@ -933,7 +947,7 @@ private: } else if (match(".int64")) { size_t size = raw->size(); raw->resize(size + 8); - (*(int64_t*)(&(*raw)[size])) = getInt(); + (*(int64_t*)(&(*raw)[size])) = getInt64(); zero = false; } else { break; |