Skip to content

Commit 1549132

Browse files
committed
chore: refacorize setting of JIT related variables
1 parent bc50058 commit 1549132

File tree

1 file changed

+22
-35
lines changed

1 file changed

+22
-35
lines changed

apache2/re_operators.c

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@
3737

3838
#include "libinjection/libinjection.h"
3939

40+
/**
41+
* @brief Set the JIT compile return code and JIT compile status.
42+
* \param regex regex structure
43+
* \param rc return code of the JIT compile
44+
* \param jit JIT compile status
45+
* \return void
46+
*/
47+
static void msc_op_set_jitrc(msc_regex_t *regex, int *rc, int *jit) {
48+
*rc = regex->jit_compile_rc;
49+
if (*rc == 0) {
50+
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, jit);
51+
*jit = (*jit > 0) ? 1 : 0;
52+
}
53+
return;
54+
}
4055

4156
/**
4257
*
@@ -724,11 +739,7 @@ static int msre_op_validateHash_param_init(msre_rule *rule, char **error_msg) {
724739
#ifdef WITH_PCRE_STUDY
725740
#ifdef WITH_PCRE_JIT
726741
#ifdef WITH_PCRE2
727-
rc = regex->jit_compile_rc;
728-
if (rc == 0) {
729-
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
730-
jit = (jit > 0) ? 1 : 0;
731-
}
742+
msc_op_set_jitrc(regex, &rc, &jit);
732743
#else
733744
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
734745
#endif
@@ -834,11 +845,7 @@ static int msre_op_validateHash_execute(modsec_rec *msr, msre_rule *rule, msre_v
834845
#ifdef WITH_PCRE_JIT
835846
if (msr->txcfg->debuglog_level >= 4) {
836847
#ifdef WITH_PCRE2
837-
rc = regex->jit_compile_rc;
838-
if (rc == 0) {
839-
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
840-
jit = (jit > 0) ? 1 : 0;
841-
}
848+
msc_op_set_jitrc(regex, &rc, &jit);
842849
#else
843850
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
844851
#endif
@@ -1009,11 +1016,7 @@ static int msre_op_rx_param_init(msre_rule *rule, char **error_msg) {
10091016
#ifdef WITH_PCRE_STUDY
10101017
#ifdef WITH_PCRE_JIT
10111018
#ifdef WITH_PCRE2
1012-
rc = regex->jit_compile_rc;
1013-
if (rc == 0) {
1014-
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
1015-
jit = (jit > 0) ? 1 : 0;
1016-
}
1019+
msc_op_set_jitrc(regex, &rc, &jit);
10171020
#else
10181021
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
10191022
#endif
@@ -1111,11 +1114,7 @@ static int msre_op_rx_execute(modsec_rec *msr, msre_rule *rule, msre_var *var, c
11111114
#ifdef WITH_PCRE_JIT
11121115
if (msr->txcfg->debuglog_level >= 4) {
11131116
#ifdef WITH_PCRE2
1114-
rc = regex->jit_compile_rc;
1115-
if (rc == 0) {
1116-
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
1117-
jit = (jit > 0) ? 1 : 0;
1118-
}
1117+
msc_op_set_jitrc(regex, &rc, &jit);
11191118
#else
11201119
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
11211120
#endif
@@ -3006,11 +3005,7 @@ static int msre_op_verifyCC_execute(modsec_rec *msr, msre_rule *rule, msre_var *
30063005
#ifdef WITH_PCRE_JIT
30073006
if (msr->txcfg->debuglog_level >= 4) {
30083007
#ifdef WITH_PCRE2
3009-
rc = regex->jit_compile_rc;
3010-
if (rc == 0) {
3011-
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
3012-
jit = (jit > 0) ? 1 : 0;
3013-
}
3008+
msc_op_set_jitrc(regex, &rc, &jit);
30143009
#else
30153010
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
30163011
#endif
@@ -3349,11 +3344,7 @@ static int msre_op_verifyCPF_execute(modsec_rec *msr, msre_rule *rule, msre_var
33493344
#ifdef WITH_PCRE_JIT
33503345
if (msr->txcfg->debuglog_level >= 4) {
33513346
#ifdef WITH_PCRE2
3352-
rc = regex->jit_compile_rc;
3353-
if (rc == 0) {
3354-
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
3355-
jit = (jit > 0) ? 1 : 0;
3356-
}
3347+
msc_op_set_jitrc(regex, &rc, &jit);
33573348
#else
33583349
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
33593350
#endif
@@ -3678,11 +3669,7 @@ static int msre_op_verifySSN_execute(modsec_rec *msr, msre_rule *rule, msre_var
36783669
#ifdef WITH_PCRE_JIT
36793670
if (msr->txcfg->debuglog_level >= 4) {
36803671
#ifdef WITH_PCRE2
3681-
rc = regex->jit_compile_rc;
3682-
if (rc == 0) {
3683-
msc_fullinfo(regex, PCRE2_INFO_JITSIZE, &jit);
3684-
jit = (jit > 0) ? 1 : 0;
3685-
}
3672+
msc_op_set_jitrc(regex, &rc, &jit);
36863673
#else
36873674
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
36883675
#endif

0 commit comments

Comments
 (0)