summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0016-Fix-bmcweb-crashes-if-socket-directory-not-present.patch
blob: bc023839fbd7402974591e324d10faa5dcf51811 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
From 48fe2a68d634970795f9ff13903afbedca801088 Mon Sep 17 00:00:00 2001
From: Nidhin MS <nidhin.ms@intel.com>
Date: Wed, 14 Apr 2021 11:28:44 +0530
Subject: [PATCH] Fix: bmcweb crashes if socket directory not present

When trying to mount virtual media image bmcweb tries to create unix
socket and if the parent directory does not exist
stream_protocol::acceptor throws error and bmcweb crashes. Fix the same

Tested:
Removed directory and mounted the vm image. bmcweb crash was not
observed

Change-Id: I3aea1d8e197c06238f425a97435c01d3c80552a9
Signed-off-by: Nidhin MS <nidhin.ms@intel.com>
---
 include/nbd_proxy.hpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/nbd_proxy.hpp b/include/nbd_proxy.hpp
index 7b90e90..3b28823 100644
--- a/include/nbd_proxy.hpp
+++ b/include/nbd_proxy.hpp
@@ -397,6 +397,17 @@ inline void requestRoutes(App& app)
                         // If the socket file exists (i.e. after bmcweb crash),
                         // we cannot reuse it.
                         std::remove((*socketValue).c_str());
+                        std::filesystem::path socketPath(*socketValue);
+                        std::error_code fsErr;
+                        if (!std::filesystem::exists(socketPath.parent_path(),
+                                                     fsErr))
+                        {
+                            BMCWEB_LOG_ERROR
+                                << "VirtualMedia socket directory not present. "
+                                << socketPath.parent_path();
+                            conn.close("Unable to create unix socket");
+                            return;
+                        }
 
                         sessions[&conn] = std::make_shared<NbdProxyServer>(
                             conn, *socketValue, *endpointValue,
-- 
2.17.1