Skip to content

Commit

Permalink
throw exception on binary req
Browse files Browse the repository at this point in the history
  • Loading branch information
hadisfr committed Jan 11, 2019
1 parent 2192458 commit 10c92c4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void split(string str, string separator, int max, vector<string> &results) {
results.push_back(str);
}

Request *parseRawReq(char *headersRaw) {
Request *parseRawReq(char *headersRaw, size_t length) {
Request *req;
string boundary;
string lastFieldKey;
Expand All @@ -71,6 +71,10 @@ Request *parseRawReq(char *headersRaw) {
enum State { REQ, HEADER, BODY, BODY_HEADER, BODY_BODY };
State state = REQ;
vector<string> headers = split(string(headersRaw), "\r\n", false);
for (size_t i = 0; i < length; i++) {
if (!headersRaw[i])
throw Server::Exception("Unsupported binary data in request.");
}
size_t realBodySize =
string(headersRaw).size() -
split(string(headersRaw), "\r\n\r\n", false)[0].size() -
Expand Down Expand Up @@ -253,7 +257,7 @@ void Server::run() {
if (recv_len > 0) {
recv_total_len += recv_len;
data[recv_total_len >= 0 ? recv_total_len : 0] = 0;
req = parseRawReq(data);
req = parseRawReq(data, recv_total_len);
} else
break;
}
Expand Down

0 comments on commit 10c92c4

Please sign in to comment.