From 4ab00aa6f30a4e6b1742ab032e256f9db8da79fa Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Sat, 30 Sep 2023 16:47:28 +0000 Subject: [PATCH 1/2] move the error checks from sslclient.cpp to wsclient.cpp where they belong, so they dont cause excessive data copies or false alarms --- src/dpp/sslclient.cpp | 22 ---------------------- src/dpp/wsclient.cpp | 4 ++++ 2 files changed, 4 insertions(+), 22 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..afeadcd576 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 if (status.size() < 3) { + log(ll_warning, "Malformed HTTP response on websocket"); + return false; } else { + log(ll_warning, "Received unhandled code: " + status[1]); return false; } } From 17c17da1f9123861f09bc7eb59cd2070ef63ea11 Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Sat, 30 Sep 2023 16:53:22 +0000 Subject: [PATCH 2/2] extra check for 200 and 204 so we dont spam console --- src/dpp/wsclient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dpp/wsclient.cpp b/src/dpp/wsclient.cpp index afeadcd576..91d1281065 100644 --- a/src/dpp/wsclient.cpp +++ b/src/dpp/wsclient.cpp @@ -159,7 +159,7 @@ bool websocket_client::handle_buffer(std::string &buffer) } else if (status.size() < 3) { log(ll_warning, "Malformed HTTP response on websocket"); return false; - } else { + } else if (status[1] != "200" && status[1] != "204") { log(ll_warning, "Received unhandled code: " + status[1]); return false; }