diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/softbusonsinkmessagereceived_fuzzer/softbusonsinkmessagereceived_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/softbusonsinkmessagereceived_fuzzer/softbusonsinkmessagereceived_fuzzer.cpp index 2037b7d843e92ae6bb4cb5efb2cb3cafcf62a34d..fc631a671cbc060f66ac21d2a62f2653fc5a6722 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/softbusonsinkmessagereceived_fuzzer/softbusonsinkmessagereceived_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/softbusonsinkmessagereceived_fuzzer/softbusonsinkmessagereceived_fuzzer.cpp @@ -15,6 +15,7 @@ #include "softbusonsinkmessagereceived_fuzzer.h" #include +#include #include "dcamera_softbus_adapter.h" @@ -22,25 +23,23 @@ namespace OHOS { namespace DistributedHardware { void SoftbusOnSinkMessageReceivedFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(uint32_t))) { + if (data == nullptr) { return; } FuzzedDataProvider fdp(data, size); int32_t sessionId = fdp.ConsumeIntegral(); - const void *receivedData = reinterpret_cast(data); - uint32_t dataLen = fdp.ConsumeIntegral(); + std::vector messageBytes = fdp.ConsumeRemainingBytes(); + const void* receivedData = messageBytes.data(); + uint32_t dataLen = static_cast(messageBytes.size()); DCameraSoftbusAdapter::GetInstance().SinkOnMessage(sessionId, receivedData, dataLen); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SoftbusOnSinkMessageReceivedFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/softbusonsinkstreamreceived_fuzzer/softbusonsinkstreamreceived_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/softbusonsinkstreamreceived_fuzzer/softbusonsinkstreamreceived_fuzzer.cpp index 5aa865b45929a214ba040ac24473e78267a0645d..337699443193e3c83dc94752583eb9f812e9c080 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/softbusonsinkstreamreceived_fuzzer/softbusonsinkstreamreceived_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/softbusonsinkstreamreceived_fuzzer/softbusonsinkstreamreceived_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,31 +14,56 @@ */ #include "softbusonsinkstreamreceived_fuzzer.h" - #include "dcamera_softbus_adapter.h" +#include "fuzzer/FuzzedDataProvider.h" +#include +#include namespace OHOS { namespace DistributedHardware { void SoftbusOnSinkStreamReceivedFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(int64_t))) { + FuzzedDataProvider fdp(data, size); + const size_t minParamsSize = sizeof(int32_t) * 2 + sizeof(int) * 6 + sizeof(int64_t); + if (fdp.remaining_bytes() < minParamsSize) { return; } - int32_t sessionId = *(reinterpret_cast(data)); - const StreamData receivedData = { - const_cast(reinterpret_cast(data)), static_cast(size) + int32_t sessionId = fdp.ConsumeIntegral(); + int32_t socket = fdp.ConsumeIntegral(); + + const StreamFrameInfo param = { + fdp.ConsumeIntegral(), + fdp.ConsumeIntegral(), + fdp.ConsumeIntegral(), + fdp.ConsumeIntegral(), + fdp.ConsumeIntegral(), + fdp.ConsumeIntegral(), + fdp.ConsumeIntegral(), + nullptr }; - const StreamData ext = { - const_cast(reinterpret_cast(data)), static_cast(size) + + const int32_t doubleNum = 2; + size_t halfRemainingBytes = fdp.remaining_bytes() / doubleNum; + + std::vector receivedDataBuffer; + if (halfRemainingBytes > 0) { + receivedDataBuffer = fdp.ConsumeBytes(halfRemainingBytes); + } + StreamData receivedData = { + reinterpret_cast(receivedDataBuffer.data()), + static_cast(receivedDataBuffer.size()) }; - const StreamFrameInfo param = { - *(reinterpret_cast(data)), *(reinterpret_cast(data)), - *(reinterpret_cast(data)), *(reinterpret_cast(data)), - *(reinterpret_cast(data)), *(reinterpret_cast(data)), - *(reinterpret_cast(data)), nullptr + + std::vector extBuffer; + if (fdp.remaining_bytes() > 0) { + extBuffer = fdp.ConsumeRemainingBytes(); + } + StreamData ext = { + reinterpret_cast(extBuffer.data()), + static_cast(extBuffer.size()) }; - int32_t socket = 1; + auto session = std::make_shared(); DCameraSoftbusAdapter::GetInstance().sinkSocketSessionMap_[socket] = session; DCameraSoftbusAdapter::GetInstance().SinkOnStream(sessionId, &receivedData, &ext, ¶m); @@ -46,11 +71,8 @@ void SoftbusOnSinkStreamReceivedFuzzTest(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::SoftbusOnSinkStreamReceivedFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp index 865823427f0f1b2b48719f739b26e0592f861ec1..6926125e82127d0690a2eacfd1733316d2d28fb6 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 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,23 +14,24 @@ */ #include "callbackonnotifyregresult_fuzzer.h" - #include "dcamera_source_callback.h" #include "distributed_camera_constants.h" #include "mock_component_enable.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void CallbackOnNotifyRegResultFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - std::string devId(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); - int32_t status = *(reinterpret_cast(data)); - std::string dataStr(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + + int32_t status = fdp.ConsumeIntegral(); + std::string devId = fdp.ConsumeRandomLengthString(); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string reqId = fdp.ConsumeRandomLengthString(); + + std::string dataStr = fdp.ConsumeRemainingBytesAsString(); + std::shared_ptr callback = std::make_shared(); sptr dcameraSourceCallback(new (std::nothrow) DCameraSourceCallback()); @@ -43,11 +44,8 @@ void CallbackOnNotifyRegResultFuzzTest(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::CallbackOnNotifyRegResultFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp index 8667fc20c606abea266892b85cceccf8b5236901..db0f23d1a5496321506248bc146941b6653627b8 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 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,23 +14,22 @@ */ #include "callbackonnotifyunregresult_fuzzer.h" - #include "dcamera_source_callback.h" #include "distributed_camera_constants.h" #include "mock_component_disable.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void CallbackOnNotifyRegResultFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - std::string devId(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); - int32_t status = *(reinterpret_cast(data)); - std::string dataStr(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + std::string devId = fdp.ConsumeRandomLengthString(); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string reqId = fdp.ConsumeRandomLengthString(); + int32_t status = fdp.ConsumeIntegral(); + std::string dataStr = fdp.ConsumeRemainingBytesAsString(); + std::shared_ptr uncallback = std::make_shared(); sptr dcameraSourceCallback(new (std::nothrow) DCameraSourceCallback()); @@ -43,11 +42,8 @@ void CallbackOnNotifyRegResultFuzzTest(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::CallbackOnNotifyRegResultFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp index 20d2ce26b9b050ad6deed059f7c784570edf3ae9..b8488534e8a6e3b6fba7d2371780c8a3ae88e03a 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 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,31 +14,28 @@ */ #include "callbackonremoterequest_fuzzer.h" - #include "dcamera_source_callback.h" #include "dcamera_source_callback_stub.h" #include "distributed_camera_constants.h" #include "iremote_object.h" #include "message_option.h" #include "message_parcel.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void CallbackOnRemoteRequestFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(uint32_t))) { - return; - } - + FuzzedDataProvider fdp(data, size); MessageParcel pdata; MessageParcel reply; MessageOption option; - uint32_t code = *(reinterpret_cast(data)) % 2; - int32_t status = *(reinterpret_cast(data)); - std::string devId(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); - std::string dataStr(reinterpret_cast(data), size); + uint32_t code = fdp.ConsumeIntegral(); + int32_t status = fdp.ConsumeIntegral(); + std::string devId = fdp.ConsumeRandomLengthString(); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string reqId = fdp.ConsumeRandomLengthString(); + std::string dataStr = fdp.ConsumeRemainingBytesAsString(); pdata.WriteInt32(status); pdata.WriteString(devId); pdata.WriteString(dhId); @@ -54,11 +51,8 @@ void CallbackOnRemoteRequestFuzzTest(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::CallbackOnRemoteRequestFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/softbushandlesourcestreamext_fuzzer/softbushandlesourcestreamext_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/softbushandlesourcestreamext_fuzzer/softbushandlesourcestreamext_fuzzer.cpp index 0f449659c956006534ccfe611d3095adef054a5d..6b572c31a12675627e449e456138b2f7f0361f91 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/softbushandlesourcestreamext_fuzzer/softbushandlesourcestreamext_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/softbushandlesourcestreamext_fuzzer/softbushandlesourcestreamext_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 @@ -16,29 +16,28 @@ #include "softbushandlesourcestreamext_fuzzer.h" #include "dcamera_softbus_adapter.h" #include "data_buffer.h" +#include "fuzzer/FuzzedDataProvider.h" +#include namespace OHOS { namespace DistributedHardware { void SoftbusHandleSourceStreamExtFuzzTest(const uint8_t* data, size_t size) { - if (data == nullptr || size == 0) { - return; - } - - auto buffer = std::make_shared(0); - + FuzzedDataProvider fdp(data, size); + size_t dataBufferCapacity = fdp.ConsumeIntegral(); + auto buffer = std::make_shared(dataBufferCapacity); + std::vector extDataVector = fdp.ConsumeRemainingBytes(); const StreamData ext = { - const_cast(reinterpret_cast(data)), static_cast(size) + extDataVector.data(), + static_cast(extDataVector.size()) }; DCameraSoftbusAdapter::GetInstance().HandleSourceStreamExt(buffer, &ext); } - } // namespace DistributedHardware } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { OHOS::DistributedHardware::SoftbusHandleSourceStreamExtFuzzTest(data, size); diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/softbusonsourcebytesreceived_fuzzer/softbusonsourcebytesreceived_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/softbusonsourcebytesreceived_fuzzer/softbusonsourcebytesreceived_fuzzer.cpp index dd53e78275b74edc61cfa7d002641f664b2fbdd2..961bb1ae86311ca97ed9c415e0655712a10e1061 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/softbusonsourcebytesreceived_fuzzer/softbusonsourcebytesreceived_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/softbusonsourcebytesreceived_fuzzer/softbusonsourcebytesreceived_fuzzer.cpp @@ -15,6 +15,9 @@ #include "softbusonsourcebytesreceived_fuzzer.h" #include +#include +#include +#include #include "dcamera_softbus_adapter.h" @@ -22,17 +25,14 @@ namespace OHOS { namespace DistributedHardware { void SoftbusOnSourceBytesReceivedFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(uint32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); + int32_t sessionId = fdp.ConsumeIntegral(); - const void *receivedData = reinterpret_cast(data); - uint32_t dataLen = fdp.ConsumeIntegral(); - DCameraSoftbusAdapter::GetInstance().SourceOnBytes(sessionId, receivedData, dataLen); - - std::string testStr = "test_suffix"; + uint32_t dataLen = fdp.ConsumeIntegralInRange(0, fdp.remaining_bytes()); + std::vector receivedBytes = fdp.ConsumeBytes(dataLen); + DCameraSoftbusAdapter::GetInstance().SourceOnBytes(sessionId, receivedBytes.data(), receivedBytes.size()); + + std::string testStr = fdp.ConsumeRandomLengthString(20); std::string randomSuffix = fdp.ConsumeRandomLengthString(10); std::string randomReplacement = fdp.ConsumeRandomLengthString(10); DCameraSoftbusAdapter::GetInstance().ReplaceSuffix(testStr, randomSuffix, randomReplacement); @@ -40,11 +40,8 @@ void SoftbusOnSourceBytesReceivedFuzzTest(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::SoftbusOnSourceBytesReceivedFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/softbusonsourcemessagereceived_fuzzer/softbusonsourcemessagereceived_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/softbusonsourcemessagereceived_fuzzer/softbusonsourcemessagereceived_fuzzer.cpp index 67f7c1f65bfe31e97b6f9e10f246a38307acfdb8..1d55b7a551094698c8fb4c6a7ada47cd744afaac 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/softbusonsourcemessagereceived_fuzzer/softbusonsourcemessagereceived_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/softbusonsourcemessagereceived_fuzzer/softbusonsourcemessagereceived_fuzzer.cpp @@ -15,32 +15,31 @@ #include "softbusonsourcemessagereceived_fuzzer.h" #include - #include "dcamera_softbus_adapter.h" +#include +#include namespace OHOS { namespace DistributedHardware { void SoftbusOnSourceMessageReceivedFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(uint32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); + int32_t sessionId = fdp.ConsumeIntegral(); - const void *receivedData = reinterpret_cast(data); - uint32_t dataLen = fdp.ConsumeIntegral(); - DCameraSoftbusAdapter::GetInstance().SourceOnMessage(sessionId, receivedData, dataLen); + uint32_t desiredDataLen = fdp.ConsumeIntegral(); + uint32_t actualDataLen = std::min(desiredDataLen, static_cast(fdp.remaining_bytes())); + + std::vector receivedDataBuffer = fdp.ConsumeBytes(actualDataLen); + const void* receivedData = receivedDataBuffer.data(); + + DCameraSoftbusAdapter::GetInstance().SourceOnMessage(sessionId, receivedData, actualDataLen); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SoftbusOnSourceMessageReceivedFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerconfigdistributedhardware_fuzzer/sourcehandlerconfigdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerconfigdistributedhardware_fuzzer/sourcehandlerconfigdistributedhardware_fuzzer.cpp index 2ca6075e71c2e8c08cc7e590e46fa93ac9937738..0a1f49fc4dd81be50e523feba18d3b6b600aced7 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerconfigdistributedhardware_fuzzer/sourcehandlerconfigdistributedhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerconfigdistributedhardware_fuzzer/sourcehandlerconfigdistributedhardware_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,35 +14,30 @@ */ #include "sourcehandlerconfigdistributedhardware_fuzzer.h" - #include #include - #include "dcamera_source_handler.h" #include "distributed_camera_constants.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SourceHandlerConfigDistributedHardwareFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - std::string devId(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); - std::string key(reinterpret_cast(data), size); - std::string value(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + + std::string devId = fdp.ConsumeRandomLengthString(); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string key = fdp.ConsumeRandomLengthString(); + std::string value = fdp.ConsumeRemainingBytesAsString(); DCameraSourceHandler::GetInstance().ConfigDistributedHardware(devId, dhId, key, value); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SourceHandlerConfigDistributedHardwareFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerinitsource_fuzzer/sourcehandlerinitsource_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerinitsource_fuzzer/sourcehandlerinitsource_fuzzer.cpp index c844037a62de095cc3ad68eb983763bc52ac6adf..0617f694036d5f216faea961203cbe37b5363a8c 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerinitsource_fuzzer/sourcehandlerinitsource_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerinitsource_fuzzer/sourcehandlerinitsource_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,9 +14,11 @@ */ #include "sourcehandlerinitsource_fuzzer.h" +#include "fuzzer/FuzzedDataProvider.h" #include #include +#include #include "dcamera_source_handler.h" #include "distributed_camera_constants.h" @@ -25,21 +27,17 @@ namespace OHOS { namespace DistributedHardware { void SourceHandlerInitSourceFuzzTest(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(); DCameraSourceHandler::GetInstance().InitSource(params); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SourceHandlerInitSourceFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_fuzzer.cpp index 466475da69aeaad3d129c069689bbe6b640498ac..32ea3e14de612df39c5a65a8ebffe43cbddc3557 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_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,30 +14,30 @@ */ #include "sourcehandlerregisterdistributedhardware_fuzzer.h" - -#include -#include - #include "dcamera_source_handler.h" #include "distributed_camera_constants.h" #include "mock_component_enable.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "refbase.h" +#include "fuzzer/FuzzedDataProvider.h" +#include +#include +#include +#include namespace OHOS { namespace DistributedHardware { void SourceHandlerRegisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - std::string devId(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); - std::string sourceVersion(reinterpret_cast(data), size); - std::string sourceAttrs(reinterpret_cast(data), size); - std::string sinkVersion(reinterpret_cast(data), size); - std::string sinkAttrs(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + std::string devId = fdp.ConsumeRandomLengthString(); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string sourceVersion = fdp.ConsumeRandomLengthString(); + std::string sourceAttrs = fdp.ConsumeRandomLengthString(); + std::string sinkVersion = fdp.ConsumeRandomLengthString(); + std::string sinkAttrs = fdp.ConsumeRemainingBytesAsString(); + EnableParam param; param.sourceVersion = sourceVersion; param.sourceAttrs = sourceAttrs; @@ -50,11 +50,8 @@ void SourceHandlerRegisterDistributedHardwareFuzzTest(const uint8_t* data, size_ } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SourceHandlerRegisterDistributedHardwareFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_fuzzer.cpp index 8d17d091710a9b8fa15cb80f6f909ef7dfd78b09..152b7c34efd2d945c61a354d9b39a34bfa122771 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_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,38 +14,39 @@ */ #include "sourcehandlerunregisterdistributedhardware_fuzzer.h" - #include #include - #include "dcamera_source_handler.h" #include "distributed_camera_constants.h" #include "mock_component_disable.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "refbase.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SourceHandlerUnregisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - std::string devId(reinterpret_cast(data), size); - std::string dhId(reinterpret_cast(data), size); - std::shared_ptr uncallback = std::make_shared(); + FuzzedDataProvider fdp(data, size); + + const int doubleNum = 2; + std::string devId = fdp.ConsumeRandomLengthString(fdp.remaining_bytes() / doubleNum); + std::string dhId = fdp.ConsumeRemainingBytesAsString(); + std::shared_ptr uncallback; + if (fdp.ConsumeBool()) { + uncallback = std::make_shared(); + } else { + uncallback = nullptr; + } DCameraSourceHandler::GetInstance().UnregisterDistributedHardware(devId, dhId, uncallback); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SourceHandlerUnregisterDistributedHardwareFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceonloadsystemabilityfail_fuzzer/sourceonloadsystemabilityfail_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceonloadsystemabilityfail_fuzzer/sourceonloadsystemabilityfail_fuzzer.cpp index 98315003501deb577818c01d5c15f1abaabfa151..5352b13139810d366c82e956877d6d882200e29a 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceonloadsystemabilityfail_fuzzer/sourceonloadsystemabilityfail_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceonloadsystemabilityfail_fuzzer/sourceonloadsystemabilityfail_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 @@ -23,16 +23,16 @@ #include "distributed_camera_constants.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SourceOnLoadSystemAbilityFailFuzzTest(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 +40,8 @@ void SourceOnLoadSystemAbilityFailFuzzTest(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::SourceOnLoadSystemAbilityFailFuzzTest(data, size); return 0; } \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp index 8db6750311f033b8de83efde942edd111e898474..df52e2439e33e2f1284d29b6b61f94d385f908c1 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_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,31 +14,30 @@ */ #include "sourceproxydcameranotify_fuzzer.h" - #include "dcamera_source_callback.h" #include "distributed_camera_constants.h" #include "distributed_camera_source_proxy.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SourceProxyDCameraNotifyFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string events(reinterpret_cast(data), size); - + FuzzedDataProvider fdp(data, size); + std::string devId = fdp.ConsumeRandomLengthString(); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string events = fdp.ConsumeRemainingBytesAsString(); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { return; } sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); + if (remoteObject == nullptr) { + return; + } std::shared_ptr dCSourceProxy = std::make_shared(remoteObject); @@ -47,11 +46,8 @@ void SourceProxyDCameraNotifyFuzzTest(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::SourceProxyDCameraNotifyFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxyunregisterdistributedhardware_fuzzer/sourceproxyunregisterdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxyunregisterdistributedhardware_fuzzer/sourceproxyunregisterdistributedhardware_fuzzer.cpp index e16eb98c5a835230f09c695354bbe06c00acd183..b28f344090f6937c0989b53940f5ce8aef0fc12d 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxyunregisterdistributedhardware_fuzzer/sourceproxyunregisterdistributedhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxyunregisterdistributedhardware_fuzzer/sourceproxyunregisterdistributedhardware_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,24 +14,21 @@ */ #include "sourceproxyunregisterdistributedhardware_fuzzer.h" - #include "dcamera_source_callback.h" #include "distributed_camera_constants.h" #include "distributed_camera_source_proxy.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SourceProxyUnregisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string reqId(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + std::string devId = fdp.ConsumeRandomLengthString(); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string reqId = fdp.ConsumeRemainingBytesAsString(); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -39,19 +36,19 @@ void SourceProxyUnregisterDistributedHardwareFuzzTest(const uint8_t* data, size_ return; } sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); + if (remoteObject == nullptr) { + // The system ability might not be running or available, which is not a crash in the fuzzer. + return; + } std::shared_ptr dCSourceProxy = std::make_shared(remoteObject); - dCSourceProxy->UnregisterDistributedHardware(devId, dhId, reqId); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SourceProxyUnregisterDistributedHardwareFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicecamdeverase_fuzzer/sourceservicecamdeverase_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicecamdeverase_fuzzer/sourceservicecamdeverase_fuzzer.cpp index 89ad8bc4a6e64c352e2a6ee4726c045bb11e3eca..d61675a0a701124b3e1c4d82d4dd1cd93c31d982 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicecamdeverase_fuzzer/sourceservicecamdeverase_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicecamdeverase_fuzzer/sourceservicecamdeverase_fuzzer.cpp @@ -16,36 +16,29 @@ #include "sourceservicecamdeverase_fuzzer.h" #include "distributed_camera_source_service.h" #include "distributed_camera_constants.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { -inline std::string ExtractString(const uint8_t* data, size_t offset, size_t length) -{ - return std::string(reinterpret_cast(data + offset), length); -} - void SourceServiceCamDevEraseFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(DCameraIndex))) { - return; - } - + FuzzedDataProvider fdp(data, size); auto sourceService = std::make_shared( DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, true); - - int doubleNum = 2; DCameraIndex index; - index.devId_ = ExtractString(data, 0, size / doubleNum); - index.dhId_ = ExtractString(data, size / doubleNum, size / doubleNum); + const int32_t doubleNum = 2; + // Consume half of the remaining bytes for devId_ and the rest for dhId_. + // This mimics the original split logic using fdp's safe consumption. + size_t halfRemaingSize = fdp.remaining_bytes() / doubleNum; + index.devId_ = fdp.ConsumeBytesAsString(halfRemaingSize); + index.dhId_ = fdp.ConsumeRemainingBytesAsString(); sourceService->CamDevErase(index); } - } // namespace DistributedHardware } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { OHOS::DistributedHardware::SourceServiceCamDevEraseFuzzTest(data, size); diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/sourceservicedcameranotify_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/sourceservicedcameranotify_fuzzer.cpp index 5f391e054a33986a1173f657d1b94210c7101ca8..fa6feb730c1e1bc262745f391dc383d7929027a4 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/sourceservicedcameranotify_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/sourceservicedcameranotify_fuzzer.cpp @@ -16,30 +16,25 @@ #include "sourceservicedcameranotify_fuzzer.h" #include "distributed_camera_source_service.h" #include "distributed_camera_constants.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SourceServiceDCameraNotifyFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return; - } - + FuzzedDataProvider fdp(data, size); auto sourceService = std::make_shared( DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, true); - - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string events(reinterpret_cast(data), size); + std::string devId = fdp.ConsumeRandomLengthString(); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string events = fdp.ConsumeRemainingBytesAsString(); sourceService->DCameraNotify(devId, dhId, events); } - } // namespace DistributedHardware } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { OHOS::DistributedHardware::SourceServiceDCameraNotifyFuzzTest(data, size); diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicegetdumpinfo_fuzzer/sourceservicegetdumpinfo_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicegetdumpinfo_fuzzer/sourceservicegetdumpinfo_fuzzer.cpp index 4d09dfb3c3ba0522e3db1022ffd83c763c453b83..2435e3e7abf58e2c1087938e60d84be67772c3a6 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicegetdumpinfo_fuzzer/sourceservicegetdumpinfo_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicegetdumpinfo_fuzzer/sourceservicegetdumpinfo_fuzzer.cpp @@ -16,15 +16,17 @@ #include "sourceservicegetdumpinfo_fuzzer.h" #include "distributed_camera_source_service.h" #include "distributed_camera_constants.h" +#include "fuzzer/FuzzedDataProvider.h" namespace OHOS { namespace DistributedHardware { void SourceServiceGetDumpInfoFuzzTest(const uint8_t* data, size_t size) { - auto sourceService = std::make_shared( - DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, true); - + FuzzedDataProvider fdp(data, size); + int saId = fdp.ConsumeIntegral(); + bool isLocal = fdp.ConsumeBool(); + auto sourceService = std::make_shared(saId, isLocal); CameraDumpInfo camDump; sourceService->GetDumpInfo(camDump); } @@ -32,10 +34,8 @@ void SourceServiceGetDumpInfoFuzzTest(const uint8_t* data, size_t size) } // namespace DistributedHardware } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { OHOS::DistributedHardware::SourceServiceGetDumpInfoFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceinitsource_fuzzer/sourceserviceinitsource_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceinitsource_fuzzer/sourceserviceinitsource_fuzzer.cpp index c3fe9e5b0db32f77fd24a53f7e9a58a816800382..e082f20bb1dff30cbdbf696b2c1e99c771561281 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceinitsource_fuzzer/sourceserviceinitsource_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceinitsource_fuzzer/sourceserviceinitsource_fuzzer.cpp @@ -26,28 +26,23 @@ namespace OHOS { namespace DistributedHardware { void SourceServiceInitSourceFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - int32_t tempLen = 32; - std::string params(fdp.ConsumeRandomLengthString(tempLen)); - + // Fuzzing constructor parameters + int32_t saId = fdp.ConsumeIntegral(); + bool isInit = fdp.ConsumeBool(); std::shared_ptr sourceService = - std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, true); + std::make_shared(saId, isInit); sptr callback(new DCameraSourceCallback()); + // Fuzzing InitSource parameter + std::string params = fdp.ConsumeRemainingBytesAsString(); sourceService->InitSource(params, callback); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SourceServiceInitSourceFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceregisterdistributedhardware_fuzzer/sourceserviceregisterdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceregisterdistributedhardware_fuzzer/sourceserviceregisterdistributedhardware_fuzzer.cpp index 7aec3949c2ff9fbf7fb781e7dc0e585ea6dd112e..326a1d37b445b172ada5f28d4e74da1050bd54f2 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceregisterdistributedhardware_fuzzer/sourceserviceregisterdistributedhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceserviceregisterdistributedhardware_fuzzer/sourceserviceregisterdistributedhardware_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,47 +14,45 @@ */ #include "sourceserviceregisterdistributedhardware_fuzzer.h" - +#include "fuzzer/FuzzedDataProvider.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 +#include namespace OHOS { namespace DistributedHardware { void SourceServiceRegisterDistributedHardwareFuzzTest(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 sourceVersion(reinterpret_cast(data), size); - std::string sourceAttrs(reinterpret_cast(data), size); - std::string sinkVersion(reinterpret_cast(data), size); - std::string sinkAttrs(reinterpret_cast(data), size); + std::string devId = fdp.ConsumeRandomLengthString(); + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string reqId = fdp.ConsumeRandomLengthString(); + EnableParam param; - param.sourceVersion = sourceVersion; - param.sourceAttrs = sourceAttrs; - param.sinkVersion = sinkVersion; - param.sinkAttrs = sinkAttrs; + param.sourceVersion = fdp.ConsumeRandomLengthString(); + param.sourceAttrs = fdp.ConsumeRandomLengthString(); + param.sinkVersion = fdp.ConsumeRandomLengthString(); + param.sinkAttrs = fdp.ConsumeRandomLengthString(); std::shared_ptr sourceService = std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, true); + if (sourceService == nullptr) { + return; + } + sourceService->RegisterDistributedHardware(devId, dhId, reqId, param); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SourceServiceRegisterDistributedHardwareFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicereleasesource_fuzzer/sourceservicereleasesource_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicereleasesource_fuzzer/sourceservicereleasesource_fuzzer.cpp index 3bad657eb81468c5d4c218aeb5a170d3f2b9f568..36018423850cd283097e6ba4de25101cae40f081 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicereleasesource_fuzzer/sourceservicereleasesource_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicereleasesource_fuzzer/sourceservicereleasesource_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 @@ -14,6 +14,7 @@ */ #include "sourceservicereleasesource_fuzzer.h" +#include "fuzzer/FuzzedDataProvider.h" #include "dcamera_source_callback.h" #include "distributed_camera_constants.h" @@ -25,23 +26,20 @@ namespace OHOS { namespace DistributedHardware { void SourceServiceReleaseSourceFuzzTest(const uint8_t* data, size_t size) { - if (data == nullptr) { - return; - } + FuzzedDataProvider fdp(data, size); + int saId = fdp.ConsumeIntegral(); + bool isDistributed = fdp.ConsumeBool(); std::shared_ptr sourceService = - std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, true); + std::make_shared(saId, isDistributed); sourceService->ReleaseSource(); } } } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ OHOS::DistributedHardware::SourceServiceReleaseSourceFuzzTest(data, size); return 0; -} - +} \ No newline at end of file