diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 09f319e36958b6902c84d87bc1bdebd645363d55..6b0b5e5fefbd8a8f37f7fae84f829cee2dbc0147 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -15,8 +15,12 @@ group("fuzztest") { testonly = true deps = [ - "dinputsinkhandler_fuzzer:fuzztest", - "dinputsourcehandler_fuzzer:fuzztest", + "dinputconfigdh_fuzzer:fuzztest", + "dinputinitsink_fuzzer:fuzztest", + "dinputinitsource_fuzzer:fuzztest", + "dinputreleasesink_fuzzer:fuzztest", + "dinputreleasesource_fuzzer:fuzztest", + "dinputsubscribelocaldh_fuzzer:fuzztest", "distributedinputclient_fuzzer:fuzztest", "distributedinputkit_fuzzer:fuzztest", "distributedinputsinktransport_fuzzer:fuzztest", diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/BUILD.gn b/test/fuzztest/dinputconfigdh_fuzzer/BUILD.gn similarity index 88% rename from test/fuzztest/dinputsourcehandler_fuzzer/BUILD.gn rename to test/fuzztest/dinputconfigdh_fuzzer/BUILD.gn index 76f3e60cd48c3fb4b3db9b31ec41a128c26558c8..9966adedbe73b02129bf8f02aae428cf6ab9e234 100644 --- a/test/fuzztest/dinputsourcehandler_fuzzer/BUILD.gn +++ b/test/fuzztest/dinputconfigdh_fuzzer/BUILD.gn @@ -17,11 +17,11 @@ import("//build/test.gni") import("../../../distributedinput.gni") ##############################fuzztest########################################## -ohos_fuzztest("DinputSourceHandlerFuzzTest") { +ohos_fuzztest("DinputConfigDhFuzzTest") { module_out_path = "distributed_input/system" fuzz_config_file = - "${distributedinput_path}/test/fuzztest/dinputsourcehandler_fuzzer" + "${distributedinput_path}/test/fuzztest/dinputconfigdh_fuzzer" include_dirs = [ "include", @@ -31,7 +31,6 @@ ohos_fuzztest("DinputSourceHandlerFuzzTest") { "${distributedinput_path}/services/sink/sinkmanager/include", "${distributedinput_path}/frameworks/include", "${distributedinput_path}/sourcehandler/include", - "${distributedinput_path}/sinkhandler/include", "${distributedinput_path}/inputdevicehandler/include", "${service_common}/include", "${common_path}/include", @@ -53,7 +52,7 @@ ohos_fuzztest("DinputSourceHandlerFuzzTest") { "-fno-omit-frame-pointer", ] - sources = [ "dinput_source_handler_fuzzer.cpp" ] + sources = [ "dinputconfigdh_fuzzer.cpp" ] deps = [ "${distributedinput_path}/sourcehandler:libdinput_source_handler", @@ -70,7 +69,7 @@ ohos_fuzztest("DinputSourceHandlerFuzzTest") { defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DinputSourceHandlerFuzzTest\"", + "DH_LOG_TAG=\"DinputConfigDhFuzzTest\"", "LOG_DOMAIN=0xD004100", ] } @@ -79,6 +78,6 @@ ohos_fuzztest("DinputSourceHandlerFuzzTest") { group("fuzztest") { testonly = true - deps = [ ":DinputSourceHandlerFuzzTest" ] + deps = [ ":DinputConfigDhFuzzTest" ] } ############################################################################### diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/corpus/init b/test/fuzztest/dinputconfigdh_fuzzer/corpus/init similarity index 100% rename from test/fuzztest/dinputsinkhandler_fuzzer/corpus/init rename to test/fuzztest/dinputconfigdh_fuzzer/corpus/init diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.cpp b/test/fuzztest/dinputconfigdh_fuzzer/dinputconfigdh_fuzzer.cpp similarity index 54% rename from test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.cpp rename to test/fuzztest/dinputconfigdh_fuzzer/dinputconfigdh_fuzzer.cpp index c3376404965fe026d7421a55374db5a850747480..fcf9cfb65fe9616167020fa80e0c9e75040ea865 100644 --- a/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.cpp +++ b/test/fuzztest/dinputconfigdh_fuzzer/dinputconfigdh_fuzzer.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "dinput_source_handler_fuzzer.h" +#include "dinputconfigdh_fuzzer.h" #include #include @@ -26,51 +26,11 @@ #include "constants_dinput.h" #include "distributed_input_handler.h" #include "distributed_input_kit.h" -#include "distributed_input_sink_handler.h" #include "distributed_input_source_handler.h" -#include "i_distributed_sink_input.h" #include "i_distributed_source_input.h" namespace OHOS { namespace DistributedHardware { -class TestRegisterInputCallback : public OHOS::DistributedHardware::RegisterCallback { -public: - TestRegisterInputCallback() = default; - virtual ~TestRegisterInputCallback() = default; - int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, - const std::string &data) override - { - return 0; - } -}; - -class TestUnregisterInputCallback : public OHOS::DistributedHardware::UnregisterCallback { -public: - TestUnregisterInputCallback() = default; - virtual ~TestUnregisterInputCallback() = default; - int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status, - const std::string &data) override - { - return 0; - } -}; - -void InitSourceFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - std::string params(reinterpret_cast(data), size); - DistributedInput::DistributedInputSourceHandler::GetInstance().InitSource(params); -} - -void ReleaseSourceFuzzTest(const uint8_t* data, size_t size) -{ - (void)data; - (void)size; - DistributedInput::DistributedInputSourceHandler::GetInstance().ReleaseSource(); -} - void ConfigDistributedHardwareFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size == 0)) { @@ -89,8 +49,6 @@ void ConfigDistributedHardwareFuzzTest(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::DistributedHardware::InitSourceFuzzTest(data, size); - OHOS::DistributedHardware::ReleaseSourceFuzzTest(data, size); OHOS::DistributedHardware::ConfigDistributedHardwareFuzzTest(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.h b/test/fuzztest/dinputconfigdh_fuzzer/dinputconfigdh_fuzzer.h similarity index 77% rename from test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.h rename to test/fuzztest/dinputconfigdh_fuzzer/dinputconfigdh_fuzzer.h index dda0d85d3c9681c7b153fc959cb1e2603fb9398e..3e9378cee5012ef63ce4b1369afb5bc1c9a389f1 100644 --- a/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.h +++ b/test/fuzztest/dinputconfigdh_fuzzer/dinputconfigdh_fuzzer.h @@ -14,9 +14,9 @@ */ -#ifndef DINPUT_SOURCE_HANDLER_FUZZER_H -#define DINPUT_SOURCE_HANDLER_FUZZER_H +#ifndef DINPUT_CONFIG_DH_FUZZER_H +#define DINPUT_CONFIG_DH_FUZZER_H -#define FUZZ_PROJECT_NAME "dinputsourcehandler_fuzzer" +#define FUZZ_PROJECT_NAME "dinputconfigdh_fuzzer" -#endif // DINPUT_SOURCE_HANDLER_FUZZER_H \ No newline at end of file +#endif // DINPUT_CONFIG_DH_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/project.xml b/test/fuzztest/dinputconfigdh_fuzzer/project.xml similarity index 100% rename from test/fuzztest/dinputsinkhandler_fuzzer/project.xml rename to test/fuzztest/dinputconfigdh_fuzzer/project.xml diff --git a/test/fuzztest/dinputinitsink_fuzzer/BUILD.gn b/test/fuzztest/dinputinitsink_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a1148cdf506ddde570a07db58413583b533dcc07 --- /dev/null +++ b/test/fuzztest/dinputinitsink_fuzzer/BUILD.gn @@ -0,0 +1,83 @@ +# Copyright (c) 2021-2023 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("../../../distributedinput.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DinputInitSinkFuzzTest") { + module_out_path = "distributed_input/system" + + fuzz_config_file = + "${distributedinput_path}/test/fuzztest/dinputinitsink_fuzzer" + + include_dirs = [ + "include", + "${distributedinput_path}/interfaces/inner_kits/include", + "${distributedinput_path}/interfaces/ipc/include", + "${distributedinput_path}/services/source/sourcemanager/include", + "${distributedinput_path}/services/sink/sinkmanager/include", + "${distributedinput_path}/frameworks/include", + "${distributedinput_path}/sinkhandler/include", + "${distributedinput_path}/inputdevicehandler/include", + "${service_common}/include", + "${common_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "//third_party/json/include", + "${fwk_interfaces_path}/include", + "${fwk_interfaces_path}/include/ipc", + "${services_source_path}/inputinject/include", + "${utils_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dinputinitsink_fuzzer.cpp" ] + + deps = [ + "${distributedinput_path}/sinkhandler:libdinput_sink_handler", + "//third_party/libevdev:libevdev", + ] + + external_deps = [ + "c_utils:utils", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DinputInitSinkFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DinputInitSinkFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/corpus/init b/test/fuzztest/dinputinitsink_fuzzer/corpus/init similarity index 100% rename from test/fuzztest/dinputsourcehandler_fuzzer/corpus/init rename to test/fuzztest/dinputinitsink_fuzzer/corpus/init diff --git a/test/fuzztest/dinputinitsink_fuzzer/dinputinitsink_fuzzer.cpp b/test/fuzztest/dinputinitsink_fuzzer/dinputinitsink_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..81a4b6bade609ced2b5fa91b28b79d5d4faa3ac9 --- /dev/null +++ b/test/fuzztest/dinputinitsink_fuzzer/dinputinitsink_fuzzer.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 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 "dinputinitsink_fuzzer.h" + +#include +#include +#include +#include +#include + +#include + +#include "constants_dinput.h" +#include "distributed_input_handler.h" +#include "distributed_input_kit.h" +#include "distributed_input_sink_handler.h" +#include "i_distributed_sink_input.h" + +namespace OHOS { +namespace DistributedHardware { +void InitSinkFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string params(reinterpret_cast(data), size); + DistributedInput::DistributedInputSinkHandler::GetInstance().InitSink(params); +} +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::InitSinkFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/dinputinitsink_fuzzer/dinputinitsink_fuzzer.h b/test/fuzztest/dinputinitsink_fuzzer/dinputinitsink_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..657a0d176a17a5ad44ee5eeefcc20050ae1ccf8d --- /dev/null +++ b/test/fuzztest/dinputinitsink_fuzzer/dinputinitsink_fuzzer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 DINPUT_INIT_SINK_FUZZER_H +#define DINPUT_INIT_SINK_FUZZER_H + +#define FUZZ_PROJECT_NAME "dinputreleasesink_fuzzer" + +#endif // DINPUT_INIT_SINK_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/project.xml b/test/fuzztest/dinputinitsink_fuzzer/project.xml similarity index 100% rename from test/fuzztest/dinputsourcehandler_fuzzer/project.xml rename to test/fuzztest/dinputinitsink_fuzzer/project.xml diff --git a/test/fuzztest/dinputinitsource_fuzzer/BUILD.gn b/test/fuzztest/dinputinitsource_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fd97c13001d1ae946afca77aa176253a24305b8a --- /dev/null +++ b/test/fuzztest/dinputinitsource_fuzzer/BUILD.gn @@ -0,0 +1,83 @@ +# Copyright (c) 2023 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("../../../distributedinput.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DinputInitSourceFuzzTest") { + module_out_path = "distributed_input/system" + + fuzz_config_file = + "${distributedinput_path}/test/fuzztest/dinputinitsource_fuzzer" + + include_dirs = [ + "include", + "${distributedinput_path}/interfaces/inner_kits/include", + "${distributedinput_path}/interfaces/ipc/include", + "${distributedinput_path}/services/source/sourcemanager/include", + "${distributedinput_path}/services/sink/sinkmanager/include", + "${distributedinput_path}/frameworks/include", + "${distributedinput_path}/sourcehandler/include", + "${distributedinput_path}/inputdevicehandler/include", + "${service_common}/include", + "${common_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "//third_party/json/include", + "${fwk_interfaces_path}/include", + "${fwk_interfaces_path}/include/ipc", + "${services_source_path}/inputinject/include", + "${utils_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dinputinitsource_fuzzer.cpp" ] + + deps = [ + "${distributedinput_path}/sourcehandler:libdinput_source_handler", + "//third_party/libevdev:libevdev", + ] + + external_deps = [ + "c_utils:utils", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DinputInitSourceFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DinputInitSourceFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/dinputinitsource_fuzzer/corpus/init b/test/fuzztest/dinputinitsource_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/dinputinitsource_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 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/test/fuzztest/dinputinitsource_fuzzer/dinputinitsource_fuzzer.cpp b/test/fuzztest/dinputinitsource_fuzzer/dinputinitsource_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a8489ab041eaed336066311e3bc757591ebe3e6f --- /dev/null +++ b/test/fuzztest/dinputinitsource_fuzzer/dinputinitsource_fuzzer.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 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 "dinputinitsource_fuzzer.h" + +#include +#include +#include +#include +#include + +#include + +#include "constants_dinput.h" +#include "distributed_input_handler.h" +#include "distributed_input_kit.h" +#include "distributed_input_source_handler.h" +#include "i_distributed_source_input.h" + +namespace OHOS { +namespace DistributedHardware { +void InitSourceFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string params(reinterpret_cast(data), size); + DistributedInput::DistributedInputSourceHandler::GetInstance().InitSource(params); +} +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::InitSourceFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/dinputinitsource_fuzzer/dinputinitsource_fuzzer.h b/test/fuzztest/dinputinitsource_fuzzer/dinputinitsource_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..9e284702563abaae4cefd01771cd3bcc662d5844 --- /dev/null +++ b/test/fuzztest/dinputinitsource_fuzzer/dinputinitsource_fuzzer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 DINPUT_INIT_SOURCE_FUZZER_H +#define DINPUT_INIT_SOURCE_FUZZER_H + +#define FUZZ_PROJECT_NAME "dinputinitsource_fuzzer" + +#endif // DINPUT_INIT_SOURCE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/dinputinitsource_fuzzer/project.xml b/test/fuzztest/dinputinitsource_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/dinputinitsource_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/BUILD.gn b/test/fuzztest/dinputreleasesink_fuzzer/BUILD.gn similarity index 88% rename from test/fuzztest/dinputsinkhandler_fuzzer/BUILD.gn rename to test/fuzztest/dinputreleasesink_fuzzer/BUILD.gn index 908aaa1b03f5423362389deb13e9758a72435537..825d94b01c25b97a86f7a691737f50adb1c55cd1 100644 --- a/test/fuzztest/dinputsinkhandler_fuzzer/BUILD.gn +++ b/test/fuzztest/dinputreleasesink_fuzzer/BUILD.gn @@ -17,11 +17,11 @@ import("//build/test.gni") import("../../../distributedinput.gni") ##############################fuzztest########################################## -ohos_fuzztest("DinputSinkHandlerFuzzTest") { +ohos_fuzztest("DinputReleaseSinkFuzzTest") { module_out_path = "distributed_input/system" fuzz_config_file = - "${distributedinput_path}/test/fuzztest/dinputsinkhandler_fuzzer" + "${distributedinput_path}/test/fuzztest/dinputreleasesink_fuzzer" include_dirs = [ "include", @@ -30,7 +30,6 @@ ohos_fuzztest("DinputSinkHandlerFuzzTest") { "${distributedinput_path}/services/source/sourcemanager/include", "${distributedinput_path}/services/sink/sinkmanager/include", "${distributedinput_path}/frameworks/include", - "${distributedinput_path}/sourcehandler/include", "${distributedinput_path}/sinkhandler/include", "${distributedinput_path}/inputdevicehandler/include", "${service_common}/include", @@ -53,7 +52,7 @@ ohos_fuzztest("DinputSinkHandlerFuzzTest") { "-fno-omit-frame-pointer", ] - sources = [ "dinput_sink_handler_fuzzer.cpp" ] + sources = [ "dinputreleasesink_fuzzer.cpp" ] deps = [ "${distributedinput_path}/sinkhandler:libdinput_sink_handler", @@ -70,7 +69,7 @@ ohos_fuzztest("DinputSinkHandlerFuzzTest") { defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DinputSinkHandlerFuzzTest\"", + "DH_LOG_TAG=\"DinputReleaseSinkFuzzTest\"", "LOG_DOMAIN=0xD004100", ] } @@ -79,6 +78,6 @@ ohos_fuzztest("DinputSinkHandlerFuzzTest") { group("fuzztest") { testonly = true - deps = [ ":DinputSinkHandlerFuzzTest" ] + deps = [ ":DinputReleaseSinkFuzzTest" ] } ############################################################################### diff --git a/test/fuzztest/dinputreleasesink_fuzzer/corpus/init b/test/fuzztest/dinputreleasesink_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/dinputreleasesink_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 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/test/fuzztest/dinputreleasesink_fuzzer/dinputreleasesink_fuzzer.cpp b/test/fuzztest/dinputreleasesink_fuzzer/dinputreleasesink_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..24500c912cfaaeb428b9eea300bbc885dbfb741f --- /dev/null +++ b/test/fuzztest/dinputreleasesink_fuzzer/dinputreleasesink_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 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 "dinputreleasesink_fuzzer.h" + +#include +#include +#include +#include +#include + +#include + +#include "constants_dinput.h" +#include "distributed_input_handler.h" +#include "distributed_input_kit.h" +#include "distributed_input_sink_handler.h" +#include "i_distributed_sink_input.h" + +namespace OHOS { +namespace DistributedHardware { +void ReleaseSinkFuzzTest(const uint8_t* data, size_t size) +{ + (void)data; + (void)size; + DistributedInput::DistributedInputSinkHandler::GetInstance().ReleaseSink(); +} +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::ReleaseSinkFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.h b/test/fuzztest/dinputreleasesink_fuzzer/dinputreleasesink_fuzzer.h similarity index 85% rename from test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.h rename to test/fuzztest/dinputreleasesink_fuzzer/dinputreleasesink_fuzzer.h index 5dd97ac8e86fe72b8db7beeeac99da78a1659608..da96037cef136aa39a99322fa8326fc6f32722d1 100644 --- a/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.h +++ b/test/fuzztest/dinputreleasesink_fuzzer/dinputreleasesink_fuzzer.h @@ -14,9 +14,9 @@ */ -#ifndef DINPUT_SINK_HANDLER_FUZZER_H -#define DINPUT_SINK_HANDLER_FUZZER_H +#ifndef DINPUT_RELEASE_SINK_FUZZER_H +#define DINPUT_RELEASE_SINK_FUZZER_H #define FUZZ_PROJECT_NAME "dinputsinkhandler_fuzzer" -#endif // DINPUT_SINK_HANDLER_FUZZER_H \ No newline at end of file +#endif // DINPUT_RELEASE_SINK_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/dinputreleasesink_fuzzer/project.xml b/test/fuzztest/dinputreleasesink_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/dinputreleasesink_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/dinputreleasesource_fuzzer/BUILD.gn b/test/fuzztest/dinputreleasesource_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5723ad6cb16647eb6750b105b94ece391499e5ef --- /dev/null +++ b/test/fuzztest/dinputreleasesource_fuzzer/BUILD.gn @@ -0,0 +1,83 @@ +# Copyright (c) 2023 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("../../../distributedinput.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DinputReleaseSourceFuzzTest") { + module_out_path = "distributed_input/system" + + fuzz_config_file = + "${distributedinput_path}/test/fuzztest/dinputreleasesource_fuzzer" + + include_dirs = [ + "include", + "${distributedinput_path}/interfaces/inner_kits/include", + "${distributedinput_path}/interfaces/ipc/include", + "${distributedinput_path}/services/source/sourcemanager/include", + "${distributedinput_path}/services/sink/sinkmanager/include", + "${distributedinput_path}/frameworks/include", + "${distributedinput_path}/sourcehandler/include", + "${distributedinput_path}/inputdevicehandler/include", + "${service_common}/include", + "${common_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "//third_party/json/include", + "${fwk_interfaces_path}/include", + "${fwk_interfaces_path}/include/ipc", + "${services_source_path}/inputinject/include", + "${utils_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dinputreleasesource_fuzzer.cpp" ] + + deps = [ + "${distributedinput_path}/sourcehandler:libdinput_source_handler", + "//third_party/libevdev:libevdev", + ] + + external_deps = [ + "c_utils:utils", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DinputReleaseSourceFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DinputReleaseSourceFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/dinputreleasesource_fuzzer/corpus/init b/test/fuzztest/dinputreleasesource_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/dinputreleasesource_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 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/test/fuzztest/dinputreleasesource_fuzzer/dinputreleasesource_fuzzer.cpp b/test/fuzztest/dinputreleasesource_fuzzer/dinputreleasesource_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d5376fa85f756a5762ac73633434d009872472c2 --- /dev/null +++ b/test/fuzztest/dinputreleasesource_fuzzer/dinputreleasesource_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 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 "dinputreleasesource_fuzzer.h" + +#include +#include +#include +#include +#include + +#include + +#include "constants_dinput.h" +#include "distributed_input_handler.h" +#include "distributed_input_kit.h" +#include "distributed_input_source_handler.h" +#include "i_distributed_source_input.h" + +namespace OHOS { +namespace DistributedHardware { +void ReleaseSourceFuzzTest(const uint8_t* data, size_t size) +{ + (void)data; + (void)size; + DistributedInput::DistributedInputSourceHandler::GetInstance().ReleaseSource(); +} +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::ReleaseSourceFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/dinputreleasesource_fuzzer/dinputreleasesource_fuzzer.h b/test/fuzztest/dinputreleasesource_fuzzer/dinputreleasesource_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..2309bf3e3575d1432c743352fac0e8300389f432 --- /dev/null +++ b/test/fuzztest/dinputreleasesource_fuzzer/dinputreleasesource_fuzzer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 DINPUT_RELEASE_SOURCE_FUZZER_H +#define DINPUT_RELEASE_SOURCE_FUZZER_H + +#define FUZZ_PROJECT_NAME "dinputreleasesource_fuzzer" + +#endif // DINPUT_RELEASE_SOURCE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/dinputreleasesource_fuzzer/project.xml b/test/fuzztest/dinputreleasesource_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/dinputreleasesource_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/dinputsubscribelocaldh_fuzzer/BUILD.gn b/test/fuzztest/dinputsubscribelocaldh_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b57d4f312f2e295a7a7e83b5beddfea1475eb455 --- /dev/null +++ b/test/fuzztest/dinputsubscribelocaldh_fuzzer/BUILD.gn @@ -0,0 +1,83 @@ +# Copyright (c) 2021-2023 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("../../../distributedinput.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DinputSubscribeLocalDhFuzzTest") { + module_out_path = "distributed_input/system" + + fuzz_config_file = + "${distributedinput_path}/test/fuzztest/dinputsubscribelocaldh_fuzzer" + + include_dirs = [ + "include", + "${distributedinput_path}/interfaces/inner_kits/include", + "${distributedinput_path}/interfaces/ipc/include", + "${distributedinput_path}/services/source/sourcemanager/include", + "${distributedinput_path}/services/sink/sinkmanager/include", + "${distributedinput_path}/frameworks/include", + "${distributedinput_path}/sinkhandler/include", + "${distributedinput_path}/inputdevicehandler/include", + "${service_common}/include", + "${common_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "//third_party/json/include", + "${fwk_interfaces_path}/include", + "${fwk_interfaces_path}/include/ipc", + "${services_source_path}/inputinject/include", + "${utils_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dinputsubscribelocaldh_fuzzer.cpp" ] + + deps = [ + "${distributedinput_path}/sinkhandler:libdinput_sink_handler", + "//third_party/libevdev:libevdev", + ] + + external_deps = [ + "c_utils:utils", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DinputSubscribeLocalDhFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DinputSubscribeLocalDhFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/dinputsubscribelocaldh_fuzzer/corpus/init b/test/fuzztest/dinputsubscribelocaldh_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/dinputsubscribelocaldh_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 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/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.cpp b/test/fuzztest/dinputsubscribelocaldh_fuzzer/dinputsubscribelocaldh_fuzzer.cpp similarity index 63% rename from test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.cpp rename to test/fuzztest/dinputsubscribelocaldh_fuzzer/dinputsubscribelocaldh_fuzzer.cpp index 2e66a6b337cf382a2066c908d845458e0f457c1c..1f10ac3de650ef680dcaa2f920d0e61c5cbb14d8 100644 --- a/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.cpp +++ b/test/fuzztest/dinputsubscribelocaldh_fuzzer/dinputsubscribelocaldh_fuzzer.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "dinput_sink_handler_fuzzer.h" +#include "dinputsubscribelocaldh_fuzzer.h" #include #include @@ -27,28 +27,10 @@ #include "distributed_input_handler.h" #include "distributed_input_kit.h" #include "distributed_input_sink_handler.h" -#include "distributed_input_source_handler.h" #include "i_distributed_sink_input.h" -#include "i_distributed_source_input.h" namespace OHOS { namespace DistributedHardware { -void InitSinkFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - std::string params(reinterpret_cast(data), size); - DistributedInput::DistributedInputSinkHandler::GetInstance().InitSink(params); -} - -void ReleaseSinkFuzzTest(const uint8_t* data, size_t size) -{ - (void)data; - (void)size; - DistributedInput::DistributedInputSinkHandler::GetInstance().ReleaseSink(); -} - void SubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size == 0)) { @@ -57,14 +39,7 @@ void SubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) std::string dhId(reinterpret_cast(data), size); std::string params(reinterpret_cast(data), size); DistributedInput::DistributedInputSinkHandler::GetInstance().SubscribeLocalHardware(dhId, params); -} -void UnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - std::string dhId(reinterpret_cast(data), size); DistributedInput::DistributedInputSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId); } } // namespace DistributedHardware @@ -74,9 +49,6 @@ void UnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::DistributedHardware::InitSinkFuzzTest(data, size); - OHOS::DistributedHardware::ReleaseSinkFuzzTest(data, size); OHOS::DistributedHardware::SubscribeLocalHardwareFuzzTest(data, size); - OHOS::DistributedHardware::UnsubscribeLocalHardwareFuzzTest(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/dinputsubscribelocaldh_fuzzer/dinputsubscribelocaldh_fuzzer.h b/test/fuzztest/dinputsubscribelocaldh_fuzzer/dinputsubscribelocaldh_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..6b9c8384901dd218246f4ae94d3a5bf521eca94a --- /dev/null +++ b/test/fuzztest/dinputsubscribelocaldh_fuzzer/dinputsubscribelocaldh_fuzzer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 DINPUT_SUBSCRIBE_LOCAL_DH_FUZZER_H +#define DINPUT_SUBSCRIBE_LOCAL_DH_FUZZER_H + +#define FUZZ_PROJECT_NAME "dinputsubscribelocaldh_fuzzer" + +#endif // DINPUT_SUBSCRIBE_LOCAL_DH_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/dinputsubscribelocaldh_fuzzer/project.xml b/test/fuzztest/dinputsubscribelocaldh_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/dinputsubscribelocaldh_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +