Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/request_body_processor/multipart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
static const char* attr_char_special = "!#$&+-.^_`~";

MultipartPartTmpFile::~MultipartPartTmpFile() {
if (!m_tmp_file_name.empty() && m_delete) {
/* make sure it is closed first */
if (m_tmp_file_fd > 0) {
Close();
}
/* make sure it is closed first */
if (m_tmp_file_fd >= 0) {
Close();
}

if (!m_tmp_file_name.empty() && m_delete) {
const int unlink_rc = unlink(m_tmp_file_name.c_str());
if (unlink_rc < 0) {
ms_dbg_a(m_transaction, 1, "Multipart: Failed to delete file (part) \"" \
Expand Down Expand Up @@ -93,7 +93,7 @@
#else
if (_chmod(m_tmp_file_name.c_str(), mode) == -1) {
#endif
m_tmp_file_fd = -1;
Close();
}
}
}
Expand Down Expand Up @@ -158,6 +158,14 @@
}

}

/* the part being built when the payload ended is not in m_parts */
if ((m_mpp != nullptr) && (m_mpp->m_type == MULTIPART_FILE)
&& (m_mpp->m_tmp_file)) {
ms_dbg_a(m_transaction, 9, "Multipart: Marking temporary file for deletion: " \
+ m_mpp->m_tmp_file->getFilename());

Check warning on line 166 in src/request_body_processor/multipart.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Modify the macro definition so that it needs to be followed by a semicolon, or remove this empty statement.

See more on https://sonarcloud.io/project/issues?id=owasp-modsecurity_ModSecurity&issues=AaC6De5oTpzexTo1TUAI&open=AaC6De5oTpzexTo1TUAI&pullRequest=3632
m_mpp->m_tmp_file->setDelete();
}
}

while (m_parts.empty() == false) {
Expand Down
4 changes: 2 additions & 2 deletions src/request_body_processor/multipart.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class MultipartPartTmpFile {
public:
explicit MultipartPartTmpFile(Transaction *transaction)
: m_transaction(transaction),
m_tmp_file_fd(0),
m_tmp_file_fd(-1),
m_delete(false)
{ }

Expand All @@ -73,7 +73,7 @@ class MultipartPartTmpFile {
const std::string& getFilename() const {return m_tmp_file_name;}
void setDelete() {m_delete = true;}

bool isValid() const {return ((m_tmp_file_fd != 0) && (!m_tmp_file_name.empty()));}
bool isValid() const {return ((m_tmp_file_fd >= 0) && (!m_tmp_file_name.empty()));}

void Open();
void Close();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[
{
"enabled": 1,
"version_min": 300000,
"title": "multipart parser (truncated body, file part without final boundary)",
"client": {
"ip": "200.249.12.31",
"port": 123
},
"server": {
"ip": "200.249.12.31",
"port": 80
},
"request": {
"headers": {
"Host": "localhost",
"User-Agent": "curl/7.38.0",
"Accept": "*/*",
"Content-Length": "117",
"Content-Type": "multipart/form-data; boundary=0000"
},
"uri": "/",
"method": "POST",
"body": [
"--0000\r\n",
"Content-Disposition: form-data; name=\"file1\"; filename=\"upload.txt\"\r\n",
"Content-Type: text/plain\r\n",
"\r\n",
"UPLOADDATA\r\n"
]
},
"response": {
"headers": {
"Date": "Mon, 13 Jul 2015 20:02:41 GMT",
"Last-Modified": "Sun, 26 Oct 2014 22:33:37 GMT",
"Content-Type": "text/html",
"Content-Length": "8"
},
"body": [
"no need."
]
},
"expected": {
"debug_log": "Multipart: Final boundary missing\\.",
"http_code": 200
},
"rules": [
"SecRuleEngine On",
"SecRequestBodyAccess On",
"SecTmpSaveUploadedFiles On",
"SecUploadDir /tmp",
"SecRule REQBODY_ERROR \"!@eq 0\" \"id:500058,phase:2,pass,log\""
]
}
]
1 change: 1 addition & 0 deletions test/test-suite.in
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ TESTS+=test/test-cases/regression/operator-verifysvnr.json
TESTS+=test/test-cases/regression/request-body-parser-json.json
TESTS+=test/test-cases/regression/request-body-parser-multipart-crlf.json
TESTS+=test/test-cases/regression/request-body-parser-multipart.json
TESTS+=test/test-cases/regression/request-body-parser-multipart-truncated.json
TESTS+=test/test-cases/regression/request-body-parser-xml.json
TESTS+=test/test-cases/regression/request-body-parser-xml-validade-dtd.json
TESTS+=test/test-cases/regression/rule-920120.json
Expand Down
Loading