Move PCRE2 match block from member variable

This commit is contained in:
Martin Vierula
2022-05-20 06:58:31 -07:00
parent 770662c0da
commit 0362af4db4
5 changed files with 41 additions and 27 deletions

View File

@@ -104,11 +104,6 @@ bool VerifyCC::init(const std::string &param2, std::string *error) {
pcre2_options, &errornumber, &erroroffset, NULL);
if (m_pc == NULL) {
return false;
} else {
m_match_data = pcre2_match_data_create_from_pattern(m_pc, NULL);
if (m_match_data == NULL) {
return false;
}
}
#else
const char *errptr = NULL;
@@ -145,15 +140,16 @@ bool VerifyCC::evaluate(Transaction *t, RuleWithActions *rule,
PCRE2_SIZE offset = 0;
size_t target_length = i.length();
PCRE2_SPTR pcre2_i = reinterpret_cast<PCRE2_SPTR>(i.c_str());
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(m_pc, NULL);
for (offset = 0; offset < target_length; offset++) {
int ret = pcre2_match(m_pc, pcre2_i, target_length, offset, 0, m_match_data, NULL);
int ret = pcre2_match(m_pc, pcre2_i, target_length, offset, 0, match_data, NULL);
/* If there was no match, then we are done. */
if (ret < 0) {
break;
}
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(m_match_data);
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(match_data);
#else
int offset = 0;
@@ -188,11 +184,18 @@ bool VerifyCC::evaluate(Transaction *t, RuleWithActions *rule,
"\" at " + i + ". [offset " +
std::to_string(offset) + "]");
}
#ifdef WITH_PCRE2
pcre2_match_data_free(match_data);
#endif
return true;
}
}
}
#ifdef WITH_PCRE2
pcre2_match_data_free(match_data);
#endif
return false;
}

View File

@@ -38,10 +38,10 @@ class VerifyCC : public Operator {
/** @ingroup ModSecurity_Operator */
explicit VerifyCC(std::unique_ptr<RunTimeString> param)
: Operator("VerifyCC", std::move(param)),
m_pc(NULL),
#if WITH_PCRE2
m_match_data(NULL) { }
m_pc(NULL) { }
#else
m_pc(NULL),
m_pce(NULL) { }
#endif
~VerifyCC();
@@ -53,7 +53,6 @@ class VerifyCC : public Operator {
private:
#if WITH_PCRE2
pcre2_code *m_pc;
pcre2_match_data *m_match_data;
#else
pcre *m_pc;
pcre_extra *m_pce;