diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2018-02-20 15:35:50 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2018-02-20 15:35:51 +0900 |
commit | af8cbfe5151604cd33ad3d6594b108d2937388b8 (patch) | |
tree | f255ad53be78221c5b168e987d557f0763dd6ada /util | |
parent | 322178004d7dd9ce4f6c7b4a836fb811ab9ce580 (diff) | |
download | re2-af8cbfe5151604cd33ad3d6594b108d2937388b8.tar.gz re2-af8cbfe5151604cd33ad3d6594b108d2937388b8.tar.bz2 re2-af8cbfe5151604cd33ad3d6594b108d2937388b8.zip |
Imported Upstream version 20170701upstream/20170701
Change-Id: Iedbad8b46139f66f03fae4cc212711509e0ab7b3
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/pcre.cc | 12 | ||||
-rw-r--r-- | util/sparse_array.h | 38 | ||||
-rw-r--r-- | util/sparse_set.h | 38 |
3 files changed, 59 insertions, 29 deletions
diff --git a/util/pcre.cc b/util/pcre.cc index fab0388..7e1d1ac 100644 --- a/util/pcre.cc +++ b/util/pcre.cc @@ -635,7 +635,17 @@ bool PCRE::DoMatchImpl(const StringPiece& text, for (int i = 0; i < n; i++) { const int start = vec[2*(i+1)]; const int limit = vec[2*(i+1)+1]; - if (!args[i]->Parse(text.data() + start, limit-start)) { + + // Avoid invoking undefined behavior when text.data() happens + // to be null and start happens to be -1, the latter being the + // case for an unmatched subexpression. Even if text.data() is + // not null, pointing one byte before was a longstanding bug. + const char* addr = NULL; + if (start != -1) { + addr = text.data() + start; + } + + if (!args[i]->Parse(addr, limit-start)) { // TODO: Should we indicate what the error was? return false; } diff --git a/util/sparse_array.h b/util/sparse_array.h index 1c3edef..7738431 100644 --- a/util/sparse_array.h +++ b/util/sparse_array.h @@ -310,6 +310,20 @@ class SparseArray { // and at the beginning and end of all public non-const member functions. void DebugCheckInvariants() const; + static bool ShouldInitializeMemory() { +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) + return true; +#else + return false; +#endif +#elif defined(RE2_ON_VALGRIND) + return true; +#else + return false; +#endif + } + int size_ = 0; int max_size_ = 0; std::unique_ptr<int[]> sparse_to_dense_; @@ -415,14 +429,12 @@ void SparseArray<Value>::resize(int max_size) { dense_.resize(max_size); -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) - for (int i = max_size_; i < max_size; i++) { - sparse_to_dense_[i] = 0xababababU; - dense_[i].index_ = 0xababababU; + if (ShouldInitializeMemory()) { + for (int i = max_size_; i < max_size; i++) { + sparse_to_dense_[i] = 0xababababU; + dense_[i].index_ = 0xababababU; + } } -#endif -#endif } max_size_ = max_size; if (size_ > max_size_) @@ -485,14 +497,12 @@ template<typename Value> SparseArray<Value>::SparseArray(int max_size) { dense_.resize(max_size); size_ = 0; -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) - for (int i = 0; i < max_size; i++) { - sparse_to_dense_[i] = 0xababababU; - dense_[i].index_ = 0xababababU; + if (ShouldInitializeMemory()) { + for (int i = 0; i < max_size; i++) { + sparse_to_dense_[i] = 0xababababU; + dense_[i].index_ = 0xababababU; + } } -#endif -#endif DebugCheckInvariants(); } diff --git a/util/sparse_set.h b/util/sparse_set.h index 6764cc7..fd35236 100644 --- a/util/sparse_set.h +++ b/util/sparse_set.h @@ -160,6 +160,20 @@ class SparseSetT { // and at the beginning and end of all public non-const member functions. void DebugCheckInvariants() const; + static bool ShouldInitializeMemory() { +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) + return true; +#else + return false; +#endif +#elif defined(RE2_ON_VALGRIND) + return true; +#else + return false; +#endif + } + int size_ = 0; int max_size_ = 0; std::unique_ptr<int[]> sparse_to_dense_; @@ -183,14 +197,12 @@ void SparseSetT<Value>::resize(int max_size) { dense_.resize(max_size); -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) - for (int i = max_size_; i < max_size; i++) { - sparse_to_dense_[i] = 0xababababU; - dense_[i] = 0xababababU; + if (ShouldInitializeMemory()) { + for (int i = max_size_; i < max_size; i++) { + sparse_to_dense_[i] = 0xababababU; + dense_[i] = 0xababababU; + } } -#endif -#endif } max_size_ = max_size; if (size_ > max_size_) @@ -226,14 +238,12 @@ template<typename Value> SparseSetT<Value>::SparseSetT(int max_size) { dense_.resize(max_size); size_ = 0; -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) - for (int i = 0; i < max_size; i++) { - sparse_to_dense_[i] = 0xababababU; - dense_[i] = 0xababababU; + if (ShouldInitializeMemory()) { + for (int i = 0; i < max_size; i++) { + sparse_to_dense_[i] = 0xababababU; + dense_[i] = 0xababababU; + } } -#endif -#endif DebugCheckInvariants(); } |