chore: refacorize setting of JIT related variables

This commit is contained in:
Ervin Hegedus 2025-05-10 13:08:29 +02:00
parent bc500582a2
commit 1549132fb5
No known key found for this signature in database
GPG Key ID: 5FA5BC3F5EC41F61

View File

@ -37,6 +37,21 @@
#include "libinjection/libinjection.h" #include "libinjection/libinjection.h"
/**
* @brief Set the JIT compile return code and JIT compile status.
* \param regex regex structure
* \param rc return code of the JIT compile
* \param jit JIT compile status
* \return void
*/
static void msc_op_set_jitrc(msc_regex_t *regex, int *rc, int *jit) {
*rc = regex->jit_compile_rc;
if (*rc == 0) {
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, jit);
*jit = (*jit > 0) ? 1 : 0;
}
return;
}
/** /**
* *
@ -724,11 +739,7 @@ static int msre_op_validateHash_param_init(msre_rule *rule, char **error_msg) {
#ifdef WITH_PCRE_STUDY #ifdef WITH_PCRE_STUDY
#ifdef WITH_PCRE_JIT #ifdef WITH_PCRE_JIT
#ifdef WITH_PCRE2 #ifdef WITH_PCRE2
rc = regex->jit_compile_rc; msc_op_set_jitrc(regex, &rc, &jit);
if (rc == 0) {
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
jit = (jit > 0) ? 1 : 0;
}
#else #else
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit); rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
#endif #endif
@ -834,11 +845,7 @@ static int msre_op_validateHash_execute(modsec_rec *msr, msre_rule *rule, msre_v
#ifdef WITH_PCRE_JIT #ifdef WITH_PCRE_JIT
if (msr->txcfg->debuglog_level >= 4) { if (msr->txcfg->debuglog_level >= 4) {
#ifdef WITH_PCRE2 #ifdef WITH_PCRE2
rc = regex->jit_compile_rc; msc_op_set_jitrc(regex, &rc, &jit);
if (rc == 0) {
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
jit = (jit > 0) ? 1 : 0;
}
#else #else
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit); rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
#endif #endif
@ -1009,11 +1016,7 @@ static int msre_op_rx_param_init(msre_rule *rule, char **error_msg) {
#ifdef WITH_PCRE_STUDY #ifdef WITH_PCRE_STUDY
#ifdef WITH_PCRE_JIT #ifdef WITH_PCRE_JIT
#ifdef WITH_PCRE2 #ifdef WITH_PCRE2
rc = regex->jit_compile_rc; msc_op_set_jitrc(regex, &rc, &jit);
if (rc == 0) {
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
jit = (jit > 0) ? 1 : 0;
}
#else #else
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit); rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
#endif #endif
@ -1111,11 +1114,7 @@ static int msre_op_rx_execute(modsec_rec *msr, msre_rule *rule, msre_var *var, c
#ifdef WITH_PCRE_JIT #ifdef WITH_PCRE_JIT
if (msr->txcfg->debuglog_level >= 4) { if (msr->txcfg->debuglog_level >= 4) {
#ifdef WITH_PCRE2 #ifdef WITH_PCRE2
rc = regex->jit_compile_rc; msc_op_set_jitrc(regex, &rc, &jit);
if (rc == 0) {
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
jit = (jit > 0) ? 1 : 0;
}
#else #else
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit); rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
#endif #endif
@ -3006,11 +3005,7 @@ static int msre_op_verifyCC_execute(modsec_rec *msr, msre_rule *rule, msre_var *
#ifdef WITH_PCRE_JIT #ifdef WITH_PCRE_JIT
if (msr->txcfg->debuglog_level >= 4) { if (msr->txcfg->debuglog_level >= 4) {
#ifdef WITH_PCRE2 #ifdef WITH_PCRE2
rc = regex->jit_compile_rc; msc_op_set_jitrc(regex, &rc, &jit);
if (rc == 0) {
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
jit = (jit > 0) ? 1 : 0;
}
#else #else
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit); rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
#endif #endif
@ -3349,11 +3344,7 @@ static int msre_op_verifyCPF_execute(modsec_rec *msr, msre_rule *rule, msre_var
#ifdef WITH_PCRE_JIT #ifdef WITH_PCRE_JIT
if (msr->txcfg->debuglog_level >= 4) { if (msr->txcfg->debuglog_level >= 4) {
#ifdef WITH_PCRE2 #ifdef WITH_PCRE2
rc = regex->jit_compile_rc; msc_op_set_jitrc(regex, &rc, &jit);
if (rc == 0) {
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
jit = (jit > 0) ? 1 : 0;
}
#else #else
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit); rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
#endif #endif
@ -3678,11 +3669,7 @@ static int msre_op_verifySSN_execute(modsec_rec *msr, msre_rule *rule, msre_var
#ifdef WITH_PCRE_JIT #ifdef WITH_PCRE_JIT
if (msr->txcfg->debuglog_level >= 4) { if (msr->txcfg->debuglog_level >= 4) {
#ifdef WITH_PCRE2 #ifdef WITH_PCRE2
rc = regex->jit_compile_rc; msc_op_set_jitrc(regex, &rc, &jit);
if (rc == 0) {
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
jit = (jit > 0) ? 1 : 0;
}
#else #else
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit); rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
#endif #endif