From 93c0202ad93c4bace9c8c79286a788300c86d08e Mon Sep 17 00:00:00 2001 From: Nan Zhou Date: Thu, 24 Feb 2022 18:21:07 -0800 Subject: 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 Change-Id: I56613a26c129736f0e6980bb24e83f22ef60eea0 --- http/routing.hpp | 2 ++ http/websocket.hpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) 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> myConnection = std::make_shared< @@ -356,6 +357,7 @@ class WebSocketRule : public BaseRule boost::beast::ssl_stream&& adaptor) override { + BMCWEB_LOG_DEBUG << "Websocket handles upgrade"; std::shared_ptr>> myConnection = std::make_shared closeHandler, std::function 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)), -- cgit v1.2.3