From 454a93f51ef8eb86b968637499967b9015960d0b Mon Sep 17 00:00:00 2001 From: pwx1285814 Date: Sat, 13 Apr 2024 19:21:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85fuzz=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 --- bundle.json | 2 +- .../native_cpp/test/fuzztest/BUILD.gn | 3 +- .../dscreensourcecallbackstub_fuzzer/BUILD.gn | 59 ++++++++++++ .../corpus/init | 14 +++ .../dscreensourcecallbackstub_fuzzer.cpp | 75 +++++++++++++++ .../dscreensourcecallbackstub_fuzzer.h | 21 +++++ .../project.xml | 25 +++++ services/screenservice/test/fuzztest/BUILD.gn | 22 +++++ .../dscreensinkstub_fuzzer/BUILD.gn | 60 ++++++++++++ .../dscreensinkstub_fuzzer/corpus/init | 16 ++++ .../dscreensinkstub_fuzzer.cpp | 84 +++++++++++++++++ .../dscreensinkstub_fuzzer.h | 21 +++++ .../dscreensinkstub_fuzzer/project.xml | 25 +++++ .../dscreenmgr/onchange_fuzzer/BUILD.gn | 7 ++ .../dscreensourcestub_fuzzer/BUILD.gn | 60 ++++++++++++ .../dscreensourcestub_fuzzer/corpus/init | 16 ++++ .../dscreensourcestub_fuzzer.cpp | 94 +++++++++++++++++++ .../dscreensourcestub_fuzzer.h | 21 +++++ .../dscreensourcestub_fuzzer/project.xml | 25 +++++ .../softbusadapter/test/fuzztest/BUILD.gn | 3 +- .../fuzztest/softbusadapter_fuzzer/BUILD.gn | 64 +++++++++++++ .../softbusadapter_fuzzer/corpus/init | 16 ++++ .../softbusadapter_fuzzer/project.xml | 25 +++++ .../softbusadapter_fuzzer.cpp | 71 ++++++++++++++ .../softbusadapter_fuzzer.h | 21 +++++ 25 files changed, 847 insertions(+), 3 deletions(-) create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/BUILD.gn create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/corpus/init create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/dscreensourcecallbackstub_fuzzer.cpp create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/dscreensourcecallbackstub_fuzzer.h create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/project.xml create mode 100644 services/screenservice/test/fuzztest/BUILD.gn create mode 100644 services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/BUILD.gn create mode 100644 services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/corpus/init create mode 100644 services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/dscreensinkstub_fuzzer.cpp create mode 100644 services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/dscreensinkstub_fuzzer.h create mode 100644 services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/project.xml create mode 100644 services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/BUILD.gn create mode 100644 services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/corpus/init create mode 100644 services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.cpp create mode 100644 services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.h create mode 100644 services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/project.xml create mode 100644 services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/BUILD.gn create mode 100644 services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/corpus/init create mode 100644 services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/project.xml create mode 100644 services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp create mode 100644 services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h diff --git a/bundle.json b/bundle.json index 9af1d0e8..1a3c4914 100644 --- a/bundle.json +++ b/bundle.json @@ -102,7 +102,7 @@ "//foundation/distributedhardware/distributed_screen/screenhandler/test/fuzztest:fuzztest", "//foundation/distributedhardware/distributed_screen/services/softbusadapter/test/fuzztest:fuzztest", "//foundation/distributedhardware/distributed_screen/interfaces/innerkits/native_cpp/test/fuzztest:fuzztest", - "//foundation/distributedhardware/distributed_screen/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer:OnChangeFuzzTest" + "//foundation/distributedhardware/distributed_screen/services/screenservice/test/fuzztest:fuzztest" ] } } diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn index 42878d82..f781614f 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-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 @@ -26,6 +26,7 @@ group("fuzztest") { "dscreen_source_callback/callbackonnotifyregresult_fuzzer:fuzztest", "dscreen_source_callback/callbackonnotifyunregresult_fuzzer:fuzztest", "dscreen_source_callback/callbackonremoterequest_fuzzer:fuzztest", + "dscreen_source_callback/dscreensourcecallbackstub_fuzzer:fuzztest", "dscreen_source_handler/handlerconfigdistributedhardware_fuzzer:fuzztest", "dscreen_source_handler/handlerinitsource_fuzzer:fuzztest", "dscreen_source_handler/handleronremotesourcesvrdied_fuzzer:fuzztest", diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/BUILD.gn new file mode 100644 index 00000000..047e26f9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/BUILD.gn @@ -0,0 +1,59 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../../../distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DscreenSourceCallbackStubFuzzTest") { + module_out_path = "${fuzz_test_path}/sourceservice" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer" + + include_dirs = [ + "${common_path}/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + ] + + configs = + [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] + + sources = [ "dscreensourcecallbackstub_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_screen_utils", + "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DscreenSourceCallbackStubFuzzTest\"", + "LOG_DOMAIN=0xD004140", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DscreenSourceCallbackStubFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/corpus/init new file mode 100644 index 00000000..e7c3fecd --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/dscreensourcecallbackstub_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/dscreensourcecallbackstub_fuzzer.cpp new file mode 100644 index 00000000..8284ee4f --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/dscreensourcecallbackstub_fuzzer.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dscreensourcecallbackstub_fuzzer.h" +#include "dscreen_errcode.h" +#include "dscreen_source_callback_stub.h" + +namespace OHOS { +namespace DistributedHardware { + +class DScreenSourceCallbackStubFuzzTest : public DScreenSourceCallbackStub { +public: + DScreenSourceCallbackStubFuzzTest() = default; + ~DScreenSourceCallbackStubFuzzTest() = default; + int32_t OnNotifyRegResult(const std::string &devId, const std::string &dhId, + const std::string &reqId, int32_t status, const std::string &data) override + { + return 0; + }; + int32_t OnNotifyUnregResult(const std::string &devId, const std::string &dhId, + const std::string &reqId, int32_t status, const std::string &data) override + { + return 0; + }; +}; + +void DscreenSourceCallbackStubFuzzTest(const uint8_t* data, size_t size) +{ + if ((size < sizeof(uint32_t)) || (data == nullptr)) { + return; + } + + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + unsigned int code = *(reinterpret_cast(data)) % 2; + uint32_t status = *(reinterpret_cast(data)); + std::string dhId(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + std::string dataStr(reinterpret_cast(data), size); + pdata.WriteInt32(status); + pdata.WriteString(devId); + pdata.WriteString(dhId); + pdata.WriteString(reqId); + pdata.WriteString(dataStr); + + std::shared_ptr dScreenSourceCallbackStub = + std::make_shared(); + dScreenSourceCallbackStub->OnRemoteRequest(code, pdata, reply, option); + dScreenSourceCallbackStub->OnNotifyRegResultInner(pdata, reply, option); + dScreenSourceCallbackStub->OnNotifyUnregResultInner(pdata, reply, option); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DscreenSourceCallbackStubFuzzTest(data, size); + return 0; +} diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/dscreensourcecallbackstub_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/dscreensourcecallbackstub_fuzzer.h new file mode 100644 index 00000000..2061b292 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/dscreensourcecallbackstub_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DSCREEN_SOURCE_CALLBACK_STUB_FUZZER_H +#define DSCREEN_SOURCE_CALLBACK_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "dscreensourcecallbackstub_fuzzer" + +#endif diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/dscreensourcecallbackstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/screenservice/test/fuzztest/BUILD.gn b/services/screenservice/test/fuzztest/BUILD.gn new file mode 100644 index 00000000..db10107d --- /dev/null +++ b/services/screenservice/test/fuzztest/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("fuzztest") { + testonly = true + + deps = [ + "sinkservice/dscreenservice/dscreensinkstub_fuzzer:fuzztest", + "sourceservice/dscreenmgr/onchange_fuzzer:fuzztest", + "sourceservice/dscreenservice/dscreensourcestub_fuzzer:fuzztest", + ] +} diff --git a/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/BUILD.gn b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/BUILD.gn new file mode 100644 index 00000000..9cb3ee8a --- /dev/null +++ b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/BUILD.gn @@ -0,0 +1,60 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../../../distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DscreenSinkStubFuzzTest") { + module_out_path = "${fuzz_test_path}/sinkservice" + fuzz_config_file = "${services_path}/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer" + + configs = + [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] + + sources = [ "dscreensinkstub_fuzzer.cpp" ] + + include_dirs = [ + "${services_path}/screenservice/sinkservice/dscreenservice/include", + "${distributedscreen_path}/interfaces/innerkits/native_cpp/screen_sink/include", + "${interfaces_path}/innerkits/native_cpp/screen_sink/include/callback", + ] + + deps = [ + "${interfaces_path}/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk", + "${services_path}/screenservice/sinkservice:distributed_screen_sink", + ] + + external_deps = [ + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "hilog:libhilog", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DscreenSinkStubFuzzTest\"", + "LOG_DOMAIN=0xD004140", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DscreenSinkStubFuzzTest" ] +} +############################################################################### diff --git a/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/corpus/init b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/corpus/init new file mode 100644 index 00000000..6198079a --- /dev/null +++ b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/dscreensinkstub_fuzzer.cpp b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/dscreensinkstub_fuzzer.cpp new file mode 100644 index 00000000..16a7bfae --- /dev/null +++ b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/dscreensinkstub_fuzzer.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dscreensinkstub_fuzzer.h" + +#include "dscreen_sink_stub.h" + +namespace OHOS { +namespace DistributedHardware { +class DScreenSinkStubFuzzTest : public OHOS::DistributedHardware::DScreenSinkStub { +public: + DScreenSinkStubFuzzTest() = default; + ~DScreenSinkStubFuzzTest() = default; + int32_t InitSink(const std::string ¶ms) override + { + return 0; + }; + int32_t ReleaseSink() override + { + return 0; + }; + int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) override + { + return 0; + }; + int32_t UnsubscribeLocalHardware(const std::string &dhId) override + { + return 0; + }; + void DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) override {}; +}; + + +void DscreenSinkStubFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + uint32_t code = *(reinterpret_cast(data)) % 2; + uint32_t status = *(reinterpret_cast(data)); + std::string dhId(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + std::string dataStr(reinterpret_cast(data), size); + pdata.WriteInt32(status); + pdata.WriteString(devId); + pdata.WriteString(dhId); + pdata.WriteString(reqId); + pdata.WriteString(dataStr); + + sptr sourceStubPtr(new DScreenSinkStubFuzzTest()); + sourceStubPtr->OnRemoteRequest(code, pdata, reply, option); + sourceStubPtr->InitSinkInner(pdata, reply, option); + sourceStubPtr->ReleaseSinkInner(pdata, reply, option); + sourceStubPtr->SubscribeDistributedHardwareInner(pdata, reply, option); + sourceStubPtr->UnsubscribeDistributedHardwareInner(pdata, reply, option); + sourceStubPtr->DScreenNotifyInner(pdata, reply, option); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DscreenSinkStubFuzzTest(data, size); + return 0; +} diff --git a/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/dscreensinkstub_fuzzer.h b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/dscreensinkstub_fuzzer.h new file mode 100644 index 00000000..645298f8 --- /dev/null +++ b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/dscreensinkstub_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DSCREEN_SOURCE_STUB_FUZZER_H +#define DSCREEN_SOURCE_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "dscreensinkstub_fuzzer" + +#endif diff --git a/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/project.xml b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/services/screenservice/test/fuzztest/sinkservice/dscreenservice/dscreensinkstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/BUILD.gn b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/BUILD.gn index fa32683e..be9d7eaa 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/BUILD.gn +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/BUILD.gn @@ -60,3 +60,10 @@ ohos_fuzztest("OnChangeFuzzTest") { "window_manager:libdm", ] } + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":OnChangeFuzzTest" ] +} +############################################################################### diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/BUILD.gn b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/BUILD.gn new file mode 100644 index 00000000..503975ed --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/BUILD.gn @@ -0,0 +1,60 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../../../distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DscreenSourceStubFuzzTest") { + module_out_path = "${fuzz_test_path}/sourceservice" + fuzz_config_file = "${services_path}/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer" + + configs = + [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] + + sources = [ "dscreensourcestub_fuzzer.cpp" ] + + include_dirs = [ + "${services_path}/screenservice/sourceservice/dscreenservice/include", + "${distributedscreen_path}/interfaces/innerkits/native_cpp/screen_source/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + ] + + deps = [ + "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", + "${services_path}/screenservice/sourceservice:distributed_screen_source", + ] + + external_deps = [ + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "hilog:libhilog", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DscreenSourceStubFuzzTest\"", + "LOG_DOMAIN=0xD004140", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DscreenSourceStubFuzzTest" ] +} +############################################################################### diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/corpus/init b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/corpus/init new file mode 100644 index 00000000..6198079a --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.cpp b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.cpp new file mode 100644 index 00000000..0353c55a --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dscreensourcestub_fuzzer.h" + +#include "idscreen_source.h" +#include "dscreen_source_stub.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; + }; + 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 DScreenNotify(const std::string &devId, int32_t eventCode, + const std::string &eventContent) override {}; +}; + + +void DscreenSourceStubFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + uint32_t code = *(reinterpret_cast(data)) % 2; + uint32_t status = *(reinterpret_cast(data)); + std::string dhId(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + std::string dataStr(reinterpret_cast(data), size); + pdata.WriteInt32(status); + pdata.WriteString(devId); + pdata.WriteString(dhId); + pdata.WriteString(reqId); + pdata.WriteString(dataStr); + + std::shared_ptr sourceStubPtr = std::make_shared(); + sourceStubPtr->OnRemoteRequest(code, pdata, reply, option); + sourceStubPtr->InitSourceInner(pdata, reply, option); + sourceStubPtr->ReleaseSourceInner(pdata, reply, option); + sourceStubPtr->RegisterDistributedHardwareInner(pdata, reply, option); + sourceStubPtr->UnregisterDistributedHardwareInner(pdata, reply, option); + sourceStubPtr->ConfigDistributedHardwareInner(pdata, reply, option); + sourceStubPtr->DScreenNotifyInner(pdata, reply, option); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DscreenSourceStubFuzzTest(data, size); + return 0; +} diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.h b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.h new file mode 100644 index 00000000..891aace0 --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DSCREEN_SOURCE_STUB_FUZZER_H +#define DSCREEN_SOURCE_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "dscreensourcestub_fuzzer" + +#endif diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/project.xml b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/softbusadapter/test/fuzztest/BUILD.gn b/services/softbusadapter/test/fuzztest/BUILD.gn index fae51a42..5798ca82 100644 --- a/services/softbusadapter/test/fuzztest/BUILD.gn +++ b/services/softbusadapter/test/fuzztest/BUILD.gn @@ -1,4 +1,4 @@ -# 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 @@ -15,6 +15,7 @@ group("fuzztest") { testonly = true deps = [ + "softbusadapter_fuzzer:fuzztest", "softbusonbytesreceived_fuzzer:fuzztest", "softbusonmessagereceived_fuzzer:fuzztest", "softbusonsessionclosed_fuzzer:fuzztest", diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..e2bf14e4 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/BUILD.gn @@ -0,0 +1,64 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SoftbusAdapterFuzzTest") { + module_out_path = "${fuzz_test_path}/softbusadapter" + fuzz_config_file = + "${services_path}/softbusadapter/test/fuzztest/softbusadapter_fuzzer" + + configs = + [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] + + sources = [ "softbusadapter_fuzzer.cpp" ] + + include_dirs = [ + "${common_path}/include", + "${services_path}/common/databuffer/include", + "${services_path}/common/screen_channel/include", + "${services_path}/common/utils/include", + "${services_path}/screentransport/screensourcetrans/include", + "${services_path}/screentransport/screendatachannel/include", + "${services_path}/screentransport/screensourceprocessor/include", + "${services_path}/screentransport/screensourceprocessor/encoder/include", + "${services_path}/softbusadapter/include", + ] + + deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] + + external_deps = [ + "c_utils:utils", + "distributed_hardware_fwk:distributed_av_receiver", + "distributed_hardware_fwk:libdhfwk_sdk", + "dsoftbus:softbus_client", + "hilog:libhilog", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SoftbusAdapterFuzzTest\"", + "LOG_DOMAIN=0xD004140", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SoftbusAdapterFuzzTest" ] +} +############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/corpus/init new file mode 100644 index 00000000..6198079a --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp new file mode 100644 index 00000000..0303ba84 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "softbusadapter_fuzzer.h" + +#include "dscreen_constants.h" +#include "dscreen_errcode.h" +#include "dscreen_util.h" +#include "isoftbus_listener.h" +#include "softbus_bus_center.h" +#include "softbus_common.h" +#include "softbus_adapter.h" + +namespace OHOS { +namespace DistributedHardware { +namespace { + const std::string PEER_SESSION_NAME = "ohos.dhardware.dscreen.session8647073e02e7a78f09473aa324"; + const std::string REMOTE_DEV_ID = "f6d4c0864707aefte7a78f09473aa122ff57fc81c00981fcf5be989e7d112324"; + const std::string DSCREEN_PKG_NAME_TEST = "ohos.dhardware.dscreen"; +} +void SoftbusAdapterFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + + PeerSocketInfo peerSocketInfo = { + .name = const_cast(PEER_SESSION_NAME.c_str()), + .networkId = const_cast(REMOTE_DEV_ID.c_str()), + .pkgName = const_cast(DSCREEN_PKG_NAME_TEST.c_str()), + .dataType = DATA_TYPE_BYTES + }; + ShutdownReason reason = SHUTDOWN_REASON_UNKNOWN; + + void *adapterData = nullptr; + uint32_t dataLen = *(reinterpret_cast(data)); + StreamData *stream = nullptr; + StreamData *ext = nullptr; + StreamFrameInfo *info = nullptr; + unsigned int dataLen1 = *(reinterpret_cast(data)); + + std::shared_ptr adapter = std::make_shared(); + adapter->sessListener_.OnBind(sessionId, peerSocketInfo); + adapter->sessListener_.OnShutdown(sessionId, reason); + adapter->sessListener_.OnBytes(sessionId, adapterData, dataLen); + adapter->sessListener_.OnStream(sessionId, stream, ext, info); + adapter->sessListener_.OnMessage(sessionId, adapterData, dataLen1); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SoftbusAdapterFuzzTest(data, size); + return 0; +} diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h new file mode 100644 index 00000000..d6ae1c1c --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOFTBUSADAPTER_FUZZER_H +#define SOFTBUSADAPTER_FUZZER_H + +#define FUZZ_PROJECT_NAME "softbusadapter_fuzzer" + +#endif -- Gitee