diff options
author | Nan Zhou <nanzhoumails@gmail.com> | 2022-02-25 05:21:07 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-02-28 20:56:53 +0300 |
commit | 93c0202ad93c4bace9c8c79286a788300c86d08e (patch) | |
tree | 912200d8381e2caba84526da83c5e74eb3d1353d | |
parent | 2b20ef6ee2a8ca656aaa49b181d9205e30ede451 (diff) | |
download | bmcweb-93c0202ad93c4bace9c8c79286a788300c86d08e.tar.xz |
websocket: fix authless
We should check if session is nullptr before referencing its data
member.
Tested:
1. build authless BMCWeb
```
meson -Drest=enabled -Dbmcweb-logging=enabled
-Dinsecure-disable-auth=enabled build && ninja -C build &&
./build/bmcweb
```
2. start websocket client without problems
```
python scripts/websocket_test.py --host localhost:18080
```
3. bmcweb log
```
[DEBUG "websocket.hpp":221] Websocket accepted connection
[DEBUG "dbus_monitor.hpp":114] Connection opened
[DEBUG "dbus_monitor.hpp":115] Connection 0x55b22d618670 opened
[DEBUG "http_response.hpp":134] 0x55b22d611040 calling completion
handler
[DEBUG "dbus_monitor.hpp":129] Connection 0x55b22d618670 received
{"paths": ["/xyz/openbmc_project/sensors"],
"interfaces": ["xyz.openbmc_project.Sensor.Value"]}
[DEBUG "dbus_monitor.hpp":231] Creating match
type='signal',interface='org.freedesktop.DBus.Properties',
path_namespace='/xyz/openbmc_project/sensors',member='PropertiesChanged',
arg0='xyz.openbmc_project.Sensor.Value'
[DEBUG "dbus_monitor.hpp":246] Creating match
type='signal',interface='org.freedesktop.DBus.ObjectManager',
path_namespace='/xyz/openbmc_project/sensors',member='InterfacesAdded'
```
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I56613a26c129736f0e6980bb24e83f22ef60eea0
-rw-r--r-- | http/routing.hpp | 2 | ||||
-rw-r--r-- | http/websocket.hpp | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/http/routing.hpp b/http/routing.hpp index e39bfcc9eb..b39442bd3a 100644 --- a/http/routing.hpp +++ b/http/routing.hpp @@ -343,6 +343,7 @@ class WebSocketRule : public BaseRule void handleUpgrade(const Request& req, Response& /*res*/, boost::asio::ip::tcp::socket&& adaptor) override { + BMCWEB_LOG_DEBUG << "Websocket handles upgrade"; std::shared_ptr< crow::websocket::ConnectionImpl<boost::asio::ip::tcp::socket>> myConnection = std::make_shared< @@ -356,6 +357,7 @@ class WebSocketRule : public BaseRule boost::beast::ssl_stream<boost::asio::ip::tcp::socket>&& adaptor) override { + BMCWEB_LOG_DEBUG << "Websocket handles upgrade"; std::shared_ptr<crow::websocket::ConnectionImpl< boost::beast::ssl_stream<boost::asio::ip::tcp::socket>>> myConnection = std::make_shared<crow::websocket::ConnectionImpl< diff --git a/http/websocket.hpp b/http/websocket.hpp index 213c4c74c0..daa510020f 100644 --- a/http/websocket.hpp +++ b/http/websocket.hpp @@ -76,7 +76,8 @@ class ConnectionImpl : public Connection messageHandler, std::function<void(Connection&, const std::string&)> closeHandler, std::function<void(Connection&)> errorHandler) : - Connection(reqIn, reqIn.session->username), + Connection(reqIn, reqIn.session == nullptr ? std::string{} + : reqIn.session->username), ws(std::move(adaptorIn)), inBuffer(inString, 131088), openHandler(std::move(openHandler)), messageHandler(std::move(messageHandler)), |