From d439a765ccf1b215101256dd07b922357d21edd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Wed, 9 Jul 2025 10:53:32 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=A0=86=E7=A7=AF=EF=BC=8C=E6=8F=92=E5=85=A5=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E6=9C=AA=E9=99=90=E5=88=B6=E5=AE=B9=E9=87=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../service/src/softbus/softbus_listener.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 565f8a932..7bd769d8e 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -47,6 +47,7 @@ const int32_t SOFTBUS_SUBSCRIBE_ID_MASK = 0x0000FFFF; const int32_t MAX_CACHED_DISCOVERED_DEVICE_SIZE = 100; const int32_t MAX_SOFTBUS_MSG_LEN = 2000; const int32_t MAX_OSTYPE_SIZE = 1000; +constexpr int32_t MAX_CACHED_MAP_NUM = 5000; #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) constexpr const char* DEVICE_ONLINE = "deviceOnLine"; constexpr const char* DEVICE_OFFLINE = "deviceOffLine"; @@ -494,6 +495,10 @@ void SoftbusListener::OnSoftbusDeviceFound(const DeviceInfo *device) { std::lock_guard lock(g_lockDeviceIdSet); if (deviceIdSet.find(std::string(dmDevInfo.deviceId)) == deviceIdSet.end()) { + if (deviceIdSet.size() > MAX_CACHED_MAP_NUM) { + LOGE("deviceIdSet size exceed the limit!"); + return; + } deviceIdSet.insert(std::string(dmDevInfo.deviceId)); struct RadarInfo info = { .funcName = "OnSoftbusDeviceFound", @@ -519,6 +524,10 @@ void SoftbusListener::OnSoftbusDeviceFound(const DeviceInfo *device) return; } std::lock_guard lock(g_lnnCbkMapMutex); + if (discoveredDeviceActionIdMap.size() > MAX_CACHED_MAP_NUM) { + LOGE("discoveredDeviceActionIdMap size exceed the limit!"); + return; + } discoveredDeviceActionIdMap[dmDevInfo.deviceId] = actionId; CacheDiscoveredDevice(device); for (auto &iter : lnnOpsCbkMap) { @@ -745,6 +754,10 @@ int32_t SoftbusListener::RegisterSoftbusLnnOpsCbk(const std::string &pkgName, return ERR_DM_POINT_NULL; } std::lock_guard lock(g_lnnCbkMapMutex); + if (lnnOpsCbkMap.size() > MAX_CACHED_MAP_NUM) { + LOGE("lnnOpsCbkMap size exceed the limit!"); + return ERR_DM_FAILED; + } lnnOpsCbkMap.erase(pkgName); lnnOpsCbkMap.emplace(pkgName, callback); return DM_OK; @@ -1157,6 +1170,10 @@ void SoftbusListener::CacheDeviceInfo(const std::string deviceId, std::shared_pt discoveredDeviceMap.erase(deviceId); } deviceVec.push_back(std::pair>(addrType, infoPtr)); + if (discoveredDeviceMap.size() > MAX_CACHED_MAP_NUM) { + LOGE("discoveredDeviceMap size exceed the limit!"); + return; + } discoveredDeviceMap.insert(std::pair>>>(deviceId, deviceVec)); } -- Gitee From 633037e9dfd71eb16ccd3482c4674e29f9d8b663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Wed, 9 Jul 2025 11:13:50 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/src/softbus/softbus_listener.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 7bd769d8e..628a51d04 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -495,7 +495,7 @@ void SoftbusListener::OnSoftbusDeviceFound(const DeviceInfo *device) { std::lock_guard lock(g_lockDeviceIdSet); if (deviceIdSet.find(std::string(dmDevInfo.deviceId)) == deviceIdSet.end()) { - if (deviceIdSet.size() > MAX_CACHED_MAP_NUM) { + if (deviceIdSet.size() >= MAX_CACHED_MAP_NUM) { LOGE("deviceIdSet size exceed the limit!"); return; } @@ -524,7 +524,7 @@ void SoftbusListener::OnSoftbusDeviceFound(const DeviceInfo *device) return; } std::lock_guard lock(g_lnnCbkMapMutex); - if (discoveredDeviceActionIdMap.size() > MAX_CACHED_MAP_NUM) { + if (discoveredDeviceActionIdMap.size() >= MAX_CACHED_MAP_NUM) { LOGE("discoveredDeviceActionIdMap size exceed the limit!"); return; } @@ -754,7 +754,7 @@ int32_t SoftbusListener::RegisterSoftbusLnnOpsCbk(const std::string &pkgName, return ERR_DM_POINT_NULL; } std::lock_guard lock(g_lnnCbkMapMutex); - if (lnnOpsCbkMap.size() > MAX_CACHED_MAP_NUM) { + if (lnnOpsCbkMap.size() >= MAX_CACHED_MAP_NUM) { LOGE("lnnOpsCbkMap size exceed the limit!"); return ERR_DM_FAILED; } @@ -1170,7 +1170,7 @@ void SoftbusListener::CacheDeviceInfo(const std::string deviceId, std::shared_pt discoveredDeviceMap.erase(deviceId); } deviceVec.push_back(std::pair>(addrType, infoPtr)); - if (discoveredDeviceMap.size() > MAX_CACHED_MAP_NUM) { + if (discoveredDeviceMap.size() >= MAX_CACHED_MAP_NUM) { LOGE("discoveredDeviceMap size exceed the limit!"); return; } -- Gitee From df94028065dd63e5722b15f5128afde5b1241815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Wed, 9 Jul 2025 11:29:56 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/src/softbus/softbus_listener.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 628a51d04..9e96c6dbf 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -1170,10 +1170,6 @@ void SoftbusListener::CacheDeviceInfo(const std::string deviceId, std::shared_pt discoveredDeviceMap.erase(deviceId); } deviceVec.push_back(std::pair>(addrType, infoPtr)); - if (discoveredDeviceMap.size() >= MAX_CACHED_MAP_NUM) { - LOGE("discoveredDeviceMap size exceed the limit!"); - return; - } discoveredDeviceMap.insert(std::pair>>>(deviceId, deviceVec)); } -- Gitee From 4b3bda47c900c3d731ca24df06b2aff2c7aa90c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Wed, 9 Jul 2025 12:10:44 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/src/softbus/softbus_listener.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 9e96c6dbf..8f0e5dcff 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -497,7 +497,7 @@ void SoftbusListener::OnSoftbusDeviceFound(const DeviceInfo *device) if (deviceIdSet.find(std::string(dmDevInfo.deviceId)) == deviceIdSet.end()) { if (deviceIdSet.size() >= MAX_CACHED_MAP_NUM) { LOGE("deviceIdSet size exceed the limit!"); - return; + deviceIdSet.erase(deviceIdSet.begin()); } deviceIdSet.insert(std::string(dmDevInfo.deviceId)); struct RadarInfo info = { @@ -526,7 +526,7 @@ void SoftbusListener::OnSoftbusDeviceFound(const DeviceInfo *device) std::lock_guard lock(g_lnnCbkMapMutex); if (discoveredDeviceActionIdMap.size() >= MAX_CACHED_MAP_NUM) { LOGE("discoveredDeviceActionIdMap size exceed the limit!"); - return; + discoveredDeviceActionIdMap.erase(discoveredDeviceActionIdMap.begin()); } discoveredDeviceActionIdMap[dmDevInfo.deviceId] = actionId; CacheDiscoveredDevice(device); -- Gitee