diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 6b0b5e5fefbd8a8f37f7fae84f829cee2dbc0147..55b7910e468723d8f0ed37a2213bfdaeb985209c 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -18,6 +18,8 @@ group("fuzztest") { "dinputconfigdh_fuzzer:fuzztest", "dinputinitsink_fuzzer:fuzztest", "dinputinitsource_fuzzer:fuzztest", + "dinputonsessionclosed_fuzzer:fuzztest", + "dinputonsessionopend_fuzzer:fuzztest", "dinputreleasesink_fuzzer:fuzztest", "dinputreleasesource_fuzzer:fuzztest", "dinputsubscribelocaldh_fuzzer:fuzztest", diff --git a/test/fuzztest/dinputonsessionclosed_fuzzer/BUILD.gn b/test/fuzztest/dinputonsessionclosed_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6b984bad3fe2bfd616e5eeb7efc026c9db9c86a7 --- /dev/null +++ b/test/fuzztest/dinputonsessionclosed_fuzzer/BUILD.gn @@ -0,0 +1,84 @@ +# 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("DinputOnSessionClosedFuzzTest") { + module_out_path = "distributed_input/system" + + fuzz_config_file = + "${distributedinput_path}/test/fuzztest/dinputonsessionclosed_fuzzer" + + include_dirs = [ + "${av_transport_path}/common/include", + "${services_source_path}/transport/include", + "${distributedinput_path}/services/transportbase/include", + "${common_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_interfaces_path}/include", + "${service_common}/include", + "${services_source_path}/inputinject/include", + "${services_source_path}/transport/include", + "//third_party/json/include", + "${dfx_utils_path}/include", + "${utils_path}/include", + "${frameworks_path}/include", + "${distributedinput_path}/inputdevicehandler/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dinputonsessionclosed_fuzzer.cpp" ] + + deps = [ + "${dfx_utils_path}:libdinput_dfx_utils", + "${distributedinput_path}/services/transportbase:libdinput_trans_base", + "${services_source_path}/inputinject:libdinput_inject", + "${utils_path}:libdinput_utils", + "//third_party/libevdev:libevdev", + ] + + external_deps = [ + "c_utils:utils", + "distributed_hardware_fwk:libdhfwk_sdk", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DinputConfigDhFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DinputOnSessionClosedFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/dinputonsessionclosed_fuzzer/corpus/init b/test/fuzztest/dinputonsessionclosed_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/dinputonsessionclosed_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/dinputonsessionclosed_fuzzer/dinputonsessionclosed_fuzzer.cpp b/test/fuzztest/dinputonsessionclosed_fuzzer/dinputonsessionclosed_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce9992aa9f08befc59778c21e964d7d152c42966 --- /dev/null +++ b/test/fuzztest/dinputonsessionclosed_fuzzer/dinputonsessionclosed_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * 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 "dinputonsessionclosed_fuzzer.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "distributed_input_transport_base.h" + +namespace OHOS { +namespace DistributedHardware { +void OnSessionClosedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + DistributedInput::DistributedInputTransportBase::GetInstance().OnSessionClosed(sessionId); +} +} // 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::OnSessionClosedFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/dinputonsessionclosed_fuzzer/dinputonsessionclosed_fuzzer.h b/test/fuzztest/dinputonsessionclosed_fuzzer/dinputonsessionclosed_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..b9bfc8da280f710ccc902d3ad8edcb6525bb0153 --- /dev/null +++ b/test/fuzztest/dinputonsessionclosed_fuzzer/dinputonsessionclosed_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_ON_SESSION_OPEND_FUZZER_H +#define DINPUT_ON_SESSION_OPEND_FUZZER_H + +#define FUZZ_PROJECT_NAME "dinputonsessionclosed_fuzzer" + +#endif // DINPUT_ON_SESSION_OPEND_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/dinputonsessionclosed_fuzzer/project.xml b/test/fuzztest/dinputonsessionclosed_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/dinputonsessionclosed_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/dinputonsessionopend_fuzzer/BUILD.gn b/test/fuzztest/dinputonsessionopend_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..31ef43217756fd840dc4bf48fa57938042774262 --- /dev/null +++ b/test/fuzztest/dinputonsessionopend_fuzzer/BUILD.gn @@ -0,0 +1,84 @@ +# 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("DinputOnSessionOpendFuzzTest") { + module_out_path = "distributed_input/system" + + fuzz_config_file = + "${distributedinput_path}/test/fuzztest/dinputonsessionopend_fuzzer" + + include_dirs = [ + "${av_transport_path}/common/include", + "${services_source_path}/transport/include", + "${distributedinput_path}/services/transportbase/include", + "${common_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_interfaces_path}/include", + "${service_common}/include", + "${services_source_path}/inputinject/include", + "${services_source_path}/transport/include", + "//third_party/json/include", + "${dfx_utils_path}/include", + "${utils_path}/include", + "${frameworks_path}/include", + "${distributedinput_path}/inputdevicehandler/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dinputonsessionopend_fuzzer.cpp" ] + + deps = [ + "${dfx_utils_path}:libdinput_dfx_utils", + "${distributedinput_path}/services/transportbase:libdinput_trans_base", + "${services_source_path}/inputinject:libdinput_inject", + "${utils_path}:libdinput_utils", + "//third_party/libevdev:libevdev", + ] + + external_deps = [ + "c_utils:utils", + "distributed_hardware_fwk:libdhfwk_sdk", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DinputOnSessionOpendFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DinputOnSessionOpendFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/dinputonsessionopend_fuzzer/corpus/init b/test/fuzztest/dinputonsessionopend_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/dinputonsessionopend_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/dinputonsessionopend_fuzzer/dinputonsessionopend_fuzzer.cpp b/test/fuzztest/dinputonsessionopend_fuzzer/dinputonsessionopend_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7abc03ad07798e27eeef2dc80c18a62f3e006bf1 --- /dev/null +++ b/test/fuzztest/dinputonsessionopend_fuzzer/dinputonsessionopend_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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 "dinputonsessionopend_fuzzer.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "distributed_input_transport_base.h" + +namespace OHOS { +namespace DistributedHardware { +void OnSessionOpenedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + int32_t result = *(reinterpret_cast(data)); + DistributedInput::DistributedInputTransportBase::GetInstance().OnSessionOpened(sessionId, result); +} +} // 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::OnSessionOpenedFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/dinputonsessionopend_fuzzer/dinputonsessionopend_fuzzer.h b/test/fuzztest/dinputonsessionopend_fuzzer/dinputonsessionopend_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8efea829c4f67cbfdb17b37c6bd913b631951bbc --- /dev/null +++ b/test/fuzztest/dinputonsessionopend_fuzzer/dinputonsessionopend_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_ON_SESSION_CLOSED_FUZZER_H +#define DINPUT_ON_SESSION_CLOSED_FUZZER_H + +#define FUZZ_PROJECT_NAME "dinputonsessionopend_fuzzer" + +#endif // DINPUT_ON_SESSION_CLOSED_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/dinputonsessionopend_fuzzer/project.xml b/test/fuzztest/dinputonsessionopend_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/dinputonsessionopend_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +