Skip to content

Commit c796804

Browse files
committed
Pre-calculate string length instead of strlen()
1 parent 2b2535c commit c796804

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Diff for: apache2/re.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static int fetch_target_exception(msre_rule *rule, modsec_rec *msr, msre_var *va
6666
char *errptr;
6767
int erroffset;
6868
int match = 0;
69+
size_t value_len;
6970

7071
if(msr == NULL)
7172
return 0;
@@ -114,12 +115,17 @@ static int fetch_target_exception(msre_rule *rule, modsec_rec *msr, msre_var *va
114115
value = NULL;
115116
}
116117

118+
value_len = 0;
119+
if (value != NULL) {
120+
value_len = strlen(value);
121+
}
122+
117123
if((strlen(myname) == strlen(name)) &&
118-
(strncasecmp(myname, name,strlen(myname)) == 0)) {
124+
(strncasecmp(myname, name, strlen(myname)) == 0)) {
119125

120126
if(value != NULL && myvalue != NULL) {
121-
if(strlen(value) > 2 && value[0] == '/' && value[strlen(value) - 1] == '/') {
122-
value[strlen(value) - 1] = '\0';
127+
if(value_len > 2 && value[0] == '/' && value[value_len - 1] == '/') {
128+
value[value_len - 1] = '\0';
123129
#ifdef WITH_PCRE2
124130
regex = msc_pregcomp(msr->mp, value + 1,
125131
PCRE2_DOTALL | PCRE2_CASELESS | PCRE2_DOLLAR_ENDONLY, (const char **)&errptr, &erroffset);
@@ -154,7 +160,7 @@ static int fetch_target_exception(msre_rule *rule, modsec_rec *msr, msre_var *va
154160
match = 1;
155161
}
156162
}
157-
} else if((strlen(myvalue) == strlen(value)) &&
163+
} else if((strlen(myvalue) == value_len) &&
158164
strncasecmp(myvalue,value,strlen(myvalue)) == 0) {
159165
if (msr->txcfg->debuglog_level >= 9) {
160166
msr_log(msr, 9, "fetch_target_exception: Target %s will not be processed.", target);

0 commit comments

Comments
 (0)