diff --git a/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.cpp b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.cpp index b1d849f03b7b2822a12bcf75d6f86b62f0134ebb..8c638dad6a66190da66ae43be6199d712c995d11 100644 --- a/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.cpp +++ b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -51,20 +52,17 @@ void OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) if ((data == nullptr) || (size < sizeof(uint32_t) + sizeof(uint32_t) + 1)) { return; } + FuzzedDataProvider fdp(data, size); + uint32_t code = fdp.ConsumeIntegral(); MessageParcel parcel; parcel.WriteInterfaceToken(FuzzGetDhDescriptorsCallbackStub().GetDescriptor()); - uint32_t dhType = *(reinterpret_cast(data)); + uint32_t dhType = fdp.ConsumeIntegral(); parcel.WriteUint32(dhType); - std::string id(reinterpret_cast(data + 4), size - 4); + std::string id = fdp.ConsumeRandomLengthString(); parcel.WriteString(id); MessageParcel reply; MessageOption option; - uint32_t code = 0; - if (size >= sizeof(uint32_t)) { - code = *(reinterpret_cast(data)); - } - FuzzGetDhDescriptorsCallbackStub stub; stub.OnRemoteRequest(code, parcel, reply, option); } diff --git a/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp index ee90ad533a4cb2339b5056f489aec1b47ed128eb..f2ccd5be1d8876b9b389ea566f18fe45863e9f45 100644 --- a/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp +++ b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -33,46 +34,40 @@ namespace OHOS { namespace DistributedHardware { void HDSinkStatusOnRemoteRequestFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(uint32_t))) { + if ((data == nullptr) || (size < sizeof(uint32_t) + sizeof(uint32_t) + 1)) { return; } + FuzzedDataProvider fdp(data, size); + uint32_t code = fdp.ConsumeIntegral(); MessageParcel parcel; parcel.WriteInterfaceToken(FuzzHDSinkStatusListenerStub().GetDescriptor()); - uint32_t dhType = *(reinterpret_cast(data)); + uint32_t dhType = fdp.ConsumeIntegral(); parcel.WriteUint32(dhType); - std::string id(reinterpret_cast(data + 4), size - 4); + std::string id = fdp.ConsumeRandomLengthString(); parcel.WriteString(id); MessageParcel reply; MessageOption option; - uint32_t code = 0; - if (size >= sizeof(uint32_t)) { - code = *(reinterpret_cast(data)); - } - FuzzHDSinkStatusListenerStub stub; stub.OnRemoteRequest(code, parcel, reply, option); } void HDSourceStatusOnRemoteRequestFuzzTest(const uint8_t *data, size_t size) { - if ((data == nullptr) || (size < sizeof(uint32_t))) { + if ((data == nullptr) || (size < sizeof(uint32_t) + sizeof(uint32_t) + 1)) { return; } - + FuzzedDataProvider fdp(data, size); + uint32_t code = fdp.ConsumeIntegral(); MessageParcel parcel; parcel.WriteInterfaceToken(FuzzHDSinkStatusListenerStub().GetDescriptor()); - uint32_t dhType = *(reinterpret_cast(data)); + uint32_t dhType = fdp.ConsumeIntegral(); parcel.WriteUint32(dhType); - std::string id(reinterpret_cast(data + 4), size - 4); + std::string id = fdp.ConsumeRandomLengthString(); parcel.WriteString(id); MessageParcel reply; MessageOption option; - uint32_t code = 0; - if (size >= sizeof(uint32_t)) { - code = *(reinterpret_cast(data)); - } FuzzHDSourceStatusListenerStub stub; stub.OnRemoteRequest(code, parcel, reply, option); } diff --git a/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/capabilityinfomanager_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/capabilityinfomanager_fuzzer.cpp index eaf84fe0ba29cf0ec24e49b116e816e26412aa58..3ebaa779cff0a82a004cfe6c1c416d2c9a5db56a 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/capabilityinfomanager_fuzzer.cpp +++ b/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/capabilityinfomanager_fuzzer.cpp @@ -15,6 +15,8 @@ #include "capabilityinfomanager_fuzzer.h" +#include + #include "constants.h" #include "capability_info.h" #include "capability_utils.h" @@ -305,9 +307,15 @@ void DumpCapabilityInfosFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size == 0)) { return; } - + FuzzedDataProvider fdp(data, size); std::vector capInfos; - + std::string dhId = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::string dhAttrs = fdp.ConsumeRandomLengthString(); + std::string dhSubtype = fdp.ConsumeRandomLengthString(); + CapabilityInfo capInfo(dhId, deviceId, deviceName, TEST_DEV_TYPE_PAD, DHType::CAMERA, dhAttrs, dhSubtype); + capInfos.push_back(capInfo); CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfos); } @@ -382,18 +390,6 @@ void AsyncGetDistributedHardwareFuzzTest(const uint8_t* data, size_t size) CapabilityInfoManager::GetInstance()->AsyncGetDistributedHardware(networkId, enableStep, callback); } -void DoAsyncGetDistributedHardwareFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - - std::string networkId(reinterpret_cast(data), size); - EnableStep enableStep = static_cast(data[0] % 4); - sptr callback(new TestGetDistributedHardwareCallback()); - CapabilityInfoManager::GetInstance()->DoAsyncGetDistributedHardware(networkId, enableStep, callback); -} - void GetEntriesByKeysFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size == 0)) { @@ -427,7 +423,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::DistributedHardware::OnChangeFuzzTest(data, size); OHOS::DistributedHardware::GetDataByDHTypeFuzzTest(data, size); OHOS::DistributedHardware::AsyncGetDistributedHardwareFuzzTest(data, size); - OHOS::DistributedHardware::DoAsyncGetDistributedHardwareFuzzTest(data, size); OHOS::DistributedHardware::GetEntriesByKeysFuzzTest(data, size); return 0; } diff --git a/services/distributedhardwarefwkservice/test/fuzztest/componentenable_fuzzer/componentenable_fuzzer.h b/services/distributedhardwarefwkservice/test/fuzztest/componentenable_fuzzer/componentenable_fuzzer.h index 3ec7cc3c63c9158e12499214864be628c2de28f6..9772f0eb16e94b7de5b0f56f863092053c9e5013 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/componentenable_fuzzer/componentenable_fuzzer.h +++ b/services/distributedhardwarefwkservice/test/fuzztest/componentenable_fuzzer/componentenable_fuzzer.h @@ -29,17 +29,17 @@ public: FuzzDistributedHardwareSource() = default; virtual ~FuzzDistributedHardwareSource() = default; - int32_t InitSource(const std::string&) override; + int32_t InitSource(const std::string& networkId) override; int32_t ReleaseSource() override; - int32_t RegisterDistributedHardware(const std::string&, const std::string&, - const EnableParam&, std::shared_ptr) override; - int32_t UnregisterDistributedHardware(const std::string&, const std::string&, + int32_t RegisterDistributedHardware(const std::string& networkId, const std::string& dhId, const EnableParam& param, + std::shared_ptr callback) override; + int32_t UnregisterDistributedHardware(const std::string& networkId, const std::string& dhId, std::shared_ptr callback) override; - int32_t ConfigDistributedHardware(const std::string&, const std::string&, const std::string&, - const std::string&) override; - void RegisterDistributedHardwareStateListener(std::shared_ptr) override; + int32_t ConfigDistributedHardware(const std::string& networkId, const std::string& dhId, const std::string& key, + const std::string& value) override; + void RegisterDistributedHardwareStateListener(std::shared_ptr listener) override; void UnregisterDistributedHardwareStateListener() override{} - void RegisterDataSyncTriggerListener(std::shared_ptr) override; + void RegisterDataSyncTriggerListener(std::shared_ptr listener) override; void UnregisterDataSyncTriggerListener() override{} }; } // namespace DistributedHardware