diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 94e8734c917315e9084bacb751caa4cd04943b29..358d452343ddf3685fb93175d07a559aafdc2d74 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -3599,10 +3599,14 @@ group("fuzztest") { ":AclGetDiskSNFuzzTest", ":AclGetSerialFuzzTest", ":AddRemoteWatcherFuzzTest", + ":AddParamEntryFuzzTest", + ":AddParamSecurityNodeFuzzTest", + ":AddSecurityLabelFuzzTest", ":AddWatcherFuzzTest", ":BuildControlMessageFuzzTest", ":ChangeSysAttributePermissionsFuzzTest", ":CheckAndCreatFileFuzzTest", + ":CheckAppWatchPermissionFuzzTest", ":CmdClientInitFuzzTest", ":CmdServiceProcessDelClientFuzzTest", ":DecodeGidFuzzTest", @@ -3679,6 +3683,7 @@ group("fuzztest") { ":HookMgrGetStagesCntFuzzTest", ":HookMgrTraversalFuzzTest", ":IsSupportedFilesystemFuzzTest", + ":InitWorkSpaceFuzzTest", ":LoadFscryptPolicyFuzzTest", ":LoadFstabFromCommandLineFuzzTest", ":LoadParamFromCmdLineFuzzTest", @@ -3692,6 +3697,8 @@ group("fuzztest") { ":MountAllWithFstabFileFuzzTest", ":MountAllWithFstabFuzzTest", ":MountOneItemFuzzTest", + ":MountOneWithFstabFileFuzzTest", + ":OnStopFuzzTest", ":ParseFstabPerLineFuzzTest", ":ParseUeventConfigFuzzTest", ":ParseUeventdConfigFileFuzzTest", diff --git a/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b139e9cfea825afa6bc83621f2afa1695b55f6e6 --- /dev/null +++ b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp @@ -0,0 +1,68 @@ +/* + * 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" + + +namespace OHOS { + bool FuzzAddParamEntry(const uint8_t* data, size_t size) + { + if (size < 2) { + return false; + } + + size_t split_pos = size / 2; + if (split_pos == 0) { + split_pos = 1; + } + + std::unique_ptr name(new char[split_pos + 1]); + if (memcpy_s(name.get(), split_pos + 1, data, split_pos) != 0) { + return false; + } + name[split_pos] = '\0'; + + size_t value_size = size - split_pos; + std::unique_ptr value(new char[value_size + 1]); + if (memcpy_s(value.get(), value_size + 1, data + split_pos, value_size) != 0) { + return false; + } + value[value_size] = '\0'; + + uint32_t index = 0; + if (memcpy_s(&index, sizeof(uint32_t), data, sizeof(uint32_t)) != 0) { + index = 0; + } + index %= 1000; + + uint8_t type = 0; + if (size > 0) { + type = data[0] % 5; + } + + 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/addparamsecuritynode_fuzzer/addparamsecuritynode_fuzzer.cpp b/test/fuzztest/addparamsecuritynode_fuzzer/addparamsecuritynode_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e886fe8ed364c9cc932ba3a278b241a549f2da8 --- /dev/null +++ b/test/fuzztest/addparamsecuritynode_fuzzer/addparamsecuritynode_fuzzer.cpp @@ -0,0 +1,51 @@ +/* + * 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 "addparamsecuritynode_fuzzer.h" +#include +#include +#include "param_trie.h" +#include "param_manager.h" + + +namespace OHOS { + bool FuzzAddParamSecurityNode(const uint8_t* data, size_t size) + { + if (size < sizeof(ParamAuditData)) { + return false; + } + + WorkSpace *workSpace = GetWorkSpace(0); + + const ParamAuditData* auditData = reinterpret_cast(data); + size_t remainingSize = size - sizeof(ParamAuditData); + + ParamAuditData safeAuditData = *auditData; + if (safeAuditData.memberNum > 0) { + size_t requiredSize = safeAuditData.memberNum * sizeof(uid_t); + if (remainingSize < requiredSize) { + safeAuditData.memberNum = remainingSize / sizeof(uid_t); + } + } + + return (AddParamSecurityNode(workSpace, &safeAuditData) == 0); + } +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::FuzzAddParamSecurityNode(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/addparamsecuritynode_fuzzer/addparamsecuritynode_fuzzer.h b/test/fuzztest/addparamsecuritynode_fuzzer/addparamsecuritynode_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..4d39bfc744c47801e39ea2875fccf28cdd89f42e --- /dev/null +++ b/test/fuzztest/addparamsecuritynode_fuzzer/addparamsecuritynode_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_SECURITY_NODE_H +#define TEST_FUZZTEST_ADD_PARAM_SECURITY_NODE_H +#include "fuzz_utils.h" +#define FUZZ_PROJECT_NAME "addparamsecuritynode_fuzzer" +#endif \ No newline at end of file diff --git a/test/fuzztest/addparamsecuritynode_fuzzer/corpus/init b/test/fuzztest/addparamsecuritynode_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /dev/null +++ b/test/fuzztest/addparamsecuritynode_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/addparamsecuritynode_fuzzer/project.xml b/test/fuzztest/addparamsecuritynode_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..949d03efd7477905377ac79f3b0bb374c8ac2e9a --- /dev/null +++ b/test/fuzztest/addparamsecuritynode_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/addsecuritylabel_fuzzer/addsecuritylabel_fuzzer.cpp b/test/fuzztest/addsecuritylabel_fuzzer/addsecuritylabel_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..11266998d61817059c490ef95000d6d39f2d354d --- /dev/null +++ b/test/fuzztest/addsecuritylabel_fuzzer/addsecuritylabel_fuzzer.cpp @@ -0,0 +1,57 @@ +/* + * 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 "addsecuritylabel_fuzzer.h" +#include +#include +#include "param_trie.h" +#include "param_manager.h" +#include "securec.h" + + +namespace OHOS { + bool FuzzAddSecurityLabel(const uint8_t* data, size_t size) + { + if (size < sizeof(ParamAuditData) + 1) { + return false; + } + + ParamAuditData auditData = {}; + if (memcpy_s(&auditData, sizeof(ParamAuditData), data, sizeof(ParamAuditData)) != 0) { + return false; + } + + size_t name_len = size - sizeof(ParamAuditData); + std::unique_ptr name_buf(new char[name_len + 1]); + if (memcpy_s(name_buf.get(), name_len + 1, data + sizeof(ParamAuditData), name_len) != 0) { + return false; + } + name_buf[name_len] = '\0'; + auditData.name = name_buf.get(); + + auditData.dacData.uid = *data % 10000; + auditData.dacData.gid = *(data + 1) % 10000; + auditData.dacData.mode = *(data + 2) % 0777; + auditData.dacData.paramType = *(data + 3) % 10; + + return (AddSecurityLabel(&auditData) == 0); + } +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::FuzzAddSecurityLabel(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/addsecuritylabel_fuzzer/addsecuritylabel_fuzzer.h b/test/fuzztest/addsecuritylabel_fuzzer/addsecuritylabel_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..c5aa0d5ba94ea6dd6a34776febe18f0b3bb0515e --- /dev/null +++ b/test/fuzztest/addsecuritylabel_fuzzer/addsecuritylabel_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_SECURITY_LABLE_H +#define TEST_FUZZTEST_ADD_SECURITY_LABLE_H +#include "fuzz_utils.h" +#define FUZZ_PROJECT_NAME "addsecuritylabel_fuzzer" +#endif \ No newline at end of file diff --git a/test/fuzztest/addsecuritylabel_fuzzer/corpus/init b/test/fuzztest/addsecuritylabel_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /dev/null +++ b/test/fuzztest/addsecuritylabel_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/addsecuritylabel_fuzzer/project.xml b/test/fuzztest/addsecuritylabel_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a03232f21591eac33f2e0b55e2902ee4ecf49296 --- /dev/null +++ b/test/fuzztest/addsecuritylabel_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 100 + + 30 + + 2048 + + 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..076285bfb5fd9cfb9a93956350dd9b179ad8a4ae --- /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" + + +namespace OHOS { + bool FuzzInitWorkSpace(const uint8_t* data, size_t size) + { + constexpr size_t min_size = sizeof(uint32_t) * 2; + if (size < min_size) { + 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..a95c0410aeb9224b33ea25a51faffabb3081d300 --- /dev/null +++ b/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * 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 + +