mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-17 09:55:28 +03:00
Refactor regex code
This commit fixes quite a few odd things in regex code: * Lack of encapsulation. * Non-method functions for matching without retrieving all groups. * Regex class being copyable without proper copy-constructor (potential UAF and double free due to pointer members m_pc and m_pce). * Redundant SMatch::m_length, which always equals to match.size() anyway. * Weird SMatch::size_ member which is initialized only by one of the three matching functions, and equals to the return value of that function anyways. * Several places in code having std::string value instead of reference.
This commit is contained in:
@@ -259,9 +259,9 @@ int ModSecurity::processContentOffset(const char *content, size_t len,
|
||||
std::string value;
|
||||
yajl_gen_map_open(g);
|
||||
vars.pop_back();
|
||||
std::string startingAt = vars.back().match;
|
||||
const std::string &startingAt = vars.back().str();
|
||||
vars.pop_back();
|
||||
std::string size = vars.back().match;
|
||||
const std::string &size = vars.back().str();
|
||||
vars.pop_back();
|
||||
yajl_gen_string(g,
|
||||
reinterpret_cast<const unsigned char*>("startingAt"),
|
||||
@@ -311,11 +311,11 @@ int ModSecurity::processContentOffset(const char *content, size_t len,
|
||||
strlen("transformation"));
|
||||
|
||||
yajl_gen_string(g,
|
||||
reinterpret_cast<const unsigned char*>(trans.back().match.c_str()),
|
||||
trans.back().match.size());
|
||||
reinterpret_cast<const unsigned char*>(trans.back().str().c_str()),
|
||||
trans.back().str().size());
|
||||
|
||||
t = modsecurity::actions::transformations::Transformation::instantiate(
|
||||
trans.back().match.c_str());
|
||||
trans.back().str().c_str());
|
||||
varValueRes = t->evaluate(varValue, NULL);
|
||||
varValue.assign(varValueRes);
|
||||
trans.pop_back();
|
||||
@@ -343,9 +343,9 @@ int ModSecurity::processContentOffset(const char *content, size_t len,
|
||||
strlen("highlight"));
|
||||
yajl_gen_map_open(g);
|
||||
ops.pop_back();
|
||||
std::string startingAt = ops.back().match;
|
||||
std::string startingAt = ops.back().str();
|
||||
ops.pop_back();
|
||||
std::string size = ops.back().match;
|
||||
std::string size = ops.back().str();
|
||||
ops.pop_back();
|
||||
yajl_gen_string(g,
|
||||
reinterpret_cast<const unsigned char*>("startingAt"),
|
||||
|
||||
Reference in New Issue
Block a user