21
21
22
22
#include " src/operators/operator.h"
23
23
24
- #ifndef WITH_PCRE2
24
+ #ifdef WITH_PCRE
25
25
#if PCRE_HAVE_JIT
26
26
#define pcre_study_opt PCRE_STUDY_JIT_COMPILE
27
27
#else
28
- # define pcre_study_opt 0
28
+ constexpr int pcre_study_opt = 0 ;
29
29
#endif
30
30
#endif
31
31
@@ -34,20 +34,20 @@ namespace modsecurity {
34
34
namespace operators {
35
35
36
36
VerifyCC::~VerifyCC () {
37
- #if WITH_PCRE2
37
+ #ifndef WITH_PCRE
38
38
pcre2_code_free (m_pc);
39
39
#else
40
- if (m_pc != NULL ) {
40
+ if (m_pc != nullptr ) {
41
41
pcre_free (m_pc);
42
- m_pc = NULL ;
42
+ m_pc = nullptr ;
43
43
}
44
- if (m_pce != NULL ) {
44
+ if (m_pce != nullptr ) {
45
45
#if PCRE_HAVE_JIT
46
46
pcre_free_study (m_pce);
47
47
#else
48
48
pcre_free (m_pce);
49
49
#endif
50
- m_pce = NULL ;
50
+ m_pce = nullptr ;
51
51
}
52
52
#endif
53
53
}
@@ -94,33 +94,33 @@ int VerifyCC::luhnVerify(const char *ccnumber, int len) {
94
94
95
95
96
96
bool VerifyCC::init (const std::string ¶m2, std::string *error) {
97
- #ifdef WITH_PCRE2
97
+ #ifndef WITH_PCRE
98
98
PCRE2_SPTR pcre2_pattern = reinterpret_cast <PCRE2_SPTR>(m_param.c_str ());
99
99
uint32_t pcre2_options = (PCRE2_DOTALL|PCRE2_MULTILINE);
100
100
int errornumber = 0 ;
101
101
PCRE2_SIZE erroroffset = 0 ;
102
102
m_pc = pcre2_compile (pcre2_pattern, PCRE2_ZERO_TERMINATED,
103
- pcre2_options, &errornumber, &erroroffset, NULL );
104
- if (m_pc == NULL ) {
103
+ pcre2_options, &errornumber, &erroroffset, nullptr );
104
+ if (m_pc == nullptr ) {
105
105
return false ;
106
106
}
107
107
m_pcje = pcre2_jit_compile (m_pc, PCRE2_JIT_COMPLETE);
108
108
#else
109
- const char *errptr = NULL ;
109
+ const char *errptr = nullptr ;
110
110
int erroffset = 0 ;
111
111
112
112
m_pc = pcre_compile (m_param.c_str (), PCRE_DOTALL|PCRE_MULTILINE,
113
- &errptr, &erroffset, NULL );
114
- if (m_pc == NULL ) {
113
+ &errptr, &erroffset, nullptr );
114
+ if (m_pc == nullptr ) {
115
115
error->assign (errptr);
116
116
return false ;
117
117
}
118
118
119
119
m_pce = pcre_study (m_pc, pcre_study_opt, &errptr);
120
- if (m_pce == NULL ) {
121
- if (errptr == NULL ) {
120
+ if (m_pce == nullptr ) {
121
+ if (errptr == nullptr ) {
122
122
/*
123
- * Per pcre_study(3) m_pce == NULL && errptr == NULL means
123
+ * Per pcre_study(3) m_pce == nullptr && errptr == nullptr means
124
124
* that no addional information is found, so no need to study
125
125
*/
126
126
return true ;
@@ -136,21 +136,21 @@ bool VerifyCC::init(const std::string ¶m2, std::string *error) {
136
136
137
137
bool VerifyCC::evaluate (Transaction *t, RuleWithActions *rule,
138
138
const std::string& i, RuleMessage &ruleMessage) {
139
- #ifdef WITH_PCRE2
139
+ #ifndef WITH_PCRE
140
140
PCRE2_SIZE offset = 0 ;
141
141
size_t target_length = i.length ();
142
142
PCRE2_SPTR pcre2_i = reinterpret_cast <PCRE2_SPTR>(i.c_str ());
143
- pcre2_match_data *match_data = pcre2_match_data_create_from_pattern (m_pc, NULL );
143
+ pcre2_match_data *match_data = pcre2_match_data_create_from_pattern (m_pc, nullptr );
144
144
145
145
int ret;
146
146
for (offset = 0 ; offset < target_length; offset++) {
147
147
148
148
if (m_pcje == 0 ) {
149
- ret = pcre2_jit_match (m_pc, pcre2_i, target_length, offset, 0 , match_data, NULL );
149
+ ret = pcre2_jit_match (m_pc, pcre2_i, target_length, offset, 0 , match_data, nullptr );
150
150
}
151
151
152
152
if (m_pcje != 0 || ret == PCRE2_ERROR_JIT_STACKLIMIT) {
153
- ret = pcre2_match (m_pc, pcre2_i, target_length, offset, PCRE2_NO_JIT, match_data, NULL );
153
+ ret = pcre2_match (m_pc, pcre2_i, target_length, offset, PCRE2_NO_JIT, match_data, nullptr );
154
154
}
155
155
156
156
/* If there was no match, then we are done. */
@@ -192,15 +192,15 @@ bool VerifyCC::evaluate(Transaction *t, RuleWithActions *rule,
192
192
" \" at " + i + " . [offset " +
193
193
std::to_string (offset) + " ]" );
194
194
}
195
- #ifdef WITH_PCRE2
195
+ #ifndef WITH_PCRE
196
196
pcre2_match_data_free (match_data);
197
197
#endif
198
198
return true ;
199
199
}
200
200
}
201
201
}
202
202
203
- #ifdef WITH_PCRE2
203
+ #ifndef WITH_PCRE
204
204
pcre2_match_data_free (match_data);
205
205
#endif
206
206
0 commit comments