From 65567e235039d85c5ea82812bebbfe847d5058a5 Mon Sep 17 00:00:00 2001 From: pwx1285814 Date: Fri, 7 Jun 2024 14:45:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dfuzz=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: pwx1285814 Change-Id: I9cb2138443c5715e36025c3fb6b454ae4bb7f185 --- .../BUILD.gn | 6 ++- .../registerdistributedhardware_fuzzer.cpp | 47 ++++++++++++++----- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/BUILD.gn index b14c8675..c58956e5 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/BUILD.gn @@ -27,6 +27,7 @@ ohos_fuzztest("ProxyRegisterDistributedHardwareFuzzTest") { "include", "include/callback", "${common_path}/include", + "${services_path}/screenservice/sourceservice/dscreenservice/include", "${interfaces_path}/innerkits/native_cpp/screen_source/include", "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", ] @@ -36,7 +37,10 @@ ohos_fuzztest("ProxyRegisterDistributedHardwareFuzzTest") { sources = [ "registerdistributedhardware_fuzzer.cpp" ] - deps = [ "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk" ] + deps = [ + "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", + "${services_path}/screenservice/sourceservice:distributed_screen_source", + ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/registerdistributedhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/registerdistributedhardware_fuzzer.cpp index cb91b02b..562294d5 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/registerdistributedhardware_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxyregisterdistributedhardware_fuzzer/registerdistributedhardware_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -21,11 +21,43 @@ #include "dscreen_constants.h" #include "dscreen_source_callback.h" #include "dscreen_source_proxy.h" +#include "dscreen_source_stub.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { +class DScreenSourceStubFuzzTest : public OHOS::DistributedHardware::DScreenSourceStub { +public: + DScreenSourceStubFuzzTest() = default; + ~DScreenSourceStubFuzzTest() = default; + int32_t InitSource(const std::string ¶ms, const sptr &callback) override + { + return 0; + }; + int32_t ReleaseSource() override + { + return 0; + }; + int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId, + const EnableParam ¶m, const std::string &reqId) override + { + return 0; + }; + void DScreenNotify(const std::string &devId, int32_t eventCode, + const std::string &eventContent) override {}; + int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId, + const std::string &reqId) override + { + return 0; + }; + int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, + const std::string &key, const std::string &value) override + { + return 0; + }; +}; + void RegisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(int32_t))) { @@ -41,19 +73,8 @@ void RegisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) param.sinkVersion = version; param.sinkAttrs = attrs; - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - return; - } - int32_t saId = *(reinterpret_cast(data)); - sptr remoteObject = samgr->GetSystemAbility(saId); - if (remoteObject == nullptr) { - return; - } - + sptr remoteObject(new DScreenSourceStubFuzzTest()); std::shared_ptr dscreenSourceProxy = std::make_shared(remoteObject); - dscreenSourceProxy->RegisterDistributedHardware(devId, dhId, param, reqId); } } -- Gitee