Skip to content

Commit 8cffc6d

Browse files
author
Felipe Zimmerle
committed
Suggestion based on #1747
1 parent f533ca9 commit 8cffc6d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/request_body_processor/multipart.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,10 @@ int Multipart::multipart_complete(std::string *error) {
10891089
#ifndef NO_LOGS
10901090
debug(1, "Multipart: Final boundary missing.");
10911091
#endif
1092+
m_flag_unmatched_boundary = 1;
1093+
m_transaction->m_variableMultipartUnmatchedBoundary.set(
1094+
std::to_string(m_flag_unmatched_boundary),
1095+
m_transaction->m_variableOffset);
10921096
error->assign("Multipart: Final boundary missing.");
10931097
return false;
10941098
}
@@ -1424,6 +1428,8 @@ bool Multipart::process(const std::string& data, std::string *error,
14241428
unsigned int inleft = data.size();
14251429
size_t z = 0;
14261430

1431+
std::list<std::string> boundaries;
1432+
14271433
if (data.size() == 0) return true;
14281434
m_seen_data = true;
14291435

@@ -1574,7 +1580,13 @@ bool Multipart::process(const std::string& data, std::string *error,
15741580
return false;
15751581
}
15761582

1577-
m_flag_unmatched_boundary = 1;
1583+
bool contains = std::find(boundaries.begin(), boundaries.end(), p) != boundaries.end();
1584+
if (contains) {
1585+
debug(4, "Multipart: unmatched boundary... '" + std::string(p) + "'.");
1586+
m_flag_unmatched_boundary = 1;
1587+
} else {
1588+
boundaries.push_back(p);
1589+
}
15781590
}
15791591
} else { /* We do not think the buffer contains a boundary. */
15801592
/* Look into the buffer to see if there's anything
@@ -1589,6 +1601,7 @@ bool Multipart::process(const std::string& data, std::string *error,
15891601
&& (p[i + 1] == '-')) {
15901602
if (strncmp(p + i + 2, m_boundary.c_str(),
15911603
m_boundary.size()) == 0) {
1604+
debug(4, "Multipart: unmatched boundary.");
15921605
m_flag_unmatched_boundary = 1;
15931606
break;
15941607
}

0 commit comments

Comments
 (0)