[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>
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 @@
 
 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;
 }