diff options
author | Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com> | 2020-01-09 11:55:06 +0530 |
---|---|---|
committer | Vernon Mauery <vernon.mauery@linux.intel.com> | 2020-01-30 08:33:06 -0800 |
commit | e3d144f1fce8fa162d6e865d61edab4cd513848a (patch) | |
tree | 2a937d1a6d57206d216469d81fb9a3c2cd627e2c /user_channel | |
parent | 619ed5f85489a3ee54d8f8c39ad112b3477b069c (diff) | |
download | phosphor-host-ipmid-e3d144f1fce8fa162d6e865d61edab4cd513848a.tar.gz phosphor-host-ipmid-e3d144f1fce8fa162d6e865d61edab4cd513848a.zip |
[user-mgmt]: Handle out of range error in path
Function must assume that object path without user name may exist,
and must handle the condition accordingly.
Tested:
1. Verified when InterfacesAdded signal sent out from Phosphor-user-manager
under base user object for global attributes, ipmid is not crashed.
Resolves openbmc/phosphor-net-ipmid#10
Change-Id: Ib19af7ca8f05fd9f4553010caf347c677d9897e2
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
Diffstat (limited to 'user_channel')
-rw-r--r-- | user_channel/user_mgmt.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/user_channel/user_mgmt.cpp b/user_channel/user_mgmt.cpp index add7ee2..102f990 100644 --- a/user_channel/user_mgmt.cpp +++ b/user_channel/user_mgmt.cpp @@ -197,12 +197,13 @@ UserAccess& getUserAccessObject() int getUserNameFromPath(const std::string& path, std::string& userName) { - static size_t pos = strlen(userObjBasePath) + 1; - if (path.find(userObjBasePath) == std::string::npos) + constexpr size_t length = strlen(userObjBasePath); + if (((length + 1) >= path.size()) || + path.compare(0, length, userObjBasePath)) { return -EINVAL; } - userName.assign(path, pos, path.size()); + userName.assign(path, length + 1, path.size()); return 0; } |