From 36d6bb96645cb5ab085417089de2ccce7825cdb1 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Fri, 13 Jan 2017 11:02:34 -0300 Subject: [PATCH] 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 --- src/utils/regex.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/utils/regex.cc b/src/utils/regex.cc index d8cc8cad..449eb605 100644 --- a/src/utils/regex.cc +++ b/src/utils/regex.cc @@ -77,18 +77,20 @@ std::list 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); }