diff options
| author | George Rimar <grimar@accesssoftek.com> | 2016-09-02 08:44:46 +0000 |
|---|---|---|
| committer | George Rimar <grimar@accesssoftek.com> | 2016-09-02 08:44:46 +0000 |
| commit | d8dfeec019e053ffc3c8205378c24a7023856a0d (patch) | |
| tree | 1f6fc93a0cdc2bb0b37478dcd405d55e0dbb4249 /llvm/lib/Support | |
| parent | d8a4ecac3bf43eb37219060e46e90df26c140c26 (diff) | |
| download | bcm5719-llvm-d8dfeec019e053ffc3c8205378c24a7023856a0d.tar.gz bcm5719-llvm-d8dfeec019e053ffc3c8205378c24a7023856a0d.zip | |
[Support] - Fix possible crash in match() of llvm::Regex.
Crash was possible if match() method
was called on object that was moved or object
created with empty constructor.
Testcases updated.
DIfferential revision: https://reviews.llvm.org/D24123
llvm-svn: 280473
Diffstat (limited to 'llvm/lib/Support')
| -rw-r--r-- | llvm/lib/Support/Regex.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Support/Regex.cpp b/llvm/lib/Support/Regex.cpp index 35641f3b7cb..68ba79e1176 100644 --- a/llvm/lib/Support/Regex.cpp +++ b/llvm/lib/Support/Regex.cpp @@ -34,6 +34,13 @@ Regex::Regex(StringRef regex, unsigned Flags) { error = llvm_regcomp(preg, regex.data(), flags|REG_PEND); } +Regex::Regex(Regex &®ex) { + preg = regex.preg; + error = regex.error; + regex.preg = nullptr; + regex.error = REG_BADPAT; +} + Regex::~Regex() { if (preg) { llvm_regfree(preg); @@ -59,6 +66,9 @@ unsigned Regex::getNumMatches() const { } bool Regex::match(StringRef String, SmallVectorImpl<StringRef> *Matches){ + if (error) + return false; + unsigned nmatch = Matches ? preg->re_nsub+1 : 0; // pmatch needs to have at least one element. |

