diff options
author | Alexander Tkachev | 2016-06-15 21:59:03 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 99c51380fdc866ce393c52eb41803a9ec119a9ad (patch) | |
tree | 83511132a8a8a75cd75ca9d9a078aa4ca091ae55 /backends/networking/sdl_net/client.cpp | |
parent | 6126435b64442ae838953e095191230737391dca (diff) | |
download | scummvm-rg350-99c51380fdc866ce393c52eb41803a9ec119a9ad.tar.gz scummvm-rg350-99c51380fdc866ce393c52eb41803a9ec119a9ad.tar.bz2 scummvm-rg350-99c51380fdc866ce393c52eb41803a9ec119a9ad.zip |
CLOUD: Add ClientState::BAD_REQUEST
Diffstat (limited to 'backends/networking/sdl_net/client.cpp')
-rw-r--r-- | backends/networking/sdl_net/client.cpp | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/backends/networking/sdl_net/client.cpp b/backends/networking/sdl_net/client.cpp index 2af940c232..8ab9ed385e 100644 --- a/backends/networking/sdl_net/client.cpp +++ b/backends/networking/sdl_net/client.cpp @@ -60,11 +60,12 @@ void Client::readHeaders() { int bytes = SDLNet_TCP_Recv(_socket, buffer, BUFFER_SIZE); if (bytes <= 0) { warning("Client::readHeaders recv fail"); - _state = INVALID; + close(); return; - } + } _headers += Common::String(buffer, bytes); checkIfHeadersEnded(); + checkIfBadRequest(); } void Client::checkIfHeadersEnded() { @@ -73,6 +74,46 @@ void Client::checkIfHeadersEnded() { if (position) _state = READ_HEADERS; } +void Client::checkIfBadRequest() { + if (_state != READING_HEADERS) return; + uint32 headersSize = _headers.size(); + bool bad = false; + + const uint32 SUSPICIOUS_HEADERS_SIZE = 128 * 1024; + if (headersSize > SUSPICIOUS_HEADERS_SIZE) bad = true; + + if (!bad) { + if (headersSize > 0) { + const char *cstr = _headers.c_str(); + const char *position = strstr(cstr, "\r\n"); + if (position) { //we have at least one line - and we want the first one + //"<METHOD> <path> HTTP/<VERSION>\r\n" + Common::String method, path, http, buf; + for (uint32 i = 0; i < headersSize; ++i) { + if (_headers[i] == ' ') { + if (method == "") method = buf; + else if (path == "") path = buf; + else if (http == "") http = buf; + else { + bad = true; + break; + } + buf = ""; + } else buf += _headers[i]; + } + + //check that method is supported + if (method != "GET" && method != "PUT" && method != "POST") bad = true; + + //check that HTTP/<VERSION> is OK + if (!http.hasPrefix("HTTP/")) bad = true; + } + } + } + + if (bad) _state = BAD_REQUEST; +} + void Client::close() { if (_set) { if (_socket) { |