From cca47cf17a9072afcf868775a73f4ae844567ab0 Mon Sep 17 00:00:00 2001 From: Brain Date: Sat, 30 Sep 2023 20:01:38 +0100 Subject: [PATCH] move the error checks from sslclient.cpp to wsclient.cpp where they belong, so they dont cause excessive data copies or false alarms (#902) --- src/dpp/sslclient.cpp | 22 ---------------------- src/dpp/wsclient.cpp | 6 +++++- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/dpp/sslclient.cpp b/src/dpp/sslclient.cpp index bf6906c7a2..d1e494fcf0 100644 --- a/src/dpp/sslclient.cpp +++ b/src/dpp/sslclient.cpp @@ -508,28 +508,6 @@ void ssl_client::read_loop() case SSL_ERROR_NONE: /* Data received, add it to the buffer */ if (r > 0) { - const std::string data(server_to_client_buffer, r); - /* Split the data into an array for every line. */ - const std::vector data_lines = utility::tokenize(data); - /* Get the first line as we always know that's the HTTP response. */ - const std::string http_reponse(data_lines[0]); - - /* Does the first line begin with a http code? */ - if (http_reponse.rfind("HTTP/1.1", 0) != std::string::npos) { - /* Now let's split the first line by every space, meaning we can check the actual HTTP code. */ - const std::vector line_split_by_space = utility::tokenize(data_lines[0], " "); - - /* We need to make sure there's at least 3 elements in line_split_by_space. */ - if (line_split_by_space.size() >= 3) { - const int http_code = std::stoi(line_split_by_space[1]); - - /* If the http_code isn't 204, 101, or 200, log it. */ - if (http_code != 204 && http_code != 101 && http_code != 200) { - log(ll_warning, "Received unhandled code: " + http_reponse); - } - } - } - buffer.append(server_to_client_buffer, r); if (!this->handle_buffer(buffer)) { return; diff --git a/src/dpp/wsclient.cpp b/src/dpp/wsclient.cpp index de229f67e3..91d1281065 100644 --- a/src/dpp/wsclient.cpp +++ b/src/dpp/wsclient.cpp @@ -156,7 +156,11 @@ bool websocket_client::handle_buffer(std::string &buffer) } state = CONNECTED; - } else { + } else if (status.size() < 3) { + log(ll_warning, "Malformed HTTP response on websocket"); + return false; + } else if (status[1] != "200" && status[1] != "204") { + log(ll_warning, "Received unhandled code: " + status[1]); return false; } }