From d0d86691831fc942ab04dfa77e1096e9f0af7cbb Mon Sep 17 00:00:00 2001 From: cat Date: Wed, 11 Jun 2025 21:21:08 +0800 Subject: [PATCH] add fuzz Signed-off-by: cat --- test/fuzztest/BUILD.gn | 197 ++++++++++++++++++ .../addparamentry_fuzzer.cpp | 70 +++++++ .../addparamentry_fuzzer.h | 20 ++ .../fuzztest/addparamentry_fuzzer/corpus/init | 16 ++ .../fuzztest/addparamentry_fuzzer/project.xml | 25 +++ .../addremotewatcher_fuzzer.cpp | 3 +- .../checkappwatchpermission_fuzzer.cpp | 43 ++++ .../checkappwatchpermission_fuzzer.h | 20 ++ .../corpus/init | 16 ++ .../project.xml | 25 +++ .../fuzztest/initworkspace_fuzzer/corpus/init | 16 ++ .../initworkspace_fuzzer.cpp | 53 +++++ .../initworkspace_fuzzer.h | 20 ++ .../fuzztest/initworkspace_fuzzer/project.xml | 25 +++ .../mountonewithfstabfile_fuzzer/corpus/init | 16 ++ .../mountonewithfstabfile_fuzzer.cpp | 47 +++++ .../mountonewithfstabfile_fuzzer.h | 20 ++ .../mountonewithfstabfile_fuzzer/project.xml | 25 +++ test/fuzztest/onstop_fuzzer/corpus/init | 16 ++ test/fuzztest/onstop_fuzzer/onstop_fuzzer.cpp | 43 ++++ test/fuzztest/onstop_fuzzer/onstop_fuzzer.h | 20 ++ test/fuzztest/onstop_fuzzer/project.xml | 25 +++ 22 files changed, 760 insertions(+), 1 deletion(-) create mode 100644 test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp create mode 100644 test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.h create mode 100644 test/fuzztest/addparamentry_fuzzer/corpus/init create mode 100644 test/fuzztest/addparamentry_fuzzer/project.xml create mode 100644 test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.cpp create mode 100644 test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.h create mode 100644 test/fuzztest/checkappwatchpermission_fuzzer/corpus/init create mode 100644 test/fuzztest/checkappwatchpermission_fuzzer/project.xml create mode 100644 test/fuzztest/initworkspace_fuzzer/corpus/init create mode 100644 test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.cpp create mode 100644 test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.h create mode 100644 test/fuzztest/initworkspace_fuzzer/project.xml create mode 100644 test/fuzztest/mountonewithfstabfile_fuzzer/corpus/init create mode 100644 test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.cpp create mode 100644 test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.h create mode 100644 test/fuzztest/mountonewithfstabfile_fuzzer/project.xml create mode 100644 test/fuzztest/onstop_fuzzer/corpus/init create mode 100644 test/fuzztest/onstop_fuzzer/onstop_fuzzer.cpp create mode 100644 test/fuzztest/onstop_fuzzer/onstop_fuzzer.h create mode 100644 test/fuzztest/onstop_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 94e8734c9..5a191d7f0 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -2866,6 +2866,198 @@ ohos_fuzztest("GetFeatureVersionFuzzTest") { defines = [ "STARTUP_INIT_TEST" ] } +ohos_fuzztest("MountOneWithFstabFileFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//base/startup/init/test/fuzztest/mountonewithfstabfile_fuzzer" + + include_dirs = [ + "//base/startup/init/interfaces/innerkits/fs_manager", + "//base/startup/init/interfaces/innerkits/include/fs_manager", + "//base/startup/init/test/fuzztest/utils/include", + ] + + deps = [ + "//base/startup/init/interfaces/innerkits:libbegetutil", + "//base/startup/init/interfaces/innerkits/fs_manager:libfsmanager_static",] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson", + ] + external_deps += [ "hilog:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.cpp", + ] + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("AddParamEntryFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//base/startup/init/test/fuzztest/addparamentry_fuzzer" + + include_dirs = [ + "//base/startup/init/services/param/include", + "//base/startup/init/test/fuzztest/utils/include", + ] + + deps = [ + "//base/startup/init/interfaces/innerkits:libbegetutil", + "//base/startup/init/services/param:parameter",] + external_deps = [ + "bounds_checking_function:libsec_static", + ] + external_deps += [ "hilog:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "addparamentry_fuzzer/addparamentry_fuzzer.cpp", + ] + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("InitWorkSpaceFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//base/startup/init/test/fuzztest/initworkspace_fuzzer" + + include_dirs = [ + "//base/startup/init/services/param/include", + "//base/startup/init/test/fuzztest/utils/include", + ] + + deps = [ + "//base/startup/init/interfaces/innerkits:libbegetutil", + "//base/startup/init/services/param:parameter",] + external_deps = [ + "bounds_checking_function:libsec_static", + ] + external_deps += [ "hilog:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "initworkspace_fuzzer/initworkspace_fuzzer.cpp", + ] + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("CheckAppWatchPermissionFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/startup/init/test/fuzztest/checkappwatchpermission_fuzzer" + + sources = [ + "//base/startup/init/services/param/linux/param_message.c", + "//base/startup/init/services/param/watcher/proxy/watcher_manager.cpp", + ] + include_dirs = [ + "//base/startup/init/interfaces/innerkits/include", + "//base/startup/init/test/fuzztest/utils/include", + "//base/startup/init/services/param/watcher/proxy", + "//base/startup/init/services/param/watcher/include", + "//base/startup/init/services/param/include", + "//base/startup/init/interfaces/innerkits/include/param", + "//base/startup/init/services/param/linux", + "//base/startup/init/services/loopevent/include", + "//base/startup/init/services/param/watcher/agent", + ] + + deps = [ + "//base/startup/init/interfaces/innerkits:libbegetutil", + "//base/startup/init/interfaces/innerkits/:param_watcher_stub", + "//base/startup/init/services/log:agent_log", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + if (init_paramwatcher_hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + } + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources += [ "checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.cpp" ] + defines = [ "STARTUP_INIT_TEST" ] + if (init_paramwatcher_hicollie_enable) { + defines += [ "HICOLLIE_ENABLE" ] + } +} + +ohos_fuzztest("OnStopFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/startup/init/test/fuzztest/onstop_fuzzer" + + sources = [ + "//base/startup/init/services/param/linux/param_message.c", + "//base/startup/init/services/param/watcher/proxy/watcher_manager.cpp", + ] + include_dirs = [ + "//base/startup/init/interfaces/innerkits/include", + "//base/startup/init/test/fuzztest/utils/include", + "//base/startup/init/services/param/watcher/proxy", + "//base/startup/init/services/param/watcher/include", + "//base/startup/init/services/param/include", + "//base/startup/init/interfaces/innerkits/include/param", + "//base/startup/init/services/param/linux", + "//base/startup/init/services/loopevent/include", + "//base/startup/init/services/param/watcher/agent", + ] + + deps = [ + "//base/startup/init/interfaces/innerkits:libbegetutil", + "//base/startup/init/interfaces/innerkits/:param_watcher_stub", + "//base/startup/init/services/log:agent_log", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + if (init_paramwatcher_hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + } + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources += [ "onstop_fuzzer/onstop_fuzzer.cpp" ] + defines = [ "STARTUP_INIT_TEST" ] + if (init_paramwatcher_hicollie_enable) { + defines += [ "HICOLLIE_ENABLE" ] + } +} + ohos_fuzztest("GetBuildVersionFuzzTest") { module_out_path = module_output_path fuzz_config_file = "//base/startup/init/test/fuzztest/getbuildversion_fuzzer" @@ -3599,10 +3791,12 @@ group("fuzztest") { ":AclGetDiskSNFuzzTest", ":AclGetSerialFuzzTest", ":AddRemoteWatcherFuzzTest", + ":AddParamEntryFuzzTest", ":AddWatcherFuzzTest", ":BuildControlMessageFuzzTest", ":ChangeSysAttributePermissionsFuzzTest", ":CheckAndCreatFileFuzzTest", + ":CheckAppWatchPermissionFuzzTest", ":CmdClientInitFuzzTest", ":CmdServiceProcessDelClientFuzzTest", ":DecodeGidFuzzTest", @@ -3678,6 +3872,7 @@ group("fuzztest") { ":HookMgrGetHooksCntFuzzTest", ":HookMgrGetStagesCntFuzzTest", ":HookMgrTraversalFuzzTest", + ":InitWorkSpaceFuzzTest", ":IsSupportedFilesystemFuzzTest", ":LoadFscryptPolicyFuzzTest", ":LoadFstabFromCommandLineFuzzTest", @@ -3692,6 +3887,7 @@ group("fuzztest") { ":MountAllWithFstabFileFuzzTest", ":MountAllWithFstabFuzzTest", ":MountOneItemFuzzTest", + ":MountOneWithFstabFileFuzzTest", ":ParseFstabPerLineFuzzTest", ":ParseUeventConfigFuzzTest", ":ParseUeventdConfigFileFuzzTest", @@ -3725,6 +3921,7 @@ group("fuzztest") { ":WaitParameterFuzzTest", ":WatchParameterFuzzTest", ":WriteAllFuzzTest", + ":OnStopFuzzTest", ] } ############################################################################### diff --git a/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp new file mode 100644 index 000000000..0e08997b8 --- /dev/null +++ b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2023 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 "addparamentry_fuzzer.h" +#include +#include +#include "param_trie.h" +#include "param_manager.h" +#include "securec.h" +constexpr int DATA_SIZE = 2; +constexpr int INDEX_MAX = 1000; +constexpr int TYPE_MAX = 5; + +namespace OHOS { + bool FuzzAddParamEntry(const uint8_t* data, size_t size) + { + if (size < DATA_SIZE) { + return false; + } + + size_t splitPos = size / DATA_SIZE; + if (splitPos == 0) { + splitPos = 1; + } + + std::unique_ptr name(new char[splitPos + 1]); + if (memcpy_s(name.get(), splitPos + 1, data, splitPos) != 0) { + return false; + } + name[splitPos] = '\0'; + + size_t valueSize = size - splitPos; + std::unique_ptr value(new char[valueSize + 1]); + if (memcpy_s(value.get(), valueSize + 1, data + splitPos, valueSize) != 0) { + return false; + } + value[valueSize] = '\0'; + + uint32_t index = 0; + if (memcpy_s(&index, sizeof(uint32_t), data, sizeof(uint32_t)) != 0) { + index = 0; + } + index %= INDEX_MAX; + + uint8_t type = 0; + if (size > 0) { + type = data[0] % TYPE_MAX; + } + + return (AddParamEntry(index, type, name.get(), value.get()) == 0); + } +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::FuzzAddParamEntry(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.h b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.h new file mode 100644 index 000000000..72d69b470 --- /dev/null +++ b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 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_ADD_PARAM_ENTRY_H +#define TEST_FUZZTEST_ADD_PARAM_ENTRY_H +#include "fuzz_utils.h" +#define FUZZ_PROJECT_NAME "addparamentry_fuzzer" +#endif \ No newline at end of file diff --git a/test/fuzztest/addparamentry_fuzzer/corpus/init b/test/fuzztest/addparamentry_fuzzer/corpus/init new file mode 100644 index 000000000..8eb5a7d6e --- /dev/null +++ b/test/fuzztest/addparamentry_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/addparamentry_fuzzer/project.xml b/test/fuzztest/addparamentry_fuzzer/project.xml new file mode 100644 index 000000000..949d03efd --- /dev/null +++ b/test/fuzztest/addparamentry_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 100 + + 30 + + 2048 + + diff --git a/test/fuzztest/addremotewatcher_fuzzer/addremotewatcher_fuzzer.cpp b/test/fuzztest/addremotewatcher_fuzzer/addremotewatcher_fuzzer.cpp index fff638a73..31c45160a 100644 --- a/test/fuzztest/addremotewatcher_fuzzer/addremotewatcher_fuzzer.cpp +++ b/test/fuzztest/addremotewatcher_fuzzer/addremotewatcher_fuzzer.cpp @@ -26,7 +26,8 @@ namespace OHOS { std::unique_ptr watcherManager = std::make_unique(0, true); uint32_t id = static_cast(*data); uint32_t watcherId = 0; - if (!watcherManager->AddRemoteWatcher(id, watcherId, nullptr)) { + sptr watcher = {0}; + if (!watcherManager->AddRemoteWatcher(id, watcherId, watcher)) { result = true; }; return result; diff --git a/test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.cpp b/test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.cpp new file mode 100644 index 000000000..5cb66cd21 --- /dev/null +++ b/test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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 "checkappwatchpermission_fuzzer.h" +#include +#include +#include "init_utils.h" +#define private public +#include "watcher_manager.h" +#undef private +using namespace OHOS::init_param; + +namespace OHOS { +bool FuzzCheckAppWatchPermission(const uint8_t* data, size_t size) + { + bool result = false; + std::string str(reinterpret_cast(data), size); + std::unique_ptr watcherManager = std::make_unique(0, true); + if (watcherManager->CheckAppWatchPermission(str)) { + result = true; + }; + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzCheckAppWatchPermission(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.h b/test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.h new file mode 100644 index 000000000..a75c318b3 --- /dev/null +++ b/test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 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_CHECK_APP_WATCH_PERMISSION_FUZZER_H +#define TEST_FUZZTEST_CHECK_APP_WATCH_PERMISSION_FUZZER_H +#include "fuzz_utils.h" +#define FUZZ_PROJECT_NAME "checkappwatchpermission_fuzzer" +#endif \ No newline at end of file diff --git a/test/fuzztest/checkappwatchpermission_fuzzer/corpus/init b/test/fuzztest/checkappwatchpermission_fuzzer/corpus/init new file mode 100644 index 000000000..8eb5a7d6e --- /dev/null +++ b/test/fuzztest/checkappwatchpermission_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/checkappwatchpermission_fuzzer/project.xml b/test/fuzztest/checkappwatchpermission_fuzzer/project.xml new file mode 100644 index 000000000..9e35ed57f --- /dev/null +++ b/test/fuzztest/checkappwatchpermission_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 100 + + 30 + + 2048 + + diff --git a/test/fuzztest/initworkspace_fuzzer/corpus/init b/test/fuzztest/initworkspace_fuzzer/corpus/init new file mode 100644 index 000000000..8eb5a7d6e --- /dev/null +++ b/test/fuzztest/initworkspace_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.cpp b/test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.cpp new file mode 100644 index 000000000..88d1b4f63 --- /dev/null +++ b/test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 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 "initworkspace_fuzzer.h" +#include +#include +#include "param_trie.h" +#include "param_manager.h" +#include "securec.h" +constexpr int DATA_SIZE = 2; + +namespace OHOS { + bool FuzzInitWorkSpace(const uint8_t* data, size_t size) + { + constexpr size_t minSize = sizeof(uint32_t) * DATA_SIZE; + if (size < minSize) { + return false; + } + + uint32_t spaceSize = 0; + if (memcpy_s(&spaceSize, sizeof(uint32_t), data, sizeof(uint32_t)) != 0) { + return false; + } + data += sizeof(uint32_t); + size -= sizeof(uint32_t); + + int onlyRead = 0; + if (memcpy_s(&onlyRead, sizeof(int), data, sizeof(int)) != 0) { + return false; + } + WorkSpace *workSpace = GetWorkSpace(0); + + return (InitWorkSpace(workSpace, onlyRead, spaceSize) == 0); + } +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::FuzzInitWorkSpace(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.h b/test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.h new file mode 100644 index 000000000..19f5ca4c0 --- /dev/null +++ b/test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 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_INIT_WORK_SPACE_H +#define TEST_FUZZTEST_INIT_WORK_SPACE_H +#include "fuzz_utils.h" +#define FUZZ_PROJECT_NAME "initworkspace_fuzzer" +#endif \ No newline at end of file diff --git a/test/fuzztest/initworkspace_fuzzer/project.xml b/test/fuzztest/initworkspace_fuzzer/project.xml new file mode 100644 index 000000000..949d03efd --- /dev/null +++ b/test/fuzztest/initworkspace_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 100 + + 30 + + 2048 + + diff --git a/test/fuzztest/mountonewithfstabfile_fuzzer/corpus/init b/test/fuzztest/mountonewithfstabfile_fuzzer/corpus/init new file mode 100644 index 000000000..8eb5a7d6e --- /dev/null +++ b/test/fuzztest/mountonewithfstabfile_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.cpp b/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.cpp new file mode 100644 index 000000000..0573214b1 --- /dev/null +++ b/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 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 "mountonewithfstabfile_fuzzer.h" +#include "securec.h" +#include +#include +#include +#include "fs_manager.h" +#include + +namespace OHOS { + bool FuzzMountOneWithFstabFile(const uint8_t* data, size_t size) + { + char fstabPath[] = "/tmp/fuzz_fstab_1"; + int fd = mkstemp(fstabPath); + if (fd < 0) { + return false; + } + + std::string str(reinterpret_cast(data), size); + + int ret = MountOneWithFstabFile(fstabPath, str.c_str(), false); + unlink(fstabPath); + if (ret == 0) { + return true; + } + return false; + } +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::FuzzMountOneWithFstabFile(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.h b/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.h new file mode 100644 index 000000000..fd3a697d3 --- /dev/null +++ b/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 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_MOUNT_ONE_WITH_FSTABFILE_H +#define TEST_FUZZTEST_MOUNT_ONE_WITH_FSTABFILE_H +#include "fuzz_utils.h" +#define FUZZ_PROJECT_NAME "mountoneWithfstabfile_fuzzer" +#endif \ No newline at end of file diff --git a/test/fuzztest/mountonewithfstabfile_fuzzer/project.xml b/test/fuzztest/mountonewithfstabfile_fuzzer/project.xml new file mode 100644 index 000000000..949d03efd --- /dev/null +++ b/test/fuzztest/mountonewithfstabfile_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 100 + + 30 + + 2048 + + diff --git a/test/fuzztest/onstop_fuzzer/corpus/init b/test/fuzztest/onstop_fuzzer/corpus/init new file mode 100644 index 000000000..8eb5a7d6e --- /dev/null +++ b/test/fuzztest/onstop_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/onstop_fuzzer/onstop_fuzzer.cpp b/test/fuzztest/onstop_fuzzer/onstop_fuzzer.cpp new file mode 100644 index 000000000..5acdd3f20 --- /dev/null +++ b/test/fuzztest/onstop_fuzzer/onstop_fuzzer.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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 "onstop_fuzzer.h" +#include +#include +#include "init_utils.h" +#define protected public +#include "watcher_manager.h" +#undef protected +using namespace OHOS::init_param; + +namespace OHOS { +bool FuzzCheckAppWatchPermission(const uint8_t* data, size_t size) + { + std::unique_ptr watcherManager = std::make_unique(0, true); + uint32_t id = static_cast(*data); + uint32_t watcherId = 0; + sptr watcher = {0}; + watcherManager->AddRemoteWatcher(id, watcherId, watcher); + watcherManager->OnStop(); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzCheckAppWatchPermission(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/onstop_fuzzer/onstop_fuzzer.h b/test/fuzztest/onstop_fuzzer/onstop_fuzzer.h new file mode 100644 index 000000000..28d288f46 --- /dev/null +++ b/test/fuzztest/onstop_fuzzer/onstop_fuzzer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 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_ON_STOP_FUZZER_H +#define TEST_FUZZTEST_ON_STOP_FUZZER_H +#include "fuzz_utils.h" +#define FUZZ_PROJECT_NAME "onstop_fuzzer" +#endif \ No newline at end of file diff --git a/test/fuzztest/onstop_fuzzer/project.xml b/test/fuzztest/onstop_fuzzer/project.xml new file mode 100644 index 000000000..949d03efd --- /dev/null +++ b/test/fuzztest/onstop_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 100 + + 30 + + 2048 + + -- Gitee