diff --git a/services/service/include/softbus/softbus_listener.h b/services/service/include/softbus/softbus_listener.h index 2b53a3624544770af02a81fb4a8b455d1bdb7cf1..10f07733d4435e81945f46c599e9ed6c2a6469d8 100644 --- a/services/service/include/softbus/softbus_listener.h +++ b/services/service/include/softbus/softbus_listener.h @@ -87,6 +87,9 @@ public: static IRefreshCallback &GetSoftbusRefreshCb(); private: int32_t InitSoftPublishLNN(); +#ifdef MINE_HARMONY + static bool IsVaildDeviceInfo(const DeviceInfo *device); +#endif private: static bool isRadarSoLoad_; diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index f2ac6cf7332a71b5867e70855926149647d5674c..318c90c14ace01ab954e83bdc4de978112e7b027 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -60,6 +60,9 @@ constexpr static char HEX_ARRAY[] = "0123456789ABCDEF"; constexpr static uint8_t BYTE_MASK = 0x0F; constexpr static uint16_t ARRAY_DOUBLE_SIZE = 2; constexpr static uint16_t BIN_HIGH_FOUR_NUM = 4; +#ifdef MINE_HARMONY +constexpr const char* DEVICE_DM_KEY = "DM"; +#endif static PulishStatus g_publishStatus = PulishStatus::STATUS_UNKNOWN; static std::mutex g_deviceMapMutex; @@ -299,7 +302,14 @@ void SoftbusListener::OnSoftbusDeviceFound(const DeviceInfo *device) LOGE("ReportDiscoverResCallback failed"); } } +#else + if (!IsVaildDeviceInfo(device)) { + LOGE("Invaild device, deviceId=%s, extraData=%s.", GetAnonyString(dmDevInfo.deviceId).c_str(), + GetAnonyString(dmDevInfo.extraData).c_str()); + return; + } #endif + LOGI("OnSoftbusDeviceFound: devId=%s, devName=%s, devType=%d, range=%d, isOnline=%d", GetAnonyString(dmDevInfo.deviceId).c_str(), dmDevInfo.deviceName, dmDevInfo.deviceTypeId, dmDevInfo.range, device->isOnline); @@ -311,6 +321,25 @@ void SoftbusListener::OnSoftbusDeviceFound(const DeviceInfo *device) } } +#ifdef MINE_HARMONY +bool SoftbusListener::IsVaildDeviceInfo(const DeviceInfo *device) +{ + cJSON *root = cJSON_Parse(device->custData); + if (root == nullptr) { + LOGE("root is nullptr."); + return false; + } + cJSON *object = cJSON_GetObjectItem(root, DEVICE_DM_KEY); + if (object == nullptr || !cJSON_IsString(object)) { + LOGE("object is not string."); + cJSON_Delete(root); + return false; + } + cJSON_Delete(root); + return true; +} +#endif + void SoftbusListener::OnSoftbusDiscoveryResult(int subscribeId, RefreshResult result) { uint16_t originId = static_cast((static_cast(subscribeId)) & SOFTBUS_SUBSCRIBE_ID_MASK);