From 1b5c7030d1d9b13e73fb5779498233630f76bdf8 Mon Sep 17 00:00:00 2001 From: PavanKumarIntel Date: Thu, 14 Sep 2023 12:14:25 +0000 Subject: [PATCH] Fix for static analyser tool reported issues Signed-off-by: PavanKumarIntel %% original patch: 0066-Fix-for-Coverity-Issues.patch --- apphandler.cpp | 11 ++--------- storagehandler.cpp | 11 ++++++----- transporthandler.cpp | 6 +++--- user_channel/channel_layer.cpp | 4 +--- user_channel/channelcommands.cpp | 4 ++-- user_channel/passwd_mgr.cpp | 10 ++++++++-- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/apphandler.cpp b/apphandler.cpp index 41dbc8f..bd2bd6f 100644 --- a/apphandler.cpp +++ b/apphandler.cpp @@ -88,9 +88,7 @@ static constexpr const char* cmdStr = "command"; static constexpr const char* cmdMaskStr = "commandMask"; static constexpr int base_16 = 16; #endif // ENABLE_I2C_WHITELIST_CHECK -static constexpr uint8_t maxIPMIWriteReadSize = 255; static constexpr uint8_t oemCmdStart = 192; -static constexpr uint8_t oemCmdEnd = 255; static constexpr uint8_t invalidParamSelectorStart = 8; static constexpr uint8_t invalidParamSelectorEnd = 191; @@ -1292,7 +1290,7 @@ ipmi::RspType= oemCmdStart) && (paramSelector <= oemCmdEnd)) + if (paramSelector >= oemCmdStart) { return ipmi::responseParmNotSupported(); } @@ -1369,7 +1367,7 @@ ipmi::RspType<> ipmiAppSetSystemInfo(uint8_t paramSelector, uint8_t data1, { return ipmi::responseInvalidFieldRequest(); } - if ((paramSelector >= oemCmdStart) && (paramSelector <= oemCmdEnd)) + if (paramSelector >= oemCmdStart) { return ipmi::responseParmNotSupported(); } @@ -1633,11 +1631,6 @@ ipmi::RspType> { return ipmi::responseInvalidFieldRequest(); } - if (readCount > maxIPMIWriteReadSize) - { - log("Master write read command: Read count exceeds limit"); - return ipmi::responseParmOutOfRange(); - } const size_t writeCount = writeData.size(); if (!readCount && !writeCount) { diff --git a/storagehandler.cpp b/storagehandler.cpp index cdd61da..d2f06cc 100644 --- a/storagehandler.cpp +++ b/storagehandler.cpp @@ -437,14 +437,15 @@ ipmi::RspType originsV4 = { }; static constexpr uint8_t oemCmdStart = 192; -static constexpr uint8_t oemCmdEnd = 255; std::optional maybeGetChannelParams(sdbusplus::bus::bus& bus, uint8_t channel) @@ -1234,7 +1233,7 @@ RspType<> setLan(Context::ptr ctx, uint4_t channelBits, uint4_t reserved1, } } - if ((parameter >= oemCmdStart) && (parameter <= oemCmdEnd)) + if (parameter >= oemCmdStart) { return setLanOem(channel, parameter, req); } @@ -1521,7 +1520,7 @@ RspType getLan(Context::ptr ctx, uint4_t channelBits, } } - if ((parameter >= oemCmdStart) && (parameter <= oemCmdEnd)) + if (parameter >= oemCmdStart) { return getLanOem(channel, parameter, set, block); } @@ -1982,6 +1981,7 @@ ipmi::RspType, std::optional> { phosphor::logging::log( "Failed to get valid baud rate from D-Bus interface"); + return ipmi::responseUnspecifiedError(); } switch (*pBaudRate) { diff --git a/user_channel/channel_layer.cpp b/user_channel/channel_layer.cpp index 03b1729..022c132 100644 --- a/user_channel/channel_layer.cpp +++ b/user_channel/channel_layer.cpp @@ -51,9 +51,7 @@ bool isValidPrivLimit(const uint8_t privLimit) bool isValidAccessMode(const uint8_t accessMode) { - return ( - (accessMode >= static_cast(EChannelAccessMode::disabled)) && - (accessMode <= static_cast(EChannelAccessMode::shared))); + return (accessMode <= static_cast(EChannelAccessMode::shared)); } bool isValidChannel(const uint8_t chNum) diff --git a/user_channel/channelcommands.cpp b/user_channel/channelcommands.cpp index 769f9ff..e3dffe8 100644 --- a/user_channel/channelcommands.cpp +++ b/user_channel/channelcommands.cpp @@ -194,9 +194,9 @@ ipmi ::RspType(accessSetMode) == nvData) { diff --git a/user_channel/passwd_mgr.cpp b/user_channel/passwd_mgr.cpp index 9b232b5..86a38d5 100644 --- a/user_channel/passwd_mgr.cpp +++ b/user_channel/passwd_mgr.cpp @@ -74,7 +74,10 @@ void PasswdMgr::restrictFilesPermission(void) { if ((st.st_mode & modeMask) != (S_IRUSR | S_IWUSR)) { - chmod(passwdFileName, S_IRUSR | S_IWUSR); + if (chmod(passwdFileName, S_IRUSR | S_IWUSR) == -1) + { + log("Error setting chmod for ipmi_pass file"); + } } } @@ -82,7 +85,10 @@ void PasswdMgr::restrictFilesPermission(void) { if ((st.st_mode & modeMask) != (S_IRUSR | S_IWUSR)) { - chmod(encryptKeyFileName, S_IRUSR | S_IWUSR); + if (chmod(encryptKeyFileName, S_IRUSR | S_IWUSR) == -1) + { + log("Error setting chmod for key_file file"); + } } } } -- 2.25.1