summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0010-Correct-several-latent-issues-discovered-by-a-Klocwo.patch
blob: 222a07aff20e6c9ab3654d871a6241a6a69b7a21 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
From 8d0cc1dfc3b48bccbe09a205f1ff2eb7721dbc6f Mon Sep 17 00:00:00 2001
From: Johnathan Mantey <johnathanx.mantey@intel.com>
Date: Mon, 21 Jun 2021 13:34:04 -0700
Subject: [PATCH] Correct several latent issues discovered by a Klocwork scan

Klocwork identified several issues:
1. ncsi_util: Null pointer dereferences
2. vlan_interface: Missing return value for non-void function

Tested:
Programmed the updated code to WCity system.

Change-Id: Ie6a601b343404f3070f35171336c0c5796c8d635
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
---
 ncsi_util.cpp      | 11 +++++++++++
 vlan_interface.cpp |  1 +
 2 files changed, 12 insertions(+)

diff --git a/ncsi_util.cpp b/ncsi_util.cpp
index 2b3fb54..4a46849 100644
--- a/ncsi_util.cpp
+++ b/ncsi_util.cpp
@@ -180,6 +180,12 @@ int applyCmd(int ifindex, int cmd, int package = DEFAULT_VALUE,
              CallBack function = nullptr)
 {
     nlSocketPtr socket(nl_socket_alloc(), &::nl_socket_free);
+    if (socket == nullptr)
+    {
+        log<level::ERR>("Unable to allocate memory for the socket.");
+        return -ENOMEM;
+    }
+
     auto ret = genl_connect(socket.get());
     if (ret < 0)
     {
@@ -195,6 +201,11 @@ int applyCmd(int ifindex, int cmd, int package = DEFAULT_VALUE,
     }
 
     nlMsgPtr msg(nlmsg_alloc(), &::nlmsg_free);
+    if (msg == nullptr)
+    {
+        log<level::ERR>("Unable to allocate memory for the message.");
+        return -ENOMEM;
+    }
 
     auto msgHdr = genlmsg_put(msg.get(), 0, 0, driverID, 0, flags, cmd, 0);
     if (!msgHdr)
diff --git a/vlan_interface.cpp b/vlan_interface.cpp
index 26282cb..baa5271 100644
--- a/vlan_interface.cpp
+++ b/vlan_interface.cpp
@@ -41,6 +41,7 @@ std::string VlanInterface::mACAddress(std::string)
 {
     log<level::ERR>("Tried to set MAC address on VLAN");
     elog<InternalFailure>();
+    return {};
 }
 
 void VlanInterface::writeDeviceFile()
-- 
2.31.1