diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 94e8734c917315e9084bacb751caa4cd04943b29..5a191d7f08476f308b2289189bd58e1db3ae033d 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 0000000000000000000000000000000000000000..0e08997b807d50e06973a5f232ed01dbe73c9c43 --- /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 0000000000000000000000000000000000000000..72d69b470c74eac4ac96ff9f2ff4f56b4f700e8e --- /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 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /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 0000000000000000000000000000000000000000..949d03efd7477905377ac79f3b0bb374c8ac2e9a --- /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 fff638a7345039756941b8939d0eec2997724994..31c45160a6ba359c4e790242aae41ec5f9220553 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 0000000000000000000000000000000000000000..5cb66cd2139201e04b0609560334786aa41817ff --- /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 0000000000000000000000000000000000000000..a75c318b3fe1106c04afab24471a9dadf54db2bd --- /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 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /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 0000000000000000000000000000000000000000..9e35ed57fbc05fcaac3016839def9debdf5b9d74 --- /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 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /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 0000000000000000000000000000000000000000..88d1b4f639764554097884099e485dc232dc0e76 --- /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 0000000000000000000000000000000000000000..19f5ca4c09129fe1ac2016792bbda93c0f13c0d5 --- /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 0000000000000000000000000000000000000000..949d03efd7477905377ac79f3b0bb374c8ac2e9a --- /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 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /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 0000000000000000000000000000000000000000..0573214b1a8a73fc3832ef3f7ad29650ebeaf280 --- /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 0000000000000000000000000000000000000000..fd3a697d3f76f54793cb3ec6aeac5addea8c125e --- /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 0000000000000000000000000000000000000000..949d03efd7477905377ac79f3b0bb374c8ac2e9a --- /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 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /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 0000000000000000000000000000000000000000..5acdd3f208e5e63b9b6ea3fcc0b1ceeb64003db4 --- /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 0000000000000000000000000000000000000000..28d288f46b104a0d5cb10adb6431b42f2bd7c624 --- /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 0000000000000000000000000000000000000000..949d03efd7477905377ac79f3b0bb374c8ac2e9a --- /dev/null +++ b/test/fuzztest/onstop_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 100 + + 30 + + 2048 + +