mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-15 23:55:03 +03:00
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:
parent
e181cb7e0a
commit
36d6bb9664
@ -77,18 +77,20 @@ std::list<SMatch> Regex::searchAll(const std::string& s) {
|
|||||||
int i;
|
int i;
|
||||||
const char *subject = s.c_str();
|
const char *subject = s.c_str();
|
||||||
int rc;
|
int rc;
|
||||||
|
const std::string tmpString = std::string(s.c_str(), s.size());
|
||||||
|
|
||||||
rc = pcre_exec(m_pc, m_pce, subject,
|
rc = pcre_exec(m_pc, m_pce, subject,
|
||||||
s.size(), 0, 0, ovector, OVECCOUNT);
|
s.size(), 0, 0, ovector, OVECCOUNT);
|
||||||
|
|
||||||
for (i = 0; i < rc; i++) {
|
for (i = 0; i < rc; i++) {
|
||||||
SMatch match;
|
SMatch match;
|
||||||
const char *substring_start = subject + ovector[2*i];
|
size_t start = ovector[2*i];
|
||||||
int substring_length = ovector[2*i+1] - ovector[2*i];
|
size_t end = ovector[2*i+1];
|
||||||
|
size_t len = end - start;
|
||||||
match.match = std::string(subject, ovector[2*i],
|
if (end >= s.size()) {
|
||||||
substring_length);
|
continue;
|
||||||
|
}
|
||||||
|
match.match = std::string(tmpString, start, len);
|
||||||
retList.push_front(match);
|
retList.push_front(match);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user