diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.cpp index ece8a40a8c397aabdadb621cc017403b4cbf11d3..3a97da2ceabf1cc7ee5f809602bf8720963a406c 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.cpp @@ -13,23 +13,24 @@ * limitations under the License. */ -#include "initsink_fuzzer.h" - #include #include +#include "initsink_fuzzer.h" #include "dscreen_sink_handler.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -void InitSinkFuzzTest(const uint8_t* data, size_t size) +void InitSinkFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string params(reinterpret_cast(data), size); - std::string networkId(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string params(dataProvider.ConsumeRandomLengthString()); + std::string networkId(dataProvider.ConsumeRandomLengthString()); DScreenSinkHandler::GetInstance().InitSink(params); DScreenSinkHandler::GetInstance().PauseDistributedHardware(networkId); @@ -37,14 +38,13 @@ void InitSinkFuzzTest(const uint8_t* data, size_t size) DScreenSinkHandler::GetInstance().StopDistributedHardware(networkId); DScreenSinkHandler::GetInstance().ReleaseSink(); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::InitSinkFuzzTest(data, size); return 0; } - diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/onremotesinksvrdied_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/onremotesinksvrdied_fuzzer.cpp index f4b45b13428fbcac01bc41f8d060923ca4ecf7f5..b3af58c013692cabd560380b5a143982663ac0fc 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/onremotesinksvrdied_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/onremotesinksvrdied_fuzzer.cpp @@ -13,27 +13,27 @@ * limitations under the License. */ -#include "onremotesinksvrdied_fuzzer.h" - #include #include +#include "onremotesinksvrdied_fuzzer.h" #include "dscreen_sink_handler.h" +#include "fuzzer/FuzzedDataProvider.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { -void OnRemoteSinkSvrDiedFuzzTest(const uint8_t* data, size_t size) +void OnRemoteSinkSvrDiedFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - int32_t saId = *(reinterpret_cast(data)); + FuzzedDataProvider dataProvider(data, size); + int32_t saId = dataProvider.ConsumeIntegral(); - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { return; } @@ -46,14 +46,13 @@ void OnRemoteSinkSvrDiedFuzzTest(const uint8_t* data, size_t size) DScreenSinkHandler::GetInstance().OnRemoteSinkSvrDied(remote); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::OnRemoteSinkSvrDiedFuzzTest(data, size); return 0; } - diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp index f2075ef097d9dff376746fa1ccf1445094740aca..36b55d304219570e4e65ca08797fd613dbd7d8f6 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp @@ -13,34 +13,34 @@ * limitations under the License. */ -#include "subscribelocalhardware_fuzzer.h" - #include #include +#include "subscribelocalhardware_fuzzer.h" #include "dscreen_sink_handler.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -void SubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +void SubscribeLocalHardwareFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string dhId(reinterpret_cast(data), size); - std::string param(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string param(dataProvider.ConsumeRandomLengthString()); DScreenSinkHandler::GetInstance().SubscribeLocalHardware(dhId, param); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::SubscribeLocalHardwareFuzzTest(data, size); return 0; } - diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp index 5a45aa867f1443933477c62987c28c78c8e19237..6e5a3e85bf1ec0e7c2af8cd627c460ebe102aa01 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp @@ -13,33 +13,33 @@ * limitations under the License. */ -#include "unsubscribelocalhardware_fuzzer.h" - #include #include +#include "unsubscribelocalhardware_fuzzer.h" #include "dscreen_sink_handler.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -void UnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +void UnsubscribeLocalHardwareFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string dhId(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string dhId(dataProvider.ConsumeRandomLengthString()); DScreenSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::UnsubscribeLocalHardwareFuzzTest(data, size); return 0; } - diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.cpp index 819d93529702214f59e075ef8999c3a0b02e6303..26b8dace07d4fadc96a90ee4d5a3a0a67f31cd3d 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.cpp @@ -13,28 +13,28 @@ * limitations under the License. */ -#include "initsink_fuzzer.h" - #include #include +#include "initsink_fuzzer.h" #include "dscreen_constants.h" #include "dscreen_sink_proxy.h" +#include "fuzzer/FuzzedDataProvider.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { -void InitSinkFuzzTest(const uint8_t* data, size_t size) +void InitSinkFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string params(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string params(dataProvider.ConsumeRandomLengthString()); - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { return; } @@ -49,14 +49,13 @@ void InitSinkFuzzTest(const uint8_t* data, size_t size) dscreenSinkProxy->InitSink(params); dscreenSinkProxy->ReleaseSink(); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::InitSinkFuzzTest(data, size); return 0; } - diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp index 554b1fe7432bd3ef63bbb7cf73b0e1f44955ea49..4eb8dece10dc298759961c85bebd6b357cbc1e81 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp @@ -13,30 +13,31 @@ * limitations under the License. */ -#include "subscribelocalhardware_fuzzer.h" - #include #include +#include "subscribelocalhardware_fuzzer.h" #include "dscreen_constants.h" #include "dscreen_sink_proxy.h" +#include "fuzzer/FuzzedDataProvider.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { constexpr int32_t DISTRIBUTED_HARDWARE_DM_SA_ID = 4802; -void SubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +void SubscribeLocalHardwareFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string dhId(reinterpret_cast(data), size); - std::string param(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string param(dataProvider.ConsumeRandomLengthString()); sptr systemAbilityManager = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemAbilityManager == nullptr) { return; } @@ -50,14 +51,13 @@ void SubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) dscreenSinkProxy->SubscribeLocalHardware(dhId, param); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::SubscribeLocalHardwareFuzzTest(data, size); return 0; } - diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp index 5b8cc851549e10a134af2b5330e1f50a1be720cc..08584f982357016aab38933114dabf11b1df4d2a 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp @@ -13,29 +13,29 @@ * limitations under the License. */ -#include "unsubscribelocalhardware_fuzzer.h" - #include #include +#include "unsubscribelocalhardware_fuzzer.h" #include "dscreen_constants.h" #include "dscreen_sink_proxy.h" +#include "fuzzer/FuzzedDataProvider.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { constexpr int32_t DISTRIBUTED_HARDWARE_DM_SA_ID = 4802; -void UnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +void UnsubscribeLocalHardwareFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string dhId(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string dhId(dataProvider.ConsumeRandomLengthString()); - sptr saMgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (saMgr == nullptr) { return; } @@ -49,14 +49,13 @@ void UnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) dscreenSinkProxy->UnsubscribeLocalHardware(dhId); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::UnsubscribeLocalHardwareFuzzTest(data, size); return 0; } - diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/sinkproxydscreennotify_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/sinkproxydscreennotify_fuzzer.cpp index 78d3cf1bddf722e03ef7b9379d26141157b46003..b8c2028c771998f02e5f33adefa4da5051e38deb 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/sinkproxydscreennotify_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/sinkproxydscreennotify_fuzzer.cpp @@ -13,28 +13,29 @@ * limitations under the License. */ -#include "sinkproxydscreennotify_fuzzer.h" - #include #include +#include "sinkproxydscreennotify_fuzzer.h" #include "dscreen_constants.h" #include "dscreen_sink_proxy.h" +#include "fuzzer/FuzzedDataProvider.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { constexpr int32_t DISTRIBUTED_HARDWARE_DM_SA_ID = 4802; -void DScreenNotifyFuzzTest(const uint8_t* data, size_t size) +void DScreenNotifyFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - std::string devId(reinterpret_cast(data), size); - int32_t eventCode = *(reinterpret_cast(data)); - std::string eventContent(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string devId(dataProvider.ConsumeRandomLengthString()); + int32_t eventCode = dataProvider.ConsumeIntegral(); + std::string eventContent(dataProvider.ConsumeRandomLengthString()); sptr saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (saMgr == nullptr) { @@ -50,14 +51,13 @@ void DScreenNotifyFuzzTest(const uint8_t* data, size_t size) dscreenSinkProxy->DScreenNotify(devId, eventCode, eventContent); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::DScreenNotifyFuzzTest(data, size); return 0; } - diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp index acaab3bec0ac27f1791f0ba1c75f8c84a33ac6da..e311bb5c6991d868cfbb2db48eb21ad7e2c3a64a 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp @@ -13,41 +13,42 @@ * limitations under the License. */ -#include "callbackonnotifyregresult_fuzzer.h" - #include #include #include +#include "callbackonnotifyregresult_fuzzer.h" #include "mock_component_enable.h" #include "dscreen_constants.h" #include "dscreen_source_callback.h" #include "dscreen_source_proxy.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -void OnNotifyRegResultFuzzTest(const uint8_t* data, size_t size) +void OnNotifyRegResultFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - std::string devId(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); - int32_t status = *(reinterpret_cast(data)); - std::string dataStr(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string reqId(dataProvider.ConsumeRandomLengthString()); + int32_t status = dataProvider.ConsumeIntegral(); + std::string dataStr(dataProvider.ConsumeRandomLengthString()); std::shared_ptr callback = std::make_shared(); sptr dScreenSourceCallback(new (std::nothrow) DScreenSourceCallback()); dScreenSourceCallback->PushRegRegisterCallback(reqId, callback); dScreenSourceCallback->OnNotifyRegResult(devId, dhId, reqId, status, dataStr); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::OnNotifyRegResultFuzzTest(data, size); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp index 4e94444c3628954057876c32ffac1acc8ba71eb6..64a317bddc5186b932a72145a158121f69fa3e7b 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp @@ -13,30 +13,31 @@ * limitations under the License. */ -#include "callbackonnotifyunregresult_fuzzer.h" - #include #include #include +#include "callbackonnotifyunregresult_fuzzer.h" #include "mock_component_disable.h" #include "dscreen_constants.h" #include "dscreen_source_callback.h" #include "dscreen_source_proxy.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -void OnNotifyUnregResultFuzzTest(const uint8_t* data, size_t size) +void OnNotifyUnregResultFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - std::string devId(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); - int32_t status = *(reinterpret_cast(data)); - std::string dataStr(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string reqId(dataProvider.ConsumeRandomLengthString()); + int32_t status = dataProvider.ConsumeIntegral(); + std::string dataStr(dataProvider.ConsumeRandomLengthString()); std::shared_ptr uncallback = std::make_shared(); sptr dScreenSourceCallback(new (std::nothrow) DScreenSourceCallback()); @@ -44,11 +45,11 @@ void OnNotifyUnregResultFuzzTest(const uint8_t* data, size_t size) dScreenSourceCallback->PushUnregisterCallback(reqId, uncallback); dScreenSourceCallback->OnNotifyUnregResult(devId, dhId, reqId, status, dataStr); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::OnNotifyUnregResultFuzzTest(data, size); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp index 8f3865fec3ed15fe62d58840882bfd77868adca8..b9f0c37c2f7ecb3c550fc03191b6c3361662c834 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp @@ -13,37 +13,39 @@ * limitations under the License. */ -#include "callbackonremoterequest_fuzzer.h" - #include #include #include +#include "callbackonremoterequest_fuzzer.h" #include "dscreen_constants.h" -#include "dscreen_source_callback.h" #include "dscreen_source_callback_stub.h" +#include "dscreen_source_callback.h" #include "dscreen_source_proxy.h" +#include "fuzzer/FuzzedDataProvider.h" #include "iremote_object.h" #include "message_option.h" #include "message_parcel.h" namespace OHOS { namespace DistributedHardware { -void CallbackOnRemoteRequestFuzzTest(const uint8_t* data, size_t size) +void CallbackOnRemoteRequestFuzzTest(const uint8_t *data, size_t size) { - if ((size < sizeof(uint32_t)) || (data == nullptr)) { + if ((data == nullptr) || (size == 0)) { return; } + FuzzedDataProvider dataProvider(data, size); + uint32_t code = dataProvider.ConsumeIntegral(); + int32_t status = dataProvider.ConsumeIntegral(); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string reqId(dataProvider.ConsumeRandomLengthString()); + std::string dataStr(dataProvider.ConsumeRandomLengthString()); + MessageParcel pdata; MessageParcel reply; MessageOption option; - uint32_t code = *(reinterpret_cast(data)) % 2; - int32_t status = *(reinterpret_cast(data)); - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); - std::string dataStr(reinterpret_cast(data), size); pdata.WriteInt32(status); pdata.WriteString(devId); pdata.WriteString(dhId); @@ -53,14 +55,13 @@ void CallbackOnRemoteRequestFuzzTest(const uint8_t* data, size_t size) sptr dScreenSourceCallback(new (std::nothrow) DScreenSourceCallback()); dScreenSourceCallback->OnRemoteRequest(code, pdata, reply, option); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::CallbackOnRemoteRequestFuzzTest(data, size); return 0; } - diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/dscreensourcecallbackstub_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/dscreensourcecallbackstub_fuzzer.cpp index 3eadc9b1d92eefaaff10cb13fd3a4b5a6883da3d..2db87ff6b7dec6987715b1f0d901504290a6b406 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/dscreensourcecallbackstub_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/dscreensourcecallbackstub_fuzzer.cpp @@ -16,41 +16,43 @@ #include "dscreensourcecallbackstub_fuzzer.h" #include "dscreen_errcode.h" #include "dscreen_source_callback_stub.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { - class DScreenSourceCallbackStubFuzzTest : public DScreenSourceCallbackStub { public: DScreenSourceCallbackStubFuzzTest() = default; ~DScreenSourceCallbackStubFuzzTest() = default; - int32_t OnNotifyRegResult(const std::string &devId, const std::string &dhId, - const std::string &reqId, int32_t status, const std::string &data) override + int32_t OnNotifyRegResult(const std::string &devId, const std::string &dhId, const std::string &reqId, + int32_t status, const std::string &data) override { return 0; }; - int32_t OnNotifyUnregResult(const std::string &devId, const std::string &dhId, - const std::string &reqId, int32_t status, const std::string &data) override + int32_t OnNotifyUnregResult(const std::string &devId, const std::string &dhId, const std::string &reqId, + int32_t status, const std::string &data) override { return 0; }; }; -void DscreenSourceCallbackStubFuzzTest(const uint8_t* data, size_t size) +void DscreenSourceCallbackStubFuzzTest(const uint8_t *data, size_t size) { - if ((size < sizeof(uint32_t)) || (data == nullptr)) { + if ((data == nullptr) || (size == 0)) { return; } + FuzzedDataProvider dataProvider(data, size); + unsigned int code = dataProvider.ConsumeIntegral(); + uint32_t status = dataProvider.ConsumeIntegral(); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string reqId(dataProvider.ConsumeRandomLengthString()); + std::string dataStr(dataProvider.ConsumeRandomLengthString()); + MessageParcel pdata; MessageParcel reply; MessageOption option; - unsigned int code = *(reinterpret_cast(data)) % 2; - uint32_t status = *(reinterpret_cast(data)); - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); - std::string dataStr(reinterpret_cast(data), size); pdata.WriteInt32(status); pdata.WriteString(devId); pdata.WriteString(dhId); @@ -63,11 +65,11 @@ void DscreenSourceCallbackStubFuzzTest(const uint8_t* data, size_t size) dScreenSourceCallbackStub->OnNotifyRegResultInner(pdata, reply, option); dScreenSourceCallbackStub->OnNotifyUnregResultInner(pdata, reply, option); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::DscreenSourceCallbackStubFuzzTest(data, size); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/project.xml index 7133b2b92440904a5ed04b838733acea0f97486a..93837373f31c924472b9b4ee2139348e97c1e470 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerconfigdistributedhardware_fuzzer/configdistributedhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerconfigdistributedhardware_fuzzer/configdistributedhardware_fuzzer.cpp index 7e66d030f31f1bc48d5edb0271b3df332371bf2e..d4a1f613a91314052762942ca4e96876d845f57b 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerconfigdistributedhardware_fuzzer/configdistributedhardware_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerconfigdistributedhardware_fuzzer/configdistributedhardware_fuzzer.cpp @@ -13,33 +13,34 @@ * limitations under the License. */ -#include "configdistributedhardware_fuzzer.h" - #include #include +#include "configdistributedhardware_fuzzer.h" #include "dscreen_source_handler.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -void ConfigDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +void ConfigDistributedHardwareFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string devId(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); - std::string key(reinterpret_cast(data), size); - std::string value(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string key(dataProvider.ConsumeRandomLengthString()); + std::string value(dataProvider.ConsumeRandomLengthString()); DScreenSourceHandler::GetInstance().ConfigDistributedHardware(devId, dhId, key, value); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::ConfigDistributedHardwareFuzzTest(data, size); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerconfigdistributedhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerconfigdistributedhardware_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerconfigdistributedhardware_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerconfigdistributedhardware_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerinitsource_fuzzer/initsource_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerinitsource_fuzzer/initsource_fuzzer.cpp index bfa212bf17dfe70aefd59b2360c2bb0e16b52df1..8f3258519f8722f0cbc5e924ae59d1026fd948c2 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerinitsource_fuzzer/initsource_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerinitsource_fuzzer/initsource_fuzzer.cpp @@ -13,31 +13,32 @@ * limitations under the License. */ -#include "initsource_fuzzer.h" - #include #include +#include "initsource_fuzzer.h" #include "dscreen_source_handler.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -void InitSourceFuzzTest(const uint8_t* data, size_t size) +void InitSourceFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string params(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string params(dataProvider.ConsumeRandomLengthString()); DScreenSourceHandler::GetInstance().InitSource(params); DScreenSourceHandler::GetInstance().ReleaseSource(); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::InitSourceFuzzTest(data, size); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerinitsource_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerinitsource_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerinitsource_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerinitsource_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handleronremotesourcesvrdied_fuzzer/onremotesourcesvrdied_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handleronremotesourcesvrdied_fuzzer/onremotesourcesvrdied_fuzzer.cpp index b4eec5ff7ccfdd6c1e048311aae0bcc19c8fbec7..f488c9e1839c1efe5489ae455f6ed48856e254bd 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handleronremotesourcesvrdied_fuzzer/onremotesourcesvrdied_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handleronremotesourcesvrdied_fuzzer/onremotesourcesvrdied_fuzzer.cpp @@ -13,21 +13,21 @@ * limitations under the License. */ -#include "onremotesourcesvrdied_fuzzer.h" - #include #include +#include "onremotesourcesvrdied_fuzzer.h" #include "dscreen_source_handler.h" +#include "fuzzer/FuzzedDataProvider.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { constexpr int32_t DISTRIBUTED_HARDWARE_DM_SA_ID = 4802; -void OnRemoteSourceSvrDiedFuzzTest(const uint8_t* data, size_t size) +void OnRemoteSourceSvrDiedFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } @@ -37,7 +37,8 @@ void OnRemoteSourceSvrDiedFuzzTest(const uint8_t* data, size_t size) return; } - int32_t saId = *(reinterpret_cast(data)); + FuzzedDataProvider dataProvider(data, size); + int32_t saId = dataProvider.ConsumeIntegral(); sptr remoteObject = systemAbilityManager->GetSystemAbility(saId); if (remoteObject == nullptr) { return; @@ -47,11 +48,11 @@ void OnRemoteSourceSvrDiedFuzzTest(const uint8_t* data, size_t size) DScreenSourceHandler::GetInstance().OnRemoteSourceSvrDied(remote); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::OnRemoteSourceSvrDiedFuzzTest(data, size); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handleronremotesourcesvrdied_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handleronremotesourcesvrdied_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handleronremotesourcesvrdied_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handleronremotesourcesvrdied_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerregisterdistributedhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerregisterdistributedhardware_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerregisterdistributedhardware_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerregisterdistributedhardware_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerregisterdistributedhardware_fuzzer/registerdistributedhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerregisterdistributedhardware_fuzzer/registerdistributedhardware_fuzzer.cpp index b6f17012b12651b80979b760fcdb55e2c8115e7e..48a693756aa53a82feed8f6f127b266ea3a44f33 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerregisterdistributedhardware_fuzzer/registerdistributedhardware_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerregisterdistributedhardware_fuzzer/registerdistributedhardware_fuzzer.cpp @@ -13,26 +13,27 @@ * limitations under the License. */ -#include "registerdistributedhardware_fuzzer.h" - #include #include +#include "registerdistributedhardware_fuzzer.h" #include "mock_component_enable.h" #include "dscreen_source_handler.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -void RegisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +void RegisterDistributedHardwareFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string devId(reinterpret_cast(data), size); - std::string version(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); - std::string attrs(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string version(dataProvider.ConsumeRandomLengthString()); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string attrs(dataProvider.ConsumeRandomLengthString()); EnableParam param; param.sinkVersion = version; param.sinkAttrs = attrs; @@ -40,11 +41,11 @@ void RegisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) DScreenSourceHandler::GetInstance().RegisterDistributedHardware(devId, dhId, param, callback); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::RegisterDistributedHardwareFuzzTest(data, size); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerunregisterdistributedhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerunregisterdistributedhardware_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerunregisterdistributedhardware_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerunregisterdistributedhardware_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerunregisterdistributedhardware_fuzzer/unregisterdistributedhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerunregisterdistributedhardware_fuzzer/unregisterdistributedhardware_fuzzer.cpp index 65a7ff01f9b8873d03168e8cc5cfebdc05fdd46f..51fa3d1bd5a0de260a6b8db19584e9020ab690d8 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerunregisterdistributedhardware_fuzzer/unregisterdistributedhardware_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerunregisterdistributedhardware_fuzzer/unregisterdistributedhardware_fuzzer.cpp @@ -13,33 +13,34 @@ * limitations under the License. */ -#include "unregisterdistributedhardware_fuzzer.h" - #include #include +#include "unregisterdistributedhardware_fuzzer.h" #include "mock_component_disable.h" #include "dscreen_source_handler.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -void UnregisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +void UnregisterDistributedHardwareFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string devId(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string dhId(dataProvider.ConsumeRandomLengthString()); std::shared_ptr uncallback = std::make_shared(); DScreenSourceHandler::GetInstance().UnregisterDistributedHardware(devId, dhId, uncallback); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::UnregisterDistributedHardwareFuzzTest(data, size); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyconfigdistributedhardware_fuzzer/configdistributedhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyconfigdistributedhardware_fuzzer/configdistributedhardware_fuzzer.cpp index 02c51758ff6ae77b3c1800355496cfa2287820e5..922471837b3faec08bb7ddc5e9efb299e6dc47d3 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyconfigdistributedhardware_fuzzer/configdistributedhardware_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyconfigdistributedhardware_fuzzer/configdistributedhardware_fuzzer.cpp @@ -13,32 +13,32 @@ * limitations under the License. */ -#include "configdistributedhardware_fuzzer.h" - #include #include +#include "configdistributedhardware_fuzzer.h" #include "dscreen_constants.h" #include "dscreen_source_proxy.h" +#include "fuzzer/FuzzedDataProvider.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { constexpr int32_t DISTRIBUTED_HARDWARE_DM_SA_ID = 4802; -void ConfigDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +void ConfigDistributedHardwareFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - std::string devId(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); - std::string key(reinterpret_cast(data), size); - std::string value(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string key(dataProvider.ConsumeRandomLengthString()); + std::string value(dataProvider.ConsumeRandomLengthString()); - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!samgr) { return; } @@ -52,11 +52,11 @@ void ConfigDistributedHardwareFuzzTest(const uint8_t* data, size_t size) dscreenSourceProxy->ConfigDistributedHardware(devId, dhId, key, value); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::ConfigDistributedHardwareFuzzTest(data, size); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyconfigdistributedhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyconfigdistributedhardware_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyconfigdistributedhardware_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyconfigdistributedhardware_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxydscreennotify_fuzzer/dscreennotify_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxydscreennotify_fuzzer/dscreennotify_fuzzer.cpp index c16da71145731b26c722d8338074c4ffb7575b6f..8ca6db8639c5922b2c7208f078e30bab026027ed 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxydscreennotify_fuzzer/dscreennotify_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxydscreennotify_fuzzer/dscreennotify_fuzzer.cpp @@ -13,31 +13,31 @@ * limitations under the License. */ -#include "dscreennotify_fuzzer.h" - #include #include +#include "dscreennotify_fuzzer.h" #include "dscreen_constants.h" #include "dscreen_source_proxy.h" +#include "fuzzer/FuzzedDataProvider.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { constexpr int32_t DISTRIBUTED_HARDWARE_DM_SA_ID = 4802; -void DScreenNotifyFuzzTest(const uint8_t* data, size_t size) +void DScreenNotifyFuzzTest(const uint8_t *data, size_t size) { - if ((size < sizeof(int32_t)) || (data == nullptr)) { + if ((data == nullptr) || (size == 0)) { return; } - std::string devId(reinterpret_cast(data), size); - int32_t eventCode = *(reinterpret_cast(data)); - std::string eventContent(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string devId(dataProvider.ConsumeRandomLengthString()); + int32_t eventCode = dataProvider.ConsumeIntegral(); + std::string eventContent(dataProvider.ConsumeRandomLengthString()); - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { return; } @@ -51,11 +51,11 @@ void DScreenNotifyFuzzTest(const uint8_t* data, size_t size) dscreenSourceProxy->DScreenNotify(devId, eventCode, eventContent); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::DScreenNotifyFuzzTest(data, size); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxydscreennotify_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxydscreennotify_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxydscreennotify_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxydscreennotify_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyinitsource_fuzzer/initsource_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyinitsource_fuzzer/initsource_fuzzer.cpp index aece8a5b0734285b1074946690678f441b1e12ed..2030a24f8286d2bac3fc07e86fc5f1043adae1b5 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyinitsource_fuzzer/initsource_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyinitsource_fuzzer/initsource_fuzzer.cpp @@ -13,34 +13,34 @@ * limitations under the License. */ -#include "initsource_fuzzer.h" - #include #include +#include "initsource_fuzzer.h" #include "dscreen_constants.h" #include "dscreen_source_callback.h" #include "dscreen_source_proxy.h" +#include "fuzzer/FuzzedDataProvider.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { -void InitSourceFuzzTest(const uint8_t* data, size_t size) +void InitSourceFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string params(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string params(dataProvider.ConsumeRandomLengthString()); sptr callback(new DScreenSourceCallback()); if (callback == nullptr) { return; } - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { return; } @@ -54,11 +54,11 @@ void InitSourceFuzzTest(const uint8_t* data, size_t size) dscreenSourceProxy->InitSource(params, callback); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::InitSourceFuzzTest(data, size); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyinitsource_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyinitsource_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyinitsource_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyinitsource_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/registerdistributedhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/registerdistributedhardware_fuzzer.cpp index 2b483a4844bfbc648fef24913935b22ec74066d2..e8d986f62ad3d456a2e1dc25f38fc187322d5771 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/registerdistributedhardware_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/registerdistributedhardware_fuzzer.cpp @@ -13,15 +13,15 @@ * limitations under the License. */ -#include "registerdistributedhardware_fuzzer.h" - #include #include +#include "registerdistributedhardware_fuzzer.h" #include "dscreen_constants.h" #include "dscreen_source_callback.h" #include "dscreen_source_proxy.h" #include "dscreen_source_stub.h" +#include "fuzzer/FuzzedDataProvider.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" @@ -39,36 +39,36 @@ public: { return 0; }; - int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId, - const EnableParam ¶m, const std::string &reqId) override + int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId, const EnableParam ¶m, + const std::string &reqId) override { return 0; }; - void DScreenNotify(const std::string &devId, int32_t eventCode, - const std::string &eventContent) override {}; + void DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) override{}; int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &reqId) override { return 0; }; - int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, - const std::string &key, const std::string &value) override + int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, + const std::string &value) override { return 0; }; }; -void RegisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +void RegisterDistributedHardwareFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - std::string devId(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); - std::string version(reinterpret_cast(data), size); - std::string attrs(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string reqId(dataProvider.ConsumeRandomLengthString()); + std::string version(dataProvider.ConsumeRandomLengthString()); + std::string attrs(dataProvider.ConsumeRandomLengthString()); EnableParam param; param.sinkVersion = version; param.sinkAttrs = attrs; @@ -77,11 +77,11 @@ void RegisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) std::shared_ptr dscreenSourceProxy = std::make_shared(remoteObject); dscreenSourceProxy->RegisterDistributedHardware(devId, dhId, param, reqId); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::RegisterDistributedHardwareFuzzTest(data, size); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyunregisterdistributedhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyunregisterdistributedhardware_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyunregisterdistributedhardware_fuzzer/project.xml +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyunregisterdistributedhardware_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyunregisterdistributedhardware_fuzzer/unregisterdistributedhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyunregisterdistributedhardware_fuzzer/unregisterdistributedhardware_fuzzer.cpp index 054811446875f12bea02a5c490339b10892125f7..769a947d56e580af08c5420808f7685dc0823bab 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyunregisterdistributedhardware_fuzzer/unregisterdistributedhardware_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyunregisterdistributedhardware_fuzzer/unregisterdistributedhardware_fuzzer.cpp @@ -13,35 +13,35 @@ * limitations under the License. */ -#include "unregisterdistributedhardware_fuzzer.h" - #include #include +#include "unregisterdistributedhardware_fuzzer.h" #include "dscreen_constants.h" #include "dscreen_source_callback.h" #include "dscreen_source_proxy.h" +#include "fuzzer/FuzzedDataProvider.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { -void UnregisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +void UnregisterDistributedHardwareFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string reqId(dataProvider.ConsumeRandomLengthString()); - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { return; } - int32_t saId = *(reinterpret_cast(data)); + int32_t saId = dataProvider.ConsumeIntegral(); sptr remoteObject = samgr->GetSystemAbility(saId); if (remoteObject == nullptr) { return; @@ -51,11 +51,11 @@ void UnregisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) dscreenSourceProxy->UnregisterDistributedHardware(devId, dhId, reqId); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::UnregisterDistributedHardwareFuzzTest(data, size); diff --git a/screenhandler/test/fuzztest/pluginhardware_fuzzer/pluginhardware_fuzzer.cpp b/screenhandler/test/fuzztest/pluginhardware_fuzzer/pluginhardware_fuzzer.cpp index 3828bec443d508f7d84481ddb6b3b1e4b3d8ec13..13521106f6d7ac4ac3de0cfe255da506b131d3ab 100644 --- a/screenhandler/test/fuzztest/pluginhardware_fuzzer/pluginhardware_fuzzer.cpp +++ b/screenhandler/test/fuzztest/pluginhardware_fuzzer/pluginhardware_fuzzer.cpp @@ -13,35 +13,35 @@ * limitations under the License. */ -#include "pluginhardware_fuzzer.h" - #include #include +#include "pluginhardware_fuzzer.h" #include "dscreen_handler.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -void PluginHardwareFuzzTest(const uint8_t* data, size_t size) +void PluginHardwareFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string dhId(reinterpret_cast(data), size); - std::string attr(reinterpret_cast(data), size); - std::string subtype(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string attr(dataProvider.ConsumeRandomLengthString()); + std::string subtype(dataProvider.ConsumeRandomLengthString()); DScreenHandler::GetInstance().PluginHardware(dhId, attr, subtype); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::PluginHardwareFuzzTest(data, size); return 0; } - diff --git a/screenhandler/test/fuzztest/pluginhardware_fuzzer/project.xml b/screenhandler/test/fuzztest/pluginhardware_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/screenhandler/test/fuzztest/pluginhardware_fuzzer/project.xml +++ b/screenhandler/test/fuzztest/pluginhardware_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/screenhandler/test/fuzztest/registerpluginlistener_fuzzer/project.xml b/screenhandler/test/fuzztest/registerpluginlistener_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/screenhandler/test/fuzztest/registerpluginlistener_fuzzer/project.xml +++ b/screenhandler/test/fuzztest/registerpluginlistener_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/screenhandler/test/fuzztest/registerpluginlistener_fuzzer/registerpluginlistener_fuzzer.cpp b/screenhandler/test/fuzztest/registerpluginlistener_fuzzer/registerpluginlistener_fuzzer.cpp index 102c094d6f91868907db514f62b7fd6455c3a90e..1f54e58d9860d6090d2f543754abc619b1aaddfe 100644 --- a/screenhandler/test/fuzztest/registerpluginlistener_fuzzer/registerpluginlistener_fuzzer.cpp +++ b/screenhandler/test/fuzztest/registerpluginlistener_fuzzer/registerpluginlistener_fuzzer.cpp @@ -13,13 +13,13 @@ * limitations under the License. */ -#include "registerpluginlistener_fuzzer.h" - #include #include +#include "registerpluginlistener_fuzzer.h" #include "dscreen_handler.h" #include "device_type.h" +#include "fuzzer/FuzzedDataProvider.h" #include "ihardware_handler.h" namespace OHOS { @@ -34,9 +34,9 @@ public: void UnPluginHardware(const std::string &dhId) override {} }; -void RegisterPluginListenerFuzzTest(const uint8_t* data, size_t size) +void RegisterPluginListenerFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } @@ -54,7 +54,8 @@ void RegisterPluginListenerFuzzTest(const uint8_t* data, size_t size) dhTypeMap[i++] = DHType::MODEM; dhTypeMap[i++] = DHType::MAX_DH; - int32_t key = *(reinterpret_cast(data)) % static_cast(dhTypeMap.size()); + FuzzedDataProvider dataProvider(data, size); + int32_t key = dataProvider.ConsumeIntegral() % static_cast(dhTypeMap.size()); if (dhTypeMap.count(key) == 0) { return; } @@ -63,14 +64,13 @@ void RegisterPluginListenerFuzzTest(const uint8_t* data, size_t size) std::shared_ptr listener = std::make_shared(dhType); DScreenHandler::GetInstance().RegisterPluginListener(listener); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::RegisterPluginListenerFuzzTest(data, size); return 0; } - diff --git a/screenhandler/test/fuzztest/unpluginhardware_fuzzer/project.xml b/screenhandler/test/fuzztest/unpluginhardware_fuzzer/project.xml index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..c7a73115e50e3bf14e38a1c71c37336f85045334 100644 --- a/screenhandler/test/fuzztest/unpluginhardware_fuzzer/project.xml +++ b/screenhandler/test/fuzztest/unpluginhardware_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/screenhandler/test/fuzztest/unpluginhardware_fuzzer/unpluginhardware_fuzzer.cpp b/screenhandler/test/fuzztest/unpluginhardware_fuzzer/unpluginhardware_fuzzer.cpp index 71270d81d96515b1c335cb182c0519bc4e546fe7..7d9aacec602ac1baf1bb79c52448fb70de74d0bc 100644 --- a/screenhandler/test/fuzztest/unpluginhardware_fuzzer/unpluginhardware_fuzzer.cpp +++ b/screenhandler/test/fuzztest/unpluginhardware_fuzzer/unpluginhardware_fuzzer.cpp @@ -13,33 +13,33 @@ * limitations under the License. */ -#include "unpluginhardware_fuzzer.h" - #include #include +#include "unpluginhardware_fuzzer.h" #include "dscreen_handler.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -void UnPluginHardwareFuzzTest(const uint8_t* data, size_t size) +void UnPluginHardwareFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string dhId(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string dhId(dataProvider.ConsumeRandomLengthString()); DScreenHandler::GetInstance().UnPluginHardware(dhId); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::UnPluginHardwareFuzzTest(data, size); return 0; } - diff --git a/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/dscreensinkstub_fuzzer.cpp b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/dscreensinkstub_fuzzer.cpp index aa46f2dd976ad793be466270a6343e8dae622023..dc22a92d392272b25c9eb035990796a869484e4f 100644 --- a/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/dscreensinkstub_fuzzer.cpp +++ b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/dscreensinkstub_fuzzer.cpp @@ -14,8 +14,8 @@ */ #include "dscreensinkstub_fuzzer.h" - #include "dscreen_sink_stub.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { @@ -39,25 +39,26 @@ public: { return 0; }; - void DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) override {}; + void DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) override{}; }; - -void DscreenSinkStubFuzzTest(const uint8_t* data, size_t size) +void DscreenSinkStubFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } + FuzzedDataProvider dataProvider(data, size); + uint32_t code = dataProvider.ConsumeIntegral(); + uint32_t status = dataProvider.ConsumeIntegral(); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string reqId(dataProvider.ConsumeRandomLengthString()); + std::string dataStr(dataProvider.ConsumeRandomLengthString()); + MessageParcel pdata; MessageParcel reply; MessageOption option; - uint32_t code = *(reinterpret_cast(data)) % 2; - uint32_t status = *(reinterpret_cast(data)); - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); - std::string dataStr(reinterpret_cast(data), size); pdata.WriteInt32(status); pdata.WriteString(devId); pdata.WriteString(dhId); @@ -72,11 +73,11 @@ void DscreenSinkStubFuzzTest(const uint8_t* data, size_t size) sourceStubPtr->UnsubscribeDistributedHardwareInner(pdata, reply, option); sourceStubPtr->DScreenNotifyInner(pdata, reply, option); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::DscreenSinkStubFuzzTest(data, size); diff --git a/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/project.xml b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/project.xml index 7133b2b92440904a5ed04b838733acea0f97486a..93837373f31c924472b9b4ee2139348e97c1e470 100644 --- a/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/project.xml +++ b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp index 221aeab3cf2009be0507fd505ebcf08b2da45816..d15e8f41e5f4f961d07f176721126762980923c7 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp @@ -13,36 +13,39 @@ * limitations under the License. */ -#include "dscreenmanager_fuzzer.h" - #include #include +#include "dscreenmanager_fuzzer.h" #include "1.0/include/dscreen_manager.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { namespace V1_0 { -void OnChangeFuzzTest(const uint8_t* data, size_t size) +void OnChangeFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(uint64_t))) { + if ((data == nullptr) || (size == 0)) { return; } + + FuzzedDataProvider dataProvider(data, size); + uint64_t screenIdOne = dataProvider.ConsumeIntegral(); std::vector screenIds; - uint64_t screenIdOne = *(reinterpret_cast(data)); screenIds.emplace_back(screenIdOne); Rosen::ScreenGroupChangeEvent event = Rosen::ScreenGroupChangeEvent::ADD_TO_GROUP; DScreenGroupListener dScreenGroupListener; dScreenGroupListener.OnChange(screenIds, event); } -void HandleScreenChangeFuzzTest(const uint8_t* data, size_t size) +void HandleScreenChangeFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(uint32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - uint32_t eventValue = *(reinterpret_cast(data)) % 3; + FuzzedDataProvider dataProvider(data, size); + uint32_t eventValue = dataProvider.ConsumeIntegral() % 3; if ((eventValue != static_cast(Rosen::ScreenGroupChangeEvent::ADD_TO_GROUP)) || (eventValue != static_cast(Rosen::ScreenGroupChangeEvent::REMOVE_FROM_GROUP)) || (eventValue != static_cast(Rosen::ScreenGroupChangeEvent::CHANGE_GROUP))) { @@ -57,13 +60,14 @@ void HandleScreenChangeFuzzTest(const uint8_t* data, size_t size) dscreenManager->HandleScreenChange(dScreen, event); } -void AddToGroupFuzzTest(const uint8_t* data, size_t size) +void AddToGroupFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(uint64_t))) { + if ((data == nullptr) || (size == 0)) { return; } - uint64_t screenId = *(reinterpret_cast(data)); + FuzzedDataProvider dataProvider(data, size); + uint64_t screenId = dataProvider.ConsumeIntegral(); std::shared_ptr dScreenCallback = std::make_shared(); std::shared_ptr dScreen = std::make_shared("devId000", "dhId000", dScreenCallback); @@ -72,15 +76,16 @@ void AddToGroupFuzzTest(const uint8_t* data, size_t size) dscreenManager->RemoveFromGroup(dScreen, screenId); } -void DScreenCallbackOnRegResultFuzzTest(const uint8_t* data, size_t size) +void DScreenCallbackOnRegResultFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - std::string screenId(reinterpret_cast(data), size); - int32_t status = *(reinterpret_cast(data)); - std::string dataStr(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string screenId(dataProvider.ConsumeRandomLengthString()); + int32_t status = dataProvider.ConsumeIntegral(); + std::string dataStr(dataProvider.ConsumeRandomLengthString()); std::shared_ptr dScreenCallback = std::make_shared(); std::shared_ptr dScreen = std::make_shared("devId000", "dhId000", dScreenCallback); @@ -88,15 +93,16 @@ void DScreenCallbackOnRegResultFuzzTest(const uint8_t* data, size_t size) dScreenCallback->OnUnregResult(dScreen, screenId, status, dataStr); } -void DScreenManagerOnUnregResultFuzzTest(const uint8_t* data, size_t size) +void DScreenManagerOnUnregResultFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - std::string reqId(reinterpret_cast(data), size); - int32_t status = *(reinterpret_cast(data)); - std::string dataStr(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string reqId(dataProvider.ConsumeRandomLengthString()); + int32_t status = dataProvider.ConsumeIntegral(); + std::string dataStr(dataProvider.ConsumeRandomLengthString()); std::shared_ptr dScreenCallback = std::make_shared(); std::shared_ptr dScreen = std::make_shared("devId000", "dhId000", dScreenCallback); @@ -105,39 +111,40 @@ void DScreenManagerOnUnregResultFuzzTest(const uint8_t* data, size_t size) dscreenManager->OnUnregResult(dScreen, reqId, status, dataStr); } -void NotifyRemoteScreenServiceFuzzTest(const uint8_t* data, size_t size) +void NotifyRemoteScreenServiceFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - std::string devId(reinterpret_cast(data), size); - int32_t eventCode = *(reinterpret_cast(data)); - std::string eventContent(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + int32_t eventCode = dataProvider.ConsumeIntegral(); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string eventContent(dataProvider.ConsumeRandomLengthString()); std::shared_ptr dscreenManager = std::make_shared(); dscreenManager->NotifyRemoteScreenService(devId, eventCode, eventContent); } -void HandleNotifySetUpResultFuzzTest(const uint8_t* data, size_t size) +void HandleNotifySetUpResultFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; } - std::string remoteDevId(reinterpret_cast(data), size); - std::string eventContent(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string remoteDevId(dataProvider.ConsumeRandomLengthString()); + std::string eventContent(dataProvider.ConsumeRandomLengthString()); std::shared_ptr dscreenManager = std::make_shared(); dscreenManager->HandleNotifySetUpResult(remoteDevId, eventContent); } - -} // namespace V1_0 -} // namespace DistributedHardware -} // namespace OHOS +} // namespace V1_0 +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::V1_0::OnChangeFuzzTest(data, size); diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/project.xml b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/project.xml index 4fdbc407f205680885fa42663163b5c987f123a6..dca0b2a0aec9fea8bdf0151dad6ec8b1acc1fc50 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/project.xml +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/dscreensourcecallbackproxy_fuzzer.cpp b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/dscreensourcecallbackproxy_fuzzer.cpp index 1d181f55aa953b93cd86a19e4e3d2c78d38edbbc..d022fcd74fa8a2454149c6a30a84353f1f84cf7c 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/dscreensourcecallbackproxy_fuzzer.cpp +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/dscreensourcecallbackproxy_fuzzer.cpp @@ -14,11 +14,11 @@ */ #include "dscreensourcecallbackproxy_fuzzer.h" - -#include "idscreen_source.h" #include "dscreen_source_callback_proxy.h" -#include "idscreen_source.h" #include "dscreen_source_stub.h" +#include "fuzzer/FuzzedDataProvider.h" +#include "idscreen_source.h" +#include "idscreen_source.h" namespace OHOS { namespace DistributedHardware { @@ -56,14 +56,16 @@ public: void DscreenSourceCallbackProxyFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - int32_t status = *(reinterpret_cast(data)); - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); - std::string resultData(reinterpret_cast(data), size); + + FuzzedDataProvider dataProvider(data, size); + int32_t status = dataProvider.ConsumeIntegral(); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string reqId(dataProvider.ConsumeRandomLengthString()); + std::string resultData(dataProvider.ConsumeRandomLengthString()); sptr dscreenSourceStubPtr(new DScreenSourceStubFuzzTest()); sptr sourceCbkProxy(new DScreenSourceCallbackProxy(dscreenSourceStubPtr)); diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/project.xml b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/project.xml index 7133b2b92440904a5ed04b838733acea0f97486a..93837373f31c924472b9b4ee2139348e97c1e470 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/project.xml +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/dscreensourceservice_fuzzer.cpp b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/dscreensourceservice_fuzzer.cpp index 1ce49e5c701a4683f7beddbf19df47f74ff0204e..36873648941f285b680be841a771cae350cd6943 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/dscreensourceservice_fuzzer.cpp +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/dscreensourceservice_fuzzer.cpp @@ -14,31 +14,32 @@ */ #include "dscreensourceservice_fuzzer.h" - -#include "string_ex.h" -#include "idscreen_source.h" -#include "dscreen_source_service.h" #include "dscreen_source_callback.h" +#include "dscreen_source_service.h" +#include "fuzzer/FuzzedDataProvider.h" +#include "idscreen_source.h" +#include "string_ex.h" namespace OHOS { namespace DistributedHardware { const std::u16string ABILITYMGR_INTERFACE_TOKEN = u"ohos.aafwk.AbilityManager"; -void DscreenSourceServiceFuzzTest(const uint8_t* data, size_t size) +void DscreenSourceServiceFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } - std::string version(reinterpret_cast(data), size); + FuzzedDataProvider dataProvider(data, size); + std::string version(dataProvider.ConsumeRandomLengthString()); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string reqId(dataProvider.ConsumeRandomLengthString()); + std::string eventContent(dataProvider.ConsumeRandomLengthString()); + std::string params(dataProvider.ConsumeRandomLengthString()); EnableParam param; param.sinkVersion = version; param.sinkAttrs = ""; uint32_t eventCode = 1; - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); - std::string eventContent(reinterpret_cast(data), size); - std::string params(reinterpret_cast(data), size); std::shared_ptr sourceServicePtr = std::make_shared(0, false); sptr callback(new DScreenSourceCallback()); sourceServicePtr->registerToService_ = true; @@ -49,11 +50,11 @@ void DscreenSourceServiceFuzzTest(const uint8_t* data, size_t size) sourceServicePtr->UnregisterDistributedHardware(devId, dhId, reqId); sourceServicePtr->ReleaseSource(); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::DscreenSourceServiceFuzzTest(data, size); diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/project.xml b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/project.xml index 7133b2b92440904a5ed04b838733acea0f97486a..93837373f31c924472b9b4ee2139348e97c1e470 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/project.xml +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.cpp b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.cpp index dfa85aacb1e415108a33191214a57339cbc89ecc..8b9255daba755d41cc8a5c2396d95cea6cd707cd 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.cpp +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.cpp @@ -14,9 +14,9 @@ */ #include "dscreensourcestub_fuzzer.h" - -#include "idscreen_source.h" #include "dscreen_source_stub.h" +#include "fuzzer/FuzzedDataProvider.h" +#include "idscreen_source.h" namespace OHOS { namespace DistributedHardware { @@ -32,8 +32,8 @@ public: { return 0; }; - int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId, - const EnableParam ¶m, const std::string &reqId) override + int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId, const EnableParam ¶m, + const std::string &reqId) override { return 0; }; @@ -42,33 +42,33 @@ public: { return 0; }; - int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, - const std::string &key, const std::string &value) override + int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, + const std::string &value) override { return 0; }; - void DScreenNotify(const std::string &devId, int32_t eventCode, - const std::string &eventContent) override {}; + void DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) override{}; }; - -void DscreenSourceStubFuzzTest(const uint8_t* data, size_t size) +void DscreenSourceStubFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size == 0)) { return; } + FuzzedDataProvider dataProvider(data, size); + uint32_t code = dataProvider.ConsumeIntegral(); + uint32_t status = dataProvider.ConsumeIntegral(); + std::string dhId(dataProvider.ConsumeRandomLengthString()); + std::string devId(dataProvider.ConsumeRandomLengthString()); + std::string reqId(dataProvider.ConsumeRandomLengthString()); + std::string dataStr(dataProvider.ConsumeRandomLengthString()); + std::string version(dataProvider.ConsumeRandomLengthString()); + std::string attrs(dataProvider.ConsumeRandomLengthString()); + MessageParcel pdata; MessageParcel reply; MessageOption option; - uint32_t code = *(reinterpret_cast(data)) % 2; - uint32_t status = *(reinterpret_cast(data)); - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); - std::string dataStr(reinterpret_cast(data), size); - std::string version(reinterpret_cast(data), size); - std::string attrs(reinterpret_cast(data), size); pdata.WriteInt32(status); pdata.WriteString(devId); pdata.WriteString(dhId); @@ -86,11 +86,11 @@ void DscreenSourceStubFuzzTest(const uint8_t* data, size_t size) sourceStubPtr->CheckRegParams(devId, dhId, version, attrs, reqId); sourceStubPtr->CheckUnregParams(devId, dhId, reqId); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::DscreenSourceStubFuzzTest(data, size); diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/project.xml b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/project.xml index 7133b2b92440904a5ed04b838733acea0f97486a..93837373f31c924472b9b4ee2139348e97c1e470 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/project.xml +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/onerror_fuzzer.cpp b/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/onerror_fuzzer.cpp index 5cceea38bdb126e67e698da62fbd9802305c0400..4881efc2755753a5d480b339cc241b98b11d0e51 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/onerror_fuzzer.cpp +++ b/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/onerror_fuzzer.cpp @@ -13,42 +13,44 @@ * limitations under the License. */ -#include "onerror_fuzzer.h" - #include +#include "onerror_fuzzer.h" #include "avcodec_common.h" +#include "avcodec_errors.h" #include "dscreen_constants.h" -#include "meta/format.h" +#include "fuzzer/FuzzedDataProvider.h" #include "iimage_source_processor_listener.h" -#include "image_source_encoder.h" #include "image_encoder_callback.h" +#include "image_source_encoder.h" #include "iscreen_channel_listener.h" -#include "avcodec_errors.h" +#include "meta/format.h" #include "screen_source_trans.h" namespace OHOS { namespace DistributedHardware { -void OnErrorFuzzTest(const uint8_t* data, size_t size) +void OnErrorFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < (sizeof(int32_t)))) { + if ((data == nullptr) || (size == 0)) { return; } + + FuzzedDataProvider dataProvider(data, size); + int32_t errorCode = dataProvider.ConsumeIntegral(); + std::shared_ptr listener = std::make_shared(); std::shared_ptr encoder = std::make_shared(listener); std::shared_ptr encoderCallback = std::make_shared(encoder); - int32_t errorCode = *(reinterpret_cast(data)); MediaAVCodec::AVCodecErrorType errorType = MediaAVCodec::AVCODEC_ERROR_INTERNAL; encoderCallback->OnError(errorType, errorCode); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::OnErrorFuzzTest(data, size); return 0; } - diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/project.xml b/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/project.xml index 4fdbc407f205680885fa42663163b5c987f123a6..dca0b2a0aec9fea8bdf0151dad6ec8b1acc1fc50 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/project.xml +++ b/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/oninputbufferavailable_fuzzer.cpp b/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/oninputbufferavailable_fuzzer.cpp index 0d84a9aad4dfdd68d9a4e2a4ab960c43a43d5889..7d16da6dcbf997db329c430f2eebcfcf3941edf8 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/oninputbufferavailable_fuzzer.cpp +++ b/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/oninputbufferavailable_fuzzer.cpp @@ -13,37 +13,39 @@ * limitations under the License. */ -#include "oninputbufferavailable_fuzzer.h" - #include +#include "oninputbufferavailable_fuzzer.h" #include "avcodec_common.h" -#include "meta/format.h" +#include "fuzzer/FuzzedDataProvider.h" #include "image_encoder_callback.h" +#include "meta/format.h" #include "screen_source_trans.h" namespace OHOS { namespace DistributedHardware { -void OnInputBufferAvailableFuzzTest(const uint8_t* data, size_t size) +void OnInputBufferAvailableFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < (sizeof(uint32_t)))) { + if ((data == nullptr) || (size == 0)) { return; } + + FuzzedDataProvider dataProvider(data, size); + uint32_t index = dataProvider.ConsumeIntegral(); + std::shared_ptr listener = std::make_shared(); std::shared_ptr encoder = std::make_shared(listener); std::shared_ptr encoderCallback = std::make_shared(encoder); - uint32_t index = *(reinterpret_cast(data)); std::shared_ptr buffer = nullptr; encoderCallback->OnInputBufferAvailable(index, buffer); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::OnInputBufferAvailableFuzzTest(data, size); return 0; } - diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/project.xml b/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/project.xml index 4fdbc407f205680885fa42663163b5c987f123a6..dca0b2a0aec9fea8bdf0151dad6ec8b1acc1fc50 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/project.xml +++ b/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300 diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/onoutputbufferavailable_fuzzer.cpp b/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/onoutputbufferavailable_fuzzer.cpp index bf6d573554611df4debaad83a57760662027d57c..db6e9146f9daa962c603c7eee097706ea5c3d896 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/onoutputbufferavailable_fuzzer.cpp +++ b/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/onoutputbufferavailable_fuzzer.cpp @@ -13,39 +13,41 @@ * limitations under the License. */ -#include "onoutputbufferavailable_fuzzer.h" - #include +#include "onoutputbufferavailable_fuzzer.h" #include "avcodec_common.h" -#include "meta/format.h" +#include "fuzzer/FuzzedDataProvider.h" #include "image_encoder_callback.h" +#include "meta/format.h" #include "screen_source_trans.h" namespace OHOS { namespace DistributedHardware { -void OnOutputBufferAvailableFuzzTest(const uint8_t* data, size_t size) +void OnOutputBufferAvailableFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < (sizeof(uint32_t)))) { + if ((data == nullptr) || (size == 0)) { return; } + + FuzzedDataProvider dataProvider(data, size); + uint32_t index = dataProvider.ConsumeIntegral(); + std::shared_ptr listener = std::make_shared(); std::shared_ptr encoder = std::make_shared(listener); std::shared_ptr encoderCallback = std::make_shared(encoder); - uint32_t index = *(reinterpret_cast(data)); MediaAVCodec::AVCodecBufferInfo info; MediaAVCodec::AVCodecBufferFlag flag = MediaAVCodec::AVCODEC_BUFFER_FLAG_NONE; std::shared_ptr buffer = nullptr; encoderCallback->OnOutputBufferAvailable(index, info, flag, buffer); } -} // namespace DistributedHardware -} // namespace OHOS +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(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::OnOutputBufferAvailableFuzzTest(data, size); return 0; } - diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/project.xml b/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/project.xml index 4fdbc407f205680885fa42663163b5c987f123a6..dca0b2a0aec9fea8bdf0151dad6ec8b1acc1fc50 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/project.xml +++ b/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 10000 300