From 37345f3d8582663152031beb8fde4feecc0bbada Mon Sep 17 00:00:00 2001 From: l30054665 Date: Thu, 24 Jul 2025 15:26:51 +0800 Subject: [PATCH 01/15] fuzz Signed-off-by: l30054665 --- test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp | 1 + .../dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp | 1 + .../dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp | 1 + .../ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp | 1 + .../ipc_server_client_proxy_fuzzer.cpp | 1 + .../ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp | 1 + .../on_softbus_device_offline_fuzzer.cpp | 1 + 7 files changed, 7 insertions(+) diff --git a/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp index dafa558a4..2a86e2e17 100644 --- a/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp +++ b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ + #include #include #include diff --git a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp index 51c8eb047..5c9869a9c 100644 --- a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ + #include "dm_negotiate_process_fuzzer.h" #include diff --git a/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp b/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp index db548cd8e..1c32ef1b6 100644 --- a/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp +++ b/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ + #include #include #include diff --git a/test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp b/test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp index 99d41ffae..8b78aad39 100644 --- a/test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp +++ b/test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "ipc_cmd_register_fuzzer.h" #include diff --git a/test/servicesfuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.cpp b/test/servicesfuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.cpp index 6f11a2ea2..1fd1e857a 100644 --- a/test/servicesfuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.cpp +++ b/test/servicesfuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ + #include "ipc_server_client_proxy_fuzzer.h" #include diff --git a/test/servicesfuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp b/test/servicesfuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp index b7c8de713..fa6e11d48 100644 --- a/test/servicesfuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp +++ b/test/servicesfuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ + #include "ipc_server_listener_fuzzer.h" #include diff --git a/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp b/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp index 0a1036bc8..3b9013d90 100644 --- a/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp +++ b/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ + #include #include #include -- Gitee From edfc3952e3352cc63244cf73398059f36acaf96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 07:32:26 +0000 Subject: [PATCH 02/15] update test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp | 55 +++++++++++++------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp index 2a86e2e17..19faa0e88 100644 --- a/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp +++ b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ - +#include #include #include #include @@ -30,39 +30,58 @@ void DmAnonyousFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size < sizeof(int32_t))) { return; } + FuzzedDataProvider fdp(data, size); std::vector strList; int64_t testNumber = 123; - int64_t decimal = 10; - strList.push_back("test1"); - strList.push_back("test2"); + std::string test1 = fdp.ConsumeRandomLengthString(); + std::string test2 = fdp.ConsumeRandomLengthString(); + strList.push_back(test1); + strList.push_back(test2); GetAnonyStringList(strList); std::vector intList; intList.push_back(1); GetAnonyInt32List(intList); + std::string key1 = fdp.ConsumeRandomLengthString(); + std::string key2 = fdp.ConsumeRandomLengthString(); + std::string key3 = fdp.ConsumeRandomLengthString(); + std::string value1 = fdp.ConsumeRandomLengthString(); + std::string value2 = fdp.ConsumeRandomLengthString(); JsonObject jsonObj; - jsonObj["key1"] = testNumber; - jsonObj["key2"] = "value2"; - jsonObj["key3"] = true; - IsUint32(jsonObj, "key1"); - IsUint64(jsonObj, "key1"); - IsBool(jsonObj, "key3"); + jsonObj[key1] = testNumber; + jsonObj[key2] = value2; + jsonObj[key3] = true; + IsUint32(jsonObj, key1); + IsUint64(jsonObj, key1); + IsBool(jsonObj, key3); std::map paramMap; - paramMap["key1"] = "value1"; - paramMap["key2"] = "value2"; + paramMap[key1] = value1; + paramMap[key2] = value2; std::map paramMap2 = {}; std::string jsonStr = ConvertMapToJsonString(paramMap); ParseMapFromJsonString(jsonStr, paramMap2); - StringToInt("123", decimal); - StringToInt64("123", decimal); + IsJsonValIntegerString(jsonObj, key2); +} + +void DmAnonyousFuzzTestFirst(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string str1 = fdp.ConsumeRandomLengthString(); + std::string str2 = fdp.ConsumeRandomLengthString(); int32_t versionNum = 0; + int64_t decimal = 10; + int64_t testNumber = 123; + StringToInt(str1, decimal); + StringToInt64(str1, decimal); GetVersionNumber("1.0.0", versionNum); GetCallerPkgName("com.example.app#test"); GetSubscribeId("123#12345"); std::multimap unorderedmap; - unorderedmap.insert(std::make_pair("key1", testNumber)); - IsValueExist(unorderedmap, "key1", testNumber); + unorderedmap.insert(std::make_pair(str1, testNumber)); + IsValueExist(unorderedmap, str1, testNumber); GetSubStr("test#123", "#", 0); - IsJsonValIntegerString(jsonObj, "key2"); } } } @@ -72,6 +91,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::DmAnonyousFuzzTest(data, size); - + OHOS::DistributedHardware::DmAnonyousFuzzTestFirst(data, size); return 0; } -- Gitee From 9d047da49644c58c785b390e7f23538322dc5014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 07:33:05 +0000 Subject: [PATCH 03/15] update test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../dm_negotiate_process_fuzzer.cpp | 50 ++----------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp index 5c9869a9c..3fa23e441 100644 --- a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp @@ -13,65 +13,28 @@ * limitations under the License. */ - +#include #include "dm_negotiate_process_fuzzer.h" #include #include #include "device_manager_service_listener.h" -#include "dm_auth_state.h" #include "dm_negotiate_process.h" namespace OHOS { namespace DistributedHardware { -void RespQueryProxyAcceseeIdsFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - std::shared_ptr context = std::make_shared(); - context->IsProxyBind = true; - context->accessee.userId = fdp.ConsumeIntegral(); - DmProxyAuthContext dmProxyAuthContext; - dmProxyAuthContext.proxyAccessee.bundleName = fdp.ConsumeRandomLengthString(); - dmProxyAuthContext.proxyAccessee.tokenId = fdp.ConsumeIntegral(); - context->subjectProxyOnes.push_back(dmProxyAuthContext); - std::shared_ptr authSinkPtr = std::make_shared(); - authSinkPtr->RespQueryProxyAcceseeIds(context); -} - -void GetSinkProxyCredTypeForP2PFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - std::shared_ptr context = std::make_shared(); - context->IsProxyBind = true; - context->accessee.userId = fdp.ConsumeIntegral(); - DmProxyAuthContext dmProxyAuthContext; - dmProxyAuthContext.proxyAccessee.bundleName = fdp.ConsumeRandomLengthString(); - dmProxyAuthContext.proxyAccessee.tokenId = fdp.ConsumeIntegral(); - dmProxyAuthContext.proxyAccessee.credInfoJson = fdp.ConsumeRandomLengthString(); - dmProxyAuthContext.proxyAccessee.aclTypeList = fdp.ConsumeRandomLengthString(); - dmProxyAuthContext.proxyAccessee.credTypeList = fdp.ConsumeRandomLengthString(); - context->subjectProxyOnes.push_back(dmProxyAuthContext); - std::shared_ptr authSinkPtr = std::make_shared(); - std::vector deleteCredInfo; - authSinkPtr->GetSinkProxyCredTypeForP2P(context, deleteCredInfo); - DistributedDeviceProfile::AccessControlProfile profile; - authSinkPtr->GetSinkProxyAclInfoForP2P(context, profile); -} - void DmNegotiateProcessFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(int32_t))) { return; } + FuzzedDataProvider fdp(data, size); std::shared_ptr context = std::make_shared(); + context->needBind = fdp.ConsumeBool(); + context->needAgreeCredential = fdp.ConsumeBool(); + context->needAuth = fdp.ConsumeBool(); NoCredNoAclImportAuthType noCredNoAclImportAuthType; noCredNoAclImportAuthType.NegotiateHandle(context); NoCredNoAclInputAuthType noCredNoAclInputAuthType; @@ -108,9 +71,6 @@ void DmNegotiateProcessFuzzTest(const uint8_t* data, size_t size) p2pCredP2pAclImportAuthType.NegotiateHandle(context); P2pCredP2pAclInputAuthType p2pCredP2pAclInputAuthType; p2pCredP2pAclInputAuthType.NegotiateHandle(context); - - RespQueryProxyAcceseeIdsFuzzTest(data, size); - GetSinkProxyCredTypeForP2PFuzzTest(data, size); } } // namespace DistributedHardware } // namespace OHOS -- Gitee From 5e799518109bd51e8c67d35ab4994e75529a8127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 07:33:54 +0000 Subject: [PATCH 04/15] update test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp b/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp index 1c32ef1b6..7e8b2d0be 100644 --- a/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp +++ b/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ - +#include #include #include #include @@ -46,11 +46,15 @@ void DpInitedCallbackFirstFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size < sizeof(int32_t))) { return; } + FuzzedDataProvider fdp(data, size); DpInitedCallback dpInitedCallback; std::unordered_map authFormMap; + DistributedDeviceProfile::TrustedDeviceInfo trustedDeviceInfo; + std::string extraDataStr = fdp.ConsumeRandomLengthString(DM_MAX_DEVICE_ID_LEN); DmDeviceInfo deviceInfo; + deviceInfo.extraData = extraDataStr; + dpInitedCallback.ConvertToTrustedDeviceInfo(authFormMap, deviceInfo, trustedDeviceInfo); deviceInfo.extraData = ""; - DistributedDeviceProfile::TrustedDeviceInfo trustedDeviceInfo; dpInitedCallback.ConvertToTrustedDeviceInfo(authFormMap, deviceInfo, trustedDeviceInfo); deviceInfo.extraData = "extraInfo"; -- Gitee From b0bf5cc195fe4f40e0ff339035cb0b38eb6985b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 07:39:14 +0000 Subject: [PATCH 05/15] update test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../dm_negotiate_process_fuzzer.cpp | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp index 3fa23e441..c013927dc 100644 --- a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp @@ -20,11 +20,52 @@ #include #include "device_manager_service_listener.h" +#include "dm_auth_state.h" #include "dm_negotiate_process.h" namespace OHOS { namespace DistributedHardware { +void RespQueryProxyAcceseeIdsFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::shared_ptr context = std::make_shared(); + context->IsProxyBind = true; + context->accessee.userId = fdp.ConsumeIntegral(); + DmProxyAuthContext dmProxyAuthContext; + dmProxyAuthContext.proxyAccessee.bundleName = fdp.ConsumeRandomLengthString(); + dmProxyAuthContext.proxyAccessee.tokenId = fdp.ConsumeIntegral(); + context->subjectProxyOnes.push_back(dmProxyAuthContext); + std::shared_ptr authSinkPtr = std::make_shared(); + authSinkPtr->RespQueryProxyAcceseeIds(context); +} + +void GetSinkProxyCredTypeForP2PFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::shared_ptr context = std::make_shared(); + context->IsProxyBind = true; + context->accessee.userId = fdp.ConsumeIntegral(); + DmProxyAuthContext dmProxyAuthContext; + dmProxyAuthContext.proxyAccessee.bundleName = fdp.ConsumeRandomLengthString(); + dmProxyAuthContext.proxyAccessee.tokenId = fdp.ConsumeIntegral(); + dmProxyAuthContext.proxyAccessee.credInfoJson = fdp.ConsumeRandomLengthString(); + dmProxyAuthContext.proxyAccessee.aclTypeList = fdp.ConsumeRandomLengthString(); + dmProxyAuthContext.proxyAccessee.credTypeList = fdp.ConsumeRandomLengthString(); + context->subjectProxyOnes.push_back(dmProxyAuthContext); + std::shared_ptr authSinkPtr = std::make_shared(); + std::vector deleteCredInfo; + authSinkPtr->GetSinkProxyCredTypeForP2P(context, deleteCredInfo); + DistributedDeviceProfile::AccessControlProfile profile; + authSinkPtr->GetSinkProxyAclInfoForP2P(context, profile); +} +void DmNegotiateProcessFuzzTest(const uint8_t* data, size_t size) void DmNegotiateProcessFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(int32_t))) { -- Gitee From f686daa8e717922a77890e0852fe3f6eabe8df45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 07:41:02 +0000 Subject: [PATCH 06/15] update test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../dm_negotiate_process_fuzzer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp index c013927dc..f42cb5003 100644 --- a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp @@ -25,6 +25,7 @@ namespace OHOS { namespace DistributedHardware { + void RespQueryProxyAcceseeIdsFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(int32_t))) { @@ -112,7 +113,9 @@ void DmNegotiateProcessFuzzTest(const uint8_t* data, size_t size) p2pCredP2pAclImportAuthType.NegotiateHandle(context); P2pCredP2pAclInputAuthType p2pCredP2pAclInputAuthType; p2pCredP2pAclInputAuthType.NegotiateHandle(context); -} + + RespQueryProxyAcceseeIdsFuzzTest(data, size); + GetSinkProxyCredTypeForP2PFuzzTest(data, size); } // namespace DistributedHardware } // namespace OHOS -- Gitee From df1d1ea231987d18c5bb2ea5de5edf897445106e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 07:41:47 +0000 Subject: [PATCH 07/15] update test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp index f42cb5003..a4f412c51 100644 --- a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp @@ -66,7 +66,6 @@ void GetSinkProxyCredTypeForP2PFuzzTest(const uint8_t* data, size_t size) authSinkPtr->GetSinkProxyAclInfoForP2P(context, profile); } -void DmNegotiateProcessFuzzTest(const uint8_t* data, size_t size) void DmNegotiateProcessFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(int32_t))) { @@ -116,6 +115,7 @@ void DmNegotiateProcessFuzzTest(const uint8_t* data, size_t size) RespQueryProxyAcceseeIdsFuzzTest(data, size); GetSinkProxyCredTypeForP2PFuzzTest(data, size); +} } // namespace DistributedHardware } // namespace OHOS -- Gitee From 9dcfa12b037861999b77eac7bb4d6e7366faf29f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 08:01:53 +0000 Subject: [PATCH 08/15] update test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp b/test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp index 8b78aad39..5c6e7f592 100644 --- a/test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp +++ b/test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include "ipc_cmd_register_fuzzer.h" #include @@ -42,8 +43,11 @@ void IpcCmdRegisterFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size == 0)) { return; } + FuzzedDataProvider fdp(data, size); int32_t cmdCode = UNREGISTER_DEVICE_MANAGER_LISTENER; std::shared_ptr req = std::make_shared(); + std::string pkgNameStr = fdp.ConsumeRandomLengthString(DM_MAX_DEVICE_ID_LEN); + req->SetPkgName(pkgNameStr); std::shared_ptr rsp = std::make_shared(); MessageParcel data1; MessageParcel reply1; -- Gitee From d2c7de355c84da7b18393e97fe5f2b6cd359f58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 08:04:41 +0000 Subject: [PATCH 09/15] update test/servicesfuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../ipc_server_client_proxy_fuzzer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/servicesfuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.cpp b/test/servicesfuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.cpp index 1fd1e857a..043ced437 100644 --- a/test/servicesfuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.cpp +++ b/test/servicesfuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ - +#include #include "ipc_server_client_proxy_fuzzer.h" #include @@ -32,11 +32,13 @@ void IpcServerClientProxyFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size == 0)) { return; } - + FuzzedDataProvider fdp(data, size); int32_t cmdCode = UNREGISTER_DEVICE_MANAGER_LISTENER; std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); sptr remoteObject = nullptr; + std::string pkgNameStr = fdp.ConsumeRandomLengthString(DM_MAX_DEVICE_ID_LEN); + req->SetPkgName(pkgNameStr); auto instance = new IpcServerClientProxy(remoteObject); if (instance != nullptr) { -- Gitee From 42f807cdca9970ecd3b64fe95b7603ca4cbfa91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 08:06:15 +0000 Subject: [PATCH 10/15] update test/servicesfuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/servicesfuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp b/test/servicesfuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp index fa6e11d48..10b09cbd7 100644 --- a/test/servicesfuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp +++ b/test/servicesfuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ - +#include #include "ipc_server_listener_fuzzer.h" #include @@ -32,10 +32,12 @@ void IpcServerListenerFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size == 0)) { return; } + FuzzedDataProvider fdp(data, size); + std::string pkgNameStr = fdp.ConsumeRandomLengthString(DM_MAX_DEVICE_ID_LEN); int32_t cmdCode = UNREGISTER_DEVICE_MANAGER_LISTENER; std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); - + req->SetPkgName(pkgNameStr); std::shared_ptr ipcServerListener = std::make_shared(); ipcServerListener->SendRequest(cmdCode, req, rsp); } -- Gitee From c39d8138efe532e9e7a162a4db3d01054710b4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 08:07:33 +0000 Subject: [PATCH 11/15] update test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../on_softbus_device_offline_fuzzer.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp b/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp index 3b9013d90..db547d5f6 100644 --- a/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp +++ b/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp @@ -13,7 +13,8 @@ * limitations under the License. */ - +#include + #include #include #include @@ -21,19 +22,22 @@ #include "device_manager_impl.h" #include "dm_constants.h" #include "softbus_listener.h" -#include "on_softbus_device_offline_fuzzer.h" +#include "on_softbus_device_online_fuzzer.h" namespace OHOS { namespace DistributedHardware { -void OnSoftbusDeviceOfflineFuzzTest(const uint8_t* data, size_t size) +void OnSoftbusDeviceOnlineFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(uint16_t) || (size > DM_MAX_DEVICE_ID_LEN))) { return; } - + auto info = std::make_unique(); + FuzzedDataProvider fdp(data, size); std::shared_ptr softbusListener = std::make_shared(); - NodeBasicInfo *info = nullptr; - softbusListener->OnSoftbusDeviceOffline(info); + info->deviceTypeId = fdp.ConsumeIntegral(); + info->osType = fdp.ConsumeIntegral(); + + softbusListener->OnSoftbusDeviceOnline(info.get()); } } } @@ -42,7 +46,7 @@ void OnSoftbusDeviceOfflineFuzzTest(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::DistributedHardware::OnSoftbusDeviceOfflineFuzzTest(data, size); + OHOS::DistributedHardware::OnSoftbusDeviceOnlineFuzzTest(data, size); return 0; } -- Gitee From 1542b5005c835a5de3dcae499c47f6891f3f6fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 08:08:02 +0000 Subject: [PATCH 12/15] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/softbusfuzztest/onsoftbusdeviceoffline=5Ffuzzer/on=5Fsoftbus?= =?UTF-8?q?=5Fdevice=5Foffline=5Ffuzzer.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../on_softbus_device_offline_fuzzer.cpp | 52 ------------------- 1 file changed, 52 deletions(-) delete mode 100644 test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp diff --git a/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp b/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp deleted file mode 100644 index db547d5f6..000000000 --- a/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include -#include -#include - -#include "device_manager_impl.h" -#include "dm_constants.h" -#include "softbus_listener.h" -#include "on_softbus_device_online_fuzzer.h" - -namespace OHOS { -namespace DistributedHardware { -void OnSoftbusDeviceOnlineFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(uint16_t) || (size > DM_MAX_DEVICE_ID_LEN))) { - return; - } - auto info = std::make_unique(); - FuzzedDataProvider fdp(data, size); - std::shared_ptr softbusListener = std::make_shared(); - info->deviceTypeId = fdp.ConsumeIntegral(); - info->osType = fdp.ConsumeIntegral(); - - softbusListener->OnSoftbusDeviceOnline(info.get()); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::OnSoftbusDeviceOnlineFuzzTest(data, size); - - return 0; -} -- Gitee From 7edfdae28e68c5581de3f322500db7a98dc72f3c Mon Sep 17 00:00:00 2001 From: l30054665 Date: Thu, 24 Jul 2025 16:10:59 +0800 Subject: [PATCH 13/15] fuzz Signed-off-by: l30054665 --- .../on_softbus_device_offline_fuzzer.cpp | 47 +++++++++++++++++++ .../on_softbus_device_online_fuzzer.cpp | 1 + 2 files changed, 48 insertions(+) create mode 100644 test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp diff --git a/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp b/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp new file mode 100644 index 000000000..86c139cc1 --- /dev/null +++ b/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "device_manager_impl.h" +#include "dm_constants.h" +#include "softbus_listener.h" +#include "on_softbus_device_offline_fuzzer.h" + +namespace OHOS { +namespace DistributedHardware { +void OnSoftbusDeviceOfflineFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint16_t) || (size > DM_MAX_DEVICE_ID_LEN))) { + return; + } + + std::shared_ptr softbusListener = std::make_shared(); + NodeBasicInfo *info = nullptr; + softbusListener->OnSoftbusDeviceOffline(info); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::OnSoftbusDeviceOfflineFuzzTest(data, size); + + return 0; +} \ No newline at end of file diff --git a/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/on_softbus_device_online_fuzzer.cpp b/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/on_softbus_device_online_fuzzer.cpp index db02ee986..bb739409b 100644 --- a/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/on_softbus_device_online_fuzzer.cpp +++ b/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/on_softbus_device_online_fuzzer.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ + #include #include #include -- Gitee From 6944d4527ac481f434f2f659e4f83b171a4c870e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 08:12:50 +0000 Subject: [PATCH 14/15] update test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/on_softbus_device_online_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../on_softbus_device_online_fuzzer.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/on_softbus_device_online_fuzzer.cpp b/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/on_softbus_device_online_fuzzer.cpp index bb739409b..db547d5f6 100644 --- a/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/on_softbus_device_online_fuzzer.cpp +++ b/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/on_softbus_device_online_fuzzer.cpp @@ -13,7 +13,8 @@ * limitations under the License. */ - +#include + #include #include #include @@ -30,10 +31,13 @@ void OnSoftbusDeviceOnlineFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size < sizeof(uint16_t) || (size > DM_MAX_DEVICE_ID_LEN))) { return; } - + auto info = std::make_unique(); + FuzzedDataProvider fdp(data, size); std::shared_ptr softbusListener = std::make_shared(); - NodeBasicInfo *info = nullptr; - softbusListener->OnSoftbusDeviceOnline(info); + info->deviceTypeId = fdp.ConsumeIntegral(); + info->osType = fdp.ConsumeIntegral(); + + softbusListener->OnSoftbusDeviceOnline(info.get()); } } } -- Gitee From ab9cc21ececc854a42a00f859588ba9664c8f367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Thu, 24 Jul 2025 08:44:18 +0000 Subject: [PATCH 15/15] update test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../dm_negotiate_process_fuzzer.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp index a4f412c51..51c8eb047 100644 --- a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include #include "dm_negotiate_process_fuzzer.h" #include @@ -71,11 +70,7 @@ void DmNegotiateProcessFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size < sizeof(int32_t))) { return; } - FuzzedDataProvider fdp(data, size); std::shared_ptr context = std::make_shared(); - context->needBind = fdp.ConsumeBool(); - context->needAgreeCredential = fdp.ConsumeBool(); - context->needAuth = fdp.ConsumeBool(); NoCredNoAclImportAuthType noCredNoAclImportAuthType; noCredNoAclImportAuthType.NegotiateHandle(context); NoCredNoAclInputAuthType noCredNoAclInputAuthType; -- Gitee