diff --git a/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp index dafa558a4119a9cb17ccf2a9d9c53691776d6037..19faa0e8823eb99e91948f5674075ca02b1bd91d 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 #include @@ -29,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"); } } } @@ -71,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; } diff --git a/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp b/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp index db548cd8ece8f263a5353f200a0c48ebc41c2e6a..7e8b2d0be66277f9388f7695c33a582f2c876402 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 #include @@ -45,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"; diff --git a/test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp b/test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp index 99d41ffae0cdcf91b6dad6cb90f3b1251d171651..5c6e7f59284f42bc2c0903a97cc0649914933336 100644 --- a/test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp +++ b/test/servicesfuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp @@ -12,6 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#include #include "ipc_cmd_register_fuzzer.h" #include @@ -41,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; 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 6f11a2ea25330d4ac9b1ce70e151e0d540e40f5b..043ced4371e340a7689a6f7a761b0307bc71c4c7 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 #include "ipc_server_client_proxy_fuzzer.h" #include @@ -31,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) { diff --git a/test/servicesfuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp b/test/servicesfuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp index b7c8de713697f2bd0b20b2e1482f938b5bec6c05..10b09cbd7b1df16042b56289e9f96e6326ef0bd3 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 #include "ipc_server_listener_fuzzer.h" #include @@ -31,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); } 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 0a1036bc86fbce79bb635a23c51fab5fb9042211..86c139cc18c53ae544730f2cf0366d6ce7689e48 100644 --- a/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp +++ b/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/on_softbus_device_offline_fuzzer.cpp @@ -44,4 +44,4 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 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 db02ee9866d640e9acbecd9ec706dd5afebc9230..db547d5f634ca6a1a1853fc30fbe32f2d66aea4e 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,8 @@ * limitations under the License. */ +#include + #include #include #include @@ -29,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()); } } }