Fixed potential DIV0 when a collection var was fetched in the same second as creation

This commit is contained in:
brectanus 2007-03-07 15:56:22 +00:00
parent 4e02be6219
commit 4370819f7b
2 changed files with 14 additions and 2 deletions

View File

@ -2,6 +2,9 @@
01 Mar 2007 - 2.1.1-dev1
------------------------
* Fixed error when a collection var was fetched in the same second as creation
by setting the rate to zero.
* Fixed ASCIIZ (NUL) parsing for application/x-www-form-urlencoded forms
* Fixed the faulty REQUEST_FILENAME variable, which used to change

View File

@ -152,6 +152,7 @@ apr_table_t *collection_retrieve(modsec_rec *msr, const char *col_name,
if (var == NULL) {
/* Error. */
} else {
int td;
counter = atoi(var->value);
var = (msc_string *)apr_table_get(col, "UPDATE_RATE");
if (var == NULL) {
@ -160,8 +161,16 @@ apr_table_t *collection_retrieve(modsec_rec *msr, const char *col_name,
var->name_len = strlen(var->name);
apr_table_setn(col, var->name, (void *)var);
}
var->value = apr_psprintf(msr->mp, "%i",
(int)((60 * counter)/(apr_time_sec(apr_time_now()) - create_time)));
/* NOTE: No rate if there has been no time elapsed */
td = (apr_time_sec(apr_time_now()) - create_time);
if (td == 0) {
var->value = apr_psprintf(msr->mp, "%i", 0);
}
else {
var->value = apr_psprintf(msr->mp, "%i",
(int)((60 * counter)/td));
}
var->value_len = strlen(var->value);
}
}