Fix substring constructor in regex search all

Apparently the substring constructor for std::string cannot handle well
\0 characters. Leading to a crash. Issue reported on #1304
This commit is contained in:
Felipe Zimmerle 2017-01-13 11:02:34 -03:00
parent e181cb7e0a
commit 36d6bb9664
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277

View File

@ -77,18 +77,20 @@ std::list<SMatch> Regex::searchAll(const std::string& s) {
int i;
const char *subject = s.c_str();
int rc;
const std::string tmpString = std::string(s.c_str(), s.size());
rc = pcre_exec(m_pc, m_pce, subject,
s.size(), 0, 0, ovector, OVECCOUNT);
for (i = 0; i < rc; i++) {
SMatch match;
const char *substring_start = subject + ovector[2*i];
int substring_length = ovector[2*i+1] - ovector[2*i];
match.match = std::string(subject, ovector[2*i],
substring_length);
size_t start = ovector[2*i];
size_t end = ovector[2*i+1];
size_t len = end - start;
if (end >= s.size()) {
continue;
}
match.match = std::string(tmpString, start, len);
retList.push_front(match);
}