diff --git a/services/screenservice/test/fuzztest/BUILD.gn b/services/screenservice/test/fuzztest/BUILD.gn index db10107df6ccfbe4722a6793fbeb45a457bc8d5a..4d55ed50920207d89a6408c48432e79078143ba7 100644 --- a/services/screenservice/test/fuzztest/BUILD.gn +++ b/services/screenservice/test/fuzztest/BUILD.gn @@ -17,6 +17,8 @@ group("fuzztest") { deps = [ "sinkservice/dscreenservice/dscreensinkstub_fuzzer:fuzztest", "sourceservice/dscreenmgr/onchange_fuzzer:fuzztest", + "sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer:fuzztest", + "sourceservice/dscreenservice/dscreensourceservice_fuzzer:fuzztest", "sourceservice/dscreenservice/dscreensourcestub_fuzzer:fuzztest", ] } diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/BUILD.gn b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a3b89ff981af3da4a26cde4853a4f7eaae513354 --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/BUILD.gn @@ -0,0 +1,61 @@ +# 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("DscreenSourceCallbackProxyFuzzTest") { + module_out_path = "${fuzz_test_path}/sourceservice" + fuzz_config_file = "${services_path}/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer" + + configs = + [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] + + sources = [ "dscreensourcecallbackproxy_fuzzer.cpp" ] + + include_dirs = [ + "${services_path}/screenservice/sourceservice/dscreenservice/include", + "${distributedscreen_path}/interfaces/innerkits/native_cpp/screen_source/include", + "${services_path}/screenservice/sourceservice/dscreenservice/include/callback", + "${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=\"DscreenSourceCallbackProxyFuzzTest\"", + "LOG_DOMAIN=0xD004140", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DscreenSourceCallbackProxyFuzzTest" ] +} +############################################################################### diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/corpus/init b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_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/dscreensourcecallbackproxy_fuzzer/dscreensourcecallbackproxy_fuzzer.cpp b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/dscreensourcecallbackproxy_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..04bb144d0a3bb498e0fac9372ef3a6a6e8b8ec62 --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/dscreensourcecallbackproxy_fuzzer.cpp @@ -0,0 +1,83 @@ +/* + * 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 "dscreensourcecallbackproxy_fuzzer.h" + +#include "idscreen_source.h" +#include "dscreen_source_callback_proxy.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; + }; + 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 DscreenSourceCallbackProxyFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + int32_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 resultData(reinterpret_cast(data), size); + + sptr dscreenSourceStubPtr(new DScreenSourceStubFuzzTest()); + sptr sourceCbkProxy(new DScreenSourceCallbackProxy(dscreenSourceStubPtr)); + sourceCbkProxy->OnNotifyRegResult(devId, dhId, reqId, status, resultData); + sourceCbkProxy->OnNotifyUnregResult(devId, dhId, reqId, status, resultData); + sourceCbkProxy->CheckParams(devId, dhId, reqId, resultData); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DscreenSourceCallbackProxyFuzzTest(data, size); + return 0; +} diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/dscreensourcecallbackproxy_fuzzer.h b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/dscreensourcecallbackproxy_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..41a71f4e0b4d0529ce78dc7711d0c085d3cdcdb0 --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/dscreensourcecallbackproxy_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 "dscreensourcecallbackproxy_fuzzer" + +#endif diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/project.xml b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/BUILD.gn b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9d80fa12e92982d16c476e6eacf1dddbe4d67db8 --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/BUILD.gn @@ -0,0 +1,74 @@ +# 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("DscreenSourceServiceFuzzTest") { + module_out_path = "${fuzz_test_path}/sourceservice" + fuzz_config_file = "${services_path}/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer" + + configs = + [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] + + sources = [ "dscreensourceservice_fuzzer.cpp" ] + + include_dirs = [ + "${common_path}/include", + "${distributedscreen_path}/interfaces/innerkits/native_cpp/screen_source/include", + "${distributedscreen_path}/interfaces/innerkits/native_cpp/screen_sink/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + "${services_path}/common/utils/include", + "${services_path}/screenservice/sourceservice/dscreenmgr", + "${services_path}/screenservice/sourceservice/dscreenservice/include", + "${services_path}/screentransport/screensourcetrans/include", + ] + + deps = [ + "${common_path}:distributed_screen_utils", + "${interfaces_path}/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk", + "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", + "${services_path}/screenservice/sourceservice:distributed_screen_source", + "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans", + ] + + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "distributed_hardware_fwk:distributed_av_receiver", + "distributed_hardware_fwk:distributedhardwareutils", + "distributed_hardware_fwk:libdhfwk_sdk", + "graphic_2d:librender_service_client", + "graphic_surface:surface", + "hilog:libhilog", + "ipc:ipc_core", + "samgr:samgr_proxy", + "window_manager:libdm", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DscreenSourceServiceFuzzTest\"", + "LOG_DOMAIN=0xD004140", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DscreenSourceServiceFuzzTest" ] +} +############################################################################### diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/corpus/init b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_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/dscreensourceservice_fuzzer/dscreensourceservice_fuzzer.cpp b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/dscreensourceservice_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e51400484df41fe6aa4ad60edc053df39d1b534f --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/dscreensourceservice_fuzzer.cpp @@ -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. + */ + +#include "dscreensourceservice_fuzzer.h" + +#include "string_ex.h" +#include "idscreen_source.h" +#include "dscreen_source_service.h" +#include "dscreen_source_callback.h" + +namespace OHOS { +namespace DistributedHardware { +const std::u16string ABILITYMGR_INTERFACE_TOKEN = u"ohos.aafwk.AbilityManager"; +void DscreenSourceServiceFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + + std::string version(reinterpret_cast(data), size); + std::string attrs(reinterpret_cast(data), size); + EnableParam param; + param.sinkVersion = version; + param.sinkAttrs = attrs; + uint32_t code = *(reinterpret_cast(data)) % 2; + std::string dhId(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + std::string eventContent(reinterpret_cast(data), size); + std::string params(reinterpret_cast(data), size); + std::shared_ptr sourceServicePtr = std::make_shared(0, false); + sptr callback(new DScreenSourceCallback()); + sourceServicePtr->registerToService_ = true; + sourceServicePtr->Init(); + sourceServicePtr->InitSource(params, callback); + sourceServicePtr->RegisterDistributedHardware(devId, dhId, param, reqId); + sourceServicePtr->DScreenNotify(devId, code, eventContent); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DscreenSourceServiceFuzzTest(data, size); + return 0; +} diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/dscreensourceservice_fuzzer.h b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/dscreensourceservice_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..9489a459ca3c229ec67e2b3c86a9a3be12e142e6 --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/dscreensourceservice_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_SERVICE_FUZZER_H +#define DSCREEN_SOURCE_SERVICE_FUZZER_H + +#define FUZZ_PROJECT_NAME "dscreensourceservice_fuzzer" + +#endif diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/project.xml b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourceservice_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + 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 index 0353c55a854799b2e6d7512449dbf555ec5d2ca2..6621b80aaae486455411e1bb4f3648c5f43ca410 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.cpp +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenservice/dscreensourcestub_fuzzer/dscreensourcestub_fuzzer.cpp @@ -67,6 +67,8 @@ void DscreenSourceStubFuzzTest(const uint8_t* data, size_t size) std::string devId(reinterpret_cast(data), size); std::string reqId(reinterpret_cast(data), size); std::string dataStr(reinterpret_cast(data), size); + std::string version(reinterpret_cast(data), size); + std::string attrs(reinterpret_cast(data), size); pdata.WriteInt32(status); pdata.WriteString(devId); pdata.WriteString(dhId); @@ -81,6 +83,8 @@ void DscreenSourceStubFuzzTest(const uint8_t* data, size_t size) sourceStubPtr->UnregisterDistributedHardwareInner(pdata, reply, option); sourceStubPtr->ConfigDistributedHardwareInner(pdata, reply, option); sourceStubPtr->DScreenNotifyInner(pdata, reply, option); + sourceStubPtr->CheckRegParams(devId, dhId, version, attrs, reqId); + sourceStubPtr->CheckUnregParams(devId, dhId, reqId); } } } diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp index 0303ba847438e44066755a02d28c61a1e2dab1c5..f2e663a67887c2a7414cfa896f90dc88a7d0a0fd 100644 --- a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp @@ -58,6 +58,9 @@ void SoftbusAdapterFuzzTest(const uint8_t* data, size_t size) adapter->sessListener_.OnBytes(sessionId, adapterData, dataLen); adapter->sessListener_.OnStream(sessionId, stream, ext, info); adapter->sessListener_.OnMessage(sessionId, adapterData, dataLen1); + adapter->SendSoftbusStream(sessionId, stream, ext, info); + adapter->SendSoftbusBytes(sessionId, adapterData, dataLen1); + adapter->CloseSoftbusSession(sessionId); } } }