From 4e961b5894378c0f57d92b6becc3b21feb241a91 Mon Sep 17 00:00:00 2001 From: houchengyu2022 Date: Tue, 11 Apr 2023 22:04:55 +0800 Subject: [PATCH 1/6] fix hmos_dev_musl warning Signed-off-by: houchengyu2022 --- .../src/key_event_value_transformation.cpp | 9 +++++-- .../src/input_display_bind_helper.cpp | 24 +++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/service/event_handler/src/key_event_value_transformation.cpp b/service/event_handler/src/key_event_value_transformation.cpp index fb84fa1c37..36c9e85f53 100644 --- a/service/event_handler/src/key_event_value_transformation.cpp +++ b/service/event_handler/src/key_event_value_transformation.cpp @@ -502,9 +502,14 @@ int32_t keyItemsTransKeyIntention(const std::vector &items) return KeyEvent::INTENTION_UNKNOWN; } - int64_t keyCodes = 0; + uint64_t keyCodes = 0; for (const auto &item : items) { - keyCodes = (keyCodes << 16) + item.GetKeyCode(); + if (item.GetKeyCode() < 0) { + MMI_HILOGE("keycode is invalid"); + return KeyEvent::INTENTION_UNKNOWN; + } + uint64_t keyCode = (uint64_t)item.GetKeyCode(); + keyCodes = (keyCodes << 16) + keyCode; } auto iter = MAP_KEY_INTENTION.find(keyCodes); if (iter == MAP_KEY_INTENTION.end()) { diff --git a/service/window_manager/src/input_display_bind_helper.cpp b/service/window_manager/src/input_display_bind_helper.cpp index 3c67e74e60..e5b3798c33 100644 --- a/service/window_manager/src/input_display_bind_helper.cpp +++ b/service/window_manager/src/input_display_bind_helper.cpp @@ -377,11 +377,17 @@ void InputDisplayBindHelper::RemoveDisplay(int32_t id) void InputDisplayBindHelper::Store() { CALL_DEBUG_ENTER; + char *realpathRes = NULL; if (infos_ == nullptr) { return; } - if (fileName_.empty()) { - MMI_HILOGE("file name is empty"); + realpathRes = realpath(fileName_.c_str(), NULL); + if (realpathRes == NULL) { + MMI.HILOGE("file name is empty"); + return; + } + if (!verify_file(realpathRes)) { + MMI.HILOGE("file name is empty"); return; } std::ofstream ofs(fileName_.c_str(), std::ios::trunc | std::ios::out | std::ios_base::binary); @@ -391,6 +397,8 @@ void InputDisplayBindHelper::Store() } ofs << *infos_; ofs.close(); + free(realpathRes); + realpathRes = NULL; } int32_t InputDisplayBindHelper::GetDisplayBindInfo(DisplayBindInfos &infos) @@ -491,8 +499,14 @@ int32_t InputDisplayBindHelper::SetDisplayBind(int32_t deviceId, int32_t display void InputDisplayBindHelper::Load() { CALL_DEBUG_ENTER; - if (fileName_.empty()) { - MMI_HILOGE("file name is empty"); + char *realpathRes = NULL; + realpathRes = realpath(fileName_.c_str(), NULL); + if (realpathRes == NULL) { + MMI.HILOGE("file name is empty"); + return; + } + if (!verify_file(realpathRes)) { + MMI.HILOGE("file name is empty"); return; } std::ifstream ifs(fileName_.c_str()); @@ -503,6 +517,8 @@ void InputDisplayBindHelper::Load() } ifs >> *configFileInfos_; ifs.close(); + free(realpathRes); + realpathRes = NULL; } std::string InputDisplayBindHelper::Dumps() const -- Gitee From 5ab1fd46d88df106cc3fb264bab92d9f719b261b Mon Sep 17 00:00:00 2001 From: houchengyu Date: Tue, 11 Apr 2023 14:37:39 +0000 Subject: [PATCH 2/6] update service/window_manager/src/input_display_bind_helper.cpp. Signed-off-by: houchengyu --- .../window_manager/src/input_display_bind_helper.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/service/window_manager/src/input_display_bind_helper.cpp b/service/window_manager/src/input_display_bind_helper.cpp index e5b3798c33..517663a0da 100644 --- a/service/window_manager/src/input_display_bind_helper.cpp +++ b/service/window_manager/src/input_display_bind_helper.cpp @@ -383,11 +383,11 @@ void InputDisplayBindHelper::Store() } realpathRes = realpath(fileName_.c_str(), NULL); if (realpathRes == NULL) { - MMI.HILOGE("file name is empty"); + MMI_HILOGE("file name is empty"); return; } if (!verify_file(realpathRes)) { - MMI.HILOGE("file name is empty"); + MMI_HILOGE("file name is empty"); return; } std::ofstream ofs(fileName_.c_str(), std::ios::trunc | std::ios::out | std::ios_base::binary); @@ -502,11 +502,11 @@ void InputDisplayBindHelper::Load() char *realpathRes = NULL; realpathRes = realpath(fileName_.c_str(), NULL); if (realpathRes == NULL) { - MMI.HILOGE("file name is empty"); + MMI_HILOGE("file name is empty"); return; } - if (!verify_file(realpathRes)) { - MMI.HILOGE("file name is empty"); + if (!VerifyFile(realpathRes)) { + MMI_HILOGE("file name is empty"); return; } std::ifstream ifs(fileName_.c_str()); -- Gitee From 2b248703021e20e7b8ec5baa11a58268346f51c0 Mon Sep 17 00:00:00 2001 From: houchengyu Date: Tue, 11 Apr 2023 14:59:22 +0000 Subject: [PATCH 3/6] update service/window_manager/src/input_display_bind_helper.cpp. Signed-off-by: houchengyu --- service/window_manager/src/input_display_bind_helper.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/service/window_manager/src/input_display_bind_helper.cpp b/service/window_manager/src/input_display_bind_helper.cpp index 517663a0da..3b84f897c6 100644 --- a/service/window_manager/src/input_display_bind_helper.cpp +++ b/service/window_manager/src/input_display_bind_helper.cpp @@ -112,6 +112,14 @@ bool operator<(const BindInfo &l, const BindInfo &r) { return (l.displayId_ < r.displayId_); } +bool verify_file(char *const filename) +{ + if (strrchr(filename, '/') == filename +len) { + return true; + } + return false; +} + std::ostream& operator<<(std::ostream &os, const BindInfo &r) { os << r.inputDeviceName_ << "<=>" << r.displayName_ << std::endl; return os; -- Gitee From 77d20ebf36d69e156da2a0d5ebb86cae26ed8378 Mon Sep 17 00:00:00 2001 From: houchengyu Date: Tue, 11 Apr 2023 15:00:04 +0000 Subject: [PATCH 4/6] update service/window_manager/src/input_display_bind_helper.cpp. Signed-off-by: houchengyu --- service/window_manager/src/input_display_bind_helper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/window_manager/src/input_display_bind_helper.cpp b/service/window_manager/src/input_display_bind_helper.cpp index 3b84f897c6..4f19336c04 100644 --- a/service/window_manager/src/input_display_bind_helper.cpp +++ b/service/window_manager/src/input_display_bind_helper.cpp @@ -513,7 +513,7 @@ void InputDisplayBindHelper::Load() MMI_HILOGE("file name is empty"); return; } - if (!VerifyFile(realpathRes)) { + if (!verify_file(realpathRes)) { MMI_HILOGE("file name is empty"); return; } -- Gitee From 30297a6e06c0f65730569c01f0d60c66ea526e2d Mon Sep 17 00:00:00 2001 From: houchengyu Date: Fri, 14 Apr 2023 09:14:41 +0000 Subject: [PATCH 5/6] update service/window_manager/src/input_display_bind_helper.cpp. Signed-off-by: houchengyu --- .../src/input_display_bind_helper.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/service/window_manager/src/input_display_bind_helper.cpp b/service/window_manager/src/input_display_bind_helper.cpp index 4f19336c04..bef0a5b978 100644 --- a/service/window_manager/src/input_display_bind_helper.cpp +++ b/service/window_manager/src/input_display_bind_helper.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -112,14 +113,6 @@ bool operator<(const BindInfo &l, const BindInfo &r) { return (l.displayId_ < r.displayId_); } -bool verify_file(char *const filename) -{ - if (strrchr(filename, '/') == filename +len) { - return true; - } - return false; -} - std::ostream& operator<<(std::ostream &os, const BindInfo &r) { os << r.inputDeviceName_ << "<=>" << r.displayName_ << std::endl; return os; @@ -382,6 +375,16 @@ void InputDisplayBindHelper::RemoveDisplay(int32_t id) infos_->UnbindDisplay(id); } +bool verify_file(char *const filename) +{ + if ((strlen(filename) <= PATH_MAX) && strncmp(filename, "/dev", 4) == 0) { + return true; + } else { + MMI_HILOGE("file name is empty"); + return false; + } +} + void InputDisplayBindHelper::Store() { CALL_DEBUG_ENTER; -- Gitee From 373716360fb682b23b5281a964850c3a61e96ef4 Mon Sep 17 00:00:00 2001 From: houchengyu Date: Mon, 17 Apr 2023 14:32:37 +0000 Subject: [PATCH 6/6] update service/window_manager/src/input_display_bind_helper.cpp. Signed-off-by: houchengyu --- service/window_manager/src/input_display_bind_helper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/window_manager/src/input_display_bind_helper.cpp b/service/window_manager/src/input_display_bind_helper.cpp index bef0a5b978..c95f6943c7 100644 --- a/service/window_manager/src/input_display_bind_helper.cpp +++ b/service/window_manager/src/input_display_bind_helper.cpp @@ -377,7 +377,7 @@ void InputDisplayBindHelper::RemoveDisplay(int32_t id) bool verify_file(char *const filename) { - if ((strlen(filename) <= PATH_MAX) && strncmp(filename, "/dev", 4) == 0) { + if ((strlen(filename) <= PATH_MAX)) { return true; } else { MMI_HILOGE("file name is empty"); -- Gitee