From 3630a4e509f72895e88e6f1685c8c8269db6e5b8 Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Tue, 25 Oct 2022 16:27:19 +0800 Subject: [PATCH] =?UTF-8?q?FUZZ=E8=A6=86=E7=9B=96=E7=8E=87=E6=8F=90?= =?UTF-8?q?=E5=8D=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinlong0101 --- .../native_cpp/test/fuzztest/BUILD.gn | 3 + .../callbackonnotifyregresult_fuzzer/BUILD.gn | 73 +++++++++++++++++++ .../callbackonnotifyregresult_fuzzer.cpp | 55 ++++++++++++++ .../callbackonnotifyregresult_fuzzer.h | 21 ++++++ .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../BUILD.gn | 73 +++++++++++++++++++ .../callbackonnotifyunregresult_fuzzer.cpp | 56 ++++++++++++++ .../callbackonnotifyunregresult_fuzzer.h | 21 ++++++ .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../callbackonremoterequest_fuzzer/BUILD.gn | 72 ++++++++++++++++++ .../callbackonremoterequest_fuzzer.cpp | 66 +++++++++++++++++ .../callbackonremoterequest_fuzzer.h | 21 ++++++ .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../src/dscreen_source_handler_test.cpp | 2 +- 17 files changed, 579 insertions(+), 1 deletion(-) create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/BUILD.gn create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.h create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/corpus/init create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/project.xml create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/BUILD.gn create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.h create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/corpus/init create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/project.xml create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/BUILD.gn create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.h create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/corpus/init create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/project.xml diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn index 19e02b6a..0c70ef08 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn @@ -23,6 +23,9 @@ group("fuzztest") { "dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer:fuzztest", "dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer:fuzztest", "dscreen_sink_proxy/sinkproxydscreennotify_fuzzer:fuzztest", + "dscreen_source_callback/callbackonnotifyregresult_fuzzer:fuzztest", + "dscreen_source_callback/callbackonnotifyunregresult_fuzzer:fuzztest", + "dscreen_source_callback/callbackonremoterequest_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/callbackonnotifyregresult_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/BUILD.gn new file mode 100644 index 00000000..52db1b2c --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2022 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( + "//foundation/distributedhardware/distributed_screen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("CallBackOnNotifyRegResultFuzzTest") { + module_out_path = "distributed_screen/dscreensourcecallback" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "include/callback", + "${common_path}/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + "${fwk_services_path}/distributedhardwarefwkservice/include", + "${fwk_services_path}/distributedhardwarefwkservice/include/componentmanager", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "callbackonnotifyregresult_fuzzer.cpp" ] + + deps = [ + "${fwk_services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", + "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"CallBackOnNotifyRegResultFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":CallBackOnNotifyRegResultFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp new file mode 100644 index 00000000..540a86c1 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 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 "callbackonnotifyregresult_fuzzer.h" + +#include +#include +#include + +#include "component_enable.h" +#include "dscreen_constants.h" +#include "dscreen_source_callback.h" +#include "dscreen_source_proxy.h" + +namespace OHOS { +namespace DistributedHardware { +void OnNotifyRegResultFuzzTest(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); + std::shared_ptr callback = std::make_shared(); + + sptr dScreenSourceCallback = new (std::nothrow) DScreenSourceCallback(); + dScreenSourceCallback->PushRegRegisterCallback(reqId, callback); + dScreenSourceCallback->OnNotifyRegResult(devId, dhId, reqId, status, dataStr); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::OnNotifyRegResultFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.h new file mode 100644 index 00000000..2d909d8c --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 CALLBACKONNOTIFYREGRESULT_FUZZER_H +#define CALLBACKONNOTIFYREGRESULT_FUZZER_H + +#define FUZZ_PROJECT_NAME "callbackonnotifyregresult_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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/callbackonnotifyregresult_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyregresult_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/BUILD.gn new file mode 100644 index 00000000..19906605 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2022 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( + "//foundation/distributedhardware/distributed_screen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("CallBackOnNotifyUnregResultFuzzTest") { + module_out_path = "distributed_screen/dscreensourcecallback" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "include/callback", + "${common_path}/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + "${fwk_services_path}/distributedhardwarefwkservice/include", + "${fwk_services_path}/distributedhardwarefwkservice/include/componentmanager", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "callbackonnotifyunregresult_fuzzer.cpp" ] + + deps = [ + "${fwk_services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", + "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"CallBackOnNotifyUnregResultFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":CallBackOnNotifyUnregResultFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp new file mode 100644 index 00000000..1f1bea6f --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 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 "callbackonnotifyunregresult_fuzzer.h" + +#include +#include +#include + +#include "component_disable.h" +#include "dscreen_constants.h" +#include "dscreen_source_callback.h" +#include "dscreen_source_proxy.h" + +namespace OHOS { +namespace DistributedHardware { +void OnNotifyUnregResultFuzzTest(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); + std::shared_ptr uncallback = std::make_shared(); + + sptr dScreenSourceCallback = new (std::nothrow) DScreenSourceCallback(); + + dScreenSourceCallback->PushUnregisterCallback(reqId, uncallback); + dScreenSourceCallback->OnNotifyUnregResult(devId, dhId, reqId, status, dataStr); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::OnNotifyUnregResultFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.h new file mode 100644 index 00000000..d4d60c9a --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 CALLBACKONNOTIFYUNREGRESULT_FUZZER_H +#define CALLBACKONNOTIFYUNREGRESULT_FUZZER_H + +#define FUZZ_PROJECT_NAME "callbackonnotifyunregresult_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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/callbackonnotifyunregresult_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonnotifyunregresult_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/BUILD.gn new file mode 100644 index 00000000..7d0dde8c --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2022 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( + "//foundation/distributedhardware/distributed_screen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("CallbackOnRemoteRequestFuzzTest") { + module_out_path = "distributed_screen/dscreensourcecallback" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "include/callback", + "${common_path}/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + "${fwk_services_path}/distributedhardwarefwkservice/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "callbackonremoterequest_fuzzer.cpp" ] + + deps = [ + "${fwk_services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", + "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"CallbackOnRemoteRequestFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":CallbackOnRemoteRequestFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp new file mode 100644 index 00000000..7d84b784 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 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 "callbackonremoterequest_fuzzer.h" + +#include +#include +#include + +#include "dscreen_constants.h" +#include "dscreen_source_callback.h" +#include "dscreen_source_callback_stub.h" +#include "dscreen_source_proxy.h" +#include "iremote_object.h" +#include "message_option.h" +#include "message_parcel.h" + +namespace OHOS { +namespace DistributedHardware { +void CallbackOnRemoteRequestFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t))) { + return; + } + + 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); + pdata.WriteInt32(status); + pdata.WriteString(devId); + pdata.WriteString(dhId); + pdata.WriteString(reqId); + pdata.WriteString(dataStr); + + sptr dScreenSourceCallback = new (std::nothrow) DScreenSourceCallback(); + dScreenSourceCallback->OnRemoteRequest(code, pdata, reply, option); +} +} +} + +/* 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; +} + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.h new file mode 100644 index 00000000..05ff48f2 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 CALLBACKONREMOTEREQUEST_FUZZER_H +#define CALLBACKONREMOTEREQUEST_FUZZER_H + +#define FUZZ_PROJECT_NAME "callbackonremoterequest_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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/callbackonremoterequest_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_callback/callbackonremoterequest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp index 86903c93..4eb35904 100644 --- a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp +++ b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp @@ -70,7 +70,7 @@ HWTEST_F(DScreenSourceHandlerTest, UnregisterDistributedHardware_001, TestSize.L const std::string dhId = "dhId"; std::shared_ptr callback = std::make_shared(); if (DScreenSourceHandler::GetInstance().dScreenSourceCallback_ == nullptr) { - DScreenSourceHandler::GetInstance().dScreenSourceCallback_ = new (std::nothrow) DScreenSourceCallback();; + DScreenSourceHandler::GetInstance().dScreenSourceCallback_ = new (std::nothrow) DScreenSourceCallback(); } int32_t ret = DScreenSourceHandler::GetInstance().UnregisterDistributedHardware(devId, dhId, callback); EXPECT_EQ(ERR_DH_SCREEN_SA_DISABLE_FAILED, ret); -- Gitee