mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
feat: PCRE2 JIT
This commit is contained in:
@@ -36,6 +36,8 @@ namespace operators {
|
||||
VerifyCC::~VerifyCC() {
|
||||
#if WITH_PCRE2
|
||||
pcre2_code_free(m_pc);
|
||||
pcre2_match_context_free(m_pmc);
|
||||
pcre2_jit_stack_free(m_pcjs);
|
||||
#else
|
||||
if (m_pc != NULL) {
|
||||
pcre_free(m_pc);
|
||||
@@ -105,6 +107,11 @@ bool VerifyCC::init(const std::string ¶m2, std::string *error) {
|
||||
if (m_pc == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pcje = pcre2_jit_compile(m_pc, PCRE2_JIT_COMPLETE);
|
||||
m_pmc = pcre2_match_context_create(NULL);
|
||||
m_pcjs = pcre2_jit_stack_create(32*1024, 512*1024, NULL);
|
||||
pcre2_jit_stack_assign(m_pmc, NULL, m_pcjs);
|
||||
#else
|
||||
const char *errptr = NULL;
|
||||
int erroffset = 0;
|
||||
@@ -142,8 +149,14 @@ bool VerifyCC::evaluate(Transaction *t, RuleWithActions *rule,
|
||||
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);
|
||||
|
||||
int ret;
|
||||
for (offset = 0; offset < target_length; offset++) {
|
||||
int ret = pcre2_match(m_pc, pcre2_i, target_length, offset, 0, match_data, NULL);
|
||||
|
||||
if (m_pcje == 0) {
|
||||
ret = pcre2_jit_match(m_pc, pcre2_i, target_length, offset, 0, match_data, m_pmc);
|
||||
} else {
|
||||
ret = pcre2_match(m_pc, pcre2_i, target_length, offset, 0, match_data, m_pmc);
|
||||
}
|
||||
|
||||
/* If there was no match, then we are done. */
|
||||
if (ret < 0) {
|
||||
|
@@ -53,6 +53,9 @@ class VerifyCC : public Operator {
|
||||
private:
|
||||
#if WITH_PCRE2
|
||||
pcre2_code *m_pc;
|
||||
pcre2_match_context *m_pmc;
|
||||
int m_pcje;
|
||||
pcre2_jit_stack *m_pcjs;
|
||||
#else
|
||||
pcre *m_pc;
|
||||
pcre_extra *m_pce;
|
||||
|
Reference in New Issue
Block a user