From 2852520d9047bbdb172fc4afa29dfe4d97c2a501 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sun, 16 Oct 2022 00:13:51 -0700 Subject: [PATCH] Fix WebSocket server sending invalid data at the end --- src/deps/libuwsockets.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/deps/libuwsockets.cpp b/src/deps/libuwsockets.cpp index d542b7ecbc..271794019f 100644 --- a/src/deps/libuwsockets.cpp +++ b/src/deps/libuwsockets.cpp @@ -488,15 +488,17 @@ uws_sendstatus_t uws_ws_send_with_options(int ssl, uws_websocket_t *ws, if (ssl) { uWS::WebSocket *uws = (uWS::WebSocket *)ws; - return (uws_sendstatus_t)uws->send(std::string_view(message), + return (uws_sendstatus_t)uws->send(std::string_view(message, length), + (uWS::OpCode)(unsigned char)opcode, + compress, fin); + } else { + + uWS::WebSocket *uws = + (uWS::WebSocket *)ws; + return (uws_sendstatus_t)uws->send(std::string_view(message, length), (uWS::OpCode)(unsigned char)opcode, compress, fin); } - uWS::WebSocket *uws = - (uWS::WebSocket *)ws; - return (uws_sendstatus_t)uws->send(std::string_view(message), - (uWS::OpCode)(unsigned char)opcode, - compress, fin); } uws_sendstatus_t uws_ws_send_fragment(int ssl, uws_websocket_t *ws, @@ -520,12 +522,12 @@ uws_sendstatus_t uws_ws_send_first_fragment(int ssl, uws_websocket_t *ws, uWS::WebSocket *uws = (uWS::WebSocket *)ws; return (uws_sendstatus_t)uws->sendFirstFragment( - std::string_view(message), uWS::OpCode::BINARY, compress); + std::string_view(message, length), uWS::OpCode::BINARY, compress); } uWS::WebSocket *uws = (uWS::WebSocket *)ws; return (uws_sendstatus_t)uws->sendFirstFragment( - std::string_view(message), uWS::OpCode::BINARY, compress); + std::string_view(message, length), uWS::OpCode::BINARY, compress); } uws_sendstatus_t uws_ws_send_first_fragment_with_opcode(int ssl, uws_websocket_t *ws,