From 709042a4720697bf0d2085ef7276a6aa190f2142 Mon Sep 17 00:00:00 2001 From: Robert Paprocki Date: Tue, 4 Oct 2016 15:45:25 -0700 Subject: [PATCH] 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. --- apache2/msc_multipart.c | 5 +++++ apache2/msc_reqbody.c | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/apache2/msc_multipart.c b/apache2/msc_multipart.c index 88eff9b7..9bf327d2 100644 --- a/apache2/msc_multipart.c +++ b/apache2/msc_multipart.c @@ -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; diff --git a/apache2/msc_reqbody.c b/apache2/msc_reqbody.c index 7d150eed..a8411fa0 100644 --- a/apache2/msc_reqbody.c +++ b/apache2/msc_reqbody.c @@ -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; } }