diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d456c342e83d537d3f2e00904b656780bbeb6b4e --- /dev/null +++ b/test/fuzztest/BUILD.gn @@ -0,0 +1,501 @@ +# 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/ohos.gni") +import("//build/test.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 0000000000000000000000000000000000000000..dac70173d80af56aa7570d79b06a8137626bd280 --- /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 0000000000000000000000000000000000000000..1a36ccdd222d32a7e8ac91b4603add09adb6a6b2 --- /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 0000000000000000000000000000000000000000..bd21922fd6eca56db1f6dd4da6e0b646fda54c70 --- /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 0000000000000000000000000000000000000000..c0a54544c135928fc88e3828eb87c4028877d2c9 --- /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 0000000000000000000000000000000000000000..3056eee883bfd06733a0a7d8762664618dcd3d90 --- /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 0000000000000000000000000000000000000000..db48c8b0aa8a6bd8806ebdf8fa2309c585c98b68 --- /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 0000000000000000000000000000000000000000..700d6e04d545db7ced9a8c25c0f72d0f24690fee --- /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"; + (void)fclose(pFile); + return false; + } + (void)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 0000000000000000000000000000000000000000..1bc393f61d4a5ce2f8a0bd5bb10a747c129f0218 --- /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 0000000000000000000000000000000000000000..2bbe8d2a4a910780346ab8c6ec34f9586e8fd157 --- /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"; + (void)fclose(pFile); + return false; + } + (void)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 0000000000000000000000000000000000000000..7ffebe94c2217a11bad0a551365f52d5707f8d6a --- /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 0000000000000000000000000000000000000000..5e5f6f63cda8c070279695f4f701a73e1f27af71 --- /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 0000000000000000000000000000000000000000..cbee46bd6b8e33190d9e6e2e22daa2a6e02941da --- /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 0000000000000000000000000000000000000000..b9ce070c15b7a0d4581b91bba25f6e7fcfcfd5dc --- /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 0000000000000000000000000000000000000000..2db8c4f295cf2b3a710d61c29185ec90cd256437 --- /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 0000000000000000000000000000000000000000..7247066844a51f61e5f47718782b062d35b6971e --- /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 0000000000000000000000000000000000000000..a1216ad1aaef4ab7c33d65959edd200c371a3798 --- /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 0000000000000000000000000000000000000000..ea1c81b4c9fc020cddb27b31ff9a00627cb7fbfe --- /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 0000000000000000000000000000000000000000..1651fd4b211b175322f31b8fdb8a1ff4e74050bc --- /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 0000000000000000000000000000000000000000..149e211bbc1c46923d24cdc8812b6cc92b14f283 --- /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 0000000000000000000000000000000000000000..2b6b5138f65e23afc9a3354fde9d16dfe1f31d34 --- /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 0000000000000000000000000000000000000000..167f89cd0cd6191bc16d3fe272fa6833f96f3c6a --- /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 0000000000000000000000000000000000000000..a9ad61173fb607fabc7db99bfea35e0c865e4ec4 --- /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 0000000000000000000000000000000000000000..617a6f1b5c6d53f6e433f74c137a39fb2e4590e9 --- /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 0000000000000000000000000000000000000000..eeb5b12a4b98a2106083bbfd4363c82f08c93978 --- /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 0000000000000000000000000000000000000000..6355563bb41222aabf871b9284121fa86d28e46a --- /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 0000000000000000000000000000000000000000..560f2f9126055497440cb217dea63382268668bb --- /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 0000000000000000000000000000000000000000..0c35ad856e4fca9812303fb05cb56df0727cc311 --- /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 0000000000000000000000000000000000000000..e6cac9857793af68be5da93cd535ef50a28d4b12 --- /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 0000000000000000000000000000000000000000..23cd010fadf82f8ac720f248dbb6a4bbfbcd40bd --- /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 0000000000000000000000000000000000000000..013b4dd4737c010c0a0413f85f7068caa9248f1e --- /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 0000000000000000000000000000000000000000..82bd23a834006a4237ee53ae8307e6e30a1ff382 --- /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 0000000000000000000000000000000000000000..beb385db2318fb493c7013399368f03e6d71665e --- /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 0000000000000000000000000000000000000000..9b1b9238245330d3c9a91cde490a964e4ba74f25 --- /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 0000000000000000000000000000000000000000..12250361b30025444781ae36ecd9d4c3115c88f3 --- /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 0000000000000000000000000000000000000000..ddf6daf1a91694f697b8832b46c96f723ac25cd4 --- /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"; + (void)fclose(pFile); + return false; + } + (void)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 0000000000000000000000000000000000000000..b4f1ad87043f15c4e8dc1f6b86b060f6107c44d0 --- /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 0000000000000000000000000000000000000000..ee0011e124c9f60b4c624252283d71dfaf9d2cdc --- /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 0000000000000000000000000000000000000000..04de9ad38f62b954c8d6493ba746ee6295082cff --- /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 0000000000000000000000000000000000000000..ee4a45eb70c62da0ffd5df9de3ce0bb5b873d7fe --- /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