diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000000000000000000000000000000000000..77126915368db5ae3448e1c0804e70f98f116144 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "D:/tools/mingw64/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000000000000000000000000000000000..a6711162d6fca5bc349e9916d98f1e8dbf841129 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "d:/bailu/code/miscdevice0730/sensors_miscdevice/test/fuzztest/vibrator/modulatepackage_fuzzer", + "program": "d:/bailu/code/miscdevice0730/sensors_miscdevice/test/fuzztest/vibrator/modulatepackage_fuzzer/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..bb879da5a0774e5e3a4e5e90dba7a0770370c0f7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/test/fuzztest/vibrator/BUILD.gn b/test/fuzztest/vibrator/BUILD.gn index 4f14c809a560bdee33844184af471ca8d27217a3..3745b9a0753cabdc3d3df653e2e1ee9251930488 100644 --- a/test/fuzztest/vibrator/BUILD.gn +++ b/test/fuzztest/vibrator/BUILD.gn @@ -54,5 +54,6 @@ group("fuzztest") { "handlevibratordata_fuzzer:fuzztest", "issupportvibratorcustom_fuzzer:fuzztest", "ishdhapticsupported_fuzzer:fuzztest", + "modulatepackage_fuzzer:fuzztest", ] } diff --git a/test/fuzztest/vibrator/modulatepackage_fuzzer/BUILD.gn b/test/fuzztest/vibrator/modulatepackage_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4abebaea5a31da3c95666e52247b335853e0ce4a --- /dev/null +++ b/test/fuzztest/vibrator/modulatepackage_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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("ModulatePackageFuzzTest") { + module_out_path = FUZZ_MODULE_OUT_PATH + + fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/vibrator/modulatepackage_fuzzer" + + include_dirs = [ + "$SUBSYSTEM_DIR/frameworks/native/vibrator", + "$SUBSYSTEM_DIR/test/fuzztest/vibrator/modulatepackage_fuzzer", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "modulatepackage_fuzzer.cpp" ] + + deps = + [ "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native" ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken_shared", + "access_token:libtokensetproc_shared", + "c_utils:utils", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ModulatePackageFuzzTest", + ] +} diff --git a/test/fuzztest/vibrator/modulatepackage_fuzzer/corpus/init b/test/fuzztest/vibrator/modulatepackage_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..65af8ee8d11bf23407ea34d4de49f7cbb6a2b791 --- /dev/null +++ b/test/fuzztest/vibrator/modulatepackage_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/modulatepackage_fuzzer/modulatepackage_fuzzer.cpp b/test/fuzztest/vibrator/modulatepackage_fuzzer/modulatepackage_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d35f6b05a2e9159b0c00db9b4e540d44c8e4938b --- /dev/null +++ b/test/fuzztest/vibrator/modulatepackage_fuzzer/modulatepackage_fuzzer.cpp @@ -0,0 +1,107 @@ +/* + * 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 "modulatepackage_fuzzer.h" + +#include +#include +#include +#include + +#include "accesstoken_kit.h" +#include "nativetoken_kit.h" +#include "securec.h" +#include "token_setproc.h" + +#include "vibrator_agent.h" + +namespace OHOS { +using namespace Security::AccessToken; +using Security::AccessToken::AccessTokenID; + +namespace { +constexpr size_t U32_AT_SIZE = 12; +VibratorCurvePoint vibratorCurvePoint{ + .time = 0, + .intensity = 100, + .frequency = 100 +}; + +VibratorEvent vibratorEvent{ + .type = EVENT_TYPE_CONTINUOUS, + .time = 0, + .duration = 500, + .intensity = 100, + .frequency = 100, + .index = 0, + .pointNum = 1, + .points = &vibratorCurvePoint +}; + +VibratorPattern vibratorPattern{ + .time = 500, + .eventNum = 10, + .patternDuration = 5000, + .events = &vibratorEvent +}; + +VibratorPackage beforeModulationPackage { + .patternNum = 1, + .packageDuration = 5000, + .patterns = &vibratorPattern +}; +} // 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; +} + +bool ModulatePackageFuzzTest(const uint8_t *data, size_t size) +{ + if (data == nullptr || size < U32_AT_SIZE) { + return false; + } + VibratorCurvePoint modulationCurve { + .time = 100, + .intensity = 0, + .frequency = 0 + }; + size_t startPos = 0; + startPos += GetObject(data + startPos, size - startPos, modulationCurve.intensity); + GetObject(data + startPos, size - startPos, modulationCurve.frequency); + int32_t curvePointNum = 1; + int32_t duration = 300; + VibratorPackage afterModulationPackage; + OHOS::Sensors::ModulatePackage(&modulationCurve, curvePointNum, duration, + beforeModulationPackage, afterModulationPackage); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::ModulatePackageFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/vibrator/modulatepackage_fuzzer/modulatepackage_fuzzer.h b/test/fuzztest/vibrator/modulatepackage_fuzzer/modulatepackage_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..434d78b3aa39016005707ee633eb098d101ec8d3 --- /dev/null +++ b/test/fuzztest/vibrator/modulatepackage_fuzzer/modulatepackage_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 MODULATE_PACKAGE_FUZZER_H +#define MODULATE_PACKAGE_FUZZER_H + +#define FUZZ_PROJECT_NAME "modulatepackage_fuzzer" + +#endif // MODULATE_PACKAGE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/vibrator/modulatepackage_fuzzer/project.xml b/test/fuzztest/vibrator/modulatepackage_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..2eb360c27f1b159e1b043e38846f10fcf37fa37c --- /dev/null +++ b/test/fuzztest/vibrator/modulatepackage_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 120 + + 2048 + +