From b208c70c772f9d4e5f54c436576d44b37691bbce Mon Sep 17 00:00:00 2001 From: bigtea Date: Tue, 27 May 2025 10:47:53 +0800 Subject: [PATCH] Fix libraryloader dlsym check Signed-off-by: bigtea --- .../cpp/src/permission/temp_permission_observer.cpp | 4 ++-- .../test/mock/library_loader_mock.cpp | 6 ++---- .../common/libraryloader/include/libraryloader.h | 2 +- services/common/libraryloader/src/libraryloader.cpp | 13 ++++++------- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/services/accesstokenmanager/main/cpp/src/permission/temp_permission_observer.cpp b/services/accesstokenmanager/main/cpp/src/permission/temp_permission_observer.cpp index 915d62094..bcce7368d 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/temp_permission_observer.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/temp_permission_observer.cpp @@ -166,7 +166,7 @@ void PermissionBackgroundTaskObserver::OnContinuousTaskStart( std::vector typeIds = continuousTaskCallbackInfo->GetTypeIds(); auto it = std::find(typeIds.begin(), typeIds.end(), static_cast(BackgroundMode::LOCATION)); if (it == typeIds.end()) { - LOGD(ATM_DOMAIN, ATM_TAG, "TypeId can not use temp permission"); + LOGI(ATM_DOMAIN, ATM_TAG, "TypeId can not use temp permission"); return; } std::vector list; @@ -188,7 +188,7 @@ void PermissionBackgroundTaskObserver::OnContinuousTaskStop( std::vector typeIds = continuousTaskCallbackInfo->GetTypeIds(); auto it = std::find(typeIds.begin(), typeIds.end(), static_cast(BackgroundMode::LOCATION)); if (it == typeIds.end()) { - LOGD(ATM_DOMAIN, ATM_TAG, "TypeId can not use temp permission"); + LOGI(ATM_DOMAIN, ATM_TAG, "TypeId can not use temp permission"); return; } std::vector list; diff --git a/services/accesstokenmanager/test/mock/library_loader_mock.cpp b/services/accesstokenmanager/test/mock/library_loader_mock.cpp index 5d5275cd5..692d976d3 100644 --- a/services/accesstokenmanager/test/mock/library_loader_mock.cpp +++ b/services/accesstokenmanager/test/mock/library_loader_mock.cpp @@ -53,10 +53,8 @@ LibraryLoader::LibraryLoader(const std::string& path) LibraryLoader::~LibraryLoader() {} -bool LibraryLoader::PrintErrorLog(const std::string& targetName) -{ - return true; -} +void LibraryLoader::PrintErrorLog(const std::string& targetName) +{} void LibraryLoader::Create() {} diff --git a/services/common/libraryloader/include/libraryloader.h b/services/common/libraryloader/include/libraryloader.h index 3cda5baaf..a26f8bcf6 100644 --- a/services/common/libraryloader/include/libraryloader.h +++ b/services/common/libraryloader/include/libraryloader.h @@ -36,7 +36,7 @@ private: void* instance_ = nullptr; void Create(); void Destroy(); - bool PrintErrorLog(const std::string& targetName); + void PrintErrorLog(const std::string& targetName); }; } // AccessToken } // Security diff --git a/services/common/libraryloader/src/libraryloader.cpp b/services/common/libraryloader/src/libraryloader.cpp index c9d535696..21d930a34 100644 --- a/services/common/libraryloader/src/libraryloader.cpp +++ b/services/common/libraryloader/src/libraryloader.cpp @@ -51,21 +51,19 @@ LibraryLoader::~LibraryLoader() #endif // FUZZ_ENABLE } -bool LibraryLoader::PrintErrorLog(const std::string& targetName) +void LibraryLoader::PrintErrorLog(const std::string& targetName) { char* error; if ((error = dlerror()) != nullptr) { - LOGE(ATM_DOMAIN, ATM_TAG, "Get %{public}s failed, errMsg=%{public}s.", - targetName.c_str(), error); - return false; + LOGE(ATM_DOMAIN, ATM_TAG, "Get %{public}s failed, errMsg=%{public}s.", targetName.c_str(), error); } - return true; } void LibraryLoader::Create() { void* (*create)(void) = reinterpret_cast(dlsym(handle_, "Create")); - if (!PrintErrorLog("Create")) { + if (create == nullptr) { + PrintErrorLog("Create"); return; } instance_ = create(); @@ -74,7 +72,8 @@ void LibraryLoader::Create() void LibraryLoader::Destroy() { void (*destroy)(void*) = reinterpret_cast(dlsym(handle_, "Destroy")); - if (!PrintErrorLog("Destroy")) { + if (destroy == nullptr) { + PrintErrorLog("Destroy"); return; } destroy(instance_); -- Gitee