From bbbc3954471c3e75f0a1d22d5ddc60a74bcc0525 Mon Sep 17 00:00:00 2001 From: Richard Marian Thomaiyar Date: Fri, 17 Jan 2020 12:13:28 +0530 Subject: [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 --- user_channel/channel_mgmt.cpp | 14 +++++++------- 1 file 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("Invalid interface path.", - entry("PATH=%s", path.c_str())); - throw std::invalid_argument("Invalid interface path"); + log("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; } -- cgit v1.2.1