From 1ff0544f3fe70b7cf7ad0655409fd66e07545d92 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 11 Aug 2025 14:27:45 +0800 Subject: [PATCH] add fuzz Signed-off-by: li-yaoyao777 --- test/fuzztest/BUILD.gn | 5 ++ .../gettouchpadpinchswitch_fuzzer/BUILD.gn | 60 ++++++++++++++++++ .../gettouchpadpinchswitch_fuzzer/corpus/init | 14 +++++ .../gettouchpadpinchswitch_fuzzer.cpp | 63 +++++++++++++++++++ .../gettouchpadpinchswitch_fuzzer.h | 21 +++++++ .../gettouchpadpinchswitch_fuzzer/project.xml | 25 ++++++++ .../BUILD.gn | 60 ++++++++++++++++++ .../corpus/init | 14 +++++ .../gettouchpadscrolldirection_fuzzer.cpp | 63 +++++++++++++++++++ .../gettouchpadscrolldirection_fuzzer.h | 21 +++++++ .../project.xml | 25 ++++++++ .../gettouchpadscrollswitch_fuzzer.cpp | 2 +- .../gettouchpadtapswitch_fuzzer/BUILD.gn | 60 ++++++++++++++++++ .../gettouchpadtapswitch_fuzzer/corpus/init | 14 +++++ .../gettouchpadtapswitch_fuzzer.cpp | 63 +++++++++++++++++++ .../gettouchpadtapswitch_fuzzer.h | 21 +++++++ .../gettouchpadtapswitch_fuzzer/project.xml | 25 ++++++++ .../settouchpadpinchswitch_fuzzer/BUILD.gn | 60 ++++++++++++++++++ .../settouchpadpinchswitch_fuzzer/corpus/init | 14 +++++ .../settouchpadpinchswitch_fuzzer/project.xml | 25 ++++++++ .../settouchpadpinchswitch_fuzzer.cpp | 63 +++++++++++++++++++ .../settouchpadpinchswitch_fuzzer.h | 21 +++++++ .../BUILD.gn | 60 ++++++++++++++++++ .../corpus/init | 14 +++++ .../project.xml | 25 ++++++++ .../settouchpadscrolldirection_fuzzer.cpp | 63 +++++++++++++++++++ .../settouchpadscrolldirection_fuzzer.h | 21 +++++++ .../settouchpadscrollswitch_fuzzer.cpp | 2 +- .../settouchpadtapswitch_fuzzer/BUILD.gn | 60 ++++++++++++++++++ .../settouchpadtapswitch_fuzzer/corpus/init | 14 +++++ .../settouchpadtapswitch_fuzzer/project.xml | 25 ++++++++ .../settouchpadtapswitch_fuzzer.cpp | 63 +++++++++++++++++++ .../settouchpadtapswitch_fuzzer.h | 21 +++++++ 33 files changed, 1105 insertions(+), 2 deletions(-) create mode 100644 test/fuzztest/gettouchpadpinchswitch_fuzzer/BUILD.gn create mode 100644 test/fuzztest/gettouchpadpinchswitch_fuzzer/corpus/init create mode 100644 test/fuzztest/gettouchpadpinchswitch_fuzzer/gettouchpadpinchswitch_fuzzer.cpp create mode 100644 test/fuzztest/gettouchpadpinchswitch_fuzzer/gettouchpadpinchswitch_fuzzer.h create mode 100644 test/fuzztest/gettouchpadpinchswitch_fuzzer/project.xml create mode 100644 test/fuzztest/gettouchpadscrolldirection_fuzzer/BUILD.gn create mode 100644 test/fuzztest/gettouchpadscrolldirection_fuzzer/corpus/init create mode 100644 test/fuzztest/gettouchpadscrolldirection_fuzzer/gettouchpadscrolldirection_fuzzer.cpp create mode 100644 test/fuzztest/gettouchpadscrolldirection_fuzzer/gettouchpadscrolldirection_fuzzer.h create mode 100644 test/fuzztest/gettouchpadscrolldirection_fuzzer/project.xml create mode 100644 test/fuzztest/gettouchpadtapswitch_fuzzer/BUILD.gn create mode 100644 test/fuzztest/gettouchpadtapswitch_fuzzer/corpus/init create mode 100644 test/fuzztest/gettouchpadtapswitch_fuzzer/gettouchpadtapswitch_fuzzer.cpp create mode 100644 test/fuzztest/gettouchpadtapswitch_fuzzer/gettouchpadtapswitch_fuzzer.h create mode 100644 test/fuzztest/gettouchpadtapswitch_fuzzer/project.xml create mode 100644 test/fuzztest/settouchpadpinchswitch_fuzzer/BUILD.gn create mode 100644 test/fuzztest/settouchpadpinchswitch_fuzzer/corpus/init create mode 100644 test/fuzztest/settouchpadpinchswitch_fuzzer/project.xml create mode 100644 test/fuzztest/settouchpadpinchswitch_fuzzer/settouchpadpinchswitch_fuzzer.cpp create mode 100644 test/fuzztest/settouchpadpinchswitch_fuzzer/settouchpadpinchswitch_fuzzer.h create mode 100644 test/fuzztest/settouchpadscrolldirection_fuzzer/BUILD.gn create mode 100644 test/fuzztest/settouchpadscrolldirection_fuzzer/corpus/init create mode 100644 test/fuzztest/settouchpadscrolldirection_fuzzer/project.xml create mode 100644 test/fuzztest/settouchpadscrolldirection_fuzzer/settouchpadscrolldirection_fuzzer.cpp create mode 100644 test/fuzztest/settouchpadscrolldirection_fuzzer/settouchpadscrolldirection_fuzzer.h create mode 100644 test/fuzztest/settouchpadtapswitch_fuzzer/BUILD.gn create mode 100644 test/fuzztest/settouchpadtapswitch_fuzzer/corpus/init create mode 100644 test/fuzztest/settouchpadtapswitch_fuzzer/project.xml create mode 100644 test/fuzztest/settouchpadtapswitch_fuzzer/settouchpadtapswitch_fuzzer.cpp create mode 100644 test/fuzztest/settouchpadtapswitch_fuzzer/settouchpadtapswitch_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index d0fb553c5a..d28b1630e2 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -51,7 +51,9 @@ group("test") { "getscreenlocked_fuzzer:fuzztest", "getshieldstatus_fuzzer:fuzztest", "gettouchpaddeviceorigins_fuzzer:fuzztest", + "gettouchpadscrolldirection_fuzzer:fuzztest", "gettouchpadscrollswitch_fuzzer:fuzztest", + "gettouchpadtapswitch_fuzzer:fuzztest", "gettprightclicktype_fuzzer:fuzztest", "getwindowpid_fuzzer:fuzztest", "hasiremitter_fuzzer:fuzztest", @@ -100,7 +102,9 @@ group("test") { "setpointerspeed_fuzzer:fuzztest", "setpointervisible_fuzzer:fuzztest", "setshieldstatus_fuzzer:fuzztest", + "settouchpadscrolldirection_fuzzer:fuzztest", "settouchpadscrollswitch_fuzzer:fuzztest", + "settouchpadtapswitch_fuzzer:fuzztest", "shieldstatus_fuzzer:fuzztest", "shiftapppointerevent_fuzzer:fuzztest", "simulateinputevent_fuzzer:fuzztest", @@ -155,6 +159,7 @@ group("test") { "stubsettouchpadrightclicktype_fuzzer:fuzztest", "stubsettouchpadscrolldirection_fuzzer:fuzztest", "stubsettouchpadscrollswitch_fuzzer:fuzztest", + "settouchpadtapswitch_fuzzer:fuzztest", "stubsettouchpadswipeswitch_fuzzer:fuzztest", "stubsettouchpadtapswitch_fuzzer:fuzztest", "stubsubscribekeyevent_fuzzer:fuzztest", diff --git a/test/fuzztest/gettouchpadpinchswitch_fuzzer/BUILD.gn b/test/fuzztest/gettouchpadpinchswitch_fuzzer/BUILD.gn new file mode 100644 index 0000000000..1d9a499c5c --- /dev/null +++ b/test/fuzztest/gettouchpadpinchswitch_fuzzer/BUILD.gn @@ -0,0 +1,60 @@ +# Copyright (c) 2025 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("../../../multimodalinput_mini.gni") +module_output_path = "input/input" + +##############################fuzztest########################################## +ohos_fuzztest("GetTouchpadPinchSwitchFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${mmi_path}/test/fuzztest/gettouchpadpinchswitch_fuzzer" + include_dirs = [ + "${mmi_path}/service/device_manager/include", + "${mmi_path}/service/device_config/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "gettouchpadpinchswitch_fuzzer.cpp" ] + + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/service:libmmi-server", + "${mmi_path}/util:libmmi-util", + ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":GetTouchpadPinchSwitchFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/gettouchpadpinchswitch_fuzzer/corpus/init b/test/fuzztest/gettouchpadpinchswitch_fuzzer/corpus/init new file mode 100644 index 0000000000..65af8ee8d1 --- /dev/null +++ b/test/fuzztest/gettouchpadpinchswitch_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2025 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/gettouchpadpinchswitch_fuzzer/gettouchpadpinchswitch_fuzzer.cpp b/test/fuzztest/gettouchpadpinchswitch_fuzzer/gettouchpadpinchswitch_fuzzer.cpp new file mode 100644 index 0000000000..0e4e8ffb3b --- /dev/null +++ b/test/fuzztest/gettouchpadpinchswitch_fuzzer/gettouchpadpinchswitch_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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 "mmi_log.h" +#include "input_device_manager.h" +#include "gettouchpadpinchswitch_fuzzer.h" + +#include "securec.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "GetTouchpadPinchSwitchFuzzTest" + +namespace OHOS { +namespace MMI { +namespace OHOS { +template +size_t GetObject(T &object, const uint8_t *data, size_t size) +{ + size_t objectSize = sizeof(object); + if (objectSize > size) { + return 0; + } + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + return 0; + } + return objectSize; +} + +bool GetTouchpadPinchSwitchFuzzTest(const uint8_t *data, size_t size) +{ + size_t startPos = 0; + bool switchFlag; + startPos += GetObject(switchFlag, data + startPos, size - startPos); + InputManager::GetInstance()->GetTouchpadPinchSwitch(switchFlag); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + return 0; + } + + OHOS::GetTouchpadPinchSwitchFuzzTest(data, size); + return 0; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/gettouchpadpinchswitch_fuzzer/gettouchpadpinchswitch_fuzzer.h b/test/fuzztest/gettouchpadpinchswitch_fuzzer/gettouchpadpinchswitch_fuzzer.h new file mode 100644 index 0000000000..e34e2e4f57 --- /dev/null +++ b/test/fuzztest/gettouchpadpinchswitch_fuzzer/gettouchpadpinchswitch_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 GETTOUCHPADPINCHSWITCH_FUZZER +#define GETTOUCHPADPINCHSWITCH_FUZZER + +#define FUZZ_PROJECT_NAME "gettouchpadpinchswitch_fuzzer" + +#endif // GETTOUCHPADPINCHSWITCH_FUZZER diff --git a/test/fuzztest/gettouchpadpinchswitch_fuzzer/project.xml b/test/fuzztest/gettouchpadpinchswitch_fuzzer/project.xml new file mode 100644 index 0000000000..500f6f4144 --- /dev/null +++ b/test/fuzztest/gettouchpadpinchswitch_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/gettouchpadscrolldirection_fuzzer/BUILD.gn b/test/fuzztest/gettouchpadscrolldirection_fuzzer/BUILD.gn new file mode 100644 index 0000000000..885ca10705 --- /dev/null +++ b/test/fuzztest/gettouchpadscrolldirection_fuzzer/BUILD.gn @@ -0,0 +1,60 @@ +# Copyright (c) 2025 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("../../../multimodalinput_mini.gni") +module_output_path = "input/input" + +##############################fuzztest########################################## +ohos_fuzztest("GetTouchpadScrollDirectionFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${mmi_path}/test/fuzztest/gettouchpadscrolldirection_fuzzer" + include_dirs = [ + "${mmi_path}/service/device_manager/include", + "${mmi_path}/service/device_config/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "gettouchpadscrolldirection_fuzzer.cpp" ] + + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/service:libmmi-server", + "${mmi_path}/util:libmmi-util", + ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":GetTouchpadScrollDirectionFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/gettouchpadscrolldirection_fuzzer/corpus/init b/test/fuzztest/gettouchpadscrolldirection_fuzzer/corpus/init new file mode 100644 index 0000000000..65af8ee8d1 --- /dev/null +++ b/test/fuzztest/gettouchpadscrolldirection_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2025 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/gettouchpadscrolldirection_fuzzer/gettouchpadscrolldirection_fuzzer.cpp b/test/fuzztest/gettouchpadscrolldirection_fuzzer/gettouchpadscrolldirection_fuzzer.cpp new file mode 100644 index 0000000000..9411c76eb0 --- /dev/null +++ b/test/fuzztest/gettouchpadscrolldirection_fuzzer/gettouchpadscrolldirection_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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 "mmi_log.h" +#include "input_device_manager.h" +#include "gettouchpadscrolldirection_fuzzer.h" + +#include "securec.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "GetTouchpadScrollDirectionFuzzTest" + +namespace OHOS { +namespace MMI { +namespace OHOS { +template +size_t GetObject(T &object, const uint8_t *data, size_t size) +{ + size_t objectSize = sizeof(object); + if (objectSize > size) { + return 0; + } + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + return 0; + } + return objectSize; +} + +bool GetTouchpadScrollDirectionFuzzTest(const uint8_t *data, size_t size) +{ + size_t startPos = 0; + bool state; + startPos += GetObject(state, data + startPos, size - startPos); + InputManager::GetInstance()->GetTouchpadScrollDirection(state); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + return 0; + } + + OHOS::GetTouchpadScrollDirectionFuzzTest(data, size); + return 0; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/gettouchpadscrolldirection_fuzzer/gettouchpadscrolldirection_fuzzer.h b/test/fuzztest/gettouchpadscrolldirection_fuzzer/gettouchpadscrolldirection_fuzzer.h new file mode 100644 index 0000000000..8e55077e6a --- /dev/null +++ b/test/fuzztest/gettouchpadscrolldirection_fuzzer/gettouchpadscrolldirection_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 GETTOUCHPADSCROLLDIRECTION_FUZZER +#define GETTOUCHPADSCROLLDIRECTION_FUZZER + +#define FUZZ_PROJECT_NAME "gettouchpadscrolldirection_fuzzer" + +#endif // GETTOUCHPADSCROLLDIRECTION_FUZZER diff --git a/test/fuzztest/gettouchpadscrolldirection_fuzzer/project.xml b/test/fuzztest/gettouchpadscrolldirection_fuzzer/project.xml new file mode 100644 index 0000000000..500f6f4144 --- /dev/null +++ b/test/fuzztest/gettouchpadscrolldirection_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/gettouchpadscrollswitch_fuzzer/gettouchpadscrollswitch_fuzzer.cpp b/test/fuzztest/gettouchpadscrollswitch_fuzzer/gettouchpadscrollswitch_fuzzer.cpp index 02edc60ef0..88a5cf28b4 100644 --- a/test/fuzztest/gettouchpadscrollswitch_fuzzer/gettouchpadscrollswitch_fuzzer.cpp +++ b/test/fuzztest/gettouchpadscrollswitch_fuzzer/gettouchpadscrollswitch_fuzzer.cpp @@ -42,7 +42,7 @@ void GetTouchpadScrollSwitchFuzzTest(const uint8_t* data, size_t size) bool switchFlag; size_t startPos = 0; startPos += GetObject(switchFlag, data + startPos, size - startPos); - InputManager::GetInstance()->RemoveMonitor(switchFlag); + InputManager::GetInstance()->GetTouchpadScrollSwitch(switchFlag); } } // MMI } // OHOS diff --git a/test/fuzztest/gettouchpadtapswitch_fuzzer/BUILD.gn b/test/fuzztest/gettouchpadtapswitch_fuzzer/BUILD.gn new file mode 100644 index 0000000000..9caaf6e84d --- /dev/null +++ b/test/fuzztest/gettouchpadtapswitch_fuzzer/BUILD.gn @@ -0,0 +1,60 @@ +# Copyright (c) 2025 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("../../../multimodalinput_mini.gni") +module_output_path = "input/input" + +##############################fuzztest########################################## +ohos_fuzztest("GetTouchpadTapSwitchFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${mmi_path}/test/fuzztest/gettouchpadtapswitch_fuzzer" + include_dirs = [ + "${mmi_path}/service/device_manager/include", + "${mmi_path}/service/device_config/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "gettouchpadtapswitch_fuzzer.cpp" ] + + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/service:libmmi-server", + "${mmi_path}/util:libmmi-util", + ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":GetTouchpadTapSwitchFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/gettouchpadtapswitch_fuzzer/corpus/init b/test/fuzztest/gettouchpadtapswitch_fuzzer/corpus/init new file mode 100644 index 0000000000..65af8ee8d1 --- /dev/null +++ b/test/fuzztest/gettouchpadtapswitch_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2025 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/gettouchpadtapswitch_fuzzer/gettouchpadtapswitch_fuzzer.cpp b/test/fuzztest/gettouchpadtapswitch_fuzzer/gettouchpadtapswitch_fuzzer.cpp new file mode 100644 index 0000000000..83d831c83e --- /dev/null +++ b/test/fuzztest/gettouchpadtapswitch_fuzzer/gettouchpadtapswitch_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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 "mmi_log.h" +#include "input_device_manager.h" +#include "gettouchpadtapswitch_fuzzer.h" + +#include "securec.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "GetTouchpadTapSwitchFuzzTest" + +namespace OHOS { +namespace MMI { +namespace OHOS { +template +size_t GetObject(T &object, const uint8_t *data, size_t size) +{ + size_t objectSize = sizeof(object); + if (objectSize > size) { + return 0; + } + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + return 0; + } + return objectSize; +} + +bool GetTouchpadTapSwitchFuzzTest(const uint8_t *data, size_t size) +{ + size_t startPos = 0; + bool switchFlag; + startPos += GetObject(switchFlag, data + startPos, size - startPos); + InputManager::GetInstance()->GetTouchpadTapSwitch(switchFlag); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + return 0; + } + + OHOS::GetTouchpadTapSwitchFuzzTest(data, size); + return 0; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/gettouchpadtapswitch_fuzzer/gettouchpadtapswitch_fuzzer.h b/test/fuzztest/gettouchpadtapswitch_fuzzer/gettouchpadtapswitch_fuzzer.h new file mode 100644 index 0000000000..e9b5947feb --- /dev/null +++ b/test/fuzztest/gettouchpadtapswitch_fuzzer/gettouchpadtapswitch_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 GETTOUCHPADTAPSWITCH_FUZZER +#define GETTOUCHPADTAPSWITCH_FUZZER + +#define FUZZ_PROJECT_NAME "gettouchpadtapswitch_fuzzer" + +#endif // GETTOUCHPADTAPSWITCH_FUZZER diff --git a/test/fuzztest/gettouchpadtapswitch_fuzzer/project.xml b/test/fuzztest/gettouchpadtapswitch_fuzzer/project.xml new file mode 100644 index 0000000000..500f6f4144 --- /dev/null +++ b/test/fuzztest/gettouchpadtapswitch_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/settouchpadpinchswitch_fuzzer/BUILD.gn b/test/fuzztest/settouchpadpinchswitch_fuzzer/BUILD.gn new file mode 100644 index 0000000000..a0abb2e113 --- /dev/null +++ b/test/fuzztest/settouchpadpinchswitch_fuzzer/BUILD.gn @@ -0,0 +1,60 @@ +# Copyright (c) 2025 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("../../../multimodalinput_mini.gni") +module_output_path = "input/input" + +##############################fuzztest########################################## +ohos_fuzztest("SetTouchpadPinchSwitchFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${mmi_path}/test/fuzztest/settouchpadpinchswitch_fuzzer" + include_dirs = [ + "${mmi_path}/service/device_manager/include", + "${mmi_path}/service/device_config/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "settouchpadpinchswitch_fuzzer.cpp" ] + + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/service:libmmi-server", + "${mmi_path}/util:libmmi-util", + ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":SetTouchpadPinchSwitchFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/settouchpadpinchswitch_fuzzer/corpus/init b/test/fuzztest/settouchpadpinchswitch_fuzzer/corpus/init new file mode 100644 index 0000000000..65af8ee8d1 --- /dev/null +++ b/test/fuzztest/settouchpadpinchswitch_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2025 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/settouchpadpinchswitch_fuzzer/project.xml b/test/fuzztest/settouchpadpinchswitch_fuzzer/project.xml new file mode 100644 index 0000000000..500f6f4144 --- /dev/null +++ b/test/fuzztest/settouchpadpinchswitch_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/settouchpadpinchswitch_fuzzer/settouchpadpinchswitch_fuzzer.cpp b/test/fuzztest/settouchpadpinchswitch_fuzzer/settouchpadpinchswitch_fuzzer.cpp new file mode 100644 index 0000000000..9f72d2ebeb --- /dev/null +++ b/test/fuzztest/settouchpadpinchswitch_fuzzer/settouchpadpinchswitch_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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 "mmi_log.h" +#include "input_device_manager.h" +#include "settouchpadpinchswitch_fuzzer.h" + +#include "securec.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "SetTouchpadPinchSwitchFuzzTest" + +namespace OHOS { +namespace MMI { +namespace OHOS { +template +size_t GetObject(T &object, const uint8_t *data, size_t size) +{ + size_t objectSize = sizeof(object); + if (objectSize > size) { + return 0; + } + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + return 0; + } + return objectSize; +} + +bool SetTouchpadPinchSwitchFuzzTest(const uint8_t *data, size_t size) +{ + size_t startPos = 0; + bool switchFlag; + startPos += GetObject(switchFlag, data + startPos, size - startPos); + InputManager::GetInstance()->SetTouchpadPinchSwitch(switchFlag); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + return 0; + } + + OHOS::SetTouchpadPinchSwitchFuzzTest(data, size); + return 0; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/settouchpadpinchswitch_fuzzer/settouchpadpinchswitch_fuzzer.h b/test/fuzztest/settouchpadpinchswitch_fuzzer/settouchpadpinchswitch_fuzzer.h new file mode 100644 index 0000000000..7e20474898 --- /dev/null +++ b/test/fuzztest/settouchpadpinchswitch_fuzzer/settouchpadpinchswitch_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 SETTOUCHPADPINCHSWITCH_FUZZER +#define SETTOUCHPADPINCHSWITCH_FUZZER + +#define FUZZ_PROJECT_NAME "settouchpadpinchswitch_fuzzer" + +#endif // SETTOUCHPADPINCHSWITCH_FUZZER diff --git a/test/fuzztest/settouchpadscrolldirection_fuzzer/BUILD.gn b/test/fuzztest/settouchpadscrolldirection_fuzzer/BUILD.gn new file mode 100644 index 0000000000..989f526641 --- /dev/null +++ b/test/fuzztest/settouchpadscrolldirection_fuzzer/BUILD.gn @@ -0,0 +1,60 @@ +# Copyright (c) 2025 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("../../../multimodalinput_mini.gni") +module_output_path = "input/input" + +##############################fuzztest########################################## +ohos_fuzztest("SetTouchpadScrollDirectionFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${mmi_path}/test/fuzztest/settouchpadscrolldirection_fuzzer" + include_dirs = [ + "${mmi_path}/service/device_manager/include", + "${mmi_path}/service/device_config/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "settouchpadscrolldirection_fuzzer.cpp" ] + + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/service:libmmi-server", + "${mmi_path}/util:libmmi-util", + ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":SetTouchpadScrollDirectionFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/settouchpadscrolldirection_fuzzer/corpus/init b/test/fuzztest/settouchpadscrolldirection_fuzzer/corpus/init new file mode 100644 index 0000000000..65af8ee8d1 --- /dev/null +++ b/test/fuzztest/settouchpadscrolldirection_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2025 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/settouchpadscrolldirection_fuzzer/project.xml b/test/fuzztest/settouchpadscrolldirection_fuzzer/project.xml new file mode 100644 index 0000000000..500f6f4144 --- /dev/null +++ b/test/fuzztest/settouchpadscrolldirection_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/settouchpadscrolldirection_fuzzer/settouchpadscrolldirection_fuzzer.cpp b/test/fuzztest/settouchpadscrolldirection_fuzzer/settouchpadscrolldirection_fuzzer.cpp new file mode 100644 index 0000000000..9978c82228 --- /dev/null +++ b/test/fuzztest/settouchpadscrolldirection_fuzzer/settouchpadscrolldirection_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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 "mmi_log.h" +#include "input_device_manager.h" +#include "gettouchpadscrolldirection_fuzzer.h" + +#include "securec.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "SetTouchpadScrollDirectionFuzzTest" + +namespace OHOS { +namespace MMI { +namespace OHOS { +template +size_t GetObject(T &object, const uint8_t *data, size_t size) +{ + size_t objectSize = sizeof(object); + if (objectSize > size) { + return 0; + } + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + return 0; + } + return objectSize; +} + +bool SetTouchpadScrollDirectionFuzzTest(const uint8_t *data, size_t size) +{ + size_t startPos = 0; + bool state; + startPos += GetObject(state, data + startPos, size - startPos); + InputManager::GetInstance()->SetTouchpadScrollDirection(state); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + return 0; + } + + OHOS::SetTouchpadScrollDirectionFuzzTest(data, size); + return 0; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/settouchpadscrolldirection_fuzzer/settouchpadscrolldirection_fuzzer.h b/test/fuzztest/settouchpadscrolldirection_fuzzer/settouchpadscrolldirection_fuzzer.h new file mode 100644 index 0000000000..8f396cc815 --- /dev/null +++ b/test/fuzztest/settouchpadscrolldirection_fuzzer/settouchpadscrolldirection_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 SETTOUCHPADSCROLLDIRECTION_FUZZER +#define SETTOUCHPADSCROLLDIRECTION_FUZZER + +#define FUZZ_PROJECT_NAME "settouchpadscrolldirection_fuzzer" + +#endif // SETTOUCHPADSCROLLDIRECTION_FUZZER diff --git a/test/fuzztest/settouchpadscrollswitch_fuzzer/settouchpadscrollswitch_fuzzer.cpp b/test/fuzztest/settouchpadscrollswitch_fuzzer/settouchpadscrollswitch_fuzzer.cpp index 1481ad31fc..7ded05d148 100644 --- a/test/fuzztest/settouchpadscrollswitch_fuzzer/settouchpadscrollswitch_fuzzer.cpp +++ b/test/fuzztest/settouchpadscrollswitch_fuzzer/settouchpadscrollswitch_fuzzer.cpp @@ -42,7 +42,7 @@ void SetTouchpadScrollSwitchFuzzTest(const uint8_t* data, size_t size) bool switchFlag; size_t startPos = 0; startPos += GetObject(switchFlag, data + startPos, size - startPos); - InputManager::GetInstance()->RemoveMonitor(switchFlag); + InputManager::GetInstance()->SetTouchpadScrollSwitch(switchFlag); } } // MMI } // OHOS diff --git a/test/fuzztest/settouchpadtapswitch_fuzzer/BUILD.gn b/test/fuzztest/settouchpadtapswitch_fuzzer/BUILD.gn new file mode 100644 index 0000000000..2d755ffd14 --- /dev/null +++ b/test/fuzztest/settouchpadtapswitch_fuzzer/BUILD.gn @@ -0,0 +1,60 @@ +# Copyright (c) 2025 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("../../../multimodalinput_mini.gni") +module_output_path = "input/input" + +##############################fuzztest########################################## +ohos_fuzztest("SetTouchpadTapSwitchFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${mmi_path}/test/fuzztest/settouchpadtapswitch_fuzzer" + include_dirs = [ + "${mmi_path}/service/device_manager/include", + "${mmi_path}/service/device_config/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "settouchpadtapswitch_fuzzer.cpp" ] + + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/service:libmmi-server", + "${mmi_path}/util:libmmi-util", + ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":SetTouchpadTapSwitchFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/settouchpadtapswitch_fuzzer/corpus/init b/test/fuzztest/settouchpadtapswitch_fuzzer/corpus/init new file mode 100644 index 0000000000..65af8ee8d1 --- /dev/null +++ b/test/fuzztest/settouchpadtapswitch_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2025 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/settouchpadtapswitch_fuzzer/project.xml b/test/fuzztest/settouchpadtapswitch_fuzzer/project.xml new file mode 100644 index 0000000000..500f6f4144 --- /dev/null +++ b/test/fuzztest/settouchpadtapswitch_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/settouchpadtapswitch_fuzzer/settouchpadtapswitch_fuzzer.cpp b/test/fuzztest/settouchpadtapswitch_fuzzer/settouchpadtapswitch_fuzzer.cpp new file mode 100644 index 0000000000..fbc1b54822 --- /dev/null +++ b/test/fuzztest/settouchpadtapswitch_fuzzer/settouchpadtapswitch_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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 "mmi_log.h" +#include "input_device_manager.h" +#include "settouchpadtapswitch_fuzzer.h" + +#include "securec.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "SetTouchpadTapSwitchFuzzTest" + +namespace OHOS { +namespace MMI { +namespace OHOS { +template +size_t GetObject(T &object, const uint8_t *data, size_t size) +{ + size_t objectSize = sizeof(object); + if (objectSize > size) { + return 0; + } + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + return 0; + } + return objectSize; +} + +bool SetTouchpadTapSwitchFuzzTest(const uint8_t *data, size_t size) +{ + size_t startPos = 0; + bool switchFlag; + startPos += GetObject(switchFlag, data + startPos, size - startPos); + InputManager::GetInstance()->SetTouchpadTapSwitch(switchFlag); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + return 0; + } + + OHOS::SetTouchpadTapSwitchFuzzTest(data, size); + return 0; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/settouchpadtapswitch_fuzzer/settouchpadtapswitch_fuzzer.h b/test/fuzztest/settouchpadtapswitch_fuzzer/settouchpadtapswitch_fuzzer.h new file mode 100644 index 0000000000..95b177581f --- /dev/null +++ b/test/fuzztest/settouchpadtapswitch_fuzzer/settouchpadtapswitch_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 SETTOUCHPADTAPSWITCH_FUZZER +#define SETTOUCHPADTAPSWITCH_FUZZER + +#define FUZZ_PROJECT_NAME "settouchpadtapswitch_fuzzer" + +#endif // SETTOUCHPADTAPSWITCH_FUZZER -- Gitee