diff --git a/test/fuzztest/getallmmisubscribedevents_fuzzer/BUILD.gn b/test/fuzztest/getallmmisubscribedevents_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9077aa67f654e4bdb8800266b35f69111aaa5aa1 --- /dev/null +++ b/test/fuzztest/getallmmisubscribedevents_fuzzer/BUILD.gn @@ -0,0 +1,53 @@ +# 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("GetAllMmiSubscribedEventsFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${mmi_path}/test/fuzztest/getallmmisubscribedevents_fuzzer" + include_dirs = [ "${mmi_path}/interfaces/util/common/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "getallmmisubscribedevents_fuzzer.cpp" ] + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + ] + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":GetAllMmiSubscribedEventsFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/getallmmisubscribedevents_fuzzer/corpus/init b/test/fuzztest/getallmmisubscribedevents_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..65af8ee8d11bf23407ea34d4de49f7cbb6a2b791 --- /dev/null +++ b/test/fuzztest/getallmmisubscribedevents_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/getallmmisubscribedevents_fuzzer/getallmmisubscribedevents_fuzzer.cpp b/test/fuzztest/getallmmisubscribedevents_fuzzer/getallmmisubscribedevents_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b00258c7e62839f9cd8c15856487fa6f1e789521 --- /dev/null +++ b/test/fuzztest/getallmmisubscribedevents_fuzzer/getallmmisubscribedevents_fuzzer.cpp @@ -0,0 +1,57 @@ +/* + * 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 +#include "getallmmisubscribedevents_fuzzer.h" + +#include "securec.h" + +#include "input_manager.h" +#include "mmi_log.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "SetMouseScrollRowsFuzzTest" + +namespace OHOS { +namespace MMI { +void GetAllMmiSubscribedEventsFuzzTest(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + std::map, int32_t> map = { + {{provider.ConsumeIntegral(), provider.ConsumeIntegral(), provider.ConsumeBytesAsString(10)}, + provider.ConsumeIntegral()}, + {{provider.ConsumeIntegral(), provider.ConsumeIntegral(), provider.ConsumeBytesAsString(10)}, + provider.ConsumeIntegral()}, + {{provider.ConsumeIntegral(), provider.ConsumeIntegral(), provider.ConsumeBytesAsString(10)}, + provider.ConsumeIntegral()} + }; + + InputManager::GetInstance()->GetAllMmiSubscribedEvents(map); +} +} // MMI +} // OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < 0) { + return 0; + } + + /* Run your code on data */ + OHOS::MMI::GetAllMmiSubscribedEventsFuzzTest(data, size); + return 0; +} + diff --git a/test/fuzztest/getallmmisubscribedevents_fuzzer/getallmmisubscribedevents_fuzzer.h b/test/fuzztest/getallmmisubscribedevents_fuzzer/getallmmisubscribedevents_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..0816717db30f243f8e3ccc1356851452e22a96b0 --- /dev/null +++ b/test/fuzztest/getallmmisubscribedevents_fuzzer/getallmmisubscribedevents_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 SETMOUSESCROLLROWS_FUZZER_H +#define SETMOUSESCROLLROWS_FUZZER_H + +#define FUZZ_PROJECT_NAME "getallmmisubscribedevents_fuzzer" + +#endif // SETMOUSESCROLLROWS_FUZZER_H diff --git a/test/fuzztest/getallmmisubscribedevents_fuzzer/project.xml b/test/fuzztest/getallmmisubscribedevents_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1dcac475475fb101b6f8670ec699e6e9696aa --- /dev/null +++ b/test/fuzztest/getallmmisubscribedevents_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/inputbusmode_fuzzer/inputbusmode_fuzzer.cpp b/test/fuzztest/inputbusmode_fuzzer/inputbusmode_fuzzer.cpp index 81b09a2988bfa4001da50261d69fac869975fbcf..7a811319c51120fbf52a562aa0ab13e3d642a401 100644 --- a/test/fuzztest/inputbusmode_fuzzer/inputbusmode_fuzzer.cpp +++ b/test/fuzztest/inputbusmode_fuzzer/inputbusmode_fuzzer.cpp @@ -14,10 +14,10 @@ */ #include - -#include "inputbusmode_fuzzer.h" -#include "input_device_manager.h" #include "mmi_log.h" +#include "input_device_manager.h" +#include "inputbusmode_fuzzer.h" + #include "securec.h" #undef MMI_LOG_TAG diff --git a/test/fuzztest/inputdevcallback_fuzzer/inputdevcallback_fuzzer.cpp b/test/fuzztest/inputdevcallback_fuzzer/inputdevcallback_fuzzer.cpp index 0d9ef695580d61a99ba8f18446869c84229b2fea..ae0a240b58e9d8fc932c5d5e86178eb5329901b5 100644 --- a/test/fuzztest/inputdevcallback_fuzzer/inputdevcallback_fuzzer.cpp +++ b/test/fuzztest/inputdevcallback_fuzzer/inputdevcallback_fuzzer.cpp @@ -14,10 +14,10 @@ */ #include - -#include "inputdevcallback_fuzzer.h" -#include "input_device_manager.h" #include "mmi_log.h" +#include "input_device_manager.h" +#include "inputdevcallback_fuzzer.h" + #include "securec.h" #undef MMI_LOG_TAG diff --git a/test/fuzztest/inputdeviceconfig_fuzzer/inputdeviceconfig_fuzzer.cpp b/test/fuzztest/inputdeviceconfig_fuzzer/inputdeviceconfig_fuzzer.cpp index 5fab205b15e07e85d403de358f74fad3f3b6c480..8e29d6a2e937deb02c7f2993e4f2a9d1461be50b 100644 --- a/test/fuzztest/inputdeviceconfig_fuzzer/inputdeviceconfig_fuzzer.cpp +++ b/test/fuzztest/inputdeviceconfig_fuzzer/inputdeviceconfig_fuzzer.cpp @@ -14,10 +14,10 @@ */ #include - -#include "inputdeviceconfig_fuzzer.h" -#include "input_device_manager.h" #include "mmi_log.h" +#include "input_device_manager.h" +#include "inputdeviceconfig_fuzzer.h" + #include "securec.h" #undef MMI_LOG_TAG diff --git a/test/fuzztest/inputgetinputdevice_fuzzer/inputgetinputdevice_fuzzer.cpp b/test/fuzztest/inputgetinputdevice_fuzzer/inputgetinputdevice_fuzzer.cpp index 94f1659185fdee13716f8f85fe5e54f4a250233d..ff35314cb973b0f75289f213572250ca20a1b283 100644 --- a/test/fuzztest/inputgetinputdevice_fuzzer/inputgetinputdevice_fuzzer.cpp +++ b/test/fuzztest/inputgetinputdevice_fuzzer/inputgetinputdevice_fuzzer.cpp @@ -14,10 +14,10 @@ */ #include - -#include "inputgetinputdevice_fuzzer.h" -#include "input_device_manager.h" #include "mmi_log.h" +#include "input_device_manager.h" +#include "inputgetinputdevice_fuzzer.h" + #include "securec.h" #undef MMI_LOG_TAG diff --git a/test/fuzztest/inputisremote_fuzzer/inputisremote_fuzzer.cpp b/test/fuzztest/inputisremote_fuzzer/inputisremote_fuzzer.cpp index 8dd3564c6251ceeaafcf02a4124997cbf0100249..0f906b0b4b3b714c1d8b9a23ccf051634d8f73da 100644 --- a/test/fuzztest/inputisremote_fuzzer/inputisremote_fuzzer.cpp +++ b/test/fuzztest/inputisremote_fuzzer/inputisremote_fuzzer.cpp @@ -14,10 +14,10 @@ */ #include - +#include "mmi_log.h" #include "input_device_manager.h" #include "inputisremote_fuzzer.h" -#include "mmi_log.h" + #include "securec.h" #undef MMI_LOG_TAG diff --git a/test/fuzztest/inputkeyboardtype_fuzzer/BUILD.gn b/test/fuzztest/inputkeyboardtype_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ed10ee2330f97a0f182f96bb8aff8776bf4fa22c --- /dev/null +++ b/test/fuzztest/inputkeyboardtype_fuzzer/BUILD.gn @@ -0,0 +1,90 @@ +# 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("InputKeyboardTypeFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${mmi_path}/test/fuzztest/inputkeyboardtype_fuzzer" + include_dirs = [ + "${mmi_path}/interfaces/util/common/include", + "${mmi_path}/service/connect_manager/include", + "${mmi_path}/service/filter/include/", + "${mmi_path}/service/nap_process/include/", + "${mmi_path}/service/module_loader/include", + "${mmi_path}/service/delegate_task/include", + "${mmi_path}/service/event_handler/include", + "${mmi_path}/service/event_dispatch/include", + "${mmi_path}/service/interceptor/include", + "${mmi_path}/service/monitor/include", + "${mmi_path}/service/key_event_normalize/include", + "${mmi_path}/service/window_manager/include", + "${mmi_path}/service/key_command/include", + "${mmi_path}/service/subscriber/include", + "${mmi_path}/service/mouse_event_normalize/include", + "${mmi_path}/service/timer_manager/include", + "${mmi_path}/service/libinput_adapter/include", + "${mmi_path}/service/message_handle/include", + "${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 = [ "inputkeyboardtype_fuzzer.cpp" ] + + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/service:libmmi-server", + "${mmi_path}/util:libmmi-util", + ] + + external_deps = [ + "ability_runtime:app_manager", + "cJSON:cjson", + "c_utils:utils", + "data_share:datashare_consumer", + "graphic_2d:2d_graphics", + "graphic_2d:librender_service_client", + "hilog:libhilog", + "image_framework:image_native", + "ipc:ipc_single", + "libinput:libinput-third-mmi", + "window_manager:libwm", + ] + + if (security_component_enable) { + external_deps += [ "security_component_manager:libsecurity_component_sdk" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":InputKeyboardTypeFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/inputkeyboardtype_fuzzer/corpus/init b/test/fuzztest/inputkeyboardtype_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..65af8ee8d11bf23407ea34d4de49f7cbb6a2b791 --- /dev/null +++ b/test/fuzztest/inputkeyboardtype_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/inputkeyboardtype_fuzzer/inputkeyboardtype_fuzzer.cpp b/test/fuzztest/inputkeyboardtype_fuzzer/inputkeyboardtype_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..45dd8bce2a800c84a22d19dd133709bf602599a1 --- /dev/null +++ b/test/fuzztest/inputkeyboardtype_fuzzer/inputkeyboardtype_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * 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 +#include "mmi_log.h" +#include "input_device_manager.h" +#include "inputkeyboardtype_fuzzer.h" + +#include "securec.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "InputDeviceManagerFuzzTest" + +namespace OHOS { +namespace MMI { +namespace OHOS { + +bool InputKeyboardTypeFuzzTest(const uint8_t *data, size_t size) +{ + FuzzedDataProvider provider(data, size); + int32_t deviceId = provider.ConsumeIntegral(); + int32_t keyboardType = provider.ConsumeIntegral(); + + INPUT_DEV_MGR->GetKeyboardType(deviceId, keyboardType); + + 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::InputKeyboardTypeFuzzTest(data, size); + return 0; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/inputkeyboardtype_fuzzer/inputkeyboardtype_fuzzer.h b/test/fuzztest/inputkeyboardtype_fuzzer/inputkeyboardtype_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..53f58881c2efdfd779f52e70f1722cd7efffc235 --- /dev/null +++ b/test/fuzztest/inputkeyboardtype_fuzzer/inputkeyboardtype_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 INPUTDEVICEMANAGER_FUZZER +#define INPUTDEVICEMANAGER_FUZZER + +#define FUZZ_PROJECT_NAME "inputkeyboardtype_fuzzer" + +#endif // INPUTDEVICEMANAGER_FUZZER diff --git a/test/fuzztest/inputkeyboardtype_fuzzer/project.xml b/test/fuzztest/inputkeyboardtype_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..500f6f414493290025d8dea9b066e5d5021a9377 --- /dev/null +++ b/test/fuzztest/inputkeyboardtype_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/inputonenable_fuzzer/inputonenable_fuzzer.cpp b/test/fuzztest/inputonenable_fuzzer/inputonenable_fuzzer.cpp index 2a20f4e64a8f3ff991ddbc871aa780688132d5c0..b8371734d28e5a5e50aa21b14fc03ee5cd51f2c0 100644 --- a/test/fuzztest/inputonenable_fuzzer/inputonenable_fuzzer.cpp +++ b/test/fuzztest/inputonenable_fuzzer/inputonenable_fuzzer.cpp @@ -14,10 +14,10 @@ */ #include - +#include "mmi_log.h" #include "input_device_manager.h" #include "inputonenable_fuzzer.h" -#include "mmi_log.h" + #include "securec.h" #undef MMI_LOG_TAG diff --git a/test/fuzztest/inputpointerdevice_fuzzer/inputpointerdevice_fuzzer.cpp b/test/fuzztest/inputpointerdevice_fuzzer/inputpointerdevice_fuzzer.cpp index 8f9668034c6de7f72e390f76a3b5b75f0ed36e32..ff69ee40511fa6729faee791c3eaf3e172fe67cc 100644 --- a/test/fuzztest/inputpointerdevice_fuzzer/inputpointerdevice_fuzzer.cpp +++ b/test/fuzztest/inputpointerdevice_fuzzer/inputpointerdevice_fuzzer.cpp @@ -14,10 +14,10 @@ */ #include - +#include "mmi_log.h" #include "input_device_manager.h" #include "inputpointerdevice_fuzzer.h" -#include "mmi_log.h" + #include "securec.h" #undef MMI_LOG_TAG diff --git a/test/fuzztest/inputsupportkey_fuzzer/inputsupportkey_fuzzer.cpp b/test/fuzztest/inputsupportkey_fuzzer/inputsupportkey_fuzzer.cpp index ef8653ccc19fbecdeacd1b56c6e93c1d28fbc429..d63e2751c44a80c443da62f31210c546a7e37232 100644 --- a/test/fuzztest/inputsupportkey_fuzzer/inputsupportkey_fuzzer.cpp +++ b/test/fuzztest/inputsupportkey_fuzzer/inputsupportkey_fuzzer.cpp @@ -14,10 +14,10 @@ */ #include - +#include "mmi_log.h" #include "input_device_manager.h" #include "inputsupportkey_fuzzer.h" -#include "mmi_log.h" + #include "securec.h" #undef MMI_LOG_TAG diff --git a/test/fuzztest/inputsupportkeys_fuzzer/inputsupportkeys_fuzzer.cpp b/test/fuzztest/inputsupportkeys_fuzzer/inputsupportkeys_fuzzer.cpp index 60a97559fd4618fe3dbc9816f983f1072cc67c70..19e378ddd54c63bba6ea60b3e2451d29e3f79148 100644 --- a/test/fuzztest/inputsupportkeys_fuzzer/inputsupportkeys_fuzzer.cpp +++ b/test/fuzztest/inputsupportkeys_fuzzer/inputsupportkeys_fuzzer.cpp @@ -14,10 +14,10 @@ */ #include - +#include "mmi_log.h" #include "input_device_manager.h" #include "inputsupportkeys_fuzzer.h" -#include "mmi_log.h" + #include "securec.h" #undef MMI_LOG_TAG diff --git a/test/fuzztest/inputvendorconfig_fuzzer/BUILD.gn b/test/fuzztest/inputvendorconfig_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f870632ba507e15b13c6c67d550958ad71fb865e --- /dev/null +++ b/test/fuzztest/inputvendorconfig_fuzzer/BUILD.gn @@ -0,0 +1,90 @@ +# 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("InputVendorConfigFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${mmi_path}/test/fuzztest/inputvendorconfig_fuzzer" + include_dirs = [ + "${mmi_path}/interfaces/util/common/include", + "${mmi_path}/service/connect_manager/include", + "${mmi_path}/service/filter/include/", + "${mmi_path}/service/nap_process/include/", + "${mmi_path}/service/module_loader/include", + "${mmi_path}/service/delegate_task/include", + "${mmi_path}/service/event_handler/include", + "${mmi_path}/service/event_dispatch/include", + "${mmi_path}/service/interceptor/include", + "${mmi_path}/service/monitor/include", + "${mmi_path}/service/key_event_normalize/include", + "${mmi_path}/service/window_manager/include", + "${mmi_path}/service/key_command/include", + "${mmi_path}/service/subscriber/include", + "${mmi_path}/service/mouse_event_normalize/include", + "${mmi_path}/service/timer_manager/include", + "${mmi_path}/service/libinput_adapter/include", + "${mmi_path}/service/message_handle/include", + "${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 = [ "inputvendorconfig_fuzzer.cpp" ] + + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/service:libmmi-server", + "${mmi_path}/util:libmmi-util", + ] + + external_deps = [ + "ability_runtime:app_manager", + "cJSON:cjson", + "c_utils:utils", + "data_share:datashare_consumer", + "graphic_2d:2d_graphics", + "graphic_2d:librender_service_client", + "hilog:libhilog", + "image_framework:image_native", + "ipc:ipc_single", + "libinput:libinput-third-mmi", + "window_manager:libwm", + ] + + if (security_component_enable) { + external_deps += [ "security_component_manager:libsecurity_component_sdk" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":InputVendorConfigFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/inputvendorconfig_fuzzer/corpus/init b/test/fuzztest/inputvendorconfig_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..65af8ee8d11bf23407ea34d4de49f7cbb6a2b791 --- /dev/null +++ b/test/fuzztest/inputvendorconfig_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/inputvendorconfig_fuzzer/inputvendorconfig_fuzzer.cpp b/test/fuzztest/inputvendorconfig_fuzzer/inputvendorconfig_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8584b969a1610eecd6a095cfc0f9a83aee8cea0b --- /dev/null +++ b/test/fuzztest/inputvendorconfig_fuzzer/inputvendorconfig_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * 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 +#include "mmi_log.h" +#include "input_device_manager.h" +#include "inputvendorconfig_fuzzer.h" + +#include "securec.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "InputDeviceManagerFuzzTest" + +namespace OHOS { +namespace MMI { +namespace OHOS { + +bool InputVendorConfigFuzzTest(const uint8_t *data, size_t size) +{ + FuzzedDataProvider provider(data, size); + int32_t deviceId = provider.ConsumeIntegral(); + + INPUT_DEV_MGR->GetVendorConfig(deviceId); + + 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::InputVendorConfigFuzzTest(data, size); + return 0; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/inputvendorconfig_fuzzer/inputvendorconfig_fuzzer.h b/test/fuzztest/inputvendorconfig_fuzzer/inputvendorconfig_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..0f7f5c074fe9b704b64439d5bbcffeaa880185d6 --- /dev/null +++ b/test/fuzztest/inputvendorconfig_fuzzer/inputvendorconfig_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 INPUTDEVICEMANAGER_FUZZER +#define INPUTDEVICEMANAGER_FUZZER + +#define FUZZ_PROJECT_NAME "inputvendorconfig_fuzzer" + +#endif // INPUTDEVICEMANAGER_FUZZER diff --git a/test/fuzztest/inputvendorconfig_fuzzer/project.xml b/test/fuzztest/inputvendorconfig_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..500f6f414493290025d8dea9b066e5d5021a9377 --- /dev/null +++ b/test/fuzztest/inputvendorconfig_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/inputvirtualdeviceid_fuzzer/BUILD.gn b/test/fuzztest/inputvirtualdeviceid_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d56cc1721d8e3bb3b3b20c39b2255b24defb1981 --- /dev/null +++ b/test/fuzztest/inputvirtualdeviceid_fuzzer/BUILD.gn @@ -0,0 +1,90 @@ +# 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("InputVirtualDeviceIdFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${mmi_path}/test/fuzztest/inputvirtualdeviceid_fuzzer" + include_dirs = [ + "${mmi_path}/interfaces/util/common/include", + "${mmi_path}/service/connect_manager/include", + "${mmi_path}/service/filter/include/", + "${mmi_path}/service/nap_process/include/", + "${mmi_path}/service/module_loader/include", + "${mmi_path}/service/delegate_task/include", + "${mmi_path}/service/event_handler/include", + "${mmi_path}/service/event_dispatch/include", + "${mmi_path}/service/interceptor/include", + "${mmi_path}/service/monitor/include", + "${mmi_path}/service/key_event_normalize/include", + "${mmi_path}/service/window_manager/include", + "${mmi_path}/service/key_command/include", + "${mmi_path}/service/subscriber/include", + "${mmi_path}/service/mouse_event_normalize/include", + "${mmi_path}/service/timer_manager/include", + "${mmi_path}/service/libinput_adapter/include", + "${mmi_path}/service/message_handle/include", + "${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 = [ "inputvirtualdeviceid_fuzzer.cpp" ] + + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/service:libmmi-server", + "${mmi_path}/util:libmmi-util", + ] + + external_deps = [ + "ability_runtime:app_manager", + "cJSON:cjson", + "c_utils:utils", + "data_share:datashare_consumer", + "graphic_2d:2d_graphics", + "graphic_2d:librender_service_client", + "hilog:libhilog", + "image_framework:image_native", + "ipc:ipc_single", + "libinput:libinput-third-mmi", + "window_manager:libwm", + ] + + if (security_component_enable) { + external_deps += [ "security_component_manager:libsecurity_component_sdk" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":InputVirtualDeviceIdFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/inputvirtualdeviceid_fuzzer/corpus/init b/test/fuzztest/inputvirtualdeviceid_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..65af8ee8d11bf23407ea34d4de49f7cbb6a2b791 --- /dev/null +++ b/test/fuzztest/inputvirtualdeviceid_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/inputvirtualdeviceid_fuzzer/inputvirtualdeviceid_fuzzer.cpp b/test/fuzztest/inputvirtualdeviceid_fuzzer/inputvirtualdeviceid_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3517c830cbb9f314f2bf5a916a87f50726030072 --- /dev/null +++ b/test/fuzztest/inputvirtualdeviceid_fuzzer/inputvirtualdeviceid_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * 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 +#include "mmi_log.h" +#include "input_device_manager.h" +#include "inputvirtualdeviceid_fuzzer.h" + +#include "securec.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "InputDeviceManagerFuzzTest" + +namespace OHOS { +namespace MMI { +namespace OHOS { + +bool InputVirtualDeviceIdFuzzTest(const uint8_t *data, size_t size) +{ + FuzzedDataProvider provider(data, size); + int32_t deviceId = provider.ConsumeIntegral(); + + INPUT_DEV_MGR->GenerateVirtualDeviceId(deviceId); + INPUT_DEV_MGR->RemoveVirtualInputDevice(deviceId); + + 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::InputVirtualDeviceIdFuzzTest(data, size); + return 0; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/inputvirtualdeviceid_fuzzer/inputvirtualdeviceid_fuzzer.h b/test/fuzztest/inputvirtualdeviceid_fuzzer/inputvirtualdeviceid_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..96c510caa41850f9cc6dced3db2baae6dfb75924 --- /dev/null +++ b/test/fuzztest/inputvirtualdeviceid_fuzzer/inputvirtualdeviceid_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 INPUTDEVICEMANAGER_FUZZER +#define INPUTDEVICEMANAGER_FUZZER + +#define FUZZ_PROJECT_NAME "inputvirtualdeviceid_fuzzer" + +#endif // INPUTDEVICEMANAGER_FUZZER diff --git a/test/fuzztest/inputvirtualdeviceid_fuzzer/project.xml b/test/fuzztest/inputvirtualdeviceid_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..500f6f414493290025d8dea9b066e5d5021a9377 --- /dev/null +++ b/test/fuzztest/inputvirtualdeviceid_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/setclearwindowpointer_fuzzer/BUILD.gn b/test/fuzztest/setclearwindowpointer_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b51658a2b6ff03a8df374346285a7b6d3e294597 --- /dev/null +++ b/test/fuzztest/setclearwindowpointer_fuzzer/BUILD.gn @@ -0,0 +1,53 @@ +# 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("SetClearWindowPointerFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${mmi_path}/test/fuzztest/setclearwindowpointer_fuzzer" + include_dirs = [ "${mmi_path}/interfaces/util/common/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "setclearwindowpointer_fuzzer.cpp" ] + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + ] + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":SetClearWindowPointerFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/setclearwindowpointer_fuzzer/corpus/init b/test/fuzztest/setclearwindowpointer_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..65af8ee8d11bf23407ea34d4de49f7cbb6a2b791 --- /dev/null +++ b/test/fuzztest/setclearwindowpointer_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/setclearwindowpointer_fuzzer/project.xml b/test/fuzztest/setclearwindowpointer_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1dcac475475fb101b6f8670ec699e6e9696aa --- /dev/null +++ b/test/fuzztest/setclearwindowpointer_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/setclearwindowpointer_fuzzer/setclearwindowpointer_fuzzer.cpp b/test/fuzztest/setclearwindowpointer_fuzzer/setclearwindowpointer_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..559eb393c3a7c51d18c41d845d1a8154bfa2c21a --- /dev/null +++ b/test/fuzztest/setclearwindowpointer_fuzzer/setclearwindowpointer_fuzzer.cpp @@ -0,0 +1,51 @@ +/* + * 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 +#include "setclearwindowpointer_fuzzer.h" + +#include "securec.h" + +#include "input_manager.h" +#include "mmi_log.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "SetMouseScrollRowsFuzzTest" + +namespace OHOS { +namespace MMI { +void SetClearWindowPointerFuzzTest(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + int32_t pid = provider.ConsumeIntegral(); + int32_t uid = provider.ConsumeIntegral(); + InputManager::GetInstance()->ClearWindowPointerStyle(pid, uid); +} +} // MMI +} // OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < 0) { + return 0; + } + + /* Run your code on data */ + OHOS::MMI::SetClearWindowPointerFuzzTest(data, size); + + return 0; +} + diff --git a/test/fuzztest/setclearwindowpointer_fuzzer/setclearwindowpointer_fuzzer.h b/test/fuzztest/setclearwindowpointer_fuzzer/setclearwindowpointer_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..b41eca1a7ec9d5cfeec93fb1faeec6de3a78bf51 --- /dev/null +++ b/test/fuzztest/setclearwindowpointer_fuzzer/setclearwindowpointer_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 SETMOUSESCROLLROWS_FUZZER_H +#define SETMOUSESCROLLROWS_FUZZER_H + +#define FUZZ_PROJECT_NAME "setclearwindowpointer_fuzzer" + +#endif // SETMOUSESCROLLROWS_FUZZER_H diff --git a/test/fuzztest/sethoverscrollstate_fuzzer/sethoverscrollstate_fuzzer.cpp b/test/fuzztest/sethoverscrollstate_fuzzer/sethoverscrollstate_fuzzer.cpp index 2b7ce9e6a5b812677fd3553f62e2b25c88475733..f358bf271ef7a99e4d58f1d94fa3b252c586b257 100644 --- a/test/fuzztest/sethoverscrollstate_fuzzer/sethoverscrollstate_fuzzer.cpp +++ b/test/fuzztest/sethoverscrollstate_fuzzer/sethoverscrollstate_fuzzer.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include "sethoverscrollstate_fuzzer.h" #include "securec.h" @@ -20,29 +21,18 @@ #include "input_manager.h" #include "mmi_log.h" +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "SetMouseScrollRowsFuzzTest" namespace OHOS { namespace MMI { -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; -} - void SetHoverScrollStateFuzzTest(const uint8_t* data, size_t size) { - bool state; - size_t startPos = 0; - startPos += GetObject(state, data + startPos, size - startPos); + FuzzedDataProvider provider(data, size); + bool state = provider.ConsumeBool(); + InputManager::GetInstance()->SetHoverScrollState(state); + InputManager::GetInstance()->GetHoverScrollState(state); } } // MMI } // OHOS @@ -50,7 +40,12 @@ void SetHoverScrollStateFuzzTest(const uint8_t* data, size_t size) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + if (data == nullptr || size < 0) { + return 0; + } /* Run your code on data */ OHOS::MMI::SetHoverScrollStateFuzzTest(data, size); + return 0; } + diff --git a/test/fuzztest/sethoverscrollstate_fuzzer/sethoverscrollstate_fuzzer.h b/test/fuzztest/sethoverscrollstate_fuzzer/sethoverscrollstate_fuzzer.h index 65dc5e98b646b9ca96302a83534924b322dd10d5..dd43ce8f350fd57212bde9f9d37317022fd81d72 100644 --- a/test/fuzztest/sethoverscrollstate_fuzzer/sethoverscrollstate_fuzzer.h +++ b/test/fuzztest/sethoverscrollstate_fuzzer/sethoverscrollstate_fuzzer.h @@ -13,9 +13,9 @@ * limitations under the License. */ -#ifndef SETHOVERSCROLLSTATE_FUZZER_H -#define SETHOVERSCROLLSTATE_FUZZER_H +#ifndef SETMOUSESCROLLROWS_FUZZER_H +#define SETMOUSESCROLLROWS_FUZZER_H #define FUZZ_PROJECT_NAME "sethoverscrollstate_fuzzer" -#endif // SETHOVERSCROLLSTATE_FUZZER_H +#endif // SETMOUSESCROLLROWS_FUZZER_H diff --git a/test/fuzztest/setkeyboardrepeatdelay_fuzzer/setkeyboardrepeatdelay_fuzzer.cpp b/test/fuzztest/setkeyboardrepeatdelay_fuzzer/setkeyboardrepeatdelay_fuzzer.cpp index 93f3791ba9234f0874a579d316d255c54bde3f61..c568ebc701f1d3f141df2b096fc50172dcb55d57 100644 --- a/test/fuzztest/setkeyboardrepeatdelay_fuzzer/setkeyboardrepeatdelay_fuzzer.cpp +++ b/test/fuzztest/setkeyboardrepeatdelay_fuzzer/setkeyboardrepeatdelay_fuzzer.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include "setkeyboardrepeatdelay_fuzzer.h" #include "securec.h" @@ -20,29 +21,17 @@ #include "input_manager.h" #include "mmi_log.h" +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "SetMouseScrollRowsFuzzTest" namespace OHOS { namespace MMI { -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; -} - void SetKeyboardRepeatDelayFuzzTest(const uint8_t* data, size_t size) { - int32_t delay; - size_t startPos = 0; - startPos += GetObject(delay, data + startPos, size - startPos); - InputManager::GetInstance()->SetKeyboardRepeatDelay(delay); + FuzzedDataProvider provider(data, size); + int32_t delayTime = provider.ConsumeIntegral(); + + InputManager::GetInstance()->SetKeyboardRepeatDelay(delayTime); } } // MMI } // OHOS @@ -50,7 +39,13 @@ void SetKeyboardRepeatDelayFuzzTest(const uint8_t* data, size_t size) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + if (data == nullptr || size < 0) { + return 0; + } + /* Run your code on data */ OHOS::MMI::SetKeyboardRepeatDelayFuzzTest(data, size); + return 0; } + diff --git a/test/fuzztest/setkeyboardrepeatdelay_fuzzer/setkeyboardrepeatdelay_fuzzer.h b/test/fuzztest/setkeyboardrepeatdelay_fuzzer/setkeyboardrepeatdelay_fuzzer.h index 80a81136858433d7f6bcc5117cd9a6c8c942b623..f609dc08fbd0af499e56c08993a9411e3469bcac 100644 --- a/test/fuzztest/setkeyboardrepeatdelay_fuzzer/setkeyboardrepeatdelay_fuzzer.h +++ b/test/fuzztest/setkeyboardrepeatdelay_fuzzer/setkeyboardrepeatdelay_fuzzer.h @@ -13,9 +13,9 @@ * limitations under the License. */ -#ifndef SETKEYBOARDREPEATDELAY_FUZZER_H -#define SETKEYBOARDREPEATDELAY_FUZZER_H +#ifndef SETMOUSESCROLLROWS_FUZZER_H +#define SETMOUSESCROLLROWS_FUZZER_H #define FUZZ_PROJECT_NAME "setkeyboardrepeatdelay_fuzzer" -#endif // SETKEYBOARDREPEATDELAY_FUZZER_H +#endif // SETMOUSESCROLLROWS_FUZZER_H