diff --git a/test/fuzztest/vibrator/BUILD.gn b/test/fuzztest/vibrator/BUILD.gn index d21bd78b73f4fa0152c5085ce32c456423406b44..bd929d9df25673ddfdf528d9c2f52d390ac1d541 100644 --- a/test/fuzztest/vibrator/BUILD.gn +++ b/test/fuzztest/vibrator/BUILD.gn @@ -51,5 +51,7 @@ group("fuzztest") { "playpackagebysessionid_fuzzer:fuzztest", "playpatternbysessionid_fuzzer:fuzztest", "stopvibratebysessionid_fuzzer:fuzztest", + "handlevibratordata_fuzzer:fuzztest", + "issupportvibratorcustom_fuzzer:fuzztest", ] } diff --git a/test/fuzztest/vibrator/handlevibratordata_fuzzer/BUILD.gn b/test/fuzztest/vibrator/handlevibratordata_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ec709b10089e35342297b5259e97f90815b63840 --- /dev/null +++ b/test/fuzztest/vibrator/handlevibratordata_fuzzer/BUILD.gn @@ -0,0 +1,69 @@ +# 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. + +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("./../../../../miscdevice.gni") + +ohos_fuzztest("HandleVibratorDataFuzzTest") { + module_out_path = FUZZ_MODULE_OUT_PATH + + fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/vibrator/handlevibratordata_fuzzer" + + include_dirs = [ + "$SUBSYSTEM_DIR/frameworks/native/vibrator/include", + "$SUBSYSTEM_DIR/test/fuzztest/vibrator/handlevibratordata_fuzzer", + "$SUBSYSTEM_DIR/utils/common/include", + "$SUBSYSTEM_DIR/utils/haptic_decoder/interface", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "handlevibratordata_fuzzer.cpp", + "$SUBSYSTEM_DIR/frameworks/native/vibrator/src/vibrator_service_client.cpp", + ] + + deps = [ + "$SUBSYSTEM_DIR/frameworks/native/light:light_ndk_header", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:libvibrator_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_proxy", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", + "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", + ] + + external_deps = [ + "c_utils:utils", + "cJSON:cjson", + "hilog:libhilog", + "hitrace:hitrace_meter", + "hisysevent:libhisysevent", + "ipc:ipc_single", + "samgr:samgr_proxy", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":HandleVibratorDataFuzzTest", + ] +} diff --git a/test/fuzztest/vibrator/handlevibratordata_fuzzer/corpus/init b/test/fuzztest/vibrator/handlevibratordata_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e010f5889b59a772ce45fc45b17e8a578984479c --- /dev/null +++ b/test/fuzztest/vibrator/handlevibratordata_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/vibrator/handlevibratordata_fuzzer/handlevibratordata_fuzzer.cpp b/test/fuzztest/vibrator/handlevibratordata_fuzzer/handlevibratordata_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c2f5f9c145a1575eba21712b83908c4e270f4397 --- /dev/null +++ b/test/fuzztest/vibrator/handlevibratordata_fuzzer/handlevibratordata_fuzzer.cpp @@ -0,0 +1,59 @@ +/* + * 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 "handlevibratordata_fuzzer.h" + +#include "securec.h" +#include "vibrator_service_client.h" + +namespace OHOS { +namespace Sensors { +namespace { +constexpr size_t DATA_MIN_SIZE = 8; +} // namespace + +template +size_t GetObject(const uint8_t *data, size_t size, T &object) +{ + 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 HandleVibratorDataFuzzTest(const uint8_t *data, size_t size) +{ + if (data == nullptr || size < DATA_MIN_SIZE) { + return; + } + size_t startPos = 0; + VibratorStatusEvent statusEvent; + startPos += GetObject(data + startPos, size - startPos, statusEvent.deviceId); + GetObject(data + startPos, size - startPos, statusEvent.vibratorCnt); + VibratorServiceClient::GetInstance().HandleVibratorData(statusEvent); +} +} // namespace Sensors +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::Sensors::HandleVibratorDataFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/vibrator/handlevibratordata_fuzzer/handlevibratordata_fuzzer.h b/test/fuzztest/vibrator/handlevibratordata_fuzzer/handlevibratordata_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..12ec62f628d9e433cafd827752b6a80b56782df3 --- /dev/null +++ b/test/fuzztest/vibrator/handlevibratordata_fuzzer/handlevibratordata_fuzzer.h @@ -0,0 +1,22 @@ +/* + * 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 HANDLE_VIBRATOR_DATA_H +#define HANDLE_VIBRATOR_DATA_H + +#define FUZZ_PROJECT_NAME "handlevibratordata_fuzzer" + +#endif // HANDLE_VIBRATOR_DATA_H + diff --git a/test/fuzztest/vibrator/handlevibratordata_fuzzer/project.xml b/test/fuzztest/vibrator/handlevibratordata_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..2eb360c27f1b159e1b043e38846f10fcf37fa37c --- /dev/null +++ b/test/fuzztest/vibrator/handlevibratordata_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 120 + + 2048 + + diff --git a/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/BUILD.gn b/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..89c6f0ecde43d92e933d4e1452f8a0c95658330b --- /dev/null +++ b/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/BUILD.gn @@ -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, software7 +# 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. + +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("./../../../../miscdevice.gni") + +ohos_fuzztest("IsSupportVibratorCustomFuzzTest") { + module_out_path = FUZZ_MODULE_OUT_PATH + + fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer" + + include_dirs = [ + "$SUBSYSTEM_DIR/interfaces/inner_api/vibrator", + "$SUBSYSTEM_DIR/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "issupportvibratorcustom_fuzzer.cpp" ] + + deps = + [ "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native" ] + + external_deps = [ "c_utils:utils" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":IsSupportVibratorCustomFuzzTest", + ] +} diff --git a/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/corpus/init b/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e010f5889b59a772ce45fc45b17e8a578984479c --- /dev/null +++ b/test/fuzztest/vibrator/issupportvibratorcustom_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/vibrator/issupportvibratorcustom_fuzzer/issupportvibratorcustom_fuzzer.cpp b/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/issupportvibratorcustom_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..149f6f2cae4737d0e45495219911ebaa608b5b1d --- /dev/null +++ b/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/issupportvibratorcustom_fuzzer.cpp @@ -0,0 +1,61 @@ +/* + * 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 "issupportvibratorcustom_fuzzer.h" + +#include "securec.h" + +#include "vibrator_agent.h" + +namespace OHOS { +namespace Sensors { +namespace { +constexpr size_t DATA_MIN_SIZE = 8; +} // namespace + +template +size_t GetObject(const uint8_t *data, size_t size, T &object) +{ + 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 IsSupportVibratorCustomFuzzTest(const uint8_t *data, size_t size) +{ + if (data == nullptr || size < DATA_MIN_SIZE) { + return; + } + size_t startPos = 0; + VibratorIdentifier identifier; + startPos += GetObject(data + startPos, size - startPos, identifier.deviceId); + GetObject(data + startPos, size - startPos, identifier.vibratorId); + OHOS::Sensors::IsSupportVibratorCustomEnhanced(identifier); + OHOS::Sensors::IsSupportVibratorCustom(); +} +} // namespace Sensors +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::Sensors::IsSupportVibratorCustomFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/issupportvibratorcustom_fuzzer.h b/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/issupportvibratorcustom_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..a4ddced61e07f14b2c3d84374d5718080e8d001d --- /dev/null +++ b/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/issupportvibratorcustom_fuzzer.h @@ -0,0 +1,22 @@ +/* + * 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 IS_SUPPORT_VIBRATOR_CUSTOM_H +#define IS_SUPPORT_VIBRATOR_CUSTOM_H + +#define FUZZ_PROJECT_NAME "issupportvibratorcustom_fuzzer" + +#endif // IS_SUPPORT_VIBRATOR_CUSTOM_H + diff --git a/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/project.xml b/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..2eb360c27f1b159e1b043e38846f10fcf37fa37c --- /dev/null +++ b/test/fuzztest/vibrator/issupportvibratorcustom_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 120 + + 2048 + +