mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-10-01 12:07:46 +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:
@@ -38,7 +38,6 @@ bool Rx::init(const std::string &arg, std::string *error) {
|
||||
|
||||
bool Rx::evaluate(Transaction *transaction, Rule *rule,
|
||||
const std::string& input, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||
SMatch match;
|
||||
std::list<SMatch> matches;
|
||||
Regex *re;
|
||||
|
||||
@@ -59,16 +58,16 @@ bool Rx::evaluate(Transaction *transaction, Rule *rule,
|
||||
matches.reverse();
|
||||
for (const SMatch& a : matches) {
|
||||
transaction->m_collections.m_tx_collection->storeOrUpdateFirst(
|
||||
std::to_string(i), a.match);
|
||||
std::to_string(i), a.str());
|
||||
ms_dbg_a(transaction, 7, "Added regex subexpression TX." +
|
||||
std::to_string(i) + ": " + a.match);
|
||||
transaction->m_matched.push_back(a.match);
|
||||
std::to_string(i) + ": " + a.str());
|
||||
transaction->m_matched.push_back(a.str());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto & i : matches) {
|
||||
logOffset(ruleMessage, i.m_offset, i.m_length);
|
||||
logOffset(ruleMessage, i.offset(), i.str().size());
|
||||
}
|
||||
|
||||
if (m_string->m_containsMacro) {
|
||||
|
Reference in New Issue
Block a user