From 2809cfb0952fe77f7f8a4e9fe5e1b151b3bf8001 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Wed, 1 Dec 2021 15:19:01 +0800 Subject: [PATCH] init: add fuzztest code Signed-off-by: xionglei6 --- test/fuzztest/BUILD.gn | 535 ++++++++++++++++++ .../DoReboot_fuzzer/DoReboot_fuzzer.cpp | 36 ++ .../DoReboot_fuzzer/DoReboot_fuzzer.h | 19 + .../GetControlFile_fuzzer.cpp | 36 ++ .../GetControlFile_fuzzer.h | 19 + .../GetControlSocket_fuzzer.cpp | 36 ++ .../GetControlSocket_fuzzer.h | 19 + .../MountAllFstab_fuzzer.cpp | 52 ++ .../MountAllFstab_fuzzer.h | 19 + .../ReadFileInDir_fuzzer.cpp | 69 +++ .../ReadFileInDir_fuzzer.h | 19 + .../StartDynamicProcess_fuzzer.cpp | 36 ++ .../StartDynamicProcess_fuzzer.h | 19 + .../StopDynamicProcess_fuzzer.cpp | 36 ++ .../StopDynamicProcess_fuzzer.h | 19 + .../SystemDumpParameters_fuzzer.cpp | 35 ++ .../SystemDumpParameters_fuzzer.h | 19 + .../SystemFindParameter_fuzzer.cpp | 38 ++ .../SystemFindParameter_fuzzer.h | 19 + .../SystemGetParameterCommitId_fuzzer.cpp | 37 ++ .../SystemGetParameterCommitId_fuzzer.h | 19 + .../SystemGetParameterName_fuzzer.cpp | 37 ++ .../SystemGetParameterName_fuzzer.h | 19 + .../SystemGetParameterValue_fuzzer.cpp | 38 ++ .../SystemGetParameterValue_fuzzer.h | 19 + .../SystemGetParameter_fuzzer.cpp | 40 ++ .../SystemGetParameter_fuzzer.h | 19 + .../SystemSetParameter_fuzzer.cpp | 36 ++ .../SystemSetParameter_fuzzer.h | 19 + .../SystemTraversalParameter_fuzzer.cpp | 70 +++ .../SystemTraversalParameter_fuzzer.h | 25 + .../SystemWaitParameter_fuzzer.cpp | 36 ++ .../SystemWaitParameter_fuzzer.h | 19 + .../SystemWatchParameter_fuzzer.cpp | 47 ++ .../SystemWatchParameter_fuzzer.h | 19 + .../UmountAllFstab_fuzzer.cpp | 53 ++ .../UmountAllFstab_fuzzer.h | 19 + test/fuzztest/project.xml | 25 + test/fuzztest/utils/fuzz_utils.cpp | 28 + test/fuzztest/utils/include/fuzz_utils.h | 20 + 40 files changed, 1724 insertions(+) create mode 100644 test/fuzztest/BUILD.gn create mode 100644 test/fuzztest/DoReboot_fuzzer/DoReboot_fuzzer.cpp create mode 100644 test/fuzztest/DoReboot_fuzzer/DoReboot_fuzzer.h create mode 100644 test/fuzztest/GetControlFile_fuzzer/GetControlFile_fuzzer.cpp create mode 100644 test/fuzztest/GetControlFile_fuzzer/GetControlFile_fuzzer.h create mode 100644 test/fuzztest/GetControlSocket_fuzzer/GetControlSocket_fuzzer.cpp create mode 100644 test/fuzztest/GetControlSocket_fuzzer/GetControlSocket_fuzzer.h create mode 100644 test/fuzztest/MountAllFstab_fuzzer/MountAllFstab_fuzzer.cpp create mode 100644 test/fuzztest/MountAllFstab_fuzzer/MountAllFstab_fuzzer.h create mode 100644 test/fuzztest/ReadFileInDir_fuzzer/ReadFileInDir_fuzzer.cpp create mode 100644 test/fuzztest/ReadFileInDir_fuzzer/ReadFileInDir_fuzzer.h create mode 100644 test/fuzztest/StartDynamicProcess_fuzzer/StartDynamicProcess_fuzzer.cpp create mode 100644 test/fuzztest/StartDynamicProcess_fuzzer/StartDynamicProcess_fuzzer.h create mode 100644 test/fuzztest/StopDynamicProcess_fuzzer/StopDynamicProcess_fuzzer.cpp create mode 100644 test/fuzztest/StopDynamicProcess_fuzzer/StopDynamicProcess_fuzzer.h create mode 100644 test/fuzztest/SystemDumpParameters_fuzzer/SystemDumpParameters_fuzzer.cpp create mode 100644 test/fuzztest/SystemDumpParameters_fuzzer/SystemDumpParameters_fuzzer.h create mode 100644 test/fuzztest/SystemFindParameter_fuzzer/SystemFindParameter_fuzzer.cpp create mode 100644 test/fuzztest/SystemFindParameter_fuzzer/SystemFindParameter_fuzzer.h create mode 100644 test/fuzztest/SystemGetParameterCommitId_fuzzer/SystemGetParameterCommitId_fuzzer.cpp create mode 100644 test/fuzztest/SystemGetParameterCommitId_fuzzer/SystemGetParameterCommitId_fuzzer.h create mode 100644 test/fuzztest/SystemGetParameterName_fuzzer/SystemGetParameterName_fuzzer.cpp create mode 100644 test/fuzztest/SystemGetParameterName_fuzzer/SystemGetParameterName_fuzzer.h create mode 100644 test/fuzztest/SystemGetParameterValue_fuzzer/SystemGetParameterValue_fuzzer.cpp create mode 100644 test/fuzztest/SystemGetParameterValue_fuzzer/SystemGetParameterValue_fuzzer.h create mode 100644 test/fuzztest/SystemGetParameter_fuzzer/SystemGetParameter_fuzzer.cpp create mode 100644 test/fuzztest/SystemGetParameter_fuzzer/SystemGetParameter_fuzzer.h create mode 100644 test/fuzztest/SystemSetParameter_fuzzer/SystemSetParameter_fuzzer.cpp create mode 100644 test/fuzztest/SystemSetParameter_fuzzer/SystemSetParameter_fuzzer.h create mode 100644 test/fuzztest/SystemTraversalParameter_fuzzer/SystemTraversalParameter_fuzzer.cpp create mode 100644 test/fuzztest/SystemTraversalParameter_fuzzer/SystemTraversalParameter_fuzzer.h create mode 100644 test/fuzztest/SystemWaitParameter_fuzzer/SystemWaitParameter_fuzzer.cpp create mode 100644 test/fuzztest/SystemWaitParameter_fuzzer/SystemWaitParameter_fuzzer.h create mode 100644 test/fuzztest/SystemWatchParameter_fuzzer/SystemWatchParameter_fuzzer.cpp create mode 100644 test/fuzztest/SystemWatchParameter_fuzzer/SystemWatchParameter_fuzzer.h create mode 100644 test/fuzztest/UmountAllFstab_fuzzer/UmountAllFstab_fuzzer.cpp create mode 100644 test/fuzztest/UmountAllFstab_fuzzer/UmountAllFstab_fuzzer.h create mode 100644 test/fuzztest/project.xml create mode 100644 test/fuzztest/utils/fuzz_utils.cpp create mode 100644 test/fuzztest/utils/include/fuzz_utils.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn new file mode 100644 index 00000000..2db793c0 --- /dev/null +++ b/test/fuzztest/BUILD.gn @@ -0,0 +1,535 @@ +# Copyright (c) 2021 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. + +module_output_path = "startup/fuzztest" + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//build/ohos.gni") + +ohos_static_library("libfuzz_utils") { + sources = [ + "utils/fuzz_utils.cpp", + ] + + include_dirs = [ "//base/startup/init_lite/test/fuzztest/utils/include" ] + + deps = [] + part_name = "init" +} + +##############################fuzztest########################################## +ohos_fuzztest("DoRebootFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ] + + deps = [ + "//base/startup/init_lite/interfaces/innerkits/reboot:libreboot_static", + "//base/startup/init_lite/services/log:init_log", + "//base/startup/init_lite/services/param:param_client", + "//third_party/bounds_checking_function:libsec_static", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "DoReboot_fuzzer/DoReboot_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("GetControlFileFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ] + + deps = [ + "//base/startup/init_lite/interfaces/innerkits/file:libfile", + "//base/startup/init_lite/services/log:init_log", + "//base/startup/init_lite/services/utils:libinit_utils", + "//third_party/bounds_checking_function:libsec_static", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "GetControlFile_fuzzer/GetControlFile_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("GetControlSocketFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ] + + deps = [ + "//base/startup/init_lite/interfaces/innerkits/socket:libsocket", + "//base/startup/init_lite/services/log:init_log", + "//third_party/bounds_checking_function:libsec_static", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "GetControlSocket_fuzzer/GetControlSocket_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("MountAllFstabFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ + "//base/startup/init_lite/interfaces/innerkits/include", + "//base/startup/init_lite/test/fuzztest/utils/include", + ] + + deps = [ + "//base/startup/init_lite/interfaces/innerkits/fs_manager:libfsmanager_static", + "//base/startup/init_lite/services/log:init_log", + "//base/startup/init_lite/services/utils:libinit_utils", + "//base/startup/init_lite/test/fuzztest:libfuzz_utils", + "//third_party/bounds_checking_function:libsec_static", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "MountAllFstab_fuzzer/MountAllFstab_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("ReadFileInDirFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ + "//base/startup/init_lite/services/init/include", + "//base/startup/init_lite/services/include", + ] + + deps = [ + "//base/startup/init_lite/services/log:init_log", + "//base/startup/init_lite/services/utils:libinit_utils", + "//third_party/bounds_checking_function:libsec_static", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "ReadFileInDir_fuzzer/ReadFileInDir_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("StartDynamicProcessFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ] + deps = [ + "//base/startup/init_lite/interfaces/innerkits/dynamic_service:dynamic_service", + "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "StartDynamicProcess_fuzzer/StartDynamicProcess_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("StopDynamicProcessFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ] + deps = [ + "//base/startup/init_lite/interfaces/innerkits/dynamic_service:dynamic_service", + "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "StopDynamicProcess_fuzzer/StopDynamicProcess_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("SystemDumpParametersFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ + "//base/startup/init_lite/services/include/param", + "//base/startup/init_lite/test/fuzztest/utils/include", + ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/param:param_client", + "//base/startup/init_lite/test/fuzztest:libfuzz_utils", + "//third_party/bounds_checking_function:libsec_static", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "SystemDumpParameters_fuzzer/SystemDumpParameters_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("SystemFindParameterFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/services/include/param" ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/param:param_client", + "//third_party/bounds_checking_function:libsec_static", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "SystemFindParameter_fuzzer/SystemFindParameter_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("SystemGetParameterFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/services/include/param" ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/param:param_client", + "//third_party/bounds_checking_function:libsec_static", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "SystemGetParameter_fuzzer/SystemGetParameter_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("SystemGetParameterCommitIdFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/services/include/param" ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/param:param_client", + "//third_party/bounds_checking_function:libsec_static", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "SystemGetParameterCommitId_fuzzer/SystemGetParameterCommitId_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("SystemGetParameterNameFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/services/include/param" ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/param:param_client", + "//third_party/bounds_checking_function:libsec_static", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "SystemGetParameterName_fuzzer/SystemGetParameterName_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("SystemGetParameterValueFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/services/include/param" ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/param:param_client", + "//third_party/bounds_checking_function:libsec_static", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "SystemGetParameterValue_fuzzer/SystemGetParameterValue_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("SystemSetParameterFuzztest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/services/include/param" ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/param:param_client", + "//third_party/bounds_checking_function:libsec_static", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "SystemSetParameter_fuzzer/SystemSetParameter_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("SystemTraversalParameterFuzztest") { + module_out_path = module_output_path + + include_dirs = [ + "//base/startup/init_lite/services/include/param", + "//base/startup/init_lite/services/init/include", + "//base/startup/init_lite/test/fuzztest/utils/include", + "//third_party/bounds_checking_function/include", + ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/param:param_client", + "//base/startup/init_lite/test/fuzztest:libfuzz_utils", + "//third_party/bounds_checking_function:libsec_static", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "SystemTraversalParameter_fuzzer/SystemTraversalParameter_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("SystemWaitParameterFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/services/include/param" ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/param:param_client", + "//third_party/bounds_checking_function:libsec_static", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "SystemWaitParameter_fuzzer/SystemWaitParameter_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("SystemWatchParameterFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ + "//base/startup/init_lite/services/include/param", + "//base/startup/init_lite/services/init/include", + ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/param:param_client", + "//base/startup/init_lite/services/param:param_watcheragent", + "//third_party/bounds_checking_function:libsec_static", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "SystemWatchParameter_fuzzer/SystemWatchParameter_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("UmountAllFstabFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ + "//base/startup/init_lite/interfaces/innerkits/include", + "//base/startup/init_lite/test/fuzztest/utils/include", + ] + + deps = [ + "//base/startup/init_lite/interfaces/innerkits/fs_manager:libfsmanager_static", + "//base/startup/init_lite/services/log:init_log", + "//base/startup/init_lite/services/utils:libinit_utils", + "//base/startup/init_lite/test/fuzztest:libfuzz_utils", + "//third_party/bounds_checking_function:libsec_static", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "UmountAllFstab_fuzzer/UmountAllFstab_fuzzer.cpp", + ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":DoRebootFuzzTest", + ":GetControlFileFuzzTest", + ":GetControlSocketFuzzTest", + ":MountAllFstabFuzzTest", + ":ReadFileInDirFuzzTest", + ":StartDynamicProcessFuzzTest", + ":StopDynamicProcessFuzzTest", + ":SystemDumpParametersFuzzTest", + ":SystemFindParameterFuzzTest", + ":SystemGetParameterCommitIdFuzzTest", + ":SystemGetParameterFuzzTest", + ":SystemGetParameterNameFuzzTest", + ":SystemGetParameterValueFuzzTest", + ":SystemSetParameterFuzztest", + ":SystemTraversalParameterFuzztest", + ":SystemWaitParameterFuzzTest", + ":SystemWatchParameterFuzzTest", + ":UmountAllFstabFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/DoReboot_fuzzer/DoReboot_fuzzer.cpp b/test/fuzztest/DoReboot_fuzzer/DoReboot_fuzzer.cpp new file mode 100644 index 00000000..dac70173 --- /dev/null +++ b/test/fuzztest/DoReboot_fuzzer/DoReboot_fuzzer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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 "DoReboot_fuzzer.h" +#include "init_reboot.h" + +namespace OHOS { + bool FuzzDoReboot(const uint8_t* data, size_t size) + { + bool result = false; + if (!DoReboot(reinterpret_cast(data))) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzDoReboot(data, size); + return 0; +} diff --git a/test/fuzztest/DoReboot_fuzzer/DoReboot_fuzzer.h b/test/fuzztest/DoReboot_fuzzer/DoReboot_fuzzer.h new file mode 100644 index 00000000..1a36ccdd --- /dev/null +++ b/test/fuzztest/DoReboot_fuzzer/DoReboot_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_DOREBOOT_FUZZER_H +#define TEST_FUZZTEST_DOREBOOT_FUZZER_H +#define FUZZ_PROJECT_NAME "DoReboot_fuzzer" +#endif diff --git a/test/fuzztest/GetControlFile_fuzzer/GetControlFile_fuzzer.cpp b/test/fuzztest/GetControlFile_fuzzer/GetControlFile_fuzzer.cpp new file mode 100644 index 00000000..bd21922f --- /dev/null +++ b/test/fuzztest/GetControlFile_fuzzer/GetControlFile_fuzzer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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 "GetControlFile_fuzzer.h" +#include "init_file.h" + +namespace OHOS { + bool FuzzGetControlFile(const uint8_t* data, size_t size) + { + bool result = false; + if (!GetControlFile(reinterpret_cast(data))) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzGetControlFile(data, size); + return 0; +} diff --git a/test/fuzztest/GetControlFile_fuzzer/GetControlFile_fuzzer.h b/test/fuzztest/GetControlFile_fuzzer/GetControlFile_fuzzer.h new file mode 100644 index 00000000..c0a54544 --- /dev/null +++ b/test/fuzztest/GetControlFile_fuzzer/GetControlFile_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_GETCONTROLFILE_FUZZER_H +#define TEST_FUZZTEST_GETCONTROLFILE_FUZZER_H +#define FUZZ_PROJECT_NAME "GetControlFile_fuzzer" +#endif diff --git a/test/fuzztest/GetControlSocket_fuzzer/GetControlSocket_fuzzer.cpp b/test/fuzztest/GetControlSocket_fuzzer/GetControlSocket_fuzzer.cpp new file mode 100644 index 00000000..3056eee8 --- /dev/null +++ b/test/fuzztest/GetControlSocket_fuzzer/GetControlSocket_fuzzer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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 "GetControlSocket_fuzzer.h" +#include "init_socket.h" + +namespace OHOS { + bool FuzzGetControlSocket(const uint8_t* data, size_t size) + { + bool result = false; + if (!GetControlSocket(reinterpret_cast(data))) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzGetControlSocket(data, size); + return 0; +} diff --git a/test/fuzztest/GetControlSocket_fuzzer/GetControlSocket_fuzzer.h b/test/fuzztest/GetControlSocket_fuzzer/GetControlSocket_fuzzer.h new file mode 100644 index 00000000..db48c8b0 --- /dev/null +++ b/test/fuzztest/GetControlSocket_fuzzer/GetControlSocket_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_GETCONTROLSOCKET_FUZZER_H +#define TEST_FUZZTEST_GETCONTROLSOCKET_FUZZER_H +#define FUZZ_PROJECT_NAME "GetControlSocket_fuzzer" +#endif diff --git a/test/fuzztest/MountAllFstab_fuzzer/MountAllFstab_fuzzer.cpp b/test/fuzztest/MountAllFstab_fuzzer/MountAllFstab_fuzzer.cpp new file mode 100644 index 00000000..067a94d9 --- /dev/null +++ b/test/fuzztest/MountAllFstab_fuzzer/MountAllFstab_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 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 "MountAllFstab_fuzzer.h" + +#include +#include "fs_manager/fs_manager.h" +#include "fuzz_utils.h" + +namespace OHOS { + bool FuzzMountAllWithFstabFile(const uint8_t* data, size_t size) + { + bool result = false; + FILE *pFile = nullptr; + pFile = fopen("fstab.test", "w+"); + if (pFile == nullptr) { + std::cout << "[fuzz] open file fstab.test failed"; + return false; + } + if (reinterpret_cast(fwrite(data, 1, size, pFile)) != size) { + std::cout << "[fuzz] write data to fstab.test failed"; + fclose(pFile); + return false; + } + fclose(pFile); + CloseStdout(); + if (!MountAllWithFstabFile("fstab.test", false)) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzMountAllWithFstabFile(data, size); + return 0; +} diff --git a/test/fuzztest/MountAllFstab_fuzzer/MountAllFstab_fuzzer.h b/test/fuzztest/MountAllFstab_fuzzer/MountAllFstab_fuzzer.h new file mode 100644 index 00000000..1bc393f6 --- /dev/null +++ b/test/fuzztest/MountAllFstab_fuzzer/MountAllFstab_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_MOUNTALLFSTAB_FUZZER_H +#define TEST_FUZZTEST_MOUNTALLFSTAB_FUZZER_H +#define FUZZ_PROJECT_NAME "MountAllFstab_fuzzer" +#endif diff --git a/test/fuzztest/ReadFileInDir_fuzzer/ReadFileInDir_fuzzer.cpp b/test/fuzztest/ReadFileInDir_fuzzer/ReadFileInDir_fuzzer.cpp new file mode 100644 index 00000000..3dd33508 --- /dev/null +++ b/test/fuzztest/ReadFileInDir_fuzzer/ReadFileInDir_fuzzer.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021 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 "ReadFileInDir_fuzzer.h" + +#include +#include +#include +#include +#include "init.h" +#include "init_utils.h" + +static int FakeParser(const char *testFile, void *context) +{ + UNUSED(context); + std::ifstream fileStream; + fileStream.open(testFile); + std::vector fileText; + std::string textLine; + while (getline(fileStream, textLine)) { + fileText.push_back(textLine); + } + fileStream.close(); + std::vector().swap(fileText); + return 0; +} + +namespace OHOS { + bool FuzzReadFileInDir(const uint8_t* data, size_t size) + { + bool result = false; + FILE *pFile = nullptr; + pFile = fopen("ReadFileInDir.test", "w+"); + if (pFile == nullptr) { + std::cout << "[fuzz] open file ReadFileInDir.test failed"; + return false; + } + if (reinterpret_cast(fwrite(data, 1, size, pFile)) != size) { + std::cout << "[fuzz] write data to ReadFileInDir.test failed"; + fclose(pFile); + return false; + } + fclose(pFile); + if (!ReadFileInDir("/data", ".test", FakeParser, NULL)) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzReadFileInDir(data, size); + return 0; +} diff --git a/test/fuzztest/ReadFileInDir_fuzzer/ReadFileInDir_fuzzer.h b/test/fuzztest/ReadFileInDir_fuzzer/ReadFileInDir_fuzzer.h new file mode 100644 index 00000000..7ffebe94 --- /dev/null +++ b/test/fuzztest/ReadFileInDir_fuzzer/ReadFileInDir_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_READFILEINDIR_FUZZER_H +#define TEST_FUZZTEST_READFILEINDIR_FUZZER_H +#define FUZZ_PROJECT_NAME "ReadFileInDir_fuzzer" +#endif diff --git a/test/fuzztest/StartDynamicProcess_fuzzer/StartDynamicProcess_fuzzer.cpp b/test/fuzztest/StartDynamicProcess_fuzzer/StartDynamicProcess_fuzzer.cpp new file mode 100644 index 00000000..5e5f6f63 --- /dev/null +++ b/test/fuzztest/StartDynamicProcess_fuzzer/StartDynamicProcess_fuzzer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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 "StartDynamicProcess_fuzzer.h" +#include "dynamic_service.h" + +namespace OHOS { + bool FuzzStartDynamicProcess(const uint8_t* data, size_t size) + { + bool result = false; + if (!StartDynamicProcess(reinterpret_cast(data))) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzStartDynamicProcess(data, size); + return 0; +} diff --git a/test/fuzztest/StartDynamicProcess_fuzzer/StartDynamicProcess_fuzzer.h b/test/fuzztest/StartDynamicProcess_fuzzer/StartDynamicProcess_fuzzer.h new file mode 100644 index 00000000..cbee46bd --- /dev/null +++ b/test/fuzztest/StartDynamicProcess_fuzzer/StartDynamicProcess_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_STARTDYNAMICPROCESS_FUZZER_H +#define TEST_FUZZTEST_STARTDYNAMICPROCESS_FUZZER_H +#define FUZZ_PROJECT_NAME "StartDynamicProcess_fuzzer" +#endif diff --git a/test/fuzztest/StopDynamicProcess_fuzzer/StopDynamicProcess_fuzzer.cpp b/test/fuzztest/StopDynamicProcess_fuzzer/StopDynamicProcess_fuzzer.cpp new file mode 100644 index 00000000..b9ce070c --- /dev/null +++ b/test/fuzztest/StopDynamicProcess_fuzzer/StopDynamicProcess_fuzzer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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 "StopDynamicProcess_fuzzer.h" +#include "dynamic_service.h" + +namespace OHOS { + bool FuzzStopDynamicProcess(const uint8_t* data, size_t size) + { + bool result = false; + if (!StopDynamicProcess(reinterpret_cast(data))) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzStopDynamicProcess(data, size); + return 0; +} diff --git a/test/fuzztest/StopDynamicProcess_fuzzer/StopDynamicProcess_fuzzer.h b/test/fuzztest/StopDynamicProcess_fuzzer/StopDynamicProcess_fuzzer.h new file mode 100644 index 00000000..2db8c4f2 --- /dev/null +++ b/test/fuzztest/StopDynamicProcess_fuzzer/StopDynamicProcess_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_STOPDYNAMICPROCESS_FUZZER_H +#define TEST_FUZZTEST_STOPDYNAMICPROCESS_FUZZER_H +#define FUZZ_PROJECT_NAME "StopDynamicProcess_fuzzer" +#endif diff --git a/test/fuzztest/SystemDumpParameters_fuzzer/SystemDumpParameters_fuzzer.cpp b/test/fuzztest/SystemDumpParameters_fuzzer/SystemDumpParameters_fuzzer.cpp new file mode 100644 index 00000000..72470668 --- /dev/null +++ b/test/fuzztest/SystemDumpParameters_fuzzer/SystemDumpParameters_fuzzer.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 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 "SystemDumpParameters_fuzzer.h" +#include "sys_param.h" +#include "fuzz_utils.h" + +namespace OHOS { + bool FuzzSystemDumpParameters(const uint8_t* data, size_t size) + { + CloseStdout(); + SystemDumpParameters(reinterpret_cast(data)); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzSystemDumpParameters(data, size); + return 0; +} diff --git a/test/fuzztest/SystemDumpParameters_fuzzer/SystemDumpParameters_fuzzer.h b/test/fuzztest/SystemDumpParameters_fuzzer/SystemDumpParameters_fuzzer.h new file mode 100644 index 00000000..a1216ad1 --- /dev/null +++ b/test/fuzztest/SystemDumpParameters_fuzzer/SystemDumpParameters_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_SYSTEMDUMPPARAMETERS_FUZZER_H +#define TEST_FUZZTEST_SYSTEMDUMPPARAMETERS_FUZZER_H +#define FUZZ_PROJECT_NAME "SystemDumpParameters_fuzzer" +#endif diff --git a/test/fuzztest/SystemFindParameter_fuzzer/SystemFindParameter_fuzzer.cpp b/test/fuzztest/SystemFindParameter_fuzzer/SystemFindParameter_fuzzer.cpp new file mode 100644 index 00000000..ea1c81b4 --- /dev/null +++ b/test/fuzztest/SystemFindParameter_fuzzer/SystemFindParameter_fuzzer.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 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 "SystemFindParameter_fuzzer.h" +#include "sys_param.h" + +static ParamHandle handle; + +namespace OHOS { + bool FuzzSystemFindParameter(const uint8_t* data, size_t size) + { + bool result = false; + if (!SystemFindParameter(reinterpret_cast(data), &handle)) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzSystemFindParameter(data, size); + return 0; +} diff --git a/test/fuzztest/SystemFindParameter_fuzzer/SystemFindParameter_fuzzer.h b/test/fuzztest/SystemFindParameter_fuzzer/SystemFindParameter_fuzzer.h new file mode 100644 index 00000000..1651fd4b --- /dev/null +++ b/test/fuzztest/SystemFindParameter_fuzzer/SystemFindParameter_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_SYSTEMFINDPARAMETER_FUZZER_H +#define TEST_FUZZTEST_SYSTEMFINDPARAMETER_FUZZER_H +#define FUZZ_PROJECT_NAME "SystemFindParameter_fuzzer" +#endif diff --git a/test/fuzztest/SystemGetParameterCommitId_fuzzer/SystemGetParameterCommitId_fuzzer.cpp b/test/fuzztest/SystemGetParameterCommitId_fuzzer/SystemGetParameterCommitId_fuzzer.cpp new file mode 100644 index 00000000..149e211b --- /dev/null +++ b/test/fuzztest/SystemGetParameterCommitId_fuzzer/SystemGetParameterCommitId_fuzzer.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 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 "SystemGetParameterCommitId_fuzzer.h" +#include "sys_param.h" + +namespace OHOS { + bool FuzzSystemGetParameterCommitId(const uint8_t* data, size_t size) + { + bool result = false; + uint32_t commitId = 0; + if (!SystemGetParameterCommitId(reinterpret_cast(data), &commitId)) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzSystemGetParameterCommitId(data, size); + return 0; +} diff --git a/test/fuzztest/SystemGetParameterCommitId_fuzzer/SystemGetParameterCommitId_fuzzer.h b/test/fuzztest/SystemGetParameterCommitId_fuzzer/SystemGetParameterCommitId_fuzzer.h new file mode 100644 index 00000000..2b6b5138 --- /dev/null +++ b/test/fuzztest/SystemGetParameterCommitId_fuzzer/SystemGetParameterCommitId_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_SYSTEMGETPARAMETERCOMMITID_FUZZER_H +#define TEST_FUZZTEST_SYSTEMGETPARAMETERCOMMITID_FUZZER_H +#define FUZZ_PROJECT_NAME "SystemGetParameterCommitId_fuzzer" +#endif diff --git a/test/fuzztest/SystemGetParameterName_fuzzer/SystemGetParameterName_fuzzer.cpp b/test/fuzztest/SystemGetParameterName_fuzzer/SystemGetParameterName_fuzzer.cpp new file mode 100644 index 00000000..167f89cd --- /dev/null +++ b/test/fuzztest/SystemGetParameterName_fuzzer/SystemGetParameterName_fuzzer.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 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 "SystemGetParameterName_fuzzer.h" +#include "sys_param.h" + +namespace OHOS { + bool FuzzSystemGetParameterName(const uint8_t* data, size_t size) + { + bool result = false; + char buffer[PARAM_NAME_LEN_MAX] = {0}; + if (!SystemGetParameterName(reinterpret_cast(data), buffer, PARAM_NAME_LEN_MAX)) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzSystemGetParameterName(data, size); + return 0; +} diff --git a/test/fuzztest/SystemGetParameterName_fuzzer/SystemGetParameterName_fuzzer.h b/test/fuzztest/SystemGetParameterName_fuzzer/SystemGetParameterName_fuzzer.h new file mode 100644 index 00000000..a9ad6117 --- /dev/null +++ b/test/fuzztest/SystemGetParameterName_fuzzer/SystemGetParameterName_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_SYSTEMGETPARAMETERNAME_FUZZER_H +#define TEST_FUZZTEST_SYSTEMGETPARAMETERNAME_FUZZER_H +#define FUZZ_PROJECT_NAME "SystemGetParameterName_fuzzer" +#endif diff --git a/test/fuzztest/SystemGetParameterValue_fuzzer/SystemGetParameterValue_fuzzer.cpp b/test/fuzztest/SystemGetParameterValue_fuzzer/SystemGetParameterValue_fuzzer.cpp new file mode 100644 index 00000000..617a6f1b --- /dev/null +++ b/test/fuzztest/SystemGetParameterValue_fuzzer/SystemGetParameterValue_fuzzer.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 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 "SystemGetParameterValue_fuzzer.h" +#include "sys_param.h" + +namespace OHOS { + bool FuzzSystemGetParameterValue(const uint8_t* data, size_t size) + { + bool result = false; + char buffer[PARAM_CONST_VALUE_LEN_MAX] = {0}; + uint32_t len = PARAM_CONST_VALUE_LEN_MAX; + if (!SystemGetParameterValue(reinterpret_cast(data), buffer, &len)) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzSystemGetParameterValue(data, size); + return 0; +} diff --git a/test/fuzztest/SystemGetParameterValue_fuzzer/SystemGetParameterValue_fuzzer.h b/test/fuzztest/SystemGetParameterValue_fuzzer/SystemGetParameterValue_fuzzer.h new file mode 100644 index 00000000..eeb5b12a --- /dev/null +++ b/test/fuzztest/SystemGetParameterValue_fuzzer/SystemGetParameterValue_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_SYSTEMGETPARAMETERVALUE_FUZZER_H +#define TEST_FUZZTEST_SYSTEMGETPARAMETERVALUE_FUZZER_H +#define FUZZ_PROJECT_NAME "SystemGetParameterValue_fuzzer" +#endif diff --git a/test/fuzztest/SystemGetParameter_fuzzer/SystemGetParameter_fuzzer.cpp b/test/fuzztest/SystemGetParameter_fuzzer/SystemGetParameter_fuzzer.cpp new file mode 100644 index 00000000..6355563b --- /dev/null +++ b/test/fuzztest/SystemGetParameter_fuzzer/SystemGetParameter_fuzzer.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 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 "SystemGetParameter_fuzzer.h" + +#include +#include "sys_param.h" + +namespace OHOS { + bool FuzzSystemGetParameter(const uint8_t* data, size_t size) + { + bool result = false; + char buffer[PARAM_CONST_VALUE_LEN_MAX] = {0}; + uint32_t len = PARAM_CONST_VALUE_LEN_MAX; + if (!SystemGetParameter(reinterpret_cast(data), buffer, &len)) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzSystemGetParameter(data, size); + return 0; +} diff --git a/test/fuzztest/SystemGetParameter_fuzzer/SystemGetParameter_fuzzer.h b/test/fuzztest/SystemGetParameter_fuzzer/SystemGetParameter_fuzzer.h new file mode 100644 index 00000000..560f2f91 --- /dev/null +++ b/test/fuzztest/SystemGetParameter_fuzzer/SystemGetParameter_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_SYSTEMGETPARAMETER_FUZZER_H +#define TEST_FUZZTEST_SYSTEMGETPARAMETER_FUZZER_H +#define FUZZ_PROJECT_NAME "SystemGetParameter_fuzzer" +#endif diff --git a/test/fuzztest/SystemSetParameter_fuzzer/SystemSetParameter_fuzzer.cpp b/test/fuzztest/SystemSetParameter_fuzzer/SystemSetParameter_fuzzer.cpp new file mode 100644 index 00000000..0c35ad85 --- /dev/null +++ b/test/fuzztest/SystemSetParameter_fuzzer/SystemSetParameter_fuzzer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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 "SystemSetParameter_fuzzer.h" +#include "sys_param.h" + +namespace OHOS { + bool FuzzSystemSetParameter(const uint8_t* data, size_t size) + { + bool result = false; + if (!SystemSetParameter(reinterpret_cast(data), reinterpret_cast(data))) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzSystemSetParameter(data, size); + return 0; +} diff --git a/test/fuzztest/SystemSetParameter_fuzzer/SystemSetParameter_fuzzer.h b/test/fuzztest/SystemSetParameter_fuzzer/SystemSetParameter_fuzzer.h new file mode 100644 index 00000000..e6cac985 --- /dev/null +++ b/test/fuzztest/SystemSetParameter_fuzzer/SystemSetParameter_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_SYSTEMSETPARAMETER_FUZZER_H +#define TEST_FUZZTEST_SYSTEMSETPARAMETER_FUZZER_H +#define FUZZ_PROJECT_NAME "SystemSetParameter_fuzzer" +#endif diff --git a/test/fuzztest/SystemTraversalParameter_fuzzer/SystemTraversalParameter_fuzzer.cpp b/test/fuzztest/SystemTraversalParameter_fuzzer/SystemTraversalParameter_fuzzer.cpp new file mode 100644 index 00000000..23cd010f --- /dev/null +++ b/test/fuzztest/SystemTraversalParameter_fuzzer/SystemTraversalParameter_fuzzer.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021 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 "SystemTraversalParameter_fuzzer.h" + +#include "fuzz_utils.h" +#include "init.h" +#include "securec.h" +#include "sys_param.h" + +static void FakeShowParam(ParamHandle handle, void *cookie) +{ + Cookie *nameAndValue = reinterpret_cast(cookie); + char *name = nameAndValue->data; + unsigned int nameLen = nameAndValue->size; + char value[PARAM_CONST_VALUE_LEN_MAX] = {0}; + SystemGetParameterName(handle, name, nameLen); + uint32_t size = PARAM_CONST_VALUE_LEN_MAX; + SystemGetParameterValue(handle, value, &size); + printf("\t%s = %s \n", name, value); +} + +namespace OHOS { + bool FuzzSystemTraversalParameter(const uint8_t* data, size_t size) + { + bool result = false; + CloseStdout(); + Cookie instance = {0, nullptr}; + Cookie *cookie = &instance; + if (size <= 0) { + return false; + } + cookie->data = static_cast(malloc(size)); + if (cookie->data == nullptr) { + return true; + } + cookie->size = size; + int ret = memcpy_s(cookie->data, size, data, size); + if (ret != EOK) { + return false; + } + if (!SystemTraversalParameter(FakeShowParam, reinterpret_cast(cookie))) { + result = true; + } + free(cookie->data); + cookie->data = nullptr; + cookie->size = 0; + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzSystemTraversalParameter(data, size); + return 0; +} diff --git a/test/fuzztest/SystemTraversalParameter_fuzzer/SystemTraversalParameter_fuzzer.h b/test/fuzztest/SystemTraversalParameter_fuzzer/SystemTraversalParameter_fuzzer.h new file mode 100644 index 00000000..013b4dd4 --- /dev/null +++ b/test/fuzztest/SystemTraversalParameter_fuzzer/SystemTraversalParameter_fuzzer.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_SYSTEMTRAVERSALPARAMETER_FUZZER_H +#define TEST_FUZZTEST_SYSTEMTRAVERSALPARAMETER_FUZZER_H +#define FUZZ_PROJECT_NAME "SystemTraversalParameter_fuzzer" + +typedef struct { + size_t size; + char *data; +} Cookie; + +#endif diff --git a/test/fuzztest/SystemWaitParameter_fuzzer/SystemWaitParameter_fuzzer.cpp b/test/fuzztest/SystemWaitParameter_fuzzer/SystemWaitParameter_fuzzer.cpp new file mode 100644 index 00000000..82bd23a8 --- /dev/null +++ b/test/fuzztest/SystemWaitParameter_fuzzer/SystemWaitParameter_fuzzer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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 "SystemWaitParameter_fuzzer.h" +#include "sys_param.h" + +namespace OHOS { + bool FuzzSystemWaitParameter(const uint8_t* data, size_t size) + { + bool result = false; + if (!SystemWaitParameter(reinterpret_cast(data), reinterpret_cast(data), 1)) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzSystemWaitParameter(data, size); + return 0; +} diff --git a/test/fuzztest/SystemWaitParameter_fuzzer/SystemWaitParameter_fuzzer.h b/test/fuzztest/SystemWaitParameter_fuzzer/SystemWaitParameter_fuzzer.h new file mode 100644 index 00000000..beb385db --- /dev/null +++ b/test/fuzztest/SystemWaitParameter_fuzzer/SystemWaitParameter_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_SYSTEMWAITPARAMETER_FUZZER_H +#define TEST_FUZZTEST_SYSTEMWAITPARAMETER_FUZZER_H +#define FUZZ_PROJECT_NAME "SystemWaitParameter_fuzzer" +#endif diff --git a/test/fuzztest/SystemWatchParameter_fuzzer/SystemWatchParameter_fuzzer.cpp b/test/fuzztest/SystemWatchParameter_fuzzer/SystemWatchParameter_fuzzer.cpp new file mode 100644 index 00000000..9b1b9238 --- /dev/null +++ b/test/fuzztest/SystemWatchParameter_fuzzer/SystemWatchParameter_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021 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 "SystemWatchParameter_fuzzer.h" + +#include "init.h" +#include "sys_param.h" + +static void HandleParamChange(const char *key, const char *value, void *context) +{ + if (key == nullptr || value == nullptr) { + return; + } + UNUSED(context); + printf("Receive parameter change %s %s \n", key, value); +} + +namespace OHOS { + bool FuzzSystemWatchParameter(const uint8_t* data, size_t size) + { + bool result = false; + if (!SystemWatchParameter(reinterpret_cast(data), HandleParamChange, NULL)) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzSystemWatchParameter(data, size); + return 0; +} diff --git a/test/fuzztest/SystemWatchParameter_fuzzer/SystemWatchParameter_fuzzer.h b/test/fuzztest/SystemWatchParameter_fuzzer/SystemWatchParameter_fuzzer.h new file mode 100644 index 00000000..12250361 --- /dev/null +++ b/test/fuzztest/SystemWatchParameter_fuzzer/SystemWatchParameter_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_SYSTEMWATCHPARAMETER_FUZZER_H +#define TEST_FUZZTEST_SYSTEMWATCHPARAMETER_FUZZER_H +#define FUZZ_PROJECT_NAME "SystemWatchParameter_fuzzer" +#endif diff --git a/test/fuzztest/UmountAllFstab_fuzzer/UmountAllFstab_fuzzer.cpp b/test/fuzztest/UmountAllFstab_fuzzer/UmountAllFstab_fuzzer.cpp new file mode 100644 index 00000000..23e7276e --- /dev/null +++ b/test/fuzztest/UmountAllFstab_fuzzer/UmountAllFstab_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021 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 "UmountAllFstab_fuzzer.h" + +#include +#include "fs_manager/fs_manager.h" +#include "fuzz_utils.h" + +namespace OHOS { + bool FuzzUmountAllWithFstabFile(const uint8_t* data, size_t size) + { + bool result = false; + FILE *pFile = nullptr; + pFile = fopen("fstab.test", "w+"); + if (pFile == nullptr) { + std::cout << "[fuzz] open file fstab.test failed"; + return false; + } + if (reinterpret_cast(fwrite(data, 1, size, pFile)) != size) { + std::cout << "[fuzz] write data to fstab.test failed"; + fclose(pFile); + return false; + } + fclose(pFile); + CloseStdout(); + if (!UmountAllWithFstabFile("fstab.test")) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzUmountAllWithFstabFile(data, size); + return 0; +} + diff --git a/test/fuzztest/UmountAllFstab_fuzzer/UmountAllFstab_fuzzer.h b/test/fuzztest/UmountAllFstab_fuzzer/UmountAllFstab_fuzzer.h new file mode 100644 index 00000000..b4f1ad87 --- /dev/null +++ b/test/fuzztest/UmountAllFstab_fuzzer/UmountAllFstab_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_UMOUNTALLFSTAB_FUZZER_H +#define TEST_FUZZTEST_UMOUNTALLFSTAB_FUZZER_H +#define FUZZ_PROJECT_NAME "UmountAllFstab_fuzzer" +#endif diff --git a/test/fuzztest/project.xml b/test/fuzztest/project.xml new file mode 100644 index 00000000..ee0011e1 --- /dev/null +++ b/test/fuzztest/project.xml @@ -0,0 +1,25 @@ + + + + + + 100 + + 300 + + 2048 + + diff --git a/test/fuzztest/utils/fuzz_utils.cpp b/test/fuzztest/utils/fuzz_utils.cpp new file mode 100644 index 00000000..04de9ad3 --- /dev/null +++ b/test/fuzztest/utils/fuzz_utils.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021 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 +#include "fuzz_utils.h" + +void CloseStdout(void) +{ + int fd = open("/dev/null", O_RDWR | O_CLOEXEC); + if (fd < 0) { + return; + } + dup2(fd, 1); + close(fd); +} diff --git a/test/fuzztest/utils/include/fuzz_utils.h b/test/fuzztest/utils/include/fuzz_utils.h new file mode 100644 index 00000000..ee4a45eb --- /dev/null +++ b/test/fuzztest/utils/include/fuzz_utils.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2021 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 FUZZ_UTILS_H +#define FUZZ_UTILS_H + +void CloseStdout(void); +#endif -- GitLab