diff --git a/tests/sdk/discovery/fuzztest/publishservice_fuzzer/BUILD.gn b/tests/sdk/discovery/fuzztest/publishservice_fuzzer/BUILD.gn index 86521c4bb3..c2682bf2bd 100644 --- a/tests/sdk/discovery/fuzztest/publishservice_fuzzer/BUILD.gn +++ b/tests/sdk/discovery/fuzztest/publishservice_fuzzer/BUILD.gn @@ -22,6 +22,7 @@ ohos_fuzztest("PublishServiceFuzzTest") { module_out_path = "dsoftbus/discovery" fuzz_config_file = "//foundation/communication/dsoftbus/tests/sdk/discovery/fuzztest/publishservice_fuzzer" include_dirs = [ + "//foundation/communication/dsoftbus/adapter/common/include", "//foundation/communication/dsoftbus/core/common/inner_communication", "//foundation/communication/dsoftbus/core/common/include", "//foundation/communication/dsoftbus/interfaces/kits/discovery", @@ -39,7 +40,10 @@ ohos_fuzztest("PublishServiceFuzzTest") { ] sources = [ "publishservice_fuzzer.cpp" ] - deps = [ "//foundation/communication/dsoftbus/sdk:softbus_client" ] + deps = [ + "//foundation/communication/dsoftbus/adapter:softbus_adapter", + "//foundation/communication/dsoftbus/sdk:softbus_client", + ] external_deps = [ "c_utils:utils" ] } diff --git a/tests/sdk/discovery/fuzztest/publishservice_fuzzer/publishservice_fuzzer.cpp b/tests/sdk/discovery/fuzztest/publishservice_fuzzer/publishservice_fuzzer.cpp index 42550d4b63..29aa44047e 100644 --- a/tests/sdk/discovery/fuzztest/publishservice_fuzzer/publishservice_fuzzer.cpp +++ b/tests/sdk/discovery/fuzztest/publishservice_fuzzer/publishservice_fuzzer.cpp @@ -14,9 +14,13 @@ */ #include "publishservice_fuzzer.h" + #include #include +#include + #include "discovery_service.h" +#include "softbus_adapter_mem.h" namespace OHOS { static int g_publishId = 0; @@ -58,7 +62,17 @@ void PublishServiceTest(const uint8_t* data, size_t size) return; } - PublishService((const char*)data, &testInfo, &g_publishCb); + // add trailing '\0' + uint8_t *pkgName = (uint8_t *)SoftBusCalloc((size + 1) * sizeof(uint8_t)); + if (pkgName == nullptr) { + return; + } + if (memcpy_s(pkgName, size + 1, data, size) != EOK) { + SoftBusFree(pkgName); + return; + } + PublishService((const char*)pkgName, &testInfo, &g_publishCb); + SoftBusFree(pkgName); } } // namespace OHOS diff --git a/tests/sdk/discovery/fuzztest/startdiscovery_fuzzer/BUILD.gn b/tests/sdk/discovery/fuzztest/startdiscovery_fuzzer/BUILD.gn index c21fdb145f..a4b24b2574 100644 --- a/tests/sdk/discovery/fuzztest/startdiscovery_fuzzer/BUILD.gn +++ b/tests/sdk/discovery/fuzztest/startdiscovery_fuzzer/BUILD.gn @@ -22,6 +22,7 @@ ohos_fuzztest("StartDiscoveryFuzzTest") { module_out_path = "dsoftbus/discovery" fuzz_config_file = "//foundation/communication/dsoftbus/tests/sdk/discovery/fuzztest/startdiscovery_fuzzer" include_dirs = [ + "//foundation/communication/dsoftbus/adapter/common/include", "//foundation/communication/dsoftbus/core/common/inner_communication", "//foundation/communication/dsoftbus/core/common/include", "//foundation/communication/dsoftbus/interfaces/kits/discovery", @@ -39,7 +40,10 @@ ohos_fuzztest("StartDiscoveryFuzzTest") { ] sources = [ "startdiscovery_fuzzer.cpp" ] - deps = [ "//foundation/communication/dsoftbus/sdk:softbus_client" ] + deps = [ + "//foundation/communication/dsoftbus/adapter:softbus_adapter", + "//foundation/communication/dsoftbus/sdk:softbus_client", + ] external_deps = [ "c_utils:utils" ] } diff --git a/tests/sdk/discovery/fuzztest/startdiscovery_fuzzer/startdiscovery_fuzzer.cpp b/tests/sdk/discovery/fuzztest/startdiscovery_fuzzer/startdiscovery_fuzzer.cpp index 7aad29a9d7..0c833528d3 100644 --- a/tests/sdk/discovery/fuzztest/startdiscovery_fuzzer/startdiscovery_fuzzer.cpp +++ b/tests/sdk/discovery/fuzztest/startdiscovery_fuzzer/startdiscovery_fuzzer.cpp @@ -14,9 +14,13 @@ */ #include "startdiscovery_fuzzer.h" + #include #include +#include + #include "discovery_service.h" +#include "softbus_adapter_mem.h" namespace OHOS { static int g_subscribeId = 0; @@ -64,7 +68,17 @@ void StartDiscoveryTest(const uint8_t* data, size_t size) return; } - StartDiscovery((const char*)data, &testInfo, &g_subscribeCb); + // add trailing '\0' + uint8_t *pkgName = (uint8_t *)SoftBusCalloc((size + 1) * sizeof(uint8_t)); + if (pkgName == nullptr) { + return; + } + if (memcpy_s(pkgName, size + 1, data, size) != EOK) { + SoftBusFree(pkgName); + return; + } + StartDiscovery((const char*)pkgName, &testInfo, &g_subscribeCb); + SoftBusFree(pkgName); } } // namespace OHOS diff --git a/tests/sdk/discovery/fuzztest/stopdiscovery_fuzzer/BUILD.gn b/tests/sdk/discovery/fuzztest/stopdiscovery_fuzzer/BUILD.gn index 4f3069769e..5f25644d47 100644 --- a/tests/sdk/discovery/fuzztest/stopdiscovery_fuzzer/BUILD.gn +++ b/tests/sdk/discovery/fuzztest/stopdiscovery_fuzzer/BUILD.gn @@ -22,6 +22,7 @@ ohos_fuzztest("StopDiscoveryFuzzTest") { module_out_path = "dsoftbus/discovery" fuzz_config_file = "//foundation/communication/dsoftbus/tests/sdk/discovery/fuzztest/stopdiscovery_fuzzer" include_dirs = [ + "//foundation/communication/dsoftbus/adapter/common/include", "//foundation/communication/dsoftbus/core/common/inner_communication", "//foundation/communication/dsoftbus/core/common/include", "//foundation/communication/dsoftbus/interfaces/kits/discovery", @@ -39,7 +40,10 @@ ohos_fuzztest("StopDiscoveryFuzzTest") { ] sources = [ "stopdiscovery_fuzzer.cpp" ] - deps = [ "//foundation/communication/dsoftbus/sdk:softbus_client" ] + deps = [ + "//foundation/communication/dsoftbus/adapter:softbus_adapter", + "//foundation/communication/dsoftbus/sdk:softbus_client", + ] external_deps = [ "c_utils:utils" ] } diff --git a/tests/sdk/discovery/fuzztest/stopdiscovery_fuzzer/stopdiscovery_fuzzer.cpp b/tests/sdk/discovery/fuzztest/stopdiscovery_fuzzer/stopdiscovery_fuzzer.cpp index 8c302ae552..e40d15fb87 100644 --- a/tests/sdk/discovery/fuzztest/stopdiscovery_fuzzer/stopdiscovery_fuzzer.cpp +++ b/tests/sdk/discovery/fuzztest/stopdiscovery_fuzzer/stopdiscovery_fuzzer.cpp @@ -14,9 +14,13 @@ */ #include "stopdiscovery_fuzzer.h" + #include #include +#include + #include "discovery_service.h" +#include "softbus_adapter_mem.h" namespace OHOS { static int g_subscribeId = 0; @@ -49,7 +53,17 @@ void StopDiscoveryTest(const uint8_t* data, size_t size) return; } - StopDiscovery((const char*)data, testInfo.subscribeId); + // add trailing '\0' + uint8_t *pkgName = (uint8_t *)SoftBusCalloc((size + 1) * sizeof(uint8_t)); + if (pkgName == nullptr) { + return; + } + if (memcpy_s(pkgName, size + 1, data, size) != EOK) { + SoftBusFree(pkgName); + return; + } + StopDiscovery((const char*)pkgName, testInfo.subscribeId); + SoftBusFree(pkgName); } } // namespace OHOS diff --git a/tests/sdk/discovery/fuzztest/unpublishservice_fuzzer/BUILD.gn b/tests/sdk/discovery/fuzztest/unpublishservice_fuzzer/BUILD.gn index 850380f819..d0cddea384 100644 --- a/tests/sdk/discovery/fuzztest/unpublishservice_fuzzer/BUILD.gn +++ b/tests/sdk/discovery/fuzztest/unpublishservice_fuzzer/BUILD.gn @@ -22,6 +22,7 @@ ohos_fuzztest("UnPublishServiceFuzzTest") { module_out_path = "dsoftbus/discovery" fuzz_config_file = "//foundation/communication/dsoftbus/tests/sdk/discovery/fuzztest/unpublishservice_fuzzer" include_dirs = [ + "//foundation/communication/dsoftbus/adapter/common/include", "//foundation/communication/dsoftbus/core/common/inner_communication", "//foundation/communication/dsoftbus/core/common/include", "//foundation/communication/dsoftbus/interfaces/kits/discovery", @@ -39,7 +40,10 @@ ohos_fuzztest("UnPublishServiceFuzzTest") { ] sources = [ "unpublishservice_fuzzer.cpp" ] - deps = [ "//foundation/communication/dsoftbus/sdk:softbus_client" ] + deps = [ + "//foundation/communication/dsoftbus/adapter:softbus_adapter", + "//foundation/communication/dsoftbus/sdk:softbus_client", + ] external_deps = [ "c_utils:utils" ] } diff --git a/tests/sdk/discovery/fuzztest/unpublishservice_fuzzer/unpublishservice_fuzzer.cpp b/tests/sdk/discovery/fuzztest/unpublishservice_fuzzer/unpublishservice_fuzzer.cpp index 691ca3069b..02680fdbda 100644 --- a/tests/sdk/discovery/fuzztest/unpublishservice_fuzzer/unpublishservice_fuzzer.cpp +++ b/tests/sdk/discovery/fuzztest/unpublishservice_fuzzer/unpublishservice_fuzzer.cpp @@ -14,9 +14,13 @@ */ #include "unpublishservice_fuzzer.h" + #include #include +#include + #include "discovery_service.h" +#include "softbus_adapter_mem.h" namespace OHOS { static int g_publishId = 0; @@ -47,7 +51,17 @@ void UnPublishServiceTest(const uint8_t* data, size_t size) return; } - UnPublishService((const char*)data, testInfo.publishId); + // add trailing '\0' + uint8_t *pkgName = (uint8_t *)SoftBusCalloc((size + 1) * sizeof(uint8_t)); + if (pkgName == nullptr) { + return; + } + if (memcpy_s(pkgName, size + 1, data, size) != EOK) { + SoftBusFree(pkgName); + return; + } + UnPublishService((const char*)pkgName, testInfo.publishId); + SoftBusFree(pkgName); } } // namespace OHOS