Don't unnecessarily rename request body parts in cleanup

When tmp_dir and upload_dir are identical, there's no reason to
rename multipart and request body parts, as this is a non-op. Let's
save the cycles and syscall.
This commit is contained in:
Robert Paprocki 2016-10-04 15:45:25 -07:00 committed by Felipe Zimmerle
parent 8559dd3b8b
commit 709042a472
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
2 changed files with 12 additions and 0 deletions

View File

@ -1327,6 +1327,11 @@ apr_status_t multipart_cleanup(modsec_rec *msr) {
} else {
/* Move file to the upload dir. */
if (parts[i]->tmp_file_name != NULL) {
if (strcmp(msr->txcfg->upload_dir, msr->txcfg->tmp_dir) == 0) {
msr_log(msr, 4, "Not moving part to identical location");
continue;
}
const char *new_filename = NULL;
const char *new_basename = NULL;

View File

@ -884,6 +884,11 @@ apr_status_t modsecurity_request_body_clear(modsec_rec *msr, char **error_msg) {
if (msr->msc_reqbody_filename != NULL) {
if (keep_body) {
if (strcmp(msr->txcfg->upload_dir, msr->txcfg->tmp_dir) == 0) {
msr_log(msr, 4, "Not moving file to identical location.");
goto nullify;
}
/* Move request body (which is a file) to the storage area. */
const char *put_filename = NULL;
const char *put_basename = NULL;
@ -933,6 +938,8 @@ apr_status_t modsecurity_request_body_clear(modsec_rec *msr, char **error_msg) {
msr->msc_reqbody_filename);
}
nullify:
msr->msc_reqbody_filename = NULL;
}
}