summaryrefslogtreecommitdiff
path: root/http/http_connection.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2023-06-30 23:21:32 +0300
committerEd Tanous <ed@tanous.net>2023-08-07 20:51:50 +0300
commite01d0c36af115ed46d54b5dbbacfe3ad92226bd3 (patch)
tree3355d0c47cc9af8068a0a3f7329a8109573f9eb1 /http/http_connection.hpp
parent1ccf70f116b28a0f78404b914a789ce05f411ddf (diff)
downloadbmcweb-e01d0c36af115ed46d54b5dbbacfe3ad92226bd3.tar.xz
Fix bugprone-unchecked-optional-access findings
Clang-tidy has the aforementioned check, which shows a few places in the core where we ignored the required optional checks. Fix all uses. Note, we cannot enable the check that this time because of some weird code in health.hpp that crashes tidy[1]. That will need to be a future improvement. There are tests that call something like ASSERT(optional) EXPECT(optional->foo()) While this isn't an actual violation, clang-tidy doesn't seem to be smart enough to deal with it, so add some explicit checks. [1] https://github.com/llvm/llvm-project/issues/55530 Tested: Redfish service validator passes. Change-Id: Ied579cd0b957efc81aff5d5d1091a740a7a2d7e3 Signed-off-by: Ed Tanous <edtanous@google.com>
Diffstat (limited to 'http/http_connection.hpp')
-rw-r--r--http/http_connection.hpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/http/http_connection.hpp b/http/http_connection.hpp
index b5d0d2e59e..ba4af3f747 100644
--- a/http/http_connection.hpp
+++ b/http/http_connection.hpp
@@ -94,6 +94,10 @@ class Connection :
// don't require auth
if (preverified)
{
+ if (!req)
+ {
+ return false;
+ }
mtlsSession = verifyMtlsUser(req->ipAddress, ctx);
if (mtlsSession)
{
@@ -202,6 +206,10 @@ class Connection :
void handle()
{
std::error_code reqEc;
+ if (!parser)
+ {
+ return;
+ }
crow::Request& thisReq = req.emplace(parser->release(), reqEc);
if (reqEc)
{
@@ -363,6 +371,10 @@ class Connection :
{
return;
}
+ if (!req)
+ {
+ return;
+ }
req->ipAddress = ip;
}
@@ -389,7 +401,10 @@ class Connection :
void doReadHeaders()
{
BMCWEB_LOG_DEBUG("{} doReadHeaders", logPtr(this));
-
+ if (!parser)
+ {
+ return;
+ }
// Clean up any previous Connection.
boost::beast::http::async_read_header(
adaptor, buffer, *parser,
@@ -475,6 +490,10 @@ class Connection :
void doRead()
{
BMCWEB_LOG_DEBUG("{} doRead", logPtr(this));
+ if (!parser)
+ {
+ return;
+ }
startDeadline();
boost::beast::http::async_read_some(
adaptor, buffer, *parser,
@@ -515,7 +534,7 @@ class Connection :
{
BMCWEB_LOG_DEBUG("{} doWrite", logPtr(this));
thisRes.preparePayload();
- serializer.emplace(*thisRes.stringResponse);
+ serializer.emplace(thisRes.stringResponse);
startDeadline();
boost::beast::http::async_write(adaptor, *serializer,
[this, self(shared_from_this())](