From 22e363ebbd3985e87c2aff523cb78638463b0259 Mon Sep 17 00:00:00 2001 From: liqiao49 Date: Wed, 26 Jul 2023 19:41:20 +0800 Subject: [PATCH] 8888 Signed-off-by: liqiao49 --- services/state/src/dinput_state.cpp | 8 +++----- utils/src/dinput_utils_tool.cpp | 5 ++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/services/state/src/dinput_state.cpp b/services/state/src/dinput_state.cpp index bf773bf..023ae13 100644 --- a/services/state/src/dinput_state.cpp +++ b/services/state/src/dinput_state.cpp @@ -168,8 +168,7 @@ void DInputState::CheckKeyboardState(std::string &dhid, std::string &keyboardNod { DHLOGI("CheckKeyboardState enter, dhid %s, keyboardNodePath %s.", GetAnonyString(dhid).c_str(), keyboardNodePath.c_str()); - char canonicalPath[PATH_MAX + 1] = {0x00}; - canonicalPath[PATH_MAX] = '\0'; + char* canonicalPath = new char(PATH_MAX); if (keyboardNodePath.length() == 0 || keyboardNodePath.length() >= PATH_MAX || realpath(keyboardNodePath.c_str(), canonicalPath) == nullptr) { DHLOGE("keyboard Nodepath check fail, error path: %s", keyboardNodePath.c_str()); @@ -209,9 +208,8 @@ void DInputState::CheckMouseKeyState(const int32_t &sessionId, const std::string { DHLOGI("CheckMouseKeyState enter, mouseNodePath %s, mouseNodeDhId %s, sessionId %d.", mouseNodePath.c_str(), GetAnonyString(mouseNodeDhId).c_str(), sessionId); - char canonicalPath[PATH_MAX + 1] = {0x00}; - canonicalPath[PATH_MAX] = '\0'; - if (mouseNodePath.length() == 0 || mouseNodePath.length() >= PATH_MAX || + char* canonicalPath = new char(PATH_MAX); + if (mouseNodePath.length() == 0 || mouseNodePath.length() > PATH_MAX || realpath(mouseNodePath.c_str(), canonicalPath) == nullptr) { DHLOGE("mouse Nodepath check fail, error path: %s", mouseNodePath.c_str()); return; diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index f4cb110..edbd4e0 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -327,9 +327,8 @@ void StringSplitToVector(const std::string& str, const char split, std::vector= PATH_MAX || + char* canonicalDevicePath = new char(PATH_MAX); + if (devicePath.length() == 0 || devicePath.length() > PATH_MAX || realpath(devicePath.c_str(), canonicalDevicePath) == nullptr) { DHLOGE("path check fail, error path: %s", devicePath.c_str()); return -1;