From e51795c994fcdccbac6a5aa961282b4b1fabab6e Mon Sep 17 00:00:00 2001 From: liuzhongming60 Date: Tue, 26 Aug 2025 16:00:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E6=A3=80=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20Signed-off-by:=20liuzhongming=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/include/dfx/standard/dm_hidumper.h | 2 ++ common/src/dfx/standard/dm_hidumper.cpp | 3 ++- .../include/ipc/lite/ipc_client_manager.h | 1 + .../include/ipc/standard/dm_service_load.h | 3 +++ .../src/ipc/lite/ipc_client_manager.cpp | 3 +++ .../src/ipc/standard/dm_service_load.cpp | 12 ++++++---- interfaces/kits/js/include/dm_native_event.h | 2 +- interfaces/kits/js/src/dm_native_event.cpp | 19 ++++++++------- .../kits/js4.0/include/dm_native_event.h | 2 +- interfaces/kits/js4.0/src/dm_native_event.cpp | 19 ++++++++------- .../src/authentication_v2/auth_manager.cpp | 7 ++---- .../dm_auth_message_processor.cpp | 12 +++++++--- .../src/device_manager_service_impl.cpp | 23 ++++++++++--------- .../src/advertise/advertise_manager.cpp | 2 ++ .../service/src/device_manager_service.cpp | 3 ++- .../src/devicenamemgr/device_name_manager.cpp | 1 + .../src/discovery/discovery_manager.cpp | 8 +++++++ .../src/ipc/lite/ipc_server_listenermgr.cpp | 1 + .../dm_package_common_event.cpp | 3 ++- .../src/relationshipsyncmgr/dm_comm_tool.cpp | 8 +++---- .../relationship_sync_mgr.cpp | 2 ++ .../standard/dm_distributed_hardware_load.h | 2 +- .../standard/dm_distributed_hardware_load.cpp | 6 ++--- 23 files changed, 91 insertions(+), 53 deletions(-) diff --git a/common/include/dfx/standard/dm_hidumper.h b/common/include/dfx/standard/dm_hidumper.h index 4bba26763..3b4f2433d 100644 --- a/common/include/dfx/standard/dm_hidumper.h +++ b/common/include/dfx/standard/dm_hidumper.h @@ -17,6 +17,7 @@ #define OHOS_DM_HIDUMPER_H #include +#include #include #include @@ -41,6 +42,7 @@ private: std::string GetDeviceType(int32_t deviceTypeId); private: + std::mutex nodeInfosLock_; std::vector nodeInfos_; }; } // namespace DistributedHardware diff --git a/common/src/dfx/standard/dm_hidumper.cpp b/common/src/dfx/standard/dm_hidumper.cpp index 3fd87652e..77238b7bb 100644 --- a/common/src/dfx/standard/dm_hidumper.cpp +++ b/common/src/dfx/standard/dm_hidumper.cpp @@ -70,6 +70,7 @@ int32_t HiDumpHelper::HiDump(const std::vector& args, std::string & void HiDumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo) { LOGI("HiDumpHelper::SetNodeInfo"); + std::lock_guard autoLock(nodeInfosLock_); CHECK_SIZE_VOID(nodeInfos_); nodeInfos_.push_back(deviceInfo); } @@ -99,7 +100,7 @@ int32_t HiDumpHelper::ShowAllLoadTrustedList(std::string &result) { LOGI("dump all trusted device List"); int32_t ret = DM_OK; - + std::lock_guard autoLock(nodeInfosLock_); if (nodeInfos_.size() == 0) { LOGE("dump trusted device list is empty"); result.append("dump trusted device list is empty"); diff --git a/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_manager.h b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_manager.h index 2d8bf57b2..9b88079a5 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_manager.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_manager.h @@ -54,6 +54,7 @@ private: private: IpcClientServerProxy serverProxy_; + std::mutex packageInitSetLock_; std::set packageInitSet_; }; } // namespace DistributedHardware diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/dm_service_load.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/dm_service_load.h index beb819b5f..955e93527 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/standard/dm_service_load.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/dm_service_load.h @@ -16,6 +16,8 @@ #ifndef OHOS_DM_SA_LOAD_H #define OHOS_DM_SA_LOAD_H +#include + #include "dm_single_instance.h" #include "iremote_object.h" #include "system_ability_load_callback_stub.h" @@ -35,6 +37,7 @@ public: void SetLoadFinish(void); private: std::atomic isDMServiceLoading_ = false; + std::mutex dmServiceLoadLock_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp index 8c546e2f1..14d6c0d2a 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp @@ -53,6 +53,7 @@ int32_t IpcClientManager::Init(const std::string &pkgName) ret); return ret; } + std::lock_guard autoLock(packageInitSetLock_); packageInitSet_.emplace(pkgName); return DM_OK; } @@ -77,6 +78,7 @@ int32_t IpcClientManager::UnInit(const std::string &pkgName) ret); return ret; } + std::lock_guard autoLock(packageInitSetLock_); packageInitSet_.erase(pkgName); LOGI("UnInitDeviceManager SUCCESS"); return DM_OK; @@ -96,6 +98,7 @@ int32_t IpcClientManager::SendRequest(int32_t cmdCode, std::shared_ptr r bool IpcClientManager::IsInit(const std::string &pkgName) { + std::lock_guard autoLock(packageInitSetLock_); for (auto &iter : packageInitSet_) { size_t len = iter.size(); if (len > pkgName.size()) { diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/dm_service_load.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/dm_service_load.cpp index baf59b9a6..3f7096d3a 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/dm_service_load.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/dm_service_load.cpp @@ -27,22 +27,23 @@ DM_IMPLEMENT_SINGLE_INSTANCE(DmServiceLoad); int32_t DmServiceLoad::LoadDMService(void) { - if (isDMServiceLoading_) { + std::lock_guard autoLock(dmServiceLoadLock_); + if (isDMServiceLoading_.load()) { LOGI("DM service is loading."); return DM_OK; } LOGI("start"); - isDMServiceLoading_ = true; + isDMServiceLoading_.store(true); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { - isDMServiceLoading_ = false; + isDMServiceLoading_.store(false); LOGE("failed to get system ability mgr."); return ERR_DM_POINT_NULL; } sptr dmLoadCallback_(new DMLoadCallback()); int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, dmLoadCallback_); if (ret != DM_OK) { - isDMServiceLoading_ = false; + isDMServiceLoading_.store(false); LOGE("Failed to Load DM service, ret code:%{public}d", ret); return ret; } @@ -51,7 +52,8 @@ int32_t DmServiceLoad::LoadDMService(void) void DmServiceLoad::SetLoadFinish(void) { - isDMServiceLoading_ = false; + std::lock_guard autoLock(dmServiceLoadLock_); + isDMServiceLoading_.store(false); } void DMLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, diff --git a/interfaces/kits/js/include/dm_native_event.h b/interfaces/kits/js/include/dm_native_event.h index da0915df8..5f8307d6d 100644 --- a/interfaces/kits/js/include/dm_native_event.h +++ b/interfaces/kits/js/include/dm_native_event.h @@ -42,7 +42,7 @@ protected: napi_ref thisVarRef_; std::map> eventMap_; #if !defined(__LITEOS_M__) - std::mutex lock_; + std::mutex eventMapLock_; #endif }; #endif // OHOS_DM_NATIVE_EVENT_H diff --git a/interfaces/kits/js/src/dm_native_event.cpp b/interfaces/kits/js/src/dm_native_event.cpp index e7a02abbd..e56cafa57 100644 --- a/interfaces/kits/js/src/dm_native_event.cpp +++ b/interfaces/kits/js/src/dm_native_event.cpp @@ -28,20 +28,23 @@ DmNativeEvent::DmNativeEvent(napi_env env, napi_value thisVar) DmNativeEvent::~DmNativeEvent() { - for (auto iter = eventMap_.begin(); iter != eventMap_.end(); iter++) { - auto listener = iter->second; - if (listener != nullptr) { - napi_delete_reference(env_, listener->handlerRef); + { + std::lock_guard autoLock(eventMapLock_); + for (auto iter = eventMap_.begin(); iter != eventMap_.end(); iter++) { + auto listener = iter->second; + if (listener != nullptr) { + napi_delete_reference(env_, listener->handlerRef); + } } + eventMap_.clear(); } - eventMap_.clear(); napi_delete_reference(env_, thisVarRef_); } void DmNativeEvent::On(std::string &eventType, napi_value handler) { LOGI("DmNativeEvent On in for event: %{public}s", eventType.c_str()); - std::lock_guard autoLock(lock_); + std::lock_guard autoLock(eventMapLock_); auto listener = std::make_shared(); listener->eventType = eventType; napi_create_reference(env_, handler, 1, &listener->handlerRef); @@ -58,7 +61,7 @@ void DmNativeEvent::Off(std::string &eventType) return; } - std::lock_guard autoLock(lock_); + std::lock_guard autoLock(eventMapLock_); auto iter = eventMap_.find(eventType); if (iter == eventMap_.end()) { LOGE("eventType %{public}s not find", eventType.c_str()); @@ -81,7 +84,7 @@ void DmNativeEvent::OnEvent(const std::string &eventType, size_t argc, const nap return; } - std::lock_guard autoLock(lock_); + std::lock_guard autoLock(eventMapLock_); auto iter = eventMap_.find(eventType); if (iter == eventMap_.end()) { LOGE("eventType %{public}s not find", eventType.c_str()); diff --git a/interfaces/kits/js4.0/include/dm_native_event.h b/interfaces/kits/js4.0/include/dm_native_event.h index da0915df8..5f8307d6d 100644 --- a/interfaces/kits/js4.0/include/dm_native_event.h +++ b/interfaces/kits/js4.0/include/dm_native_event.h @@ -42,7 +42,7 @@ protected: napi_ref thisVarRef_; std::map> eventMap_; #if !defined(__LITEOS_M__) - std::mutex lock_; + std::mutex eventMapLock_; #endif }; #endif // OHOS_DM_NATIVE_EVENT_H diff --git a/interfaces/kits/js4.0/src/dm_native_event.cpp b/interfaces/kits/js4.0/src/dm_native_event.cpp index d60a6f090..c37a9a1e0 100644 --- a/interfaces/kits/js4.0/src/dm_native_event.cpp +++ b/interfaces/kits/js4.0/src/dm_native_event.cpp @@ -28,19 +28,22 @@ DmNativeEvent::DmNativeEvent(napi_env env, napi_value thisVar) DmNativeEvent::~DmNativeEvent() { - for (auto iter = eventMap_.begin(); iter != eventMap_.end(); iter++) { - auto listener = iter->second; - CHECK_NULL_VOID(listener); - napi_delete_reference(env_, listener->handlerRef); + { + std::lock_guard autoLock(eventMapLock_); + for (auto iter = eventMap_.begin(); iter != eventMap_.end(); iter++) { + auto listener = iter->second; + CHECK_NULL_VOID(listener); + napi_delete_reference(env_, listener->handlerRef); + } + eventMap_.clear(); } - eventMap_.clear(); napi_delete_reference(env_, thisVarRef_); } void DmNativeEvent::On(std::string &eventType, napi_value handler) { LOGI("DmNativeEvent On in for event: %{public}s", eventType.c_str()); - std::lock_guard autoLock(lock_); + std::lock_guard autoLock(eventMapLock_); auto listener = std::make_shared(); listener->eventType = eventType; napi_create_reference(env_, handler, 1, &listener->handlerRef); @@ -57,7 +60,7 @@ void DmNativeEvent::Off(std::string &eventType) return; } - std::lock_guard autoLock(lock_); + std::lock_guard autoLock(eventMapLock_); auto iter = eventMap_.find(eventType); if (iter == eventMap_.end()) { LOGE("eventType %{public}s not find", eventType.c_str()); @@ -80,7 +83,7 @@ void DmNativeEvent::OnEvent(const std::string &eventType, size_t argc, const nap return; } - std::lock_guard autoLock(lock_); + std::lock_guard autoLock(eventMapLock_); auto iter = eventMap_.find(eventType); if (iter == eventMap_.end()) { LOGE("eventType %{public}s not find", eventType.c_str()); diff --git a/services/implementation/src/authentication_v2/auth_manager.cpp b/services/implementation/src/authentication_v2/auth_manager.cpp index 09e29468b..4b85bd8fa 100644 --- a/services/implementation/src/authentication_v2/auth_manager.cpp +++ b/services/implementation/src/authentication_v2/auth_manager.cpp @@ -562,7 +562,7 @@ int32_t AuthManager::GetBindLevel(int32_t bindLevel) void AuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { - LOGI("Get auth param with pkgName %{public}s and extra %{public}s.", pkgName.c_str(), extra.c_str()); + LOGI("Get auth param with pkgName %{public}s.", pkgName.c_str()); char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); context_->accesser.deviceId = std::string(localDeviceId); @@ -616,7 +616,7 @@ void AuthManager::InitAuthState(const std::string &pkgName, int32_t authType, int32_t AuthManager::AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { - LOGI("AuthManager::AuthenticateDevice start auth type %{public}d, extra %{public}s.", authType, extra.c_str()); + LOGI("AuthManager::AuthenticateDevice start auth type %{public}d.", authType); SetAuthType(authType); context_->processInfo.pkgName = pkgName; GetBindCallerInfo(); @@ -652,9 +652,6 @@ int32_t AuthManager::BindTarget(const std::string &pkgName, const PeerTargetId & { int ret = DM_OK; LOGI("AuthManager::BindTarget start. pkgName: %{public}s", pkgName.c_str()); - for (auto iter = bindParam.begin(); iter != bindParam.end(); iter++) { - LOGI("AuthManager::BindTarget para: %{public}s : %{public}s ", iter->first.c_str(), iter->second.c_str()); - } struct RadarInfo info = { .funcName = "AuthenticateDevice", diff --git a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp index 9d8cc425b..43f367ea3 100644 --- a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp @@ -115,6 +115,7 @@ const char* TAG_DEVICE_TYPE = "DEVICETYPE"; constexpr int32_t DM_ULTRASONIC_FORWARD = 0; constexpr int32_t DM_ULTRASONIC_REVERSE = 1; constexpr uint32_t MAX_SESSION_KEY_LENGTH = 512; +constexpr uint32_t MAX_MESSAGE_LENGTH = 64 * 1024 * 1024; void ParseDmAccessToSync(const std::string &jsonString, DmAccess &access, bool isUseDeviceFullName) { @@ -694,7 +695,6 @@ int32_t DmAuthMessageProcessor::ParseMessageRspCredExchange(const JsonObject &js LOGE("DmAuthMessageProcessor::ParseMessageRspCredExchange error, decrypt data failed."); return ERR_DM_FAILED; } - LOGI("plainText=%{public}s", GetAnonyJsonString(plainText).c_str()); JsonObject jsonData(plainText); @@ -1960,7 +1960,10 @@ std::string DmAuthMessageProcessor::Base64Encode(std::string &inputStr) // Convert input string to binary const unsigned char* src = reinterpret_cast(inputStr.data()); size_t srcLen = inputStr.size(); - + if (srcLen >= MAX_MESSAGE_LENGTH) { + LOGE("inputStr too long"); + return ""; + } // Calculate the maximum length after base64 encoding size_t maxEncodeLen = ((srcLen + 2) / 3) * 4 + 1; std::vector buffer(maxEncodeLen); @@ -1980,7 +1983,10 @@ std::string DmAuthMessageProcessor::Base64Decode(std::string &inputStr) // Convert input string to binary const unsigned char* src = reinterpret_cast(inputStr.data()); size_t srcLen = inputStr.size(); - + if (srcLen >= MAX_MESSAGE_LENGTH) { + LOGE("inputStr too long"); + return ""; + } // Calculate the maximum length after base64 encoding size_t maxEncodeLen = (srcLen / 4) * 3 + 1; std::vector buffer(maxEncodeLen); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index dea0e21e5..f9feb56c2 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -240,8 +240,8 @@ void DeviceManagerServiceImpl::ImportAuthCodeToConfig(std::shared_ptr authMgr = nullptr; // Create a new auth_mgr, create authMgr if (isSrcSide) { @@ -267,7 +267,7 @@ int32_t DeviceManagerServiceImpl::InitNewProtocolAuthMgr(bool isSrcSide, uint64_ int32_t DeviceManagerServiceImpl::InitOldProtocolAuthMgr(uint64_t tokenId, const std::string &pkgName, int sessionId) { - LOGI("tokenId: %{public}" PRIu64 ", pkgname:%{public}s", tokenId, pkgName.c_str()); + LOGI("tokenId: %{public}s, pkgname:%{public}s", GetAnonyInt32(tokenId).c_str(), pkgName.c_str()); { std::lock_guard lock(authMgrMtx_); if (authMgr_ == nullptr) { @@ -1066,7 +1066,8 @@ int32_t DeviceManagerServiceImpl::TransferSrcOldAuthMgr(std::shared_ptr uint64_t tokenId = 0; int32_t ret = GetLogicalIdAndTokenIdBySessionId(logicalSessionId, tokenId, sessionId); if (ret != DM_OK) { - LOGE("failed, logicalSessionId: %{public}" PRIu64 ", tokenId: %{public}" PRIu64 "", logicalSessionId, tokenId); + LOGE("failed, logicalSessionId: %{public}" PRIu64 ", tokenId: %{public}s", logicalSessionId, + GetAnonyInt32(tokenId).c_str()); return ret; } std::string pkgName; @@ -1888,7 +1889,7 @@ void DeviceManagerServiceImpl::BindTargetImpl(uint64_t tokenId, const std::strin CleanAuthMgrByLogicalSessionId(logicalSessionId); OnAuthResultAndOnBindResult(processInfo, targetId, targetIdTmp.deviceId, ret, tokenId); } - LOGI("end, tokenId %{public}" PRIu64".", tokenId); + LOGI("end, tokenId %{public}s.", GetAnonyInt32(tokenId).c_str()); return; } @@ -2095,7 +2096,7 @@ void DeviceManagerServiceImpl::ScreenCommonEventCallback(std::string commonEvent std::lock_guard lock(authMgrMapMtx_); for (auto& pair : authMgrMap_) { if (pair.second != nullptr) { - LOGI("tokenId: %{public}" PRId64 ".", pair.first); + LOGI("tokenId: %{public}s.", GetAnonyInt32(pair.first).c_str()); pair.second->OnScreenLocked(); } } @@ -2263,7 +2264,7 @@ void DeviceManagerServiceImpl::HandleDevUnBindEvent(int32_t remoteUserId, const void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId) { - LOGI("tokenId = %{public}d.", tokenId); + LOGI("tokenId = %{public}s.", GetAnonyInt32(tokenId).c_str()); char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); std::string localUdid = std::string(localUdidTemp); @@ -2335,8 +2336,8 @@ void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const void DeviceManagerServiceImpl::HandleServiceUnBindEvent(int32_t userId, const std::string &remoteUdid, int32_t remoteTokenId) { - LOGI("remoteTokenId = %{public}d, userId: %{public}d, remoteUdid: %{public}s.", - remoteTokenId, userId, GetAnonyString(remoteUdid).c_str()); + LOGI("remoteTokenId = %{public}s, userId: %{public}d, remoteUdid: %{public}s.", + GetAnonyInt32(remoteTokenId).c_str(), userId, GetAnonyString(remoteUdid).c_str()); char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); std::string localUdid = std::string(localUdidTemp); @@ -3099,8 +3100,8 @@ void DeviceManagerServiceImpl::GetBindCallerInfo(DmBindCallerInfo &bindCallerInf bindCallerInfo.hostPkgLabel = hostPkgLabel; bindCallerInfo.processName = processName; bindCallerInfo.isSystemSA = isSystemSA; - LOGI("userId %{public}d, tokenId %{public}d, bindLevel %{public}d, bundleName %{public}s, hostPkgLabel %{public}s," - "processName %{public}s, isSystemSA %{public}d", userId, callingTokenId, bindLevel, + LOGI("userId %{public}d, tokenId %{public}s, bindLevel %{public}d, bundleName %{public}s, hostPkgLabel %{public}s," + "processName %{public}s, isSystemSA %{public}d", userId, GetAnonyInt32(callingTokenId).c_str(), bindLevel, GetAnonyString(bundleName).c_str(), GetAnonyString(hostPkgLabel).c_str(), GetAnonyString(processName).c_str(), isSystemSA); } diff --git a/services/service/src/advertise/advertise_manager.cpp b/services/service/src/advertise/advertise_manager.cpp index 769ba0ba5..5acf52a6d 100644 --- a/services/service/src/advertise/advertise_manager.cpp +++ b/services/service/src/advertise/advertise_manager.cpp @@ -153,6 +153,8 @@ int32_t AdvertiseManager::GenInnerPublishId(const std::string &pkgName, int32_t int32_t tempPublishId = DM_INVALID_FLAG_ID; { std::lock_guard autoLock(pubMapLock_); + CHECK_SIZE_RETURN(pkgName2PubIdMap_, DM_INVALID_FLAG_ID); + CHECK_SIZE_RETURN(publishIdSet_, DM_INVALID_FLAG_ID); if (pkgName2PubIdMap_[pkgName].find(publishId) != pkgName2PubIdMap_[pkgName].end()) { return pkgName2PubIdMap_[pkgName][publishId]; } diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 707429bb2..45925abff 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2930,7 +2930,8 @@ DM_EXPORT int32_t DeviceManagerService::GetUdidHashByAnoyDeviceId( void DeviceManagerService::SendUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId, int32_t bindLevel) { - LOGI("TokenId %{public}" PRId64", bindLevel %{public}d, userId %{public}d.", tokenId, bindLevel, userId); + LOGI("TokenId %{public}s, bindLevel %{public}d, userId %{public}d.", GetAnonyInt32(tokenId).c_str(), + bindLevel, userId); if (static_cast(bindLevel) == USER) { SendDeviceUnBindBroadCast(peerUdids, userId); return; diff --git a/services/service/src/devicenamemgr/device_name_manager.cpp b/services/service/src/devicenamemgr/device_name_manager.cpp index 4e05f530f..59b30fab4 100644 --- a/services/service/src/devicenamemgr/device_name_manager.cpp +++ b/services/service/src/devicenamemgr/device_name_manager.cpp @@ -225,6 +225,7 @@ void DeviceNameManager::RegisterDeviceNameChangeMonitor(int32_t curUserId, int32 LOGE("monitor is nullptr"); return; } + CHECK_SIZE_VOID(monitorMap_); monitorMap_[curUserId] = monitor; } std::string proxyUri = GetProxyUriStr(SETTINGSDATA_SECURE, curUserId); diff --git a/services/service/src/discovery/discovery_manager.cpp b/services/service/src/discovery/discovery_manager.cpp index edd0ecda8..7b3f32ac1 100644 --- a/services/service/src/discovery/discovery_manager.cpp +++ b/services/service/src/discovery/discovery_manager.cpp @@ -225,6 +225,7 @@ int32_t DiscoveryManager::StartDiscovering4MineLibary(const std::string &pkgName pkgName.c_str(), std::string(dmSubInfo.capability).c_str()); { std::lock_guard capLock(capabilityMapLocks_); + CHECK_SIZE_RETURN(capabilityMap_, ERR_DM_START_DISCOVERING_FAILED); capabilityMap_[pkgName] = std::string(dmSubInfo.capability); } int32_t ret = mineSoftbusListener_->RefreshSoftbusLNN(pkgName, searchJson, dmSubInfo); @@ -254,6 +255,7 @@ int32_t DiscoveryManager::StartDiscoveringNoMetaType(const std::string &pkgName, { std::lock_guard capLock(capabilityMapLocks_); + CHECK_SIZE_RETURN(capabilityMap_, ERR_DM_START_DISCOVERING_FAILED); capabilityMap_[pkgName] = std::string(dmSubInfo.capability); } std::string customData = LNN_DISC_CAPABILITY; @@ -306,6 +308,7 @@ int32_t DiscoveryManager::StartDiscovering4MetaType(const std::string &pkgName, LOGI("capability = %{public}s,", std::string(dmSubInfo.capability).c_str()); { std::lock_guard capLock(capabilityMapLocks_); + CHECK_SIZE_RETURN(capabilityMap_, ERR_DM_START_DISCOVERING_FAILED); capabilityMap_[pkgName] =std::string(dmSubInfo.capability); } @@ -521,6 +524,8 @@ int32_t DiscoveryManager::HandleDiscoveryQueue(const std::string &pkgName, uint1 } { std::lock_guard autoLock(locks_); + CHECK_SIZE_RETURN(pkgNameSet_, ERR_DM_DISCOVERY_REPEATED); + CHECK_SIZE_RETURN(discoveryContextMap_, ERR_DM_DISCOVERY_REPEATED); if (pkgNameSet_.find(pkgName) == pkgNameSet_.end()) { pkgNameSet_.emplace(pkgName); DiscoveryContext context = {pkgName, filterData, subscribeId, dmFilter.filterOp_, dmFilter.filters_}; @@ -746,6 +751,7 @@ std::string DiscoveryManager::AddMultiUserIdentify(const std::string &pkgName) std::string pkgNameTemp = ComposeStr(pkgName, userId); { std::lock_guard autoLock(multiUserDiscLocks_); + CHECK_SIZE_RETURN(multiUserDiscMap_, pkgNameTemp); multiUserDiscMap_[pkgNameTemp] = multiUserDisc; } return pkgNameTemp; @@ -790,6 +796,8 @@ int32_t DiscoveryManager::GenInnerSubId(const std::string &pkgName, uint16_t sub uint16_t tempSubId = DM_INVALID_FLAG_ID; { std::lock_guard autoLock(subIdMapLocks_); + CHECK_SIZE_RETURN(pkgName2SubIdMap_, tempSubId); + CHECK_SIZE_RETURN(pkgName2SubIdMap_[pkgName], tempSubId); if (pkgName2SubIdMap_[pkgName].find(subId) != pkgName2SubIdMap_[pkgName].end()) { return pkgName2SubIdMap_[pkgName][subId]; } diff --git a/services/service/src/ipc/lite/ipc_server_listenermgr.cpp b/services/service/src/ipc/lite/ipc_server_listenermgr.cpp index 36bf2276c..da2e129ff 100644 --- a/services/service/src/ipc/lite/ipc_server_listenermgr.cpp +++ b/services/service/src/ipc/lite/ipc_server_listenermgr.cpp @@ -30,6 +30,7 @@ int32_t IpcServerListenermgr::RegisterListener(std::string &pkgName, const Commo } LOGI("new listener register:%{public}s", pkgName.c_str()); std::lock_guard autoLock(lock_); + CHECK_SIZE_RETURN(dmListenerMap_, ERR_DM_FAILED); dmListenerMap_[pkgName] = *svcId; return DM_OK; } diff --git a/services/service/src/publishcommonevent/dm_package_common_event.cpp b/services/service/src/publishcommonevent/dm_package_common_event.cpp index e914eb3ec..58b7c62fe 100644 --- a/services/service/src/publishcommonevent/dm_package_common_event.cpp +++ b/services/service/src/publishcommonevent/dm_package_common_event.cpp @@ -139,7 +139,8 @@ void DmPackageEventSubscriber::OnReceiveEvent(const CommonEventData &data) std::string appId = data.GetWant().GetStringParam(APP_ID); int32_t accessTokenId = static_cast(data.GetWant().GetIntParam(ACCESS_TOKEN_ID, 0)); if (accessTokenId == -1 || appId == "") { - LOGE("Invalid parameters: accessTokenId = %{public}d, appId = %{public}s", accessTokenId, appId.c_str()); + LOGE("Invalid parameters: accessTokenId = %{public}s, appId = %{public}s", + GetAnonyInt32(accessTokenId).c_str(), appId.c_str()); return; } LOGI("Received package event: %{public}s", receiveEvent.c_str()); diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 5b0508964..19993d8d9 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -530,8 +530,8 @@ void DMCommTool::ProcessReceiveUninstAppEvent(const std::shared_ptrremoteNetworkId, commMsg->socketId); if (uninstAppMsg.userId_ == -1 || uninstAppMsg.tokenId_ == -1) { - LOGE("param invalid, userId: %{public}d, tokenId: %{public}d", - uninstAppMsg.userId_, uninstAppMsg.tokenId_); + LOGE("param invalid, userId: %{public}d, tokenId: %{public}s", + uninstAppMsg.userId_, GetAnonyInt32(uninstAppMsg.tokenId_).c_str()); return; } else { DeviceManagerService::GetInstance().ProcessUninstApp(uninstAppMsg.userId_, @@ -558,8 +558,8 @@ void DMCommTool::ProcessReceiveUnBindAppEvent(const std::shared_ptrremoteNetworkId, commMsg->socketId); if (unBindAppMsg.userId_ == -1 || unBindAppMsg.tokenId_ == -1) { - LOGE("param invalid, userId: %{public}d, tokenId: %{public}d", - unBindAppMsg.userId_, unBindAppMsg.tokenId_); + LOGE("param invalid, userId: %{public}d, tokenId: %{public}s", + unBindAppMsg.userId_, GetAnonyInt32(unBindAppMsg.tokenId_).c_str()); return; } else { DeviceManagerService::GetInstance().ProcessUnBindApp(unBindAppMsg.userId_, diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index bec3b0930..bd4919cb3 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -19,6 +19,7 @@ #include #include "dm_anonymous.h" +#include "dm_constants.h" #include "dm_log.h" namespace OHOS { @@ -963,6 +964,7 @@ bool ReleationShipSyncMgr::IsNewBroadCastId(const RelationShipChangeMsg &msg) } auto iter = recvBroadCastIdMap_.find(key); if (iter == recvBroadCastIdMap_.end()) { + CHECK_SIZE_RETURN(recvBroadCastIdMap_, true); recvBroadCastIdMap_[key] = msg.broadCastId; timer_->StartTimer(key, BROADCAST_TIMEOUT_S, [this](std::string key) { ReleationShipSyncMgr::HandleRecvBroadCastTimeout(key); diff --git a/utils/include/fwkload/standard/dm_distributed_hardware_load.h b/utils/include/fwkload/standard/dm_distributed_hardware_load.h index c9ac3c548..c709f23a2 100644 --- a/utils/include/fwkload/standard/dm_distributed_hardware_load.h +++ b/utils/include/fwkload/standard/dm_distributed_hardware_load.h @@ -35,7 +35,7 @@ public: void InitDistributedHardwareLoadCount(void); uint32_t GetDistributedHardwareLoadCount(void); private: - uint32_t distributedHardwareLoadCount_; + std::atomic distributedHardwareLoadCount_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp index 43c1dd014..43ec5ea5d 100644 --- a/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp +++ b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp @@ -33,7 +33,7 @@ DM_EXPORT void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) LOGE("failed to get system ability mgr."); return; } - distributedHardwareLoadCount_++; + distributedHardwareLoadCount_.fetch_add(1); sptr distributedHardwareLoadCallback_(new DistributedHardwareLoadCallback()); int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SA_ID, distributedHardwareLoadCallback_); if (ret != DM_OK) { @@ -44,11 +44,11 @@ DM_EXPORT void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) } void DmDistributedHardwareLoad::InitDistributedHardwareLoadCount(void) { - distributedHardwareLoadCount_ = 0; + distributedHardwareLoadCount_.store(0); } uint32_t DmDistributedHardwareLoad::GetDistributedHardwareLoadCount() { - return distributedHardwareLoadCount_; + return distributedHardwareLoadCount_.load(); } void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess( -- Gitee