From e3d144f1fce8fa162d6e865d61edab4cd513848a Mon Sep 17 00:00:00 2001 From: Richard Marian Thomaiyar Date: Thu, 9 Jan 2020 11:55:06 +0530 Subject: [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 --- user_channel/user_mgmt.cpp | 7 ++++--- 1 file 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; } -- cgit v1.2.1