From c7462bd8f68a122a3711d2f33b9f5f72ecb91c48 Mon Sep 17 00:00:00 2001 From: libo429 Date: Thu, 24 Jul 2025 16:09:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E6=A3=80=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: libo429 --- common/include/dm_constants.h | 1 + common/src/dfx/standard/dm_hidumper.cpp | 6 +- common/src/dm_constants.cpp | 1 + .../src/deviceprofile_connector.cpp | 79 +++++++++--------- .../src/multiple_user_connector.cpp | 5 ++ .../src/main/ets/pages/ConfirmDialog.ets | 1 - .../src/main/ets/pages/ConfirmDialogTv.ets | 1 - .../main/ets/pages/ConfirmDialogWearable.ets | 1 - .../src/main/ets/pages/InputPinDialog.ets | 1 - .../main/ets/pages/InputPinDialogWearable.ets | 2 +- .../cj/kits/include/device_manager_impl.h | 1 + .../cj/kits/src/device_manager_impl.cpp | 81 ++++++++++++++----- .../native_cpp/src/device_manager_impl.cpp | 22 +++-- .../src/ipc/lite/ipc_client_manager.cpp | 4 + .../src/ipc/standard/ipc_client_manager.cpp | 5 ++ .../src/notify/device_manager_notify.cpp | 76 +++++++++++++++-- .../kits/js/src/native_devicemanager_js.cpp | 76 ++++++++++++----- .../js4.0/src/native_devicemanager_js.cpp | 59 +++++++++++--- radar/include/dm_radar_helper.h | 4 +- radar/src/dm_radar_helper.cpp | 2 +- radar/src/lite/dm_radar_helper.cpp | 2 +- .../commonevent/dm_common_event_manager.h | 1 - .../dm_auth_message_processor.cpp | 5 +- .../commonevent/dm_common_event_manager.cpp | 8 +- .../src/device_manager_service_impl.cpp | 6 +- .../dm_account_common_event.h | 1 - .../dm_datashare_common_event.h | 1 - .../dm_package_common_event.h | 1 - .../dm_publish_common_event.h | 1 - .../dm_screen_common_event.h | 1 - .../src/discovery/discovery_manager.cpp | 9 ++- .../dm_account_common_event.cpp | 8 +- .../dm_datashare_common_event.cpp | 8 +- .../dm_package_common_event.cpp | 8 +- .../dm_publish_common_event.cpp | 8 +- .../dm_screen_common_event.cpp | 8 +- .../src/softbus/mine_softbus_listener.cpp | 5 +- .../service/src/softbus/softbus_listener.cpp | 3 + .../softbuscache/src/dm_softbus_cache.cpp | 12 +++ utils/BUILD.gn | 3 + utils/src/appInfo/standard/app_manager.cpp | 5 ++ 41 files changed, 379 insertions(+), 153 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 2505b96ba..774572e67 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -184,6 +184,7 @@ enum ScreenState { // errCode map DM_EXPORT extern const std::map MAP_ERROR_CODE; // wise device +DM_EXPORT extern const int32_t MAX_CONTAINER_SIZE; DM_EXPORT extern const int32_t MAX_DEVICE_PROFILE_SIZE; const int32_t DEVICE_NAME_MAX_BYTES = 100; diff --git a/common/src/dfx/standard/dm_hidumper.cpp b/common/src/dfx/standard/dm_hidumper.cpp index 2c8952df3..62f18202d 100644 --- a/common/src/dfx/standard/dm_hidumper.cpp +++ b/common/src/dfx/standard/dm_hidumper.cpp @@ -17,7 +17,7 @@ #include // for __hash_map_const_iterator, unordered_map #include // for pair - +#include "dm_constants.h" #include "dm_anonymous.h" // for GetAnonyString #include "dm_error_type.h" #include "dm_log.h" // for LOGI, LOGE @@ -70,6 +70,10 @@ int32_t HiDumpHelper::HiDump(const std::vector& args, std::string & void HiDumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo) { LOGI("HiDumpHelper::SetNodeInfo"); + if (nodeInfos_.size() >= MAX_CONTAINER_SIZE) { + LOGE("nodeInfos_ size is more than max size"); + return; + } nodeInfos_.push_back(deviceInfo); } diff --git a/common/src/dm_constants.cpp b/common/src/dm_constants.cpp index 2a268e59e..0a7a79a3d 100644 --- a/common/src/dm_constants.cpp +++ b/common/src/dm_constants.cpp @@ -174,6 +174,7 @@ const std::map MAP_ERROR_CODE = { }; // wise device +const int32_t MAX_CONTAINER_SIZE = 1000; const int32_t MAX_DEVICE_PROFILE_SIZE = 500; const char* ACL_IS_LNN_ACL_KEY = "IsLnnAcl"; const char* ACL_IS_LNN_ACL_VAL_TRUE = "true"; diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 132a0a795..f10d9dd62 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -73,7 +73,6 @@ void PrintProfile(const AccessControlProfile &profile) std::string acerDeviceId = profile.GetAccesser().GetAccesserDeviceId(); int32_t acerUserId = profile.GetAccesser().GetAccesserUserId(); std::string acerAccountId = profile.GetAccesser().GetAccesserAccountId(); - int32_t acerTokenId = static_cast(profile.GetAccesser().GetAccesserTokenId()); std::string acerPkgName = profile.GetAccesser().GetAccesserBundleName(); std::string acerCredId = profile.GetAccesser().GetAccesserCredentialIdStr(); int32_t acerSkId = profile.GetAccesser().GetAccesserSessionKeyId(); @@ -81,18 +80,17 @@ void PrintProfile(const AccessControlProfile &profile) std::string aceeDeviceId = profile.GetAccessee().GetAccesseeDeviceId(); int32_t aceeUserId = profile.GetAccessee().GetAccesseeUserId(); std::string aceeAccountId = profile.GetAccessee().GetAccesseeAccountId(); - int32_t aceeTokenId = static_cast(profile.GetAccessee().GetAccesseeTokenId()); std::string aceePkgName = profile.GetAccessee().GetAccesseeBundleName(); std::string aceeCredId = profile.GetAccessee().GetAccesseeCredentialIdStr(); int32_t aceeSkId = profile.GetAccessee().GetAccesseeSessionKeyId(); LOGI("bindType %{public}d, bindLevel %{public}d, acerDeviceId %{public}s, acerUserId %{public}d," - "acerAccountId %{public}s, acerTokenId %{public}d, acerPkgName %{public}s, acerCredId %{public}s," + "acerAccountId %{public}s, acerPkgName %{public}s, acerCredId %{public}s," "acerSkId %{public}d, aceeDeviceId %{public}s, aceeUserId %{public}d, aceeAccountId %{public}s," - "aceeTokenId %{public}d, aceePkgName %{public}s, aceeCredId %{public}s, aceeSkId %{public}d.", + "aceePkgName %{public}s, aceeCredId %{public}s, aceeSkId %{public}d.", bindType, bindLevel, GetAnonyString(acerDeviceId).c_str(), acerUserId, GetAnonyString(acerAccountId).c_str(), - acerTokenId, acerPkgName.c_str(), GetAnonyString(acerCredId).c_str(), acerSkId, - GetAnonyString(aceeDeviceId).c_str(), aceeUserId, GetAnonyString(aceeAccountId).c_str(), aceeTokenId, + acerPkgName.c_str(), GetAnonyString(acerCredId).c_str(), acerSkId, + GetAnonyString(aceeDeviceId).c_str(), aceeUserId, GetAnonyString(aceeAccountId).c_str(), aceePkgName.c_str(), GetAnonyString(aceeCredId).c_str(), aceeSkId); } @@ -1476,12 +1474,12 @@ void DeviceProfileConnector::DeleteAppBindLevel(DmOfflineParam &offlineParam, co const std::vector &profiles, const std::string &localUdid, const std::string &remoteUdid, const std::string &extra) { - LOGI("DeviceProfileConnector::DeleteAppBindLevel extra %{public}s", extra.c_str()); int32_t bindNums = 0; int32_t deleteNums = 0; uint64_t peerTokenId = 0; std::string peerBundleName; JsonStrHandle::GetInstance().GetPeerAppInfoParseExtra(extra, peerTokenId, peerBundleName); + LOGI("DeviceProfileConnector::DeleteAppBindLevel peerBundleName %{public}s", peerBundleName.c_str()); for (auto &item : profiles) { if (item.GetTrustDeviceId() != remoteUdid || item.GetBindType() == DM_IDENTICAL_ACCOUNT || item.GetBindLevel() != APP) { @@ -1825,11 +1823,11 @@ DM_EXPORT bool DeviceProfileConnector::CheckAccessControl( const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { - LOGI("srcUdid %{public}s, srcUserId %{public}d, srcPkgName %{public}s, srcTokenId %{public}d," + LOGI("srcUdid %{public}s, srcUserId %{public}d, srcPkgName %{public}s" "srcAccountId %{public}s, sinkUdid %{public}s, sinkUserId %{public}d, sinkPkgName %{public}s," - "sinkTokenId %{public}d, sinkAccountId %{public}s.", GetAnonyString(srcUdid).c_str(), caller.userId, - caller.pkgName.c_str(), static_cast(caller.tokenId), GetAnonyString(caller.accountId).c_str(), - GetAnonyString(sinkUdid).c_str(), callee.userId, callee.pkgName.c_str(), static_cast(callee.tokenId), + "sinkAccountId %{public}s.", GetAnonyString(srcUdid).c_str(), caller.userId, + caller.pkgName.c_str(), GetAnonyString(caller.accountId).c_str(), + GetAnonyString(sinkUdid).c_str(), callee.userId, callee.pkgName.c_str(), GetAnonyString(callee.accountId).c_str()); std::vector profiles = GetAllAccessControlProfile(); std::vector profilesFilter = @@ -1903,11 +1901,11 @@ DM_EXPORT bool DeviceProfileConnector::CheckIsSameAccount( const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { - LOGI("srcUdid %{public}s, srcUserId %{public}d, srcPkgName %{public}s, srcTokenId %{public}d," + LOGI("srcUdid %{public}s, srcUserId %{public}d, srcPkgName %{public}s," "srcAccountId %{public}s, sinkUdid %{public}s, sinkUserId %{public}d, sinkPkgName %{public}s," - "sinkTokenId %{public}d, sinkAccountId %{public}s.", GetAnonyString(srcUdid).c_str(), caller.userId, - caller.pkgName.c_str(), static_cast(caller.tokenId), GetAnonyString(caller.accountId).c_str(), - GetAnonyString(sinkUdid).c_str(), callee.userId, callee.pkgName.c_str(), static_cast(callee.tokenId), + "sinkAccountId %{public}s.", GetAnonyString(srcUdid).c_str(), caller.userId, + caller.pkgName.c_str(), GetAnonyString(caller.accountId).c_str(), + GetAnonyString(sinkUdid).c_str(), callee.userId, callee.pkgName.c_str(), GetAnonyString(callee.accountId).c_str()); std::vector profiles = GetAllAccessControlProfile(); std::vector profilesFilter @@ -1928,8 +1926,7 @@ DM_EXPORT bool DeviceProfileConnector::CheckIsSameAccount( DM_EXPORT int32_t DeviceProfileConnector::GetBindLevel(const std::string &pkgName, const std::string &localUdid, const std::string &udid, uint64_t &tokenId) { - LOGI("pkgName %{public}s, tokenId %{public}" PRId64", udid %{public}s.", pkgName.c_str(), - tokenId, GetAnonyString(udid).c_str()); + LOGI("pkgName %{public}s, udid %{public}s.", pkgName.c_str(), GetAnonyString(udid).c_str()); std::vector profiles = GetAclProfileByDeviceIdAndUserId(localUdid, MultipleUserConnector::GetFirstForegroundUserId()); int32_t bindLevel = INVALIED_TYPE; @@ -1942,7 +1939,7 @@ DM_EXPORT int32_t DeviceProfileConnector::GetBindLevel(const std::string &pkgNam item.GetAccessee().GetAccesseeDeviceId() == udid) { tokenId = static_cast(item.GetAccesser().GetAccesserTokenId()); bindLevel = static_cast(item.GetBindLevel()); - LOGI("Src get bindLevel %{public}d, tokenid %{public}" PRId64".", bindLevel, tokenId); + LOGI("Src get bindLevel %{public}d.", bindLevel); continue; } if (item.GetAccessee().GetAccesseeBundleName() == pkgName && @@ -1950,7 +1947,7 @@ DM_EXPORT int32_t DeviceProfileConnector::GetBindLevel(const std::string &pkgNam item.GetAccesser().GetAccesserDeviceId() == udid) { tokenId = static_cast(item.GetAccessee().GetAccesseeTokenId()); bindLevel = static_cast(item.GetBindLevel()); - LOGI("Sink get bindLevel %{public}d, tokenid %{public}" PRId64".", bindLevel, tokenId); + LOGI("Sink get bindLevel %{public}d.", bindLevel); continue; } } @@ -2136,8 +2133,8 @@ DM_EXPORT int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUse DM_EXPORT DmOfflineParam DeviceProfileConnector::HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid) { - LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, tokenId %{public}d, localUdid %{public}s.", - remoteUserId, GetAnonyString(remoteUdid).c_str(), tokenId, GetAnonyString(localUdid).c_str()); + LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, localUdid %{public}s.", + remoteUserId, GetAnonyString(remoteUdid).c_str(), GetAnonyString(localUdid).c_str()); std::vector profiles = GetAclProfileByDeviceIdAndUserId(remoteUdid, remoteUserId, localUdid); DmOfflineParam offlineParam; if (profiles.empty()) { @@ -2213,8 +2210,8 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces DM_EXPORT DmOfflineParam DeviceProfileConnector::HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid, int32_t peerTokenId) { - LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, tokenId %{public}d, localUdid %{public}s.", - remoteUserId, GetAnonyString(remoteUdid).c_str(), tokenId, GetAnonyString(localUdid).c_str()); + LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, localUdid %{public}s.", + remoteUserId, GetAnonyString(remoteUdid).c_str(), GetAnonyString(localUdid).c_str()); std::vector profiles = GetAclProfileByDeviceIdAndUserId(remoteUdid, remoteUserId, localUdid); DmOfflineParam offlineParam; if (profiles.empty()) { @@ -2291,8 +2288,8 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces DmOfflineParam DeviceProfileConnector::HandleServiceUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, const std::string &localUdid, int32_t tokenId) { - LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, tokenId %{public}d, localUdid %{public}s.", - remoteUserId, GetAnonyString(remoteUdid).c_str(), tokenId, GetAnonyString(localUdid).c_str()); + LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, localUdid %{public}s.", + remoteUserId, GetAnonyString(remoteUdid).c_str(), GetAnonyString(localUdid).c_str()); std::vector profiles = GetAclProfileByDeviceIdAndUserId(remoteUdid, remoteUserId, localUdid); DmOfflineParam offlineParam; if (profiles.empty()) { @@ -3110,11 +3107,11 @@ DM_EXPORT int32_t DeviceProfileConnector::HandleAccountCommonEvent( DM_EXPORT bool DeviceProfileConnector::CheckSrcAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { - LOGI("srcUdid %{public}s, srcUserId %{public}d, srcPkgName %{public}s, srcTokenId %{public}d," + LOGI("srcUdid %{public}s, srcUserId %{public}d, srcPkgName %{public}s," "srcAccountId %{public}s, sinkUdid %{public}s, sinkUserId %{public}d, sinkPkgName %{public}s," - "sinkTokenId %{public}d, sinkAccountId %{public}s.", GetAnonyString(srcUdid).c_str(), caller.userId, - caller.pkgName.c_str(), static_cast(caller.tokenId), GetAnonyString(caller.accountId).c_str(), - GetAnonyString(sinkUdid).c_str(), callee.userId, callee.pkgName.c_str(), static_cast(callee.tokenId), + "sinkAccountId %{public}s.", GetAnonyString(srcUdid).c_str(), caller.userId, + caller.pkgName.c_str(), GetAnonyString(caller.accountId).c_str(), + GetAnonyString(sinkUdid).c_str(), callee.userId, callee.pkgName.c_str(), GetAnonyString(callee.accountId).c_str()); std::vector profiles = GetAllAccessControlProfile(); std::string localUdid = GetLocalDeviceId(); @@ -3235,11 +3232,11 @@ bool DeviceProfileConnector::CheckSrcP2PAccessControl(const DistributedDevicePro DM_EXPORT bool DeviceProfileConnector::CheckSinkAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { - LOGI("srcUdid %{public}s, srcUserId %{public}d, srcPkgName %{public}s, srcTokenId %{public}d," + LOGI("srcUdid %{public}s, srcUserId %{public}d, srcPkgName %{public}s," "srcAccountId %{public}s, sinkUdid %{public}s, sinkUserId %{public}d, sinkPkgName %{public}s," - "sinkTokenId %{public}d, sinkAccountId %{public}s.", GetAnonyString(srcUdid).c_str(), caller.userId, - caller.pkgName.c_str(), static_cast(caller.tokenId), GetAnonyString(caller.accountId).c_str(), - GetAnonyString(sinkUdid).c_str(), callee.userId, callee.pkgName.c_str(), static_cast(callee.tokenId), + "sinkAccountId %{public}s.", GetAnonyString(srcUdid).c_str(), caller.userId, + caller.pkgName.c_str(), GetAnonyString(caller.accountId).c_str(), + GetAnonyString(sinkUdid).c_str(), callee.userId, callee.pkgName.c_str(), GetAnonyString(callee.accountId).c_str()); std::vector profiles = GetAllAccessControlProfile(); std::string localUdid = GetLocalDeviceId(); @@ -3392,11 +3389,11 @@ bool DeviceProfileConnector::CheckSinkAppOrServiceP2PAcl(const DistributedDevice DM_EXPORT bool DeviceProfileConnector::CheckSrcIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { - LOGI("srcUdid %{public}s, srcUserId %{public}d, srcPkgName %{public}s, srcTokenId %{public}d," + LOGI("srcUdid %{public}s, srcUserId %{public}d, srcPkgName %{public}s, " "srcAccountId %{public}s, sinkUdid %{public}s, sinkUserId %{public}d, sinkPkgName %{public}s," - "sinkTokenId %{public}d, sinkAccountId %{public}s.", GetAnonyString(srcUdid).c_str(), caller.userId, - caller.pkgName.c_str(), static_cast(caller.tokenId), GetAnonyString(caller.accountId).c_str(), - GetAnonyString(sinkUdid).c_str(), callee.userId, callee.pkgName.c_str(), static_cast(callee.tokenId), + "sinkAccountId %{public}s.", GetAnonyString(srcUdid).c_str(), caller.userId, + caller.pkgName.c_str(), GetAnonyString(caller.accountId).c_str(), + GetAnonyString(sinkUdid).c_str(), callee.userId, callee.pkgName.c_str(), GetAnonyString(callee.accountId).c_str()); std::vector profiles = GetAllAccessControlProfile(); std::string localUdid = GetLocalDeviceId(); @@ -3417,11 +3414,11 @@ DM_EXPORT bool DeviceProfileConnector::CheckSrcIsSameAccount(const DmAccessCalle DM_EXPORT bool DeviceProfileConnector::CheckSinkIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { - LOGI("srcUdid %{public}s, srcUserId %{public}d, srcPkgName %{public}s, srcTokenId %{public}d," + LOGI("srcUdid %{public}s, srcUserId %{public}d, srcPkgName %{public}s," "srcAccountId %{public}s, sinkUdid %{public}s, sinkUserId %{public}d, sinkPkgName %{public}s," - "sinkTokenId %{public}d, sinkAccountId %{public}s.", GetAnonyString(srcUdid).c_str(), caller.userId, - caller.pkgName.c_str(), static_cast(caller.tokenId), GetAnonyString(caller.accountId).c_str(), - GetAnonyString(sinkUdid).c_str(), callee.userId, callee.pkgName.c_str(), static_cast(callee.tokenId), + "sinkAccountId %{public}s.", GetAnonyString(srcUdid).c_str(), caller.userId, + caller.pkgName.c_str(), GetAnonyString(caller.accountId).c_str(), + GetAnonyString(sinkUdid).c_str(), callee.userId, callee.pkgName.c_str(), GetAnonyString(callee.accountId).c_str()); std::vector profiles = GetAllAccessControlProfile(); std::string localUdid = GetLocalDeviceId(); diff --git a/commondependency/src/multiple_user_connector.cpp b/commondependency/src/multiple_user_connector.cpp index 4855dd1b1..d03e33440 100644 --- a/commondependency/src/multiple_user_connector.cpp +++ b/commondependency/src/multiple_user_connector.cpp @@ -17,6 +17,7 @@ #include "dm_error_type.h" #include "dm_log.h" +#include "dm_constants.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "account_info.h" #include "ipc_skeleton.h" @@ -208,6 +209,10 @@ DM_EXPORT void MultipleUserConnector::SetAccountInfo(int32_t userId, DMAccountInfo dmAccountInfo) { std::lock_guard lock(dmAccountInfoMaplock_); + if (dmAccountInfoMap_.size() >= MAX_CONTAINER_SIZE) { + LOGE("dmAccountInfoMap_ size is more than max size"); + return; + } dmAccountInfoMap_[userId] = dmAccountInfo; } diff --git a/display/entry/src/main/ets/pages/ConfirmDialog.ets b/display/entry/src/main/ets/pages/ConfirmDialog.ets index 93269fa12..40b25383e 100644 --- a/display/entry/src/main/ets/pages/ConfirmDialog.ets +++ b/display/entry/src/main/ets/pages/ConfirmDialog.ets @@ -353,7 +353,6 @@ struct ConfirmCustomDialog { item => item.bundleName !== app.bundleName ); } - console.log('The currently selected data:', this.selectedAppDataList); } getImages(peerdeviceType: number): Resource { diff --git a/display/entry/src/main/ets/pages/ConfirmDialogTv.ets b/display/entry/src/main/ets/pages/ConfirmDialogTv.ets index be34eafce..49f3ce1e4 100644 --- a/display/entry/src/main/ets/pages/ConfirmDialogTv.ets +++ b/display/entry/src/main/ets/pages/ConfirmDialogTv.ets @@ -65,7 +65,6 @@ struct ConfirmCustomDialog { if (AppStorage.get('deviceName') != null) { this.peerDeviceName = AppStorage.get('deviceName') as string + ' '; - console.log('peerDeviceName is ' + this.peerDeviceName); } let customDescriptionStr: string = AppStorage.get('customDescriptionStr') as string; let hostPkgLabel: string = AppStorage.get('hostPkgLabel') as string; diff --git a/display/entry/src/main/ets/pages/ConfirmDialogWearable.ets b/display/entry/src/main/ets/pages/ConfirmDialogWearable.ets index 62435a1ba..8509bc09a 100644 --- a/display/entry/src/main/ets/pages/ConfirmDialogWearable.ets +++ b/display/entry/src/main/ets/pages/ConfirmDialogWearable.ets @@ -145,7 +145,6 @@ struct Index { if (AppStorage.get('deviceName') != null) { this.peerDeviceName = AppStorage.get('deviceName') as string; - console.log('peerDeviceName is ' + this.peerDeviceName); } let hostPkgLabel: string = AppStorage.get('hostPkgLabel') as string; if (hostPkgLabel === CAST_PKG_NAME) { diff --git a/display/entry/src/main/ets/pages/InputPinDialog.ets b/display/entry/src/main/ets/pages/InputPinDialog.ets index 3eddbe3ac..1c6949c57 100644 --- a/display/entry/src/main/ets/pages/InputPinDialog.ets +++ b/display/entry/src/main/ets/pages/InputPinDialog.ets @@ -128,7 +128,6 @@ struct InputCustomDialog { } if (AppStorage.get('targetDeviceName') != null) { this.targetDeviceName = AppStorage.get('targetDeviceName') as string; - console.log('targetDeviceName is ' + this.targetDeviceName); } if (AppStorage.get('model') != null) { this.model = AppStorage.get('model') as string; diff --git a/display/entry/src/main/ets/pages/InputPinDialogWearable.ets b/display/entry/src/main/ets/pages/InputPinDialogWearable.ets index 581575719..f7a91899f 100644 --- a/display/entry/src/main/ets/pages/InputPinDialogWearable.ets +++ b/display/entry/src/main/ets/pages/InputPinDialogWearable.ets @@ -125,7 +125,7 @@ struct Index { } setUserOperation(operation: number, extra: string) { - console.log('setUserOperation: ' + operation + 'input' + extra); + console.log('setUserOperation: ' + operation); if (dmClass === null) { console.log('setUserOperation: ' + 'dmClass null'); return; diff --git a/interfaces/cj/kits/include/device_manager_impl.h b/interfaces/cj/kits/include/device_manager_impl.h index fa231c187..0d17884fe 100644 --- a/interfaces/cj/kits/include/device_manager_impl.h +++ b/interfaces/cj/kits/include/device_manager_impl.h @@ -63,6 +63,7 @@ private: static int32_t Transform2FfiDeviceBasicInfo(const DmDeviceBasicInfo &in, FfiDeviceBasicInfo &out); int32_t BindTargetWarpper(const std::string &deviceId, const std::string &bindParam, std::shared_ptr callback); + int32_t BindDevice(const std::string &deviceId, const std::string &bindParam); int32_t WaitForCallbackCv(); int32_t RegisterDevStatusCallback(); diff --git a/interfaces/cj/kits/src/device_manager_impl.cpp b/interfaces/cj/kits/src/device_manager_impl.cpp index 478173ee0..1c5e15823 100644 --- a/interfaces/cj/kits/src/device_manager_impl.cpp +++ b/interfaces/cj/kits/src/device_manager_impl.cpp @@ -156,10 +156,18 @@ DeviceManagerFfiImpl::DeviceManagerFfiImpl(const std::string &bundleName, int32_ } { std::lock_guard autoLock(g_initCallbackMapMutex); + if (g_initCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_initCallbackMap map size is more than max size"); + return; + } g_initCallbackMap[bundleName_] = initCallback; } std::lock_guard autoLock(g_deviceManagerMapMutex); + if (g_deviceManagerMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_deviceManagerMap map size is more than max size"); + return; + } g_deviceManagerMap[bundleName_] = this; } @@ -369,6 +377,10 @@ int32_t DeviceManagerFfiImpl::StartDiscovering(const std::string &extra) std::lock_guard autoLock(g_discoveryCallbackMapMutex); auto iter = g_DiscoveryCallbackMap.find(bundleName_); if (iter == g_DiscoveryCallbackMap.end()) { + if (g_DiscoveryCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_DiscoveryCallbackMap map size is more than max size"); + return DM_ERR_FAILED; + } discoveryCallback = std::make_shared(bundleName_); g_DiscoveryCallbackMap[bundleName_] = discoveryCallback; } else { @@ -401,6 +413,34 @@ int32_t DeviceManagerFfiImpl::StopDiscovering() return ERR_OK; } +int32_t DeviceManagerFfiImpl::BindDevice(const std::string &deviceId, const std::string &bindParam) +{ + std::shared_ptr bindDeviceCallback = nullptr; + { + std::lock_guard autoLock(g_authCallbackMapMutex); + auto iter = g_authCallbackMap.find(bundleName_); + if (iter == g_authCallbackMap.end()) { + bindDeviceCallback = std::make_shared(bundleName_); + if (g_authCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_authCallbackMap map size is more than max size"); + return DM_ERR_FAILED; + } + g_authCallbackMap[bundleName_] = bindDeviceCallback; + } else { + bindDeviceCallback = iter->second; + } + } + constexpr int32_t bindType = 1; + int32_t ret = DeviceManager::GetInstance().BindDevice(bundleName_, bindType, deviceId, + bindParam, bindDeviceCallback); + if (ret != 0) { + ret = TransformErrCode(ret); + LOGE("BindDevice for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); + return ret; + } + return WaitForCallbackCv(); +} + int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, const std::string &bindParam, const bool isMetaType) { @@ -418,7 +458,10 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, { std::lock_guard autoLock(g_bindCallbackMapMutex); auto iter = g_bindCallbackMap.find(bundleName_); - if (iter == g_bindCallbackMap.end()) { + if (iter == g_bindCallbackMap.end() && g_bindCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_bindCallbackMap map size is more than max size"); + return DM_ERR_FAILED; + } else if (iter == g_bindCallbackMap.end() && g_bindCallbackMap.size() < MAX_CONTAINER_SIZE) { bindTargetCallback = std::make_shared(bundleName_); g_bindCallbackMap[bundleName_] = bindTargetCallback; } else { @@ -434,25 +477,7 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, return WaitForCallbackCv(); } - std::shared_ptr bindDeviceCallback = nullptr; - { - std::lock_guard autoLock(g_authCallbackMapMutex); - auto iter = g_authCallbackMap.find(bundleName_); - if (iter == g_authCallbackMap.end()) { - bindDeviceCallback = std::make_shared(bundleName_); - g_authCallbackMap[bundleName_] = bindDeviceCallback; - } else { - bindDeviceCallback = iter->second; - } - } - constexpr int32_t bindType = 1; - ret = DeviceManager::GetInstance().BindDevice(bundleName_, bindType, deviceId, bindParam, bindDeviceCallback); - if (ret != 0) { - ret = TransformErrCode(ret); - LOGE("BindDevice for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); - return ret; - } - return WaitForCallbackCv(); + return BindDevice(deviceId, bindParam); } int32_t DeviceManagerFfiImpl::WaitForCallbackCv() @@ -719,6 +744,10 @@ int32_t DeviceManagerFfiImpl::RegisterDevStatusCallback() } { std::lock_guard autoLock(g_deviceStatusCallbackMapMutex); + if (g_deviceStatusCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_deviceStatusCallbackMap map size is more than max size"); + return DM_ERR_FAILED; + } g_deviceStatusCallbackMap[bundleName_] = callback; } return ERR_OK; @@ -729,6 +758,10 @@ int32_t DeviceManagerFfiImpl::RegisterDiscoveryCallback() auto discoveryCallback = std::make_shared(bundleName_); { std::lock_guard autoLock(g_discoveryCallbackMapMutex); + if (g_DiscoveryCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_DiscoveryCallbackMap map size is more than max size"); + return DM_ERR_FAILED; + } g_DiscoveryCallbackMap[bundleName_] = discoveryCallback; } discoveryCallback->IncreaseRefCount(); @@ -740,6 +773,10 @@ int32_t DeviceManagerFfiImpl::RegisterPublishCallback() auto publishCallback = std::make_shared(bundleName_); { std::lock_guard autoLock(g_publishCallbackMapMutex); + if (g_publishCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_publishCallbackMap map size is more than max size"); + return DM_ERR_FAILED; + } g_publishCallbackMap[bundleName_] = publishCallback; } publishCallback->IncreaseRefCount(); @@ -757,6 +794,10 @@ int32_t DeviceManagerFfiImpl::RegisterReplyCallback() } { std::lock_guard autoLock(g_dmUiCallbackMapMutex); + if (g_dmUiCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_dmUiCallbackMap map size is more than max size"); + return DM_ERR_FAILED; + } g_dmUiCallbackMap[bundleName_] = dmUiCallback; } return ERR_OK; diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 0b2bfebae..8b44688a6 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -689,7 +689,7 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, strDeviceId, callback); JsonObject extraJson(extra); if (extraJson.IsDiscarded()) { - LOGE("extra bindParam %{public}s.", extra.c_str()); + LOGE("extra bindParam invalid."); return ERR_DM_INPUT_PARA_INVALID; } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -1536,7 +1536,7 @@ int32_t DeviceManagerImpl::BindDevice(const std::string &pkgName, int32_t bindTy LOGI("start, pkgName: %{public}s", pkgName.c_str()); JsonObject paramJson(bindParam); if (paramJson.IsDiscarded()) { - LOGE("BindDevice bindParam %{public}s.", bindParam.c_str()); + LOGE("BindDevice bindParam invalid."); return ERR_DM_INPUT_PARA_INVALID; } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -1654,11 +1654,9 @@ int32_t DeviceManagerImpl::GetNetworkTypeByNetworkId(const std::string &pkgName, int32_t DeviceManagerImpl::ImportAuthCode(const std::string &pkgName, const std::string &authCode) { if (authCode.empty() || pkgName.empty()) { - LOGE("ImportAuthCode error: Invalid para, authCode: %{public}s, pkgName: %{public}s", - GetAnonyString(authCode).c_str(), pkgName.c_str()); + LOGE("ImportAuthCode error: Invalid para, pkgName: %{public}s", pkgName.c_str()); return ERR_DM_INPUT_PARA_INVALID; } - LOGI("Start, authCode: %{public}s", GetAnonyString(authCode).c_str()); int32_t length = static_cast(authCode.length()); if (length < DM_IMPORT_AUTH_CODE_MIN_LENGTH || length > DM_IMPORT_AUTH_CODE_MAX_LENGTH) { LOGE("ImportAuthCode error: Invalid para, authCode size error."); @@ -1711,7 +1709,7 @@ int32_t DeviceManagerImpl::ExportAuthCode(std::string &authCode) } authCode = rsp->GetAuthCode(); - LOGI("Success, authCode: %{public}s.", GetAnonyString(authCode).c_str()); + LOGI("Success."); return DM_OK; } @@ -1988,9 +1986,17 @@ uint16_t DeviceManagerImpl::AddDiscoveryCallback(const std::string &pkgName, std::lock_guard autoLock(subMapLock); auto item = pkgName2SubIdMap_.find(pkgNameTemp); if (item == pkgName2SubIdMap_.end() && subscribeId == DM_INVALID_FLAG_ID) { + if (pkgName2SubIdMap_.size() >= MAX_CONTAINER_SIZE || randSubIdSet_.size() >= MAX_CONTAINER_SIZE) { + LOGE("pkgName2SubIdMap_ or randSubIdSet_ size is more than max size"); + return DM_INVALID_FLAG_ID; + } subscribeId = GenUniqueRandUint(randSubIdSet_); pkgName2SubIdMap_[pkgNameTemp] = subscribeId; } else if (item == pkgName2SubIdMap_.end() && subscribeId != DM_INVALID_FLAG_ID) { + if (pkgName2SubIdMap_.size() >= MAX_CONTAINER_SIZE || randSubIdSet_.size() >= MAX_CONTAINER_SIZE) { + LOGE("pkgName2SubIdMap_ or randSubIdSet_ size is more than max size"); + return DM_INVALID_FLAG_ID; + } pkgName2SubIdMap_[pkgNameTemp] = subscribeId; randSubIdSet_.emplace(subscribeId); } else if (item != pkgName2SubIdMap_.end()) { @@ -2028,6 +2034,10 @@ int32_t DeviceManagerImpl::AddPublishCallback(const std::string &pkgName) if (pkgName2PubIdMap_.find(pkgName) != pkgName2PubIdMap_.end()) { publishId = pkgName2PubIdMap_[pkgName]; } else { + if (pkgName2PubIdMap_.size() >= MAX_CONTAINER_SIZE || randPubIdSet_.size() >= MAX_CONTAINER_SIZE) { + LOGE("pkgName2PubIdMap_ or randPubIdSet_ is more than max size"); + return DM_INVALID_FLAG_ID; + } publishId = GenUniqueRandUint(randPubIdSet_); pkgName2PubIdMap_[pkgName] = publishId; } 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 74a5c38df..f7731d277 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 @@ -37,6 +37,10 @@ int32_t IpcClientManager::Init(const std::string &pkgName) LOGE("ipcclientstub init failed."); return ERR_DM_INIT_FAILED; } + if (packageInitSet_.size() >= MAX_CONTAINER_SIZE) { + LOGE("packageInitSet_ size is more than max size"); + return ERR_DM_FAILED; + } std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp index f912db8d9..93b2ef4fb 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp @@ -20,6 +20,7 @@ #include "device_manager_ipc_interface_code.h" #include "device_manager_notify.h" #include "device_manager_impl.h" +#include "dm_constants.h" #include "dm_error_type.h" #include "dm_log.h" #include "dm_service_load.h" @@ -84,6 +85,10 @@ int32_t IpcClientManager::Init(const std::string &pkgName) LOGE("InitDeviceManager Failed with ret %{public}d", ret); return ret; } + if (dmListener_.size() >= MAX_CONTAINER_SIZE) { + LOGE("dmListener_ size is more than max size"); + return ERR_DM_FAILED; + } sptr listener = sptr(new IpcClientStub()); std::shared_ptr req = std::make_shared(); diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index 278ebade4..8e276a232 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -15,6 +15,7 @@ #include "device_manager_notify.h" #include +#include "dm_constants.h" #include "dm_anonymous.h" #include "dm_error_type.h" #include "dm_device_info.h" @@ -27,7 +28,6 @@ namespace OHOS { namespace DistributedHardware { namespace { constexpr const char* UK_SEPARATOR = "#"; -constexpr int32_t MAX_CONTAINER_SIZE = 500; } DM_IMPLEMENT_SINGLE_INSTANCE(DeviceManagerNotify); #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -46,6 +46,10 @@ void DeviceManagerNotify::RegisterDeathRecipientCallback(const std::string &pkgN return; } std::lock_guard autoLock(lock_); + if (dmInitCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("dmInitCallback_ map size is more than max size"); + return; + } dmInitCallback_[pkgName] = dmInitCallback; } @@ -67,6 +71,10 @@ void DeviceManagerNotify::RegisterDeviceStateCallback(const std::string &pkgName return; } std::lock_guard autoLock(lock_); + if (deviceStateCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("deviceStateCallback_ map size is more than max size"); + return; + } deviceStateCallback_[pkgName] = callback; } @@ -98,6 +106,10 @@ void DeviceManagerNotify::RegisterDeviceStatusCallback(const std::string &pkgNam return; } std::lock_guard autoLock(lock_); + if (deviceStatusCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("deviceStateCallback_ map size is more than max size"); + return; + } deviceStatusCallback_[pkgName] = callback; } @@ -110,6 +122,10 @@ void DeviceManagerNotify::RegisterDiscoveryCallback(const std::string &pkgName, } std::lock_guard autoLock(lock_); if (deviceDiscoveryCallbacks_.count(pkgName) == 0) { + if (deviceDiscoveryCallbacks_.size() >= MAX_CONTAINER_SIZE) { + LOGE("deviceDiscoveryCallbacks_ map size is more than max size"); + return; + } deviceDiscoveryCallbacks_[pkgName] = std::map>(); } deviceDiscoveryCallbacks_[pkgName][subscribeId] = callback; @@ -140,6 +156,10 @@ void DeviceManagerNotify::RegisterPublishCallback(const std::string &pkgName, } std::lock_guard autoLock(lock_); if (devicePublishCallbacks_.count(pkgName) == 0) { + if (devicePublishCallbacks_.size() >= MAX_CONTAINER_SIZE) { + LOGE("devicePublishCallbacks_ map size is more than max size"); + return; + } devicePublishCallbacks_[pkgName] = std::map>(); } devicePublishCallbacks_[pkgName][publishId] = callback; @@ -170,6 +190,10 @@ void DeviceManagerNotify::RegisterAuthenticateCallback(const std::string &pkgNam } std::lock_guard autoLock(lock_); if (authenticateCallback_.count(pkgName) == 0) { + if (authenticateCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("devicePublishCallbacks_ map size is more than max size"); + return; + } authenticateCallback_[pkgName] = std::map>(); } authenticateCallback_[pkgName][deviceId] = callback; @@ -216,6 +240,10 @@ void DeviceManagerNotify::RegisterDeviceManagerFaCallback(const std::string &pkg std::shared_ptr callback) { std::lock_guard autoLock(lock_); + if (dmUiCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("dmUiCallback_ map size is more than max size"); + return; + } dmUiCallback_[pkgName] = callback; } @@ -237,6 +265,10 @@ void DeviceManagerNotify::RegisterCredentialCallback(const std::string &pkgName, return; } std::lock_guard autoLock(lock_); + if (credentialCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("credentialCallback_ map size is more than max size"); + return; + } credentialCallback_[pkgName] = callback; } @@ -258,6 +290,10 @@ void DeviceManagerNotify::RegisterPinHolderCallback(const std::string &pkgName, return; } std::lock_guard autoLock(lock_); + if (pinHolderCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("pinHolderCallback_ map size is more than max size"); + return; + } pinHolderCallback_[pkgName] = callback; } @@ -733,6 +769,10 @@ void DeviceManagerNotify::RegisterBindCallback(const std::string &pkgName, const } std::lock_guard autoLock(bindLock_); if (bindCallback_.count(pkgName) == 0) { + if (bindCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("bindCallback_ map size is more than max size"); + return; + } bindCallback_[pkgName] = std::map>(); } bindCallback_[pkgName][targetId] = callback; @@ -748,6 +788,10 @@ void DeviceManagerNotify::RegisterUnbindCallback(const std::string &pkgName, con } std::lock_guard autoLock(lock_); if (unbindCallback_.count(pkgName) == 0) { + if (unbindCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("unbindCallback_ map size is more than max size"); + return; + } unbindCallback_[pkgName] = std::map>(); } unbindCallback_[pkgName][targetId] = callback; @@ -1008,6 +1052,10 @@ void DeviceManagerNotify::RegDevTrustChangeCallback(const std::string &pkgName, return; } std::lock_guard autoLock(lock_); + if (devTrustChangeCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("devTrustChangeCallback_ map size is more than max size"); + return; + } devTrustChangeCallback_[pkgName] = callback; } @@ -1065,6 +1113,10 @@ void DeviceManagerNotify::RegisterDeviceScreenStatusCallback(const std::string & return; } std::lock_guard autoLock(lock_); + if (deviceScreenStatusCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("deviceScreenStatusCallback_ map size is more than max size"); + return; + } deviceScreenStatusCallback_[pkgName] = callback; } @@ -1109,6 +1161,10 @@ void DeviceManagerNotify::RegisterCredentialAuthStatusCallback(const std::string return; } std::lock_guard autoLock(lock_); + if (credentialAuthStatusCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("credentialAuthStatusCallback_ map size is more than max size"); + return; + } credentialAuthStatusCallback_[pkgName] = callback; } @@ -1154,6 +1210,10 @@ void DeviceManagerNotify::RegisterSinkBindCallback(const std::string &pkgName, return; } std::lock_guard autoLock(lock_); + if (sinkBindTargetCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("sinkBindTargetCallback_ map size is more than max size"); + return; + } sinkBindTargetCallback_[pkgName] = callback; } @@ -1263,7 +1323,7 @@ int32_t DeviceManagerNotify::RegisterGetDeviceProfileInfoListCallback(const std: return ERR_DM_CALLBACK_REGISTER_FAILED; } std::lock_guard autoLock(bindLock_); - if (getDeviceProfileInfoCallback_.size() > MAX_CONTAINER_SIZE) { + if (getDeviceProfileInfoCallback_.size() >= MAX_CONTAINER_SIZE) { LOGE("callback map size is more than max size"); return ERR_DM_CALLBACK_REGISTER_FAILED; } @@ -1305,7 +1365,7 @@ int32_t DeviceManagerNotify::RegisterGetDeviceIconInfoCallback(const std::string return ERR_DM_CALLBACK_REGISTER_FAILED; } std::lock_guard autoLock(bindLock_); - if (getDeviceIconInfoCallback_.size() > MAX_CONTAINER_SIZE) { + if (getDeviceIconInfoCallback_.size() >= MAX_CONTAINER_SIZE) { LOGE("callback map size is more than max size"); return ERR_DM_CALLBACK_REGISTER_FAILED; } @@ -1314,11 +1374,11 @@ int32_t DeviceManagerNotify::RegisterGetDeviceIconInfoCallback(const std::string getDeviceIconInfoCallback_[pkgName][uk] = {callback}; return DM_OK; } - if (iter->second.size() > MAX_CONTAINER_SIZE) { + if (iter->second.size() >= MAX_CONTAINER_SIZE) { LOGE("callback map for pkg size is more than max size"); return ERR_DM_CALLBACK_REGISTER_FAILED; } - if (iter->second[uk].size() > MAX_CONTAINER_SIZE) { + if (iter->second[uk].size() >= MAX_CONTAINER_SIZE) { LOGE("callback set size is more than max size"); return ERR_DM_CALLBACK_REGISTER_FAILED; } @@ -1375,7 +1435,7 @@ int32_t DeviceManagerNotify::RegisterSetLocalDeviceNameCallback(const std::strin return ERR_DM_CALLBACK_REGISTER_FAILED; } std::lock_guard autoLock(bindLock_); - if (setLocalDeviceNameCallback_.size() > MAX_CONTAINER_SIZE) { + if (setLocalDeviceNameCallback_.size() >= MAX_CONTAINER_SIZE) { LOGE("callback map size is more than max size"); return ERR_DM_CALLBACK_REGISTER_FAILED; } @@ -1392,7 +1452,7 @@ int32_t DeviceManagerNotify::RegisterSetRemoteDeviceNameCallback(const std::stri return ERR_DM_CALLBACK_REGISTER_FAILED; } std::lock_guard autoLock(bindLock_); - if (setRemoteDeviceNameCallback_.size() > MAX_CONTAINER_SIZE) { + if (setRemoteDeviceNameCallback_.size() >= MAX_CONTAINER_SIZE) { LOGE("callback map size is more than max size"); return ERR_DM_CALLBACK_REGISTER_FAILED; } @@ -1401,7 +1461,7 @@ int32_t DeviceManagerNotify::RegisterSetRemoteDeviceNameCallback(const std::stri setRemoteDeviceNameCallback_[pkgName][deviceId] = callback; return DM_OK; } - if (iter->second.size() > MAX_CONTAINER_SIZE) { + if (iter->second.size() >= MAX_CONTAINER_SIZE) { LOGE("callback map size is more than max size"); return ERR_DM_CALLBACK_REGISTER_FAILED; } diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 2eb015b6c..9643f6d6b 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -1294,7 +1294,7 @@ void DeviceManagerNapi::JsToDmDiscoveryExtra(const napi_env &env, const napi_val } NAPI_CALL_RETURN_VOID(env, napi_get_value_string_utf8(env, object, filterOption, typeLen + 1, &typeLen)); extra = filterOption; - LOGI("JsToDmDiscoveryExtra, extra :%{public}s, typeLen : %{public}zu", extra.c_str(), typeLen); + LOGI("JsToDmDiscoveryExtra, typeLen : %{public}zu", typeLen); } bool DeviceManagerNapi::IsSystemApp() @@ -1326,6 +1326,10 @@ void DeviceManagerNapi::RegisterDevStateCallback(napi_env env, std::string &bund } { std::lock_guard autoLock(g_deviceStateCallbackMapMutex); + if (g_deviceStateCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_deviceStateCallbackMap map size is more than max size"); + return; + } g_deviceStateCallbackMap[bundleName] = callback; } return; @@ -1343,6 +1347,10 @@ void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, auto callback = std::make_shared(env, bundleName); { std::lock_guard autoLock(g_discoveryCallbackMapMutex); + if (g_DiscoveryCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_DiscoveryCallbackMap map size is more than max size"); + return; + } g_DiscoveryCallbackMap[bundleName] = callback; } std::shared_ptr discoveryCallback = callback; @@ -1354,6 +1362,10 @@ void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, auto callback = std::make_shared(env, bundleName); { std::lock_guard autoLock(g_publishCallbackMapMutex); + if (g_publishCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_publishCallbackMap map size is more than max size"); + return; + } g_publishCallbackMap[bundleName] = callback; } std::shared_ptr publishCallback = callback; @@ -1363,13 +1375,16 @@ void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, if (eventType == DM_NAPI_EVENT_UI_STATE_CHANGE) { auto callback = std::make_shared(env, bundleName); - int32_t ret = DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(bundleName, callback); - if (ret != 0) { + if (DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(bundleName, callback) != 0) { LOGE("RegisterDeviceManagerFaCallback failed for bundleName %{public}s", bundleName.c_str()); return; } { std::lock_guard autoLock(g_dmUiCallbackMapMutex); + if (g_dmUiCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_dmUiCallbackMap map size is more than max size"); + return; + } g_dmUiCallbackMap[bundleName] = callback; } } @@ -1378,8 +1393,8 @@ void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, std::string &eventType, std::string &extra) { - LOGI("CreateDmCallback for bundleName %{public}s eventType %{public}s extra = %{public}s", - bundleName.c_str(), eventType.c_str(), extra.c_str()); + LOGI("CreateDmCallback for bundleName %{public}s eventType %{public}s", + bundleName.c_str(), eventType.c_str()); if (eventType == DM_NAPI_EVENT_DEVICE_STATE_CHANGE) { auto callback = std::make_shared(env, bundleName); int32_t ret = DeviceManager::GetInstance().RegisterDevStateCallback(bundleName, extra, callback); @@ -1389,6 +1404,10 @@ void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, } { std::lock_guard autoLock(g_deviceStateCallbackMapMutex); + if (g_deviceStateCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_deviceStateCallbackMap map size is more than max size"); + return; + } g_deviceStateCallbackMap[bundleName] = callback; } } @@ -2258,6 +2277,10 @@ void DeviceManagerNapi::LockDiscoveryCallbackMutex(napi_env env, DmSubscribeInfo auto iter = g_DiscoveryCallbackMap.find(bundleName); if (iter == g_DiscoveryCallbackMap.end()) { discoveryCallback = std::make_shared(env, bundleName); + if (g_DiscoveryCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_DiscoveryCallbackMap map size is more than max size"); + return; + } g_DiscoveryCallbackMap[bundleName] = discoveryCallback; } else { discoveryCallback = iter->second; @@ -2382,6 +2405,10 @@ napi_value DeviceManagerNapi::PublishDeviceDiscoverySync(napi_env env, napi_call auto iter = g_publishCallbackMap.find(deviceManagerWrapper->bundleName_); if (iter == g_publishCallbackMap.end()) { publishCallback = std::make_shared(env, deviceManagerWrapper->bundleName_); + if (g_publishCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_publishCallbackMap map size is more than max size"); + return nullptr; + } g_publishCallbackMap[deviceManagerWrapper->bundleName_] = publishCallback; } else { publishCallback = iter->second; @@ -2453,13 +2480,9 @@ napi_value DeviceManagerNapi::AuthenticateDevice(napi_env env, napi_callback_inf return nullptr; } napi_value result = nullptr; - if (!IsJSObjectType(env, argv[0], "deviceInfo")) { - return nullptr; - } - if (!IsJSObjectType(env, argv[DM_NAPI_ARGS_ONE], "authParam")) { - return nullptr; - } - if (!IsFunctionType(env, argv[DM_NAPI_ARGS_TWO])) { + if (!IsJSObjectType(env, argv[0], "deviceInfo") || + !IsJSObjectType(env, argv[DM_NAPI_ARGS_ONE], "authParam") || + !IsFunctionType(env, argv[DM_NAPI_ARGS_TWO])) { return nullptr; } @@ -2477,6 +2500,10 @@ napi_value DeviceManagerNapi::AuthenticateDevice(napi_env env, napi_callback_inf auto iter = g_authCallbackMap.find(deviceManagerWrapper->bundleName_); if (iter == g_authCallbackMap.end()) { authCallback = std::make_shared(env, deviceManagerWrapper->bundleName_); + if (g_authCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_authCallbackMap map size is more than max size"); + return nullptr; + } g_authCallbackMap[deviceManagerWrapper->bundleName_] = authCallback; } else { authCallback = iter->second; @@ -2555,6 +2582,10 @@ int32_t DeviceManagerNapi::RegisterCredentialCallback(napi_env env, const std::s auto iter = g_creCallbackMap.find(pkgName); if (iter == g_creCallbackMap.end()) { creCallback = std::make_shared(env, pkgName); + if (g_creCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_creCallbackMap map size is more than max size"); + return ERR_DM_FAILED; + } g_creCallbackMap[pkgName] = creCallback; } else { creCallback = iter->second; @@ -2710,7 +2741,6 @@ napi_value DeviceManagerNapi::JsOnFrench(napi_env env, int32_t num, napi_value t char extra[DM_NAPI_BUF_LENGTH] = {0}; napi_get_value_string_utf8(env, argv[1], extra, extraLen + 1, &extraLen); std::string extraString = extra; - LOGI("extra = %{public}s", extraString.c_str()); CreateDmCallback(env, deviceManagerWrapper->bundleName_, eventType, extraString); } else { CreateDmCallback(env, deviceManagerWrapper->bundleName_, eventType); @@ -2972,14 +3002,20 @@ void DeviceManagerNapi::HandleCreateDmCallBack(const napi_env &env, AsyncCallbac std::string bundleName = std::string(asyCallbackInfo->bundleName); std::shared_ptr initCallback = std::make_shared(env, bundleName); int32_t ret = DeviceManager::GetInstance().InitDeviceManager(bundleName, initCallback); - if (ret == 0) { - std::lock_guard autoLock(g_initCallbackMapMutex); - g_initCallbackMap[bundleName] = initCallback; - asyCallbackInfo->status = 0; - } else { + if (ret != 0) { asyCallbackInfo->status = 1; asyCallbackInfo->ret = ret; + return; } + std::lock_guard autoLock(g_initCallbackMapMutex); + if (g_initCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_initCallbackMap map size is more than max size"); + asyCallbackInfo->status = 1; + asyCallbackInfo->ret = ERR_DM_NOT_INIT; + return; + } + g_initCallbackMap[bundleName] = initCallback; + asyCallbackInfo->status = 0; }, HandleCreateDmCallBackCompletedCB, (void *)asCallbackInfo, &asCallbackInfo->asyncWork); napi_queue_async_work_with_qos(env, asCallbackInfo->asyncWork, napi_qos_user_initiated); } @@ -3229,6 +3265,10 @@ napi_value DeviceManagerNapi::Constructor(napi_env env, napi_callback_info info) obj->bundleName_ = std::string(bundleName); std::lock_guard autoLock(g_deviceManagerMapMutex); + if (g_deviceManagerMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_deviceManagerMap map size is more than max size"); + return nullptr; + } g_deviceManagerMap[obj->bundleName_] = obj; napi_status status = napi_wrap( env, thisVar, reinterpret_cast(obj), diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index 2aa78c1ab..fbd037f43 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -832,6 +832,10 @@ void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, auto callback = std::make_shared(env, bundleName); { std::lock_guard autoLock(g_discoveryCallbackMapMutex); + if (g_DiscoveryCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_DiscoveryCallbackMap map size is more than max size"); + return; + } g_DiscoveryCallbackMap[bundleName] = callback; } std::shared_ptr discoveryCallback = callback; @@ -843,6 +847,10 @@ void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, auto callback = std::make_shared(env, bundleName); { std::lock_guard autoLock(g_publishCallbackMapMutex); + if (g_publishCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_publishCallbackMap map size is more than max size"); + return; + } g_publishCallbackMap[bundleName] = callback; } std::shared_ptr publishCallback = callback; @@ -852,16 +860,18 @@ void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, if (eventType == DM_NAPI_EVENT_REPLY_RESULT) { auto callback = std::make_shared(env, bundleName); - int32_t ret = DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(bundleName, callback); - if (ret != 0) { + if (DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(bundleName, callback) != 0) { LOGE("RegisterDeviceManagerFaCallback failed for bundleName %{public}s", bundleName.c_str()); return; } { std::lock_guard autoLock(g_dmUiCallbackMapMutex); + if (g_dmUiCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_dmUiCallbackMap map size is more than max size"); + return; + } g_dmUiCallbackMap[bundleName] = callback; } - return; } } @@ -884,6 +894,10 @@ void DeviceManagerNapi::RegisterDevStatusCallback(napi_env env, std::string &bun } { std::lock_guard autoLock(g_deviceStatusCallbackMapMutex); + if (g_deviceStatusCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_deviceStatusCallbackMap map size is more than max size"); + return; + } g_deviceStatusCallbackMap[bundleName] = callback; } return; @@ -903,6 +917,10 @@ void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, } { std::lock_guard autoLock(g_deviceStatusCallbackMapMutex); + if (g_deviceStatusCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_deviceStatusCallbackMap map size is more than max size"); + return; + } g_deviceStatusCallbackMap[bundleName] = callback; } } @@ -1538,6 +1556,10 @@ void DeviceManagerNapi::LockDiscoveryCallbackMutex(napi_env env, std::string &bu auto iter = g_DiscoveryCallbackMap.find(bundleName); if (iter == g_DiscoveryCallbackMap.end()) { discoveryCallback = std::make_shared(env, bundleName); + if (g_DiscoveryCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_DiscoveryCallbackMap map size is more than max size"); + return; + } g_DiscoveryCallbackMap[bundleName] = discoveryCallback; } else { discoveryCallback = iter->second; @@ -1652,7 +1674,10 @@ napi_value DeviceManagerNapi::PublishDeviceDiscoverySync(napi_env env, napi_call { std::lock_guard autoLock(g_publishCallbackMapMutex); auto iter = g_publishCallbackMap.find(deviceManagerWrapper->bundleName_); - if (iter == g_publishCallbackMap.end()) { + if (iter == g_publishCallbackMap.end() && g_publishCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_publishCallbackMap map size is more than max size"); + return nullptr; + } else if (iter == g_publishCallbackMap.end() && g_publishCallbackMap.size() < MAX_CONTAINER_SIZE) { publishCallback = std::make_shared(env, deviceManagerWrapper->bundleName_); g_publishCallbackMap[deviceManagerWrapper->bundleName_] = publishCallback; } else { @@ -1717,7 +1742,7 @@ napi_value DeviceManagerNapi::UnPublishDeviceDiscoverySync(napi_env env, napi_ca void DeviceManagerNapi::BindDevOrTarget(DeviceManagerNapi *deviceManagerWrapper, const std::string &deviceId, napi_env env, napi_value &object) { - LOGI("Bind devices or target start"); + LOGI("Bind devices or target start bundleName %{public}s", deviceManagerWrapper->bundleName_.c_str()); std::string bindParam; bool isMetaType = false; JsToBindParam(env, object, bindParam, authAsyncCallbackInfo_.authType, isMetaType); @@ -1727,7 +1752,10 @@ void DeviceManagerNapi::BindDevOrTarget(DeviceManagerNapi *deviceManagerWrapper, { std::lock_guard autoLock(g_bindCallbackMapMutex); auto iter = g_bindCallbackMap.find(deviceManagerWrapper->bundleName_); - if (iter == g_bindCallbackMap.end()) { + if (iter == g_bindCallbackMap.end() && g_bindCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_bindCallbackMap map size is more than max size"); + return; + } else if (iter == g_bindCallbackMap.end() && g_bindCallbackMap.size() < MAX_CONTAINER_SIZE) { bindTargetCallback = std::make_shared(env, deviceManagerWrapper->bundleName_); g_bindCallbackMap[deviceManagerWrapper->bundleName_] = bindTargetCallback; } else { @@ -1736,8 +1764,7 @@ void DeviceManagerNapi::BindDevOrTarget(DeviceManagerNapi *deviceManagerWrapper, } int32_t ret = BindTargetWarpper(deviceManagerWrapper->bundleName_, deviceId, bindParam, bindTargetCallback); if (ret != 0) { - LOGE("BindTarget for bundleName %{public}s failed, ret %{public}d", - deviceManagerWrapper->bundleName_.c_str(), ret); + LOGE("BindTarget failed, ret %{public}d", ret); CreateBusinessError(env, ret); } return; @@ -1749,6 +1776,10 @@ void DeviceManagerNapi::BindDevOrTarget(DeviceManagerNapi *deviceManagerWrapper, auto iter = g_authCallbackMap.find(deviceManagerWrapper->bundleName_); if (iter == g_authCallbackMap.end()) { bindDeviceCallback = std::make_shared(env, deviceManagerWrapper->bundleName_); + if (g_authCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_authCallbackMap map size is more than max size"); + return; + } g_authCallbackMap[deviceManagerWrapper->bundleName_] = bindDeviceCallback; } else { bindDeviceCallback = iter->second; @@ -1757,8 +1788,7 @@ void DeviceManagerNapi::BindDevOrTarget(DeviceManagerNapi *deviceManagerWrapper, int32_t ret = DeviceManager::GetInstance().BindDevice(deviceManagerWrapper->bundleName_, authAsyncCallbackInfo_.authType, deviceId, bindParam, bindDeviceCallback); if (ret != 0) { - LOGE("BindDevice for bundleName %{public}s failed, ret %{public}d", - deviceManagerWrapper->bundleName_.c_str(), ret); + LOGE("BindDevice failed, ret %{public}d", ret); CreateBusinessError(env, ret); } return; @@ -1852,7 +1882,6 @@ napi_value DeviceManagerNapi::JsOnFrench(napi_env env, int32_t num, napi_value t if (!JsToStringAndCheck(env, argv[1], "extra", extraString)) { return nullptr; } - LOGI("extra = %{public}s", extraString.c_str()); CreateDmCallback(env, deviceManagerWrapper->bundleName_, eventType, extraString); } else { CreateDmCallback(env, deviceManagerWrapper->bundleName_, eventType); @@ -2744,6 +2773,10 @@ napi_value DeviceManagerNapi::CreateDeviceManager(napi_env env, napi_callback_in } { std::lock_guard autoLock(g_initCallbackMapMutex); + if (g_initCallbackMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_initCallbackMap map size is more than max size"); + return nullptr; + } g_initCallbackMap[bundleName] = initCallback; } napi_value ctor = nullptr; @@ -2778,6 +2811,10 @@ napi_value DeviceManagerNapi::Constructor(napi_env env, napi_callback_info info) obj->bundleName_ = bundleName; std::lock_guard autoLock(g_deviceManagerMapMutex); + if (g_deviceManagerMap.size() >= MAX_CONTAINER_SIZE) { + LOGE("g_deviceManagerMap map size is more than max size"); + return nullptr; + } g_deviceManagerMap[obj->bundleName_] = obj; napi_status status = napi_wrap( env, thisVar, reinterpret_cast(obj), diff --git a/radar/include/dm_radar_helper.h b/radar/include/dm_radar_helper.h index 7c3909fee..6cd189e3b 100644 --- a/radar/include/dm_radar_helper.h +++ b/radar/include/dm_radar_helper.h @@ -150,7 +150,7 @@ public: */ virtual bool ReportDiscoverRegCallback(struct RadarInfo &info) = 0; virtual bool ReportDiscoverResCallback(struct RadarInfo &info) = 0; - virtual bool ReportDiscoverUserRes(struct RadarInfo &info) = 0; + virtual bool ReportDiscoverUserRes(struct RadarInfo info) = 0; virtual bool ReportAuthStart(const std::string &peerUdid, const std::string &pkgName) = 0; virtual bool ReportAuthOpenSession(struct RadarInfo &info) = 0; virtual bool ReportAuthSessionOpenCb(struct RadarInfo &info) = 0; @@ -187,7 +187,7 @@ class DmRadarHelper : public IDmRadarHelper { public: bool ReportDiscoverRegCallback(struct RadarInfo &info) override; bool ReportDiscoverResCallback(struct RadarInfo &info) override; - bool ReportDiscoverUserRes(struct RadarInfo &info) override; + bool ReportDiscoverUserRes(struct RadarInfo info) override; bool ReportAuthStart(const std::string &peerUdid, const std::string &pkgName) override; bool ReportAuthOpenSession(struct RadarInfo &info) override; bool ReportAuthSessionOpenCb(struct RadarInfo &info) override; diff --git a/radar/src/dm_radar_helper.cpp b/radar/src/dm_radar_helper.cpp index 7c8f66f80..3c43a715b 100644 --- a/radar/src/dm_radar_helper.cpp +++ b/radar/src/dm_radar_helper.cpp @@ -249,7 +249,7 @@ int32_t DmRadarHelper::ReportDiscoverUserResStageOther(struct RadarInfo &info) DM_DISCOVER_BEHAVIOR, HISYSEVENT_BEHAVIOR, params, len); } -bool DmRadarHelper::ReportDiscoverUserRes(struct RadarInfo &info) +bool DmRadarHelper::ReportDiscoverUserRes(struct RadarInfo info) { int32_t res = DM_OK; if (info.stageRes == static_cast(StageRes::STAGE_CANCEL)) { diff --git a/radar/src/lite/dm_radar_helper.cpp b/radar/src/lite/dm_radar_helper.cpp index 16ca40be6..16b5c809e 100644 --- a/radar/src/lite/dm_radar_helper.cpp +++ b/radar/src/lite/dm_radar_helper.cpp @@ -40,7 +40,7 @@ bool DmRadarHelper::ReportDiscoverResCallback(struct RadarInfo &info) return true; } -bool DmRadarHelper::ReportDiscoverUserRes(struct RadarInfo &info) +bool DmRadarHelper::ReportDiscoverUserRes(struct RadarInfo info) { return true; } diff --git a/services/implementation/include/dependency/commonevent/dm_common_event_manager.h b/services/implementation/include/dependency/commonevent/dm_common_event_manager.h index dfec8652c..0315cf8e8 100644 --- a/services/implementation/include/dependency/commonevent/dm_common_event_manager.h +++ b/services/implementation/include/dependency/commonevent/dm_common_event_manager.h @@ -65,7 +65,6 @@ private: std::mutex evenSubscriberMutex_; std::shared_ptr subscriber_ = nullptr; sptr statusChangeListener_ = nullptr; - int32_t counter_ = 0; private: class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { 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 8eb382827..2fecdacfc 100644 --- a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp @@ -223,10 +223,7 @@ int32_t DmAuthMessageProcessor::SaveDerivativeSessionKeyToDP(int32_t userId, con } std::vector sessionKey = cryptoMgr_->GetSessionKey(); size_t keyLen = sessionKey.size(); - std::string keyStr; - for (size_t i = 0; i < sessionKey.size(); ++i) { - keyStr = keyStr + (char)sessionKey.data()[i]; - } + std::string keyStr(sessionKey.begin(), sessionKey.end()); std::string newKeyStr = Crypto::Sha256(keyStr + suffix); DMSessionKey newSessionKey; size_t newKeyLen = std::min(keyLen, newKeyStr.size()); diff --git a/services/implementation/src/dependency/commonevent/dm_common_event_manager.cpp b/services/implementation/src/dependency/commonevent/dm_common_event_manager.cpp index 8d61b628b..28507bced 100644 --- a/services/implementation/src/dependency/commonevent/dm_common_event_manager.cpp +++ b/services/implementation/src/dependency/commonevent/dm_common_event_manager.cpp @@ -73,14 +73,14 @@ bool DmCommonEventManager::SubscribeServiceEvent(const std::vector subscriber_ = nullptr; return false; } - while (counter_ != MAX_TRY_TIMES) { + int32_t counter = 0; + while (counter <= MAX_TRY_TIMES) { if (samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_) == ERR_OK) { LOGI("SubscribeServiceEvent success."); - counter_ = 0; break; } - if (++counter_ == MAX_TRY_TIMES) { - LOGI("SubscribeServiceEvent failed."); + if (++counter == MAX_TRY_TIMES) { + LOGE("SubscribeServiceEvent failed."); } sleep(1); } diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 3b29c520a..75dfdec64 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -2889,7 +2889,11 @@ int32_t DeviceManagerServiceImpl::DeleteAclForProcV2(const std::string &localUdi bool DeviceManagerServiceImpl::IsProxyUnbind(const std::string &extra) { - JsonObject jsonObject(extra); + if (extra.empty()) { + return false; + } + JsonObject jsonObject; + jsonObject.Parse(extra); if (jsonObject.IsDiscarded()) { return false; } diff --git a/services/service/include/publishcommonevent/dm_account_common_event.h b/services/service/include/publishcommonevent/dm_account_common_event.h index eb0ce5d94..ce8f09ee9 100644 --- a/services/service/include/publishcommonevent/dm_account_common_event.h +++ b/services/service/include/publishcommonevent/dm_account_common_event.h @@ -66,7 +66,6 @@ private: std::mutex evenSubscriberMutex_; std::shared_ptr subscriber_ = nullptr; sptr statusChangeListener_ = nullptr; - int32_t counter_ = 0; private: class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { diff --git a/services/service/include/publishcommonevent/dm_datashare_common_event.h b/services/service/include/publishcommonevent/dm_datashare_common_event.h index a8013c325..f8856970b 100644 --- a/services/service/include/publishcommonevent/dm_datashare_common_event.h +++ b/services/service/include/publishcommonevent/dm_datashare_common_event.h @@ -54,7 +54,6 @@ private: std::mutex evenSubscriberMutex_; std::shared_ptr subscriber_ = nullptr; sptr statusChangeListener_ = nullptr; - int32_t counter_ = 0; private: class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { diff --git a/services/service/include/publishcommonevent/dm_package_common_event.h b/services/service/include/publishcommonevent/dm_package_common_event.h index d914ac117..20a890e96 100644 --- a/services/service/include/publishcommonevent/dm_package_common_event.h +++ b/services/service/include/publishcommonevent/dm_package_common_event.h @@ -54,7 +54,6 @@ private: std::mutex evenSubscriberMutex_; std::shared_ptr subscriber_ = nullptr; sptr statusChangeListener_ = nullptr; - int32_t counter_ = 0; private: class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { diff --git a/services/service/include/publishcommonevent/dm_publish_common_event.h b/services/service/include/publishcommonevent/dm_publish_common_event.h index 65645f98f..50dfa9841 100644 --- a/services/service/include/publishcommonevent/dm_publish_common_event.h +++ b/services/service/include/publishcommonevent/dm_publish_common_event.h @@ -72,7 +72,6 @@ private: std::mutex subscriberMutex_; std::shared_ptr subscriber_ = nullptr; sptr statusChangeListener_ = nullptr; - int32_t counter_ = 0; private: class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { diff --git a/services/service/include/publishcommonevent/dm_screen_common_event.h b/services/service/include/publishcommonevent/dm_screen_common_event.h index fc1c63b63..97d458d55 100644 --- a/services/service/include/publishcommonevent/dm_screen_common_event.h +++ b/services/service/include/publishcommonevent/dm_screen_common_event.h @@ -54,7 +54,6 @@ private: std::mutex evenSubscriberMutex_; std::shared_ptr subscriber_ = nullptr; sptr statusChangeListener_ = nullptr; - int32_t counter_ = 0; private: class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { diff --git a/services/service/src/discovery/discovery_manager.cpp b/services/service/src/discovery/discovery_manager.cpp index a26cf7af1..c83110f90 100644 --- a/services/service/src/discovery/discovery_manager.cpp +++ b/services/service/src/discovery/discovery_manager.cpp @@ -270,9 +270,12 @@ int32_t DiscoveryManager::StartDiscoveringNoMetaType(const std::string &pkgName, int32_t DiscoveryManager::StartDiscovering4MetaType(const std::string &pkgName, DmSubscribeInfo &dmSubInfo, const std::map ¶m) { - LOGI("meta node process, input metaType = %{public}s, pkgName = %{public}s", - (param.find(PARAM_KEY_META_TYPE)->second).c_str(), pkgName.c_str()); - MetaNodeType metaType = (MetaNodeType)(std::atoi((param.find(PARAM_KEY_META_TYPE)->second).c_str())); + MetaNodeType metaType = MetaNodeType::CUSTOM_UNKNOWN; + if (param.find(PARAM_KEY_META_TYPE) != param.end()) { + LOGI("meta node process, input metaType = %{public}s, pkgName = %{public}s", + (param.find(PARAM_KEY_META_TYPE)->second).c_str(), pkgName.c_str()); + metaType = (MetaNodeType)(std::atoi((param.find(PARAM_KEY_META_TYPE)->second).c_str())); + } switch (metaType) { case MetaNodeType::PROXY_SHARE: if (strcpy_s(dmSubInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, DM_CAPABILITY_SHARE) != EOK) { diff --git a/services/service/src/publishcommonevent/dm_account_common_event.cpp b/services/service/src/publishcommonevent/dm_account_common_event.cpp index b8c556a67..1c51b58ce 100644 --- a/services/service/src/publishcommonevent/dm_account_common_event.cpp +++ b/services/service/src/publishcommonevent/dm_account_common_event.cpp @@ -79,14 +79,14 @@ bool DmAccountCommonEventManager::SubscribeAccountCommonEvent(const std::vector< subscriber_ = nullptr; return false; } - while (counter_ != MAX_TRY_TIMES) { + int32_t counter = 0; + while (counter <= MAX_TRY_TIMES) { if (samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_) == ERR_OK) { LOGI("SubscribeAccountEvent success."); - counter_ = 0; break; } - if (++counter_ == MAX_TRY_TIMES) { - LOGI("SubscribeAccountEvent failed."); + if (++counter == MAX_TRY_TIMES) { + LOGE("SubscribeAccountEvent failed."); } sleep(1); } diff --git a/services/service/src/publishcommonevent/dm_datashare_common_event.cpp b/services/service/src/publishcommonevent/dm_datashare_common_event.cpp index dd903b834..a18715aa2 100644 --- a/services/service/src/publishcommonevent/dm_datashare_common_event.cpp +++ b/services/service/src/publishcommonevent/dm_datashare_common_event.cpp @@ -78,14 +78,14 @@ bool DmDataShareCommonEventManager::SubscribeDataShareCommonEvent(const std::vec subscriber_ = nullptr; return false; } - while (counter_ != MAX_TRY_TIMES) { + int32_t counter = 0; + while (counter <= MAX_TRY_TIMES) { if (samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_) == ERR_OK) { LOGI("SubscribeAccountEvent success."); - counter_ = 0; break; } - if (++counter_ == MAX_TRY_TIMES) { - LOGI("SubscribeAccountEvent failed."); + if (++counter == MAX_TRY_TIMES) { + LOGE("SubscribeAccountEvent failed."); } sleep(1); } diff --git a/services/service/src/publishcommonevent/dm_package_common_event.cpp b/services/service/src/publishcommonevent/dm_package_common_event.cpp index 0aea00516..e914eb3ec 100644 --- a/services/service/src/publishcommonevent/dm_package_common_event.cpp +++ b/services/service/src/publishcommonevent/dm_package_common_event.cpp @@ -80,14 +80,14 @@ bool DmPackageCommonEventManager::SubscribePackageCommonEvent(const std::vector< subscriber_ = nullptr; return false; } - while (counter_ != MAX_TRY_TIMES) { + int32_t counter = 0; + while (counter <= MAX_TRY_TIMES) { if (samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_) == ERR_OK) { LOGI("SubscribePackageEvent success."); - counter_ = 0; break; } - if (++counter_ == MAX_TRY_TIMES) { - LOGI("SubscribePackageEvent failed."); + if (++counter == MAX_TRY_TIMES) { + LOGE("SubscribePackageEvent failed."); } sleep(1); } diff --git a/services/service/src/publishcommonevent/dm_publish_common_event.cpp b/services/service/src/publishcommonevent/dm_publish_common_event.cpp index 4c9af611d..c1487d322 100644 --- a/services/service/src/publishcommonevent/dm_publish_common_event.cpp +++ b/services/service/src/publishcommonevent/dm_publish_common_event.cpp @@ -82,14 +82,14 @@ bool DmPublishCommonEventManager::SubscribePublishCommonEvent(const std::vector< subscriber_ = nullptr; return false; } - while (counter_ != MAX_TRY_TIMES) { + int32_t counter = 0; + while (counter <= MAX_TRY_TIMES) { if (samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_) == ERR_OK) { LOGI("SubscribeServiceEvent success."); - counter_ = 0; break; } - if (++counter_ == MAX_TRY_TIMES) { - LOGI("SubscribeServiceEvent failed."); + if (++counter == MAX_TRY_TIMES) { + LOGE("SubscribeServiceEvent failed."); } sleep(1); } diff --git a/services/service/src/publishcommonevent/dm_screen_common_event.cpp b/services/service/src/publishcommonevent/dm_screen_common_event.cpp index ce7d5ecdf..e8557570b 100644 --- a/services/service/src/publishcommonevent/dm_screen_common_event.cpp +++ b/services/service/src/publishcommonevent/dm_screen_common_event.cpp @@ -79,14 +79,14 @@ bool DmScreenCommonEventManager::SubscribeScreenCommonEvent(const std::vectorSubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_) == ERR_OK) { LOGI("SubscribeScreenEvent success."); - counter_ = 0; break; } - if (++counter_ == MAX_TRY_TIMES) { - LOGI("SubscribeScreenEvent failed."); + if (++counter == MAX_TRY_TIMES) { + LOGE("SubscribeScreenEvent failed."); } sleep(1); } diff --git a/services/service/src/softbus/mine_softbus_listener.cpp b/services/service/src/softbus/mine_softbus_listener.cpp index 5ff9f402e..f476a967c 100644 --- a/services/service/src/softbus/mine_softbus_listener.cpp +++ b/services/service/src/softbus/mine_softbus_listener.cpp @@ -247,7 +247,10 @@ int32_t MineSoftbusListener::ParseSearchJson(const string &pkgName, const string return ERR_DM_INVALID_JSON_STRING; } int32_t retValue = DM_OK; - uint32_t findMode = object[FIELD_DEVICE_MODE].Get(); + uint32_t findMode = 0; + if (IsUint32(object, FIELD_DEVICE_MODE)) { + findMode = object[FIELD_DEVICE_MODE].Get(); + } LOGI("quick search device mode is: %{public}u", findMode); switch (findMode) { case FIND_ALL_DEVICE: diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 2491cc636..f834a08e3 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -87,6 +87,7 @@ static std::set deviceIdSet; bool SoftbusListener::isRadarSoLoad_ = false; IDmRadarHelper* SoftbusListener::dmRadarHelper_ = nullptr; void* SoftbusListener::radarHandle_ = nullptr; +static std::mutex g_hostNameMutex; std::string SoftbusListener::hostName_ = ""; int32_t g_onlineDeviceNum = 0; @@ -1209,11 +1210,13 @@ int32_t SoftbusListener::GetIPAddrTypeFromCache(const std::string &deviceId, con void SoftbusListener::SetHostPkgName(const std::string hostName) { + std::lock_guard lock(g_hostNameMutex); hostName_ = hostName; } std::string SoftbusListener::GetHostPkgName() { + std::lock_guard lock(g_hostNameMutex); return hostName_; } diff --git a/services/softbuscache/src/dm_softbus_cache.cpp b/services/softbuscache/src/dm_softbus_cache.cpp index 4fcf6b54a..fb537cda2 100644 --- a/services/softbuscache/src/dm_softbus_cache.cpp +++ b/services/softbuscache/src/dm_softbus_cache.cpp @@ -143,6 +143,10 @@ void SoftbusCache::SaveDeviceInfo(DmDeviceInfo deviceInfo) return; } std::lock_guard mutexLock(deviceInfosMutex_); + if (deviceInfo_.size() >= MAX_CONTAINER_SIZE) { + LOGE("deviceInfo_ map size is more than max size"); + return; + } deviceInfo_[udid] = std::pair(uuid, deviceInfo); LOGI("success udid %{public}s, networkId %{public}s", GetAnonyString(udid).c_str(), GetAnonyString(std::string(deviceInfo.networkId)).c_str()); @@ -301,6 +305,10 @@ void SoftbusCache::SaveDeviceSecurityLevel(const char *networkId) if (deviceSecurityLevel_.find(std::string(networkId)) != deviceSecurityLevel_.end()) { return; } + if (deviceSecurityLevel_.size() >= MAX_CONTAINER_SIZE) { + LOGE("deviceSecurityLevel_ map size is more than max size"); + return; + } int32_t tempSecurityLevel = -1; if (GetNodeKeyInfo(DM_PKG_NAME, networkId, NodeDeviceInfoKey::NODE_KEY_DEVICE_SECURITY_LEVEL, reinterpret_cast(&tempSecurityLevel), LNN_COMMON_LEN) != DM_OK) { @@ -346,6 +354,10 @@ int32_t SoftbusCache::GetDevLevelFromBus(const char *networkId, int32_t &securit LOGE("[SOFTBUS]GetNodeKeyInfo networkType failed."); return ERR_DM_FAILED; } + if (deviceSecurityLevel_.size() >= MAX_CONTAINER_SIZE) { + LOGE("deviceSecurityLevel_ map size is more than max size"); + return ERR_DM_FAILED; + } securityLevel = tempSecurityLevel; deviceSecurityLevel_[std::string(networkId)] = tempSecurityLevel; LOGI("Get dev level from softbus success, networkId is %{public}s.", diff --git a/utils/BUILD.gn b/utils/BUILD.gn index c4d1ba8fe..b533b2e49 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -46,6 +46,7 @@ if (defined(ohos_lite)) { "${common_path}/src/dfx/lite/dm_hisysevent.cpp", "${common_path}/src/dfx/lite/dm_hitrace.cpp", "${common_path}/src/dm_anonymous.cpp", + "${common_path}/src/dm_constants.cpp", "${common_path}/src/dm_error_message.cpp", "${common_path}/src/ipc/lite/ipc_cmd_register.cpp", "src/appInfo/lite/app_manager.cpp", @@ -128,6 +129,7 @@ if (defined(ohos_lite)) { sources = [ "${common_path}/src/dm_anonymous.cpp", + "${common_path}/src/dm_constants.cpp", "src/appInfo/standard/app_manager.cpp", "src/crypto/dm_crypto.cpp", "src/dm_random.cpp", @@ -208,6 +210,7 @@ if (defined(ohos_lite)) { sources = [ "${common_path}/src/dm_anonymous.cpp", + "${common_path}/src/dm_constants.cpp", "src/appInfo/standard/app_manager.cpp", "src/crypto/dm_crypto.cpp", "src/dm_random.cpp", diff --git a/utils/src/appInfo/standard/app_manager.cpp b/utils/src/appInfo/standard/app_manager.cpp index b424debff..42cf4b60a 100644 --- a/utils/src/appInfo/standard/app_manager.cpp +++ b/utils/src/appInfo/standard/app_manager.cpp @@ -24,6 +24,7 @@ #include "system_ability_definition.h" #include "tokenid_kit.h" +#include "dm_constants.h" #include "dm_anonymous.h" #include "dm_error_type.h" #include "dm_log.h" @@ -83,6 +84,10 @@ DM_EXPORT void AppManager::RegisterCallerAppId(const std::string &pkgName) } LOGI("PkgName %{public}s, appId %{public}s.", pkgName.c_str(), GetAnonyString(appId).c_str()); std::lock_guard lock(appIdMapLock_); + if (appIdMap_.size() >= MAX_CONTAINER_SIZE) { + LOGE("appIdMap_ map size is more than max size"); + return; + } appIdMap_[pkgName] = appId; } -- Gitee