Skip to content

Commit cca47cf

Browse files
move the error checks from sslclient.cpp to wsclient.cpp where they belong, so they dont cause excessive data copies or false alarms (#902)
1 parent 7cc57af commit cca47cf

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

src/dpp/sslclient.cpp

-22
Original file line numberDiff line numberDiff line change
@@ -508,28 +508,6 @@ void ssl_client::read_loop()
508508
case SSL_ERROR_NONE:
509509
/* Data received, add it to the buffer */
510510
if (r > 0) {
511-
const std::string data(server_to_client_buffer, r);
512-
/* Split the data into an array for every line. */
513-
const std::vector<std::string> data_lines = utility::tokenize(data);
514-
/* Get the first line as we always know that's the HTTP response. */
515-
const std::string http_reponse(data_lines[0]);
516-
517-
/* Does the first line begin with a http code? */
518-
if (http_reponse.rfind("HTTP/1.1", 0) != std::string::npos) {
519-
/* Now let's split the first line by every space, meaning we can check the actual HTTP code. */
520-
const std::vector<std::string> line_split_by_space = utility::tokenize(data_lines[0], " ");
521-
522-
/* We need to make sure there's at least 3 elements in line_split_by_space. */
523-
if (line_split_by_space.size() >= 3) {
524-
const int http_code = std::stoi(line_split_by_space[1]);
525-
526-
/* If the http_code isn't 204, 101, or 200, log it. */
527-
if (http_code != 204 && http_code != 101 && http_code != 200) {
528-
log(ll_warning, "Received unhandled code: " + http_reponse);
529-
}
530-
}
531-
}
532-
533511
buffer.append(server_to_client_buffer, r);
534512
if (!this->handle_buffer(buffer)) {
535513
return;

src/dpp/wsclient.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ bool websocket_client::handle_buffer(std::string &buffer)
156156
}
157157

158158
state = CONNECTED;
159-
} else {
159+
} else if (status.size() < 3) {
160+
log(ll_warning, "Malformed HTTP response on websocket");
161+
return false;
162+
} else if (status[1] != "200" && status[1] != "204") {
163+
log(ll_warning, "Received unhandled code: " + status[1]);
160164
return false;
161165
}
162166
}

0 commit comments

Comments
 (0)