diff options
author | Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com> | 2020-01-17 12:13:28 +0530 |
---|---|---|
committer | Vernon Mauery <vernon.mauery@linux.intel.com> | 2020-01-30 17:30:49 +0000 |
commit | bbbc3954471c3e75f0a1d22d5ddc60a74bcc0525 (patch) | |
tree | 762286cdb7c12d6fd95a260b0b0ba3e1ea9c70fc | |
parent | e3d144f1fce8fa162d6e865d61edab4cd513848a (diff) | |
download | phosphor-host-ipmid-bbbc3954471c3e75f0a1d22d5ddc60a74bcc0525.tar.gz phosphor-host-ipmid-bbbc3954471c3e75f0a1d22d5ddc60a74bcc0525.zip |
[channel-mgmt]: Handle out of range error in path
Function must assume that object path without any network name
may be advertised, and must handle the condition accordingly.
Tested:
1. Verified that ipmi user is properly enabled with channel
based permission and it works fine.
Change-Id: Id51f09bb7c19a9750cb06c2c55f7271afc6b1d2a
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
-rw-r--r-- | user_channel/channel_mgmt.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/user_channel/channel_mgmt.cpp b/user_channel/channel_mgmt.cpp index c3994f1..759de43 100644 --- a/user_channel/channel_mgmt.cpp +++ b/user_channel/channel_mgmt.cpp @@ -168,15 +168,15 @@ int ChannelConfig::convertToChannelNumberFromChannelName( std::string ChannelConfig::getChannelNameFromPath(const std::string& path) { - std::size_t pos = path.find(networkIntfObjectBasePath); - if (pos == std::string::npos) + + constexpr size_t length = strlen(networkIntfObjectBasePath); + if (((length + 1) >= path.size()) || + path.compare(0, length, networkIntfObjectBasePath)) { - log<level::ERR>("Invalid interface path.", - entry("PATH=%s", path.c_str())); - throw std::invalid_argument("Invalid interface path"); + log<level::ERR>("Invalid object path.", entry("PATH=%s", path.c_str())); + throw std::invalid_argument("Invalid object path"); } - std::string chName = - path.substr(pos + strlen(networkIntfObjectBasePath) + 1); + std::string chName(path, length + 1); return chName; } |