mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-17 01:56:07 +03:00
Fix multipart parser on binary content
This commit is contained in:
parent
23d843259d
commit
97214edf6e
@ -192,7 +192,6 @@ bool Multipart::process(std::string data) {
|
|||||||
debug(4, "Multipart: Boundary was not the first thing.");
|
debug(4, "Multipart: Boundary was not the first thing.");
|
||||||
this->containsDataBefore = true;
|
this->containsDataBefore = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (start != std::string::npos) {
|
while (start != std::string::npos) {
|
||||||
size_t end = data.find(m_boundary, start + m_boundary.length());
|
size_t end = data.find(m_boundary, start + m_boundary.length());
|
||||||
if (end == std::string::npos) {
|
if (end == std::string::npos) {
|
||||||
@ -204,6 +203,10 @@ bool Multipart::process(std::string data) {
|
|||||||
|
|
||||||
checkForCrlfLf(block);
|
checkForCrlfLf(block);
|
||||||
|
|
||||||
|
if (this->crlf) {
|
||||||
|
block.erase(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
blobs.push_back(block);
|
blobs.push_back(block);
|
||||||
lastValidBoundary = end;
|
lastValidBoundary = end;
|
||||||
start = end;
|
start = end;
|
||||||
@ -223,21 +226,31 @@ bool Multipart::process(std::string data) {
|
|||||||
|
|
||||||
std::string filename("");
|
std::string filename("");
|
||||||
std::string name("");
|
std::string name("");
|
||||||
|
int i = 0;
|
||||||
for (std::string x : blobs) {
|
for (std::string x : blobs) {
|
||||||
|
i++;
|
||||||
|
debug(5, "Multipart: Inspecting blob: " + std::to_string(i));
|
||||||
MultipartBlob m(x, this);
|
MultipartBlob m(x, this);
|
||||||
|
|
||||||
if (m.name.empty() == false) {
|
if (m.name.empty() == false) {
|
||||||
name = m.name;
|
name = m.name;
|
||||||
|
} else {
|
||||||
|
name = "no-name-" + std::to_string(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m.filename.empty() == false) {
|
if (m.filename.empty() == false) {
|
||||||
filename = m.filename;
|
filename = m.filename;
|
||||||
variables.emplace("FILES:" + m.name, m.filename);
|
} else {
|
||||||
variables.emplace("FILES_NAMES:" + m.name, m.name);
|
filename = "no-file-name-" + std::to_string(i);
|
||||||
variables.emplace("FILES_SIZES:" + m.name,
|
|
||||||
std::to_string(m.content.size()));
|
|
||||||
variables.emplace("FILES_TMP_CONTENT:" + m.name, m.content);
|
|
||||||
files_size = files_size + m.content.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variables.emplace("FILES:" + name, filename);
|
||||||
|
variables.emplace("FILES_NAMES:" + name, name);
|
||||||
|
variables.emplace("FILES_SIZES:" + name,
|
||||||
|
std::to_string(m.content.size()));
|
||||||
|
debug(5, "Multipart: Saving FILES_TMP_CONTENT:" + name + " variable.");
|
||||||
|
variables.emplace("FILES_TMP_CONTENT:" + name, m.content);
|
||||||
|
files_size = files_size + m.content.size();
|
||||||
if (m.invalidQuote) {
|
if (m.invalidQuote) {
|
||||||
debug(4, "Multipart: Found invalid quoting.");
|
debug(4, "Multipart: Found invalid quoting.");
|
||||||
this->invalidQuote = true;
|
this->invalidQuote = true;
|
||||||
|
@ -41,7 +41,6 @@ bool MultipartBlob::processContent() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::string firstLine = std::string(m_blob, offset, end);
|
std::string firstLine = std::string(m_blob, offset, end);
|
||||||
|
|
||||||
offset = end + 1;
|
offset = end + 1;
|
||||||
end = m_blob.find("\n", offset);
|
end = m_blob.find("\n", offset);
|
||||||
if (end == std::string::npos) {
|
if (end == std::string::npos) {
|
||||||
@ -93,7 +92,8 @@ bool MultipartBlob::processContentDispositionLine(
|
|||||||
const std::string &dispositionLine) {
|
const std::string &dispositionLine) {
|
||||||
size_t offset;
|
size_t offset;
|
||||||
|
|
||||||
if (dispositionLine.compare(21, 9, "form-data") != 0) {
|
if (dispositionLine.size() < 30 ||
|
||||||
|
dispositionLine.compare(21, 9, "form-data") != 0) {
|
||||||
debug(4, "Multipart: Content-Disposition is unknown");
|
debug(4, "Multipart: Content-Disposition is unknown");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user