diff --git a/common/include/dfx/standard/dm_hidumper.h b/common/include/dfx/standard/dm_hidumper.h index 4bba267633e5136766d4a2e5becbefd0fcd37e42..3b4f2433dea69b2d0055221133c08d457429e3d4 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 3fd87652e99660c91c5de388f9e5a0a08b3f9c37..77238b7bb4612f7688b7dee6eff4da4450e9daf0 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 2d8bf57b2633a8e489a8a66904497b2e12e6d8b0..9b88079a5e1c9aa8dc1f46831a7734c5235a6ac4 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 beb819b5f8b476052563ece14ff5453c8c02e95e..955e935276419165a9e4ad131559d1cfe77362b6 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 8c546e2f1920bb6661f440f2145d6e68111e16b5..14d6c0d2a87873f141acf30b26a44abe5d18a493 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 baf59b9a6b2e738c86602336786e8378075f735f..3f7096d3a0442b6e0ed73227ffb692c531f60f3c 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 da0915df85078553f0ce8ffd090e3cc45bd1f352..5f8307d6d531de117c60e18d265ad9d2975c99f0 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 e7a02abbd830b8f60bb3f588452aca87149beb88..e56cafa5747ea35fa2e0974386ecdf5005046bcd 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 da0915df85078553f0ce8ffd090e3cc45bd1f352..5f8307d6d531de117c60e18d265ad9d2975c99f0 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 d60a6f090165d2e531c47f4c7b8fb2437cd98350..c37a9a1e053f1e6356a88e255945e8f72002d816 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 09e29468b2e896a94dcee664af3f49de16f2f17c..4b85bd8fa48abb5307a6a0499d4c599763ef5eb8 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 9d8cc425b7ad9e5154f860177945dec689fe7427..43f367ea373d73d62bd35b0dd2f81116ac354050 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 dea0e21e5c724f5af9d35c7efeb5dddbc1e8b724..f9feb56c2a5e2c1cc854c72e2bcb48dd6f67324f 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 769ba0ba5c2ff3ab9aadee7ab59a06ae4937ed4f..5acf52a6def9f1306aa13299f246636449420a7b 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 707429bb2109385a93a67e18411d1d82fb86d426..45925abffa3eadb13348f4b1052ef81e64597065 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 4e05f530fb8a1ea59fe42f936e333c89237ac267..59b30fab41e17a82f73e20c503edb5acd34bd658 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 edd0ecda873228ea4535fb4a3fab9829d926a5af..7b3f32ac1241f40acdd428143981aace7da8da17 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 36bf2276cadb3ee5e71a8139bc74be55003fdf89..da2e129ffb4cf4cd868e2ae255bcfbf97e023456 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 e914eb3eccc6c2e43f7fd17fe3ff57cc438051d4..58b7c62fe07a326b3bd3fc47c5afa8b0a66f04dd 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 5b0508964272535fc25973f1ee58fea73018c5ef..19993d8d9db18035592b01638f60e6480406ca61 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 bec3b0930780488dc80d185d02b4d470130c3b1d..bd4919cb3e8cdf0f2ba18cdf6ebde4a6401a5666 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 c9ac3c54846f96becbea8ef29aa5241ea4b0dfda..c709f23a2237c515d746fa31787f4c59f9f978da 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 43c1dd014517530f53bfcb0840c4b5bf524086d4..43ec5ea5dc8fe804571d64bf34d1706468675c43 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(