Compare commits

...

5 Commits

Author SHA1 Message Date
Benjamin Sergeant
09aac56ab4 (websocket client + server) WebSocketMessage class tweak to fix unsafe patterns 2021-06-03 18:41:22 -07:00
Nikos Athanasiou
26897b2425 Fix unsafe calls and safeguard WebSocketMessage (#294)
* Fix unsafe calls and safeguard WebSocketMessage from being called w/
temporaries

* Use unnamed namespace to express internal linkage
2021-06-03 18:39:38 -07:00
Benjamin Sergeant
e3c98a03cc (websocket server) Handle and accept firefox browser special upgrade value (keep-alive, Upgrade) 2021-05-27 10:54:21 -07:00
Benjamin Sergeant
97fedf9482 (Windows) move EINVAL (re)definition from IXSocket.h to IXNetSystem.h (fix #289) 2021-05-27 10:54:21 -07:00
Benjamin Sergeant
ae187c0e98 Readme: Add mingw to build matrix 2021-05-18 11:15:21 -07:00
8 changed files with 44 additions and 8 deletions

View File

@@ -132,6 +132,7 @@ To check the performance of a websocket library, you can look at the [autoroute]
| Windows | Disabled | None | [![Build2][5]][0] | | Windows | Disabled | None | [![Build2][5]][0] |
| UWP | Disabled | None | [![Build2][6]][0] | | UWP | Disabled | None | [![Build2][6]][0] |
| Linux | OpenSSL | Address Sanitizer | [![Build2][7]][0] | | Linux | OpenSSL | Address Sanitizer | [![Build2][7]][0] |
| Mingw | Disabled | None | [![Build2][8]][0] |
* ASAN fails on Linux because of a known problem, we need a * ASAN fails on Linux because of a known problem, we need a
* Some tests are disabled on Windows/UWP because of a pathing problem * Some tests are disabled on Windows/UWP because of a pathing problem
@@ -145,4 +146,5 @@ To check the performance of a websocket library, you can look at the [autoroute]
[5]: https://github.com/machinezone/IXWebSocket/workflows/windows/badge.svg [5]: https://github.com/machinezone/IXWebSocket/workflows/windows/badge.svg
[6]: https://github.com/machinezone/IXWebSocket/workflows/uwp/badge.svg [6]: https://github.com/machinezone/IXWebSocket/workflows/uwp/badge.svg
[7]: https://github.com/machinezone/IXWebSocket/workflows/linux_asan/badge.svg [7]: https://github.com/machinezone/IXWebSocket/workflows/linux_asan/badge.svg
[8]: https://github.com/machinezone/IXWebSocket/workflows/unittest_windows_gcc/badge.svg

View File

@@ -2,6 +2,18 @@
All changes to this project will be documented in this file. All changes to this project will be documented in this file.
## [11.2.8] - 2021-06-03
(websocket client + server) WebSocketMessage class tweak to fix unsafe patterns
## [11.2.7] - 2021-05-27
(websocket server) Handle and accept firefox browser special upgrade value (keep-alive, Upgrade)
## [11.2.6] - 2021-05-18
(Windows) move EINVAL (re)definition from IXSocket.h to IXNetSystem.h (fix #289)
## [11.2.5] - 2021-04-04 ## [11.2.5] - 2021-04-04
(http client) DEL is not an HTTP method name, but DELETE is (http client) DEL is not an HTTP method name, but DELETE is

View File

@@ -137,7 +137,7 @@ namespace ix
{ {
contentLength = std::stoi(headers["Content-Length"]); contentLength = std::stoi(headers["Content-Length"]);
} }
catch(const std::exception&) catch (const std::exception&)
{ {
return std::make_tuple( return std::make_tuple(
false, "Error parsing HTTP Header 'Content-Length'", httpRequest); false, "Error parsing HTTP Header 'Content-Length'", httpRequest);

View File

@@ -15,6 +15,12 @@
#include <cmath> #include <cmath>
namespace
{
const std::string emptyMsg;
} // namespace
namespace ix namespace ix
{ {
OnTrafficTrackerCallback WebSocket::_onTrafficTrackerCallback = nullptr; OnTrafficTrackerCallback WebSocket::_onTrafficTrackerCallback = nullptr;
@@ -38,7 +44,7 @@ namespace ix
[this](uint16_t code, const std::string& reason, size_t wireSize, bool remote) { [this](uint16_t code, const std::string& reason, size_t wireSize, bool remote) {
_onMessageCallback( _onMessageCallback(
ix::make_unique<WebSocketMessage>(WebSocketMessageType::Close, ix::make_unique<WebSocketMessage>(WebSocketMessageType::Close,
"", emptyMsg,
wireSize, wireSize,
WebSocketErrorInfo(), WebSocketErrorInfo(),
WebSocketOpenInfo(), WebSocketOpenInfo(),
@@ -217,7 +223,7 @@ namespace ix
_onMessageCallback(ix::make_unique<WebSocketMessage>( _onMessageCallback(ix::make_unique<WebSocketMessage>(
WebSocketMessageType::Open, WebSocketMessageType::Open,
"", emptyMsg,
0, 0,
WebSocketErrorInfo(), WebSocketErrorInfo(),
WebSocketOpenInfo(status.uri, status.headers, status.protocol), WebSocketOpenInfo(status.uri, status.headers, status.protocol),
@@ -251,7 +257,7 @@ namespace ix
_onMessageCallback( _onMessageCallback(
ix::make_unique<WebSocketMessage>(WebSocketMessageType::Open, ix::make_unique<WebSocketMessage>(WebSocketMessageType::Open,
"", emptyMsg,
0, 0,
WebSocketErrorInfo(), WebSocketErrorInfo(),
WebSocketOpenInfo(status.uri, status.headers), WebSocketOpenInfo(status.uri, status.headers),
@@ -338,7 +344,7 @@ namespace ix
connectErr.http_status = status.http_status; connectErr.http_status = status.http_status;
_onMessageCallback(ix::make_unique<WebSocketMessage>(WebSocketMessageType::Error, _onMessageCallback(ix::make_unique<WebSocketMessage>(WebSocketMessageType::Error,
"", emptyMsg,
0, 0,
connectErr, connectErr,
WebSocketOpenInfo(), WebSocketOpenInfo(),

View File

@@ -204,6 +204,9 @@ namespace ix
// Check the value of the connection field // Check the value of the connection field
// Some websocket servers (Go/Gorilla?) send lowercase values for the // Some websocket servers (Go/Gorilla?) send lowercase values for the
// connection header, so do a case insensitive comparison // connection header, so do a case insensitive comparison
//
// See https://github.com/apache/thrift/commit/7c4bdf9914fcba6c89e0f69ae48b9675578f084a
//
if (!insensitiveStringCompare(headers["connection"], "Upgrade")) if (!insensitiveStringCompare(headers["connection"], "Upgrade"))
{ {
std::stringstream ss; std::stringstream ss;
@@ -296,7 +299,8 @@ namespace ix
return sendErrorResponse(400, "Missing Upgrade header"); return sendErrorResponse(400, "Missing Upgrade header");
} }
if (!insensitiveStringCompare(headers["upgrade"], "WebSocket")) if (!insensitiveStringCompare(headers["upgrade"], "WebSocket") &&
headers["Upgrade"] != "keep-alive, Upgrade") // special case for firefox
{ {
return sendErrorResponse(400, return sendErrorResponse(400,
"Invalid Upgrade header, " "Invalid Upgrade header, "

View File

@@ -42,6 +42,18 @@ namespace ix
{ {
; ;
} }
/**
* @brief Deleted overload to prevent binding `str` to a temporary, which would cause
* undefined behavior since class members don't extend lifetime beyond the constructor call.
*/
WebSocketMessage(WebSocketMessageType t,
std::string&& s,
size_t w,
WebSocketErrorInfo e,
WebSocketOpenInfo o,
WebSocketCloseInfo c,
bool b = false) = delete;
}; };
using WebSocketMessagePtr = std::unique_ptr<WebSocketMessage>; using WebSocketMessagePtr = std::unique_ptr<WebSocketMessage>;

View File

@@ -6,4 +6,4 @@
#pragma once #pragma once
#define IX_WEBSOCKET_VERSION "11.2.5" #define IX_WEBSOCKET_VERSION "11.2.8"