From c1670516fef84b21a92d74a34ba1785b615671c8 Mon Sep 17 00:00:00 2001 From: Tome Date: Tue, 2 Sep 2025 19:09:16 +0800 Subject: [PATCH 1/2] FUZZ improve Signed-off-by: Tome --- .../callbackonnotifyresourceinfo_fuzzer.cpp | 25 ++++++++----------- .../encodeoninputbufferavailable_fuzzer.cpp | 19 ++++++-------- .../sinkhandlerinitsink_fuzzer.cpp | 14 +++++------ ...handlerpausedistributedhardware_fuzzer.cpp | 15 +++++------ ...handlerregisterprivacyresources_fuzzer.cpp | 21 ++++++++-------- ...andlerresumedistributedhardware_fuzzer.cpp | 15 +++++------ ...khandlerstopdistributedhardware_fuzzer.cpp | 16 +++++------- ...nkhandlersubscribelocalhardware_fuzzer.cpp | 18 ++++++------- ...handlerunsubscribelocalhardware_fuzzer.cpp | 15 +++++------ .../sinkonloadsystemabilityfail_fuzzer.cpp | 15 +++++------ ...ceunregisterdistributedhardware_fuzzer.cpp | 20 ++++++--------- 11 files changed, 80 insertions(+), 113 deletions(-) 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 cad43507..0c53f08d 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 @@ -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 9d4d969c..b5d49e6b 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) 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 b207fecb..e431bee1 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) 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 da2e2dc1..05fd49f1 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) 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 7a646d9f..b09a8eb5 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) 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 00e51a1a..b765bf0e 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) 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 b13ae3d9..24b15dc3 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) 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 36128b37..c00dc3b6 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) 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 9684a8f6..44c040c5 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) 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 eef0b392..53be21e8 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) 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/sourcefuzztest/sourceserviceunregisterdistributedhardware_fuzzer/sourceserviceunregisterdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceunregisterdistributedhardware_fuzzer/sourceserviceunregisterdistributedhardware_fuzzer.cpp index f2a3f945..25695955 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) 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 -- Gitee From 23a0ec821b9135acf28336ae02581f6e67f153d1 Mon Sep 17 00:00:00 2001 From: Tome Date: Wed, 3 Sep 2025 10:33:31 +0800 Subject: [PATCH 2/2] FUZZ improve Signed-off-by: Tome --- .../callbackonnotifyresourceinfo_fuzzer.cpp | 2 +- .../encodeoninputbufferavailable_fuzzer.cpp | 2 +- .../sinkhandlerinitsink_fuzzer.cpp | 2 +- ...handlerpausedistributedhardware_fuzzer.cpp | 2 +- ...handlerregisterprivacyresources_fuzzer.cpp | 2 +- ...andlerresumedistributedhardware_fuzzer.cpp | 2 +- ...khandlerstopdistributedhardware_fuzzer.cpp | 2 +- ...nkhandlersubscribelocalhardware_fuzzer.cpp | 2 +- ...handlerunsubscribelocalhardware_fuzzer.cpp | 2 +- .../sinkonloadsystemabilityfail_fuzzer.cpp | 2 +- .../sinkproxychannelneg_fuzzer.cpp | 21 +++++++-------- .../sinkproxyclosechannel_fuzzer.cpp | 15 +++++------ .../sinkproxyopenchannel_fuzzer.cpp | 16 +++++------ .../sinkproxyreleasesink_fuzzer.cpp | 15 +++++------ ...sinkproxysubscribelocalhardware_fuzzer.cpp | 23 +++++++++------- .../sinkservicechannelneg_fuzzer.cpp | 18 ++++++------- .../sinkserviceclosechannel_fuzzer.cpp | 17 ++++++------ .../sinkservicedump_fuzzer.cpp | 26 +++++++++++------- .../sinkservicegetcamerainfo_fuzzer.cpp | 27 ++++++++++--------- .../sinkserviceinitsink_fuzzer.cpp | 15 ++++++----- .../sinkserviceopenchannel_fuzzer.cpp | 21 +++++++-------- ...ceunregisterdistributedhardware_fuzzer.cpp | 2 +- 22 files changed, 120 insertions(+), 116 deletions(-) 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 0c53f08d..deb0b36e 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 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 b5d49e6b..23e861dc 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) 2025 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 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 e431bee1..ecb54dfa 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) 2025 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 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 05fd49f1..f50fbfd6 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) 2025 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 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 b09a8eb5..acaa42cf 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) 2025 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 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 b765bf0e..c4a1ccdf 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) 2025 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 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 24b15dc3..86465dc7 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) 2025 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 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 c00dc3b6..1c3931bd 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) 2025 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 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 44c040c5..28b484ca 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) 2025 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 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 53be21e8..5da8d739 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) 2025 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 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 d4dd0255..08a3c9b2 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 f1ac84dd..84317daa 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 4d3bef6d..661a1633 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 b3d29b04..350ae517 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 65394049..1a600f5f 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 0a5996df..51df3abc 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 e00bc19c..6ee8ab42 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 744af481..a73fea31 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 b602abfb..e23df78d 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 610a1275..b8fc135a 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 9b4f62e8..cf61fdb3 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 25695955..ca367a62 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) 2025 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 -- Gitee