mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Fixed partial transformation caching and reduced some debugging output.
This commit is contained in:
35
apache2/re.c
35
apache2/re.c
@@ -1732,7 +1732,6 @@ static apr_status_t msre_rule_process_normal(msre_rule *rule, modsec_rec *msr) {
|
|||||||
if (strcmp(action->param, "none") == 0) {
|
if (strcmp(action->param, "none") == 0) {
|
||||||
apr_table_clear(normtab);
|
apr_table_clear(normtab);
|
||||||
tfnspath = NULL;
|
tfnspath = NULL;
|
||||||
tfnskey = NULL;
|
|
||||||
tfnscount = 0;
|
tfnscount = 0;
|
||||||
last_cached_tfn = 0;
|
last_cached_tfn = 0;
|
||||||
continue;
|
continue;
|
||||||
@@ -1740,17 +1739,24 @@ static apr_status_t msre_rule_process_normal(msre_rule *rule, modsec_rec *msr) {
|
|||||||
|
|
||||||
if (action->param_plusminus == NEGATIVE_VALUE) {
|
if (action->param_plusminus == NEGATIVE_VALUE) {
|
||||||
apr_table_unset(normtab, action->param);
|
apr_table_unset(normtab, action->param);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
|
tfnscount++;
|
||||||
|
|
||||||
apr_table_addn(normtab, action->param, (void *)action);
|
apr_table_addn(normtab, action->param, (void *)action);
|
||||||
|
|
||||||
/* check cache, saving the 'most complete' */
|
/* Check the cache, saving the 'most complete' as a
|
||||||
|
* starting point
|
||||||
|
*/
|
||||||
|
if (usecache) {
|
||||||
|
tfnspath = apr_psprintf(msr->mp, "%s%s%s", (tfnspath?tfnspath:""), (tfnspath?",":""), action->param);
|
||||||
|
tfnskey = apr_psprintf(msr->mp, "%x;%s", tfnscount, tfnspath);
|
||||||
crec = (msre_cache_rec *)apr_table_get(cachetab, tfnskey);
|
crec = (msre_cache_rec *)apr_table_get(cachetab, tfnskey);
|
||||||
if (crec != NULL) {
|
if (crec != NULL) {
|
||||||
last_crec = crec;
|
last_crec = crec;
|
||||||
last_cached_tfn = tfnscount;
|
last_cached_tfn = tfnscount;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
tfnscount++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1813,16 +1819,25 @@ static apr_status_t msre_rule_process_normal(msre_rule *rule, modsec_rec *msr) {
|
|||||||
|
|
||||||
/* Start after the last known cached transformation if we can */
|
/* Start after the last known cached transformation if we can */
|
||||||
if (!multi_match && (last_crec != NULL)) {
|
if (!multi_match && (last_crec != NULL)) {
|
||||||
k = last_cached_tfn + 1;
|
k = last_cached_tfn;
|
||||||
tfnspath = last_crec->path;
|
tfnspath = last_crec->path;
|
||||||
msr_log(msr, 9, "CACHE: starting after '%s'", tfnspath);
|
last_crec->hits++;
|
||||||
|
|
||||||
|
if ((changed = last_crec->changed) == 1) {
|
||||||
|
var->value = apr_pmemdup(msr->mp, last_crec->val, last_crec->val_len);
|
||||||
|
var->value_len = last_crec->val_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msr->txcfg->debuglog_level >= 9) {
|
||||||
|
msr_log(msr, 9, "T (%d) %s: \"%s\" [partially cached hits=%d]", last_crec->changed, tfnspath, log_escape_nq_ex(mptmp, var->value, var->value_len), last_crec->hits);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
changed = 1;
|
||||||
tfnspath = NULL;
|
tfnspath = NULL;
|
||||||
k = 0;
|
k = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
changed = 1;
|
|
||||||
telts = (const apr_table_entry_t*)tarr->elts;
|
telts = (const apr_table_entry_t*)tarr->elts;
|
||||||
for (; k < tarr->nelts; k++) {
|
for (; k < tarr->nelts; k++) {
|
||||||
char *rval = NULL;
|
char *rval = NULL;
|
||||||
@@ -1878,7 +1893,9 @@ static apr_status_t msre_rule_process_normal(msre_rule *rule, modsec_rec *msr) {
|
|||||||
tfnskey = apr_psprintf(msr->mp, "%x;%s", (k + 1), tfnspath);
|
tfnskey = apr_psprintf(msr->mp, "%x;%s", (k + 1), tfnspath);
|
||||||
|
|
||||||
/* Try to fetch this transformation from cache */
|
/* Try to fetch this transformation from cache */
|
||||||
|
#ifdef CACHE_DEBUG
|
||||||
msr_log(msr, 9, "CACHE: Fetching %s %s ", var->name, tfnskey);
|
msr_log(msr, 9, "CACHE: Fetching %s %s ", var->name, tfnskey);
|
||||||
|
#endif
|
||||||
crec = (msre_cache_rec *)apr_table_get(cachetab, tfnskey);
|
crec = (msre_cache_rec *)apr_table_get(cachetab, tfnskey);
|
||||||
if (crec != NULL) {
|
if (crec != NULL) {
|
||||||
crec->hits++;
|
crec->hits++;
|
||||||
@@ -1916,7 +1933,9 @@ static apr_status_t msre_rule_process_normal(msre_rule *rule, modsec_rec *msr) {
|
|||||||
crec->path = tfnspath;
|
crec->path = tfnspath;
|
||||||
crec->val = changed ? apr_pmemdup(msr->mp, var->value, var->value_len) : NULL;
|
crec->val = changed ? apr_pmemdup(msr->mp, var->value, var->value_len) : NULL;
|
||||||
crec->val_len = changed ? var->value_len : 0;
|
crec->val_len = changed ? var->value_len : 0;
|
||||||
|
#ifdef CACHE_DEBUG
|
||||||
msr_log(msr, 9, "CACHE: Caching %s=\"%.*s\"", tfnskey, var->value_len, log_escape_nq_ex(mptmp, var->value, var->value_len));
|
msr_log(msr, 9, "CACHE: Caching %s=\"%.*s\"", tfnskey, var->value_len, log_escape_nq_ex(mptmp, var->value, var->value_len));
|
||||||
|
#endif
|
||||||
apr_table_setn(cachetab, tfnskey, (void *)crec);
|
apr_table_setn(cachetab, tfnskey, (void *)crec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user