diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/callbackonnotifyresourceinfo_fuzzer/callbackonnotifyresourceinfo_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/callbackonnotifyresourceinfo_fuzzer/callbackonnotifyresourceinfo_fuzzer.cpp index cad43507dd3a01ca98dfc8f3b9d2ef7c09ff6dbe..deb0b36e50d1db49f343ec42cb55574c6d1866a5 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/callbackonnotifyresourceinfo_fuzzer/callbackonnotifyresourceinfo_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/callbackonnotifyresourceinfo_fuzzer/callbackonnotifyresourceinfo_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,16 +14,15 @@ */ #include "callbackonnotifyresourceinfo_fuzzer.h" - #include "dcamera_sink_callback.h" #include "distributed_camera_constants.h" #include "mock_component_resourceinfo.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -const uint32_t DC_RESOURCE_VALUE = 2; -const uint32_t DC_RESOURCE_SIZE = 3; -const ResourceEventType resourceEventType[DC_RESOURCE_SIZE] { + +const ResourceEventType VALID_EVENT_TYPES[] = { ResourceEventType::EVENT_TYPE_QUERY_RESOURCE, ResourceEventType::EVENT_TYPE_PULL_UP_PAGE, ResourceEventType::EVENT_TYPE_CLOSE_PAGE @@ -31,14 +30,14 @@ const ResourceEventType resourceEventType[DC_RESOURCE_SIZE] { void CallbackOnNotifyResourceInfoFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - ResourceEventType type = resourceEventType[data[0] % DC_RESOURCE_SIZE]; - std::string subtype(reinterpret_cast(data), size); - std::string networkId(reinterpret_cast(data), size); - bool isSensitive = data[0] % DC_RESOURCE_VALUE; - bool isSameAccout = data[0] % DC_RESOURCE_VALUE; + FuzzedDataProvider fdp(data, size); + + ResourceEventType type = fdp.PickValueInArray(VALID_EVENT_TYPES); + std::string subtype = fdp.ConsumeRandomLengthString(); + std::string networkId = fdp.ConsumeRandomLengthString(); + bool isSensitive = fdp.ConsumeBool(); + bool isSameAccout = fdp.ConsumeBool(); + std::shared_ptr callback = std::make_shared(); sptr dcameraSinkCallback(new (std::nothrow) DCameraSinkCallback()); @@ -51,10 +50,8 @@ void CallbackOnNotifyResourceInfoFuzzTest(const uint8_t* data, size_t size) } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::CallbackOnNotifyResourceInfoFuzzTest(data, size); return 0; } diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/encodeoninputbufferavailable_fuzzer/encodeoninputbufferavailable_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/encodeoninputbufferavailable_fuzzer/encodeoninputbufferavailable_fuzzer.cpp index 9d4d969c952f0ccfdd891317a3b7fdb2e60bd031..23e861dc8d3a7f8db252c655c0ce4f86690794fc 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/encodeoninputbufferavailable_fuzzer/encodeoninputbufferavailable_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/encodeoninputbufferavailable_fuzzer/encodeoninputbufferavailable_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,33 +14,30 @@ */ #include "encodeoninputbufferavailable_fuzzer.h" - #include "encode_video_callback.h" +#include "fuzzer/FuzzedDataProvider.h" +#include namespace OHOS { namespace DistributedHardware { void EncodeOnInputBufferAvailableFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(uint32_t))) { - return; - } + FuzzedDataProvider fdp(data, size); + + uint32_t index = fdp.ConsumeIntegral(); - uint32_t index = *(reinterpret_cast(data)); std::shared_ptr sinkPipeline = std::make_shared(); std::shared_ptr encodeDataProcess = std::make_shared(sinkPipeline); std::shared_ptr encodeVideoCallback = std::make_shared(encodeDataProcess); - std::shared_ptr buffer = nullptr; + std::shared_ptr buffer; encodeVideoCallback->OnInputBufferAvailable(index, buffer); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::EncodeOnInputBufferAvailableFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerinitsink_fuzzer/sinkhandlerinitsink_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerinitsink_fuzzer/sinkhandlerinitsink_fuzzer.cpp index b207fecb0858205408861eb3d4aa7e47c6178e29..ecb54dfa3af9c03c2c7c57b73f94ab1e77b6b222 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerinitsink_fuzzer/sinkhandlerinitsink_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerinitsink_fuzzer/sinkhandlerinitsink_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,6 +17,7 @@ #include #include +#include "fuzzer/FuzzedDataProvider.h" #include "dcamera_sink_handler.h" #include "distributed_camera_constants.h" @@ -28,10 +29,9 @@ namespace OHOS { namespace DistributedHardware { void SinkHandlerInitSinkFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - std::string params(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + + std::string params = fdp.ConsumeRemainingBytesAsString(); DCameraSinkHandler::GetInstance().InitSink(params); } @@ -41,8 +41,6 @@ void SinkHandlerInitSinkFuzzTest(const uint8_t* data, size_t size) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkHandlerInitSinkFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.cpp index da2e2dc106646b1f0892be9e2be204d493a8a21b..f50fbfd6494e6aa86152ce89af841e91d201a6a0 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,18 +14,17 @@ */ #include "sinkhandlerpausedistributedhardware_fuzzer.h" - #include "dcamera_sink_handler.h" #include "distributed_camera_constants.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SinkHandlerPauseDistributedHardwareFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - std::string networkId(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + + std::string networkId = fdp.ConsumeRemainingBytesAsString(); DCameraSinkHandler::GetInstance().PauseDistributedHardware(networkId); } @@ -35,8 +34,6 @@ void SinkHandlerPauseDistributedHardwareFuzzTest(const uint8_t* data, size_t siz /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkHandlerPauseDistributedHardwareFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp index 7a646d9f5d1d9954c24f87b1557db9eb0012f7da..acaa42cf1a344ea446711bc4727f9894389cf8f7 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,30 +14,29 @@ */ #include "sinkhandlerregisterprivacyresources_fuzzer.h" - #include "dcamera_sink_handler.h" #include "distributed_camera_constants.h" #include "mock_component_resourceinfo.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SinkHandlerRegisterPrivacyResourcesFuzzTest(const uint8_t* data, size_t size) { - if (data == nullptr) { - return; - } - std::shared_ptr callback = std::make_shared(); + FuzzedDataProvider fdp(data, size); + const size_t maxRegistrations = 5; + size_t numRegistrations = fdp.ConsumeIntegralInRange(0, maxRegistrations); - DCameraSinkHandler::GetInstance().RegisterPrivacyResources(callback); + for (size_t i = 0; i < numRegistrations; ++i) { + std::shared_ptr callback = std::make_shared(); + DCameraSinkHandler::GetInstance().RegisterPrivacyResources(callback); + } } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkHandlerRegisterPrivacyResourcesFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.cpp index 00e51a1a2160664b3efd8926d1ed056ea38c1f22..c4a1ccdfb4e03dd5671d550452822c93225fbc9c 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,26 +17,23 @@ #include "dcamera_sink_handler.h" #include "distributed_camera_constants.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SinkHandlerResumeDistributedHardwareFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - std::string networkId(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + + std::string networkId = fdp.ConsumeRemainingBytesAsString(); DCameraSinkHandler::GetInstance().ResumeDistributedHardware(networkId); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkHandlerResumeDistributedHardwareFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.cpp index b13ae3d9b31d55e08e6ac6be60c3c316e1163120..86465dc722ee9eb4fbfefd58f6c80024c3b5584a 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,29 +14,25 @@ */ #include "sinkhandlerstopdistributedhardware_fuzzer.h" - #include "dcamera_sink_handler.h" #include "distributed_camera_constants.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SinkHandlerStopDistributedHardwareFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - std::string networkId(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + + std::string networkId = fdp.ConsumeRemainingBytesAsString(); DCameraSinkHandler::GetInstance().StopDistributedHardware(networkId); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkHandlerStopDistributedHardwareFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlersubscribelocalhardware_fuzzer/sinkhandlersubscribelocalhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlersubscribelocalhardware_fuzzer/sinkhandlersubscribelocalhardware_fuzzer.cpp index 36128b37c95a31b9fdb36e12e9543d93a0cdcb66..1c3931bd7dbb78fdc59cebfd8bd2cbcdaaf5a039 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlersubscribelocalhardware_fuzzer/sinkhandlersubscribelocalhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlersubscribelocalhardware_fuzzer/sinkhandlersubscribelocalhardware_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -22,28 +22,24 @@ #include "distributed_camera_constants.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" - +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SinkHandlerSubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - std::string param(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string param = fdp.ConsumeRemainingBytesAsString(); DCameraSinkHandler::GetInstance().SubscribeLocalHardware(dhId, param); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkHandlerSubscribeLocalHardwareFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/sinkhandlerunsubscribelocalhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/sinkhandlerunsubscribelocalhardware_fuzzer.cpp index 9684a8f6a83ca694f4ff2bf04a55330ea503d55f..28b484ca951ac3979f69fda46a2d1348e6617ebd 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/sinkhandlerunsubscribelocalhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/sinkhandlerunsubscribelocalhardware_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,32 +17,29 @@ #include #include +#include #include "dcamera_sink_handler.h" #include "distributed_camera_constants.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SinkHandlerUnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - std::string dhId(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + std::string dhId = fdp.ConsumeRemainingBytesAsString(); DCameraSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkHandlerUnsubscribeLocalHardwareFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkonloadsystemabilityfail_fuzzer/sinkonloadsystemabilityfail_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkonloadsystemabilityfail_fuzzer/sinkonloadsystemabilityfail_fuzzer.cpp index eef0b392afc230485a190891cd46a814b5eb94a3..5da8d739ccde7a9d48c4bb2dc7884eb560e0c054 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkonloadsystemabilityfail_fuzzer/sinkonloadsystemabilityfail_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkonloadsystemabilityfail_fuzzer/sinkonloadsystemabilityfail_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,7 +14,7 @@ */ #include "sinkonloadsystemabilityfail_fuzzer.h" - +#include "fuzzer/FuzzedDataProvider.h" #include #include @@ -28,11 +28,10 @@ namespace OHOS { namespace DistributedHardware { void SinkOnLoadSystemAbilityFailFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - int32_t systemAbilityId = *(reinterpret_cast(data)); - std::string params(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + + int32_t systemAbilityId = fdp.ConsumeIntegral(); + std::string params = fdp.ConsumeRemainingBytesAsString(); std::shared_ptr callback = std::make_shared(params); callback->OnLoadSystemAbilityFail(systemAbilityId); @@ -40,10 +39,8 @@ void SinkOnLoadSystemAbilityFailFuzzTest(const uint8_t* data, size_t size) } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkOnLoadSystemAbilityFailFuzzTest(data, size); return 0; } \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/sinkproxychannelneg_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/sinkproxychannelneg_fuzzer.cpp index d4dd02557dea9034324ee9bc1d9cfc7e0da2c2cf..08a3c9b2170eaac9c62ca4041c27e5f8d64c1b50 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/sinkproxychannelneg_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/sinkproxychannelneg_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,9 +14,10 @@ */ #include "sinkproxychannelneg_fuzzer.h" - +#include "fuzzer/FuzzedDataProvider.h" #include #include +#include #include "distributed_camera_constants.h" #include "distributed_camera_sink_proxy.h" @@ -27,12 +28,10 @@ namespace OHOS { namespace DistributedHardware { void SinkProxyChannelNegFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } + FuzzedDataProvider fdp(data, size); - std::string dhId(reinterpret_cast(data), size); - std::string channelInfo(reinterpret_cast(data), size); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string channelInfo = fdp.ConsumeRemainingBytesAsString(); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -40,6 +39,9 @@ void SinkProxyChannelNegFuzzTest(const uint8_t* data, size_t size) return; } sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); + if (remoteObject == nullptr) { + return; + } std::shared_ptr dCSinkProxy = std::make_shared(remoteObject); @@ -48,11 +50,8 @@ void SinkProxyChannelNegFuzzTest(const uint8_t* data, size_t size) } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkProxyChannelNegFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/sinkproxyclosechannel_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/sinkproxyclosechannel_fuzzer.cpp index f1ac84dd67e731500d974e86ba4bfb3cd1c99f9c..84317daae31f270e30499db0e382775029fb0e2c 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/sinkproxyclosechannel_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/sinkproxyclosechannel_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -22,15 +22,15 @@ #include "distributed_camera_sink_proxy.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SinkProxyCloseChannelFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - std::string dhId(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + + std::string dhId = fdp.ConsumeRemainingBytesAsString(); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -46,11 +46,8 @@ void SinkProxyCloseChannelFuzzTest(const uint8_t* data, size_t size) } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkProxyCloseChannelFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/sinkproxyopenchannel_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/sinkproxyopenchannel_fuzzer.cpp index 4d3bef6db7f6b44adbda2170ec7a97a9ba5c8655..661a1633e108de496aa06b0b6ee234cd978920e1 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/sinkproxyopenchannel_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/sinkproxyopenchannel_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -22,17 +22,16 @@ #include "distributed_camera_sink_proxy.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SinkProxyOpenChannelFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } + FuzzedDataProvider fdp(data, size); - std::string dhId(reinterpret_cast(data), size); - std::string openInfo(reinterpret_cast(data), size); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string openInfo = fdp.ConsumeRemainingBytesAsString(); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -48,11 +47,8 @@ void SinkProxyOpenChannelFuzzTest(const uint8_t* data, size_t size) } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkProxyOpenChannelFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyreleasesink_fuzzer/sinkproxyreleasesink_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyreleasesink_fuzzer/sinkproxyreleasesink_fuzzer.cpp index b3d29b04c956f91a17c3b52ed365064d547a969d..350ae517f8e353d2dd320a92e501e5759926f0b4 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyreleasesink_fuzzer/sinkproxyreleasesink_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyreleasesink_fuzzer/sinkproxyreleasesink_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,14 +23,13 @@ #include "distributed_camera_sink_proxy.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SinkProxyReleaseSinkFuzzTest(const uint8_t* data, size_t size) { - if (data == nullptr) { - return; - } + FuzzedDataProvider fdp(data, size); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -40,16 +39,16 @@ void SinkProxyReleaseSinkFuzzTest(const uint8_t* data, size_t size) sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); std::shared_ptr dCSinkProxy = std::make_shared(remoteObject); + + fdp.ConsumeRemainingBytes(); + dCSinkProxy->ReleaseSink(); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkProxyReleaseSinkFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxysubscribelocalhardware_fuzzer/sinkproxysubscribelocalhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxysubscribelocalhardware_fuzzer/sinkproxysubscribelocalhardware_fuzzer.cpp index 653940498138a6a3676628ff98b35f190c201cb3..1a600f5fb73ea28c631aa83d4d9049acd03ab393 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxysubscribelocalhardware_fuzzer/sinkproxysubscribelocalhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxysubscribelocalhardware_fuzzer/sinkproxysubscribelocalhardware_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,9 +14,12 @@ */ #include "sinkproxysubscribelocalhardware_fuzzer.h" +#include "fuzzer/FuzzedDataProvider.h" #include #include +#include +#include #include "distributed_camera_constants.h" #include "distributed_camera_sink_proxy.h" @@ -27,12 +30,12 @@ namespace OHOS { namespace DistributedHardware { void SinkProxySubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } + FuzzedDataProvider fdp(data, size); - std::string params(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); + size_t dhIdLen = fdp.ConsumeIntegralInRange(0, fdp.remaining_bytes()); + std::string dhId = fdp.ConsumeBytesAsString(dhIdLen); + + std::string params = fdp.ConsumeRemainingBytesAsString(); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -40,6 +43,9 @@ void SinkProxySubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) return; } sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); + if (remoteObject == nullptr) { + return; + } std::shared_ptr dCSinkProxy = std::make_shared(remoteObject); @@ -48,11 +54,8 @@ void SinkProxySubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkProxySubscribeLocalHardwareFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/sinkservicechannelneg_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/sinkservicechannelneg_fuzzer.cpp index 0a5996df154835b562463aac79e823803d611069..51df3abc69c2407a513021e59939731bfd8f5b06 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/sinkservicechannelneg_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/sinkservicechannelneg_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,9 +14,11 @@ */ #include "sinkservicechannelneg_fuzzer.h" +#include "fuzzer/FuzzedDataProvider.h" #include #include +#include #include "dcamera_sink_callback.h" #include "distributed_camera_constants.h" @@ -28,12 +30,11 @@ namespace OHOS { namespace DistributedHardware { void SinkServiceChannelNegFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } + FuzzedDataProvider fdp(data, size); - std::string dhId = "1"; - std::string channelInfo(reinterpret_cast(data), size); + std::string dhId = fdp.ConsumeBytesAsString(fdp.ConsumeIntegralInRange(1, 64)); + + std::string channelInfo = fdp.ConsumeRemainingBytesAsString(); std::shared_ptr sinkService = std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); @@ -45,11 +46,8 @@ void SinkServiceChannelNegFuzzTest(const uint8_t* data, size_t size) } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkServiceChannelNegFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/sinkserviceclosechannel_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/sinkserviceclosechannel_fuzzer.cpp index e00bc19ce1b5e5371b59202e762d232963142e30..6ee8ab429eec393fb5744f4a88a017de8a089c16 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/sinkserviceclosechannel_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/sinkserviceclosechannel_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,6 +17,7 @@ #include #include +#include "fuzzer/FuzzedDataProvider.h" #include "dcamera_sink_controller.h" #include "dcamera_sink_access_control.h" @@ -25,15 +26,16 @@ #include "distributed_camera_sink_service.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" +#include +#include namespace OHOS { namespace DistributedHardware { void SinkServiceCloseChannelFuzzTest(const uint8_t* data, size_t size) { - if (data == nullptr) { - return; - } - std::string dhId = "1"; + FuzzedDataProvider fdp(data, size); + + std::string dhId = fdp.ConsumeRandomLengthString(fdp.ConsumeIntegralInRange(1, 128)); std::shared_ptr sinkService = std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); @@ -47,11 +49,8 @@ void SinkServiceCloseChannelFuzzTest(const uint8_t* data, size_t size) } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkServiceCloseChannelFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicedump_fuzzer/sinkservicedump_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicedump_fuzzer/sinkservicedump_fuzzer.cpp index 744af481e3244754af61739786c1acacbc14aab5..a73fea31c894115f4fe96a014bb81d3d653a184d 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicedump_fuzzer/sinkservicedump_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicedump_fuzzer/sinkservicedump_fuzzer.cpp @@ -20,24 +20,32 @@ #include #include #include - +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SinkServiceDumpFuzzTest(const uint8_t* data, size_t size) { - if (data == nullptr || size == 0) { - return; + FuzzedDataProvider fdp(data, size); + + int fd = fdp.ConsumeIntegral(); + + std::vector args; + int numArgs = fdp.ConsumeIntegralInRange(0, 5); + for (int i = 0; i < numArgs; ++i) { + std::string s = fdp.ConsumeRandomLengthString(); + std::u16string u16s; + u16s.reserve(s.length()); + for (char c : s) { + u16s.push_back(static_cast(c)); + } + args.push_back(u16s); } + auto sinkService = std::make_shared( DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); - - std::vector args; - std::u16string arg(reinterpret_cast(data), size / sizeof(char16_t)); - if (arg.empty() || std::all_of(arg.begin(), arg.end(), [](char16_t c) { return c == 0; })) { + if (sinkService == nullptr) { return; } - args.push_back(arg); - int fd = STDOUT_FILENO; sinkService->Dump(fd, args); } diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicegetcamerainfo_fuzzer/sinkservicegetcamerainfo_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicegetcamerainfo_fuzzer/sinkservicegetcamerainfo_fuzzer.cpp index b602abfb368dfa3d1e80093dea636a3524c08466..e23df78db5c5163cf5ed86d896cc43894cbe2e58 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicegetcamerainfo_fuzzer/sinkservicegetcamerainfo_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicegetcamerainfo_fuzzer/sinkservicegetcamerainfo_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,9 +14,11 @@ */ #include "sinkservicegetcamerainfo_fuzzer.h" - +#include "fuzzer/FuzzedDataProvider.h" #include #include +#include +#include #include "dcamera_sink_controller.h" #include "dcamera_sink_access_control.h" @@ -28,22 +30,26 @@ namespace OHOS { namespace DistributedHardware { + +const size_t MAX_FUZZ_STRING_LENGTH = 1024; + void SinkServiceGetCameraInfoFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } + FuzzedDataProvider fdp(data, size); - std::string dhId = "1"; - std::string cameraInfo(reinterpret_cast(data), size); + std::string dhId = fdp.ConsumeRandomLengthString(MAX_FUZZ_STRING_LENGTH); + std::string cameraInfo = fdp.ConsumeRemainingBytesAsString(); + bool isDistributed = fdp.ConsumeBool(); std::shared_ptr sinkService = - std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); + std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, isDistributed); sptr sinkCallback(new DCameraSinkCallback()); std::shared_ptr sinkDevice = std::make_shared(dhId, sinkCallback); sinkDevice->accessControl_ = std::make_shared(); sinkDevice->controller_ = std::make_shared(sinkDevice->accessControl_, sinkCallback); + sinkService->camerasMap_.emplace(dhId, sinkDevice); + sinkService->GetCameraInfo(dhId, cameraInfo); sinkService->GetCamIds(); sinkService->IsCurSinkDev(sinkDevice); @@ -51,11 +57,8 @@ void SinkServiceGetCameraInfoFuzzTest(const uint8_t* data, size_t size) } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkServiceGetCameraInfoFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp index 610a12751655925280ee9f314f3b425fc8e7a60f..b8fc135a2a2859660cf3ce067dcd0c84fb59acfe 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp @@ -17,19 +17,22 @@ #include "distributed_camera_sink_service.h" #include "dcamera_sink_callback.h" #include "distributed_camera_constants.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SinkServiceInitSinkFuzzTest(const uint8_t* data, size_t size) { - if (data == nullptr || size == 0) { - return; - } - auto sinkService = std::make_shared( - DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); - std::string param(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + + int serviceId = fdp.ConsumeIntegral(); + bool isServiceAvailable = fdp.ConsumeBool(); + auto sinkService = std::make_shared(serviceId, isServiceAvailable); + + std::string param = fdp.ConsumeRemainingBytesAsString(); sptr callback(new DCameraSinkCallback()); + sinkService->InitSink(param, callback); } } diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/sinkserviceopenchannel_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/sinkserviceopenchannel_fuzzer.cpp index 9b4f62e8f261f237271c5d2463ebbb16c0a5f570..cf61fdb3307ee472c7c786d8e2413a1903ff5011 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/sinkserviceopenchannel_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/sinkserviceopenchannel_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,6 +17,9 @@ #include #include +#include + +#include "fuzzer/FuzzedDataProvider.h" #include "dcamera_sink_callback.h" #include "distributed_camera_constants.h" @@ -28,15 +31,14 @@ namespace OHOS { namespace DistributedHardware { void SinkServiceOpenChannelFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } + FuzzedDataProvider fdp(data, size); - std::string dhId = "1"; - std::string openInfo(reinterpret_cast(data), size); + bool serviceEnable = fdp.ConsumeBool(); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string openInfo = fdp.ConsumeRemainingBytesAsString(); std::shared_ptr sinkService = - std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); + std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, serviceEnable); sptr sinkCallback(new DCameraSinkCallback()); std::shared_ptr sinkDevice = std::make_shared(dhId, sinkCallback); sinkService->camerasMap_.emplace(dhId, sinkDevice); @@ -45,11 +47,8 @@ void SinkServiceOpenChannelFuzzTest(const uint8_t* data, size_t size) } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SinkServiceOpenChannelFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceunregisterdistributedhardware_fuzzer/sourceserviceunregisterdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceunregisterdistributedhardware_fuzzer/sourceserviceunregisterdistributedhardware_fuzzer.cpp index f2a3f945cb3f86c5e3b0cf157f9d44180b242cbf..ca367a62935956176ef688f4ec5e7e745b0ad2c4 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceunregisterdistributedhardware_fuzzer/sourceserviceunregisterdistributedhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceunregisterdistributedhardware_fuzzer/sourceserviceunregisterdistributedhardware_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,24 +14,23 @@ */ #include "sourceserviceunregisterdistributedhardware_fuzzer.h" - #include "dcamera_source_callback.h" #include "distributed_camera_constants.h" #include "distributed_camera_source_service.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" +#include "fuzzer/FuzzedDataProvider.h" +#include namespace OHOS { namespace DistributedHardware { void SourceServiceUnregisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } + FuzzedDataProvider fdp(data, size); - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string devId = fdp.ConsumeRandomLengthString(); + std::string reqId = fdp.ConsumeRemainingBytesAsString(); std::shared_ptr sourceService = std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, true); @@ -41,11 +40,8 @@ void SourceServiceUnregisterDistributedHardwareFuzzTest(const uint8_t* data, siz } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SourceServiceUnregisterDistributedHardwareFuzzTest(data, size); return 0; -} - +} \ No newline at end of file