From 30adce7ee3c6ecc16f9cc76b6ba1e27de949329f Mon Sep 17 00:00:00 2001 From: wangpggg Date: Thu, 28 Mar 2024 08:51:45 +0800 Subject: [PATCH] add fuzz testcases to improve cover Signed-off-by: wangpeng --- test/fuzztest/BUILD.gn | 3 + .../fileaccessserviceproxy_fuzzer/BUILD.gn | 56 ++++++++ .../fileaccessserviceproxy_fuzzer/corpus/init | 16 +++ .../fileaccessservicemock.h | 38 ++++++ .../fileaccessserviceproxy_fuzzer.cpp | 115 +++++++++++++++++ .../fileaccessserviceproxy_fuzzer.h | 21 +++ .../fileaccessserviceproxy_fuzzer/project.xml | 25 ++++ .../fileaccessservicemock.h | 10 +- .../fileinfosharedmemory_fuzzer/BUILD.gn | 44 +++++++ .../fileinfosharedmemory_fuzzer/corpus/init | 16 +++ .../fileinfosharedmemory_fuzzer.cpp | 121 ++++++++++++++++++ .../fileinfosharedmemory_fuzzer.h | 21 +++ .../fileinfosharedmemory_fuzzer/project.xml | 25 ++++ .../useraccesscommonutils_fuzzer/BUILD.gn | 39 ++++++ .../useraccesscommonutils_fuzzer/corpus/init | 16 +++ .../useraccesscommonutils_fuzzer/project.xml | 25 ++++ .../useraccesscommonutils_fuzzer.cpp | 49 +++++++ .../useraccesscommonutils_fuzzer.h | 21 +++ 18 files changed, 656 insertions(+), 5 deletions(-) create mode 100644 test/fuzztest/fileaccessserviceproxy_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fileaccessserviceproxy_fuzzer/corpus/init create mode 100644 test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessservicemock.h create mode 100644 test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.cpp create mode 100644 test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.h create mode 100644 test/fuzztest/fileaccessserviceproxy_fuzzer/project.xml create mode 100644 test/fuzztest/fileinfosharedmemory_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fileinfosharedmemory_fuzzer/corpus/init create mode 100644 test/fuzztest/fileinfosharedmemory_fuzzer/fileinfosharedmemory_fuzzer.cpp create mode 100644 test/fuzztest/fileinfosharedmemory_fuzzer/fileinfosharedmemory_fuzzer.h create mode 100644 test/fuzztest/fileinfosharedmemory_fuzzer/project.xml create mode 100644 test/fuzztest/useraccesscommonutils_fuzzer/BUILD.gn create mode 100644 test/fuzztest/useraccesscommonutils_fuzzer/corpus/init create mode 100644 test/fuzztest/useraccesscommonutils_fuzzer/project.xml create mode 100644 test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.cpp create mode 100644 test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index b3901c58..5b5753df 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -29,6 +29,9 @@ group("user_file_service_fuzz_test") { "externalfileaccessrename_fuzzer:ExternalFileAccessRenameFuzzTest", "externalfileaccessscanfile_fuzzer:ExternalFileAccessScanFileFuzzTest", "fileaccessextstub_fuzzer:FileAccessExtStubFuzzTest", + "fileaccessserviceproxy_fuzzer:FileAccessServiceProxyFuzzTest", "fileaccessservicestub_fuzzer:FileAccessServiceStubFuzzTest", + "fileinfosharedmemory_fuzzer:FileInfoSharedMemoryFuzzTest", + "useraccesscommonutils_fuzzer:UserAccessCommonUtilsFuzzTest", ] } diff --git a/test/fuzztest/fileaccessserviceproxy_fuzzer/BUILD.gn b/test/fuzztest/fileaccessserviceproxy_fuzzer/BUILD.gn new file mode 100644 index 00000000..14478a84 --- /dev/null +++ b/test/fuzztest/fileaccessserviceproxy_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/filemanagement/user_file_service/filemanagement_aafwk.gni") +ohos_fuzztest("FileAccessServiceProxyFuzzTest") { + module_out_path = "user_file_service/user_file_service" + fuzz_config_file = + "${user_file_service_path}/test/fuzztest/fileaccessserviceproxy_fuzzer" + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", + "${user_file_service_path}/interfaces/inner_api/file_access/include", + "${user_file_service_path}/services/native/file_access_service/include", + "${user_file_service_path}/interfaces/kits/js/src/common", + "${user_file_service_path}/utils", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${user_file_service_path}/services/native/file_access_service/src/file_access_service_proxy.cpp", + "${user_file_service_path}/services/native/file_access_service/src/file_access_service_stub.cpp", + "${user_file_service_path}/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.cpp", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + "safwk:system_ability_fwk", + ] + + defines = [ "private=public" ] +} diff --git a/test/fuzztest/fileaccessserviceproxy_fuzzer/corpus/init b/test/fuzztest/fileaccessserviceproxy_fuzzer/corpus/init new file mode 100644 index 00000000..6198079a --- /dev/null +++ b/test/fuzztest/fileaccessserviceproxy_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessservicemock.h b/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessservicemock.h new file mode 100644 index 00000000..363527a7 --- /dev/null +++ b/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessservicemock.h @@ -0,0 +1,38 @@ +/* + * 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 FILE_ACCESS_SERVICE_MOCK_H +#define FILE_ACCESS_SERVICE_MOCK_H + +#include "file_access_service_stub.h" + +namespace OHOS { +namespace FileAccessFwk { +class FileAccessServiceMock final : public FileAccessServiceStub { +public: + virtual ~FileAccessServiceMock() = default; + + int32_t OnChange(Uri uri, NotifyType notifyType) override { return 0; } + int32_t RegisterNotify(Uri uri, bool notifyForDescendants, const sptr &observer, + const std::shared_ptr &info) override { return 0; } + int32_t UnregisterNotify(Uri uri, const sptr &observer, + const std::shared_ptr &info) override { return 0; } + int32_t GetExensionProxy(const std::shared_ptr &info, + sptr &extensionProxy) override { return 0; } + int32_t CleanAllNotify(Uri uri, const std::shared_ptr &info) override { return 0; } +}; +} // namespace FileAccessFwk +} // namespace OHOS +#endif // FILE_ACCESS_SERVICE_MOCK_H \ No newline at end of file diff --git a/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.cpp b/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.cpp new file mode 100644 index 00000000..a2f8c00d --- /dev/null +++ b/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.cpp @@ -0,0 +1,115 @@ +/* + * 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 "fileaccessserviceproxy_fuzzer.h" + +#include +#include + +#include "file_access_service_proxy.h" +#include "fileaccessservicemock.h" +#include "iservice_registry.h" +#include "refbase.h" + +namespace OHOS { +using namespace std; +using namespace FileAccessFwk; + +SystemAbilityManagerClient& SystemAbilityManagerClient::GetInstance() +{ + static auto instance = new SystemAbilityManagerClient(); + return *instance; +} + +sptr SystemAbilityManagerClient::GetSystemAbilityManager() +{ + return nullptr; +} + +void SystemAbilityManagerClient::DestroySystemAbilityManagerObject() +{} + +template +T TypeCast(const uint8_t *data, int *pos = nullptr) +{ + if (pos) { + *pos += sizeof(T); + } + return *(reinterpret_cast(data)); +} + +bool OnChangeFuzzTest(shared_ptr proxy, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(NotifyType)) { + return true; + } + + int pos = 0; + NotifyType notifyType = TypeCast(data, &pos); + Uri uri(string(reinterpret_cast(data + pos), size - pos)); + + proxy->OnChange(uri, notifyType); + return true; +} + +bool RegisterNotifyFuzzTest(shared_ptr proxy, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(bool)) { + return true; + } + + int pos = 0; + auto info = make_shared(); + bool notifyForDescendants = TypeCast(data, &pos); + Uri uri(string(reinterpret_cast(data + pos), size - pos)); + + proxy->RegisterNotify(uri, notifyForDescendants, nullptr, info); + return true; +} + +bool UnregisterNotifyFuzzTest(shared_ptr proxy, const uint8_t *data, size_t size) +{ + auto info = make_shared(); + Uri uri(string(reinterpret_cast(data), size)); + + proxy->UnregisterNotify(uri, nullptr, info); + return true; +} + +bool GetExensionProxyFuzzTest(shared_ptr proxy, const uint8_t *data, size_t size) +{ + auto info = make_shared(); + sptr extensionProxy = nullptr; + + proxy->GetExensionProxy(info, extensionProxy); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + auto impl = std::make_unique(); + auto proxy = std::make_shared(OHOS::sptr(impl.release())); + if (proxy == nullptr || impl == nullptr) { + return 0; + } + + OHOS::OnChangeFuzzTest(proxy, data, size); + OHOS::RegisterNotifyFuzzTest(proxy, data, size); + OHOS::UnregisterNotifyFuzzTest(proxy, data, size); + OHOS::GetExensionProxyFuzzTest(proxy, data, size); + + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.h b/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.h new file mode 100644 index 00000000..4e5738aa --- /dev/null +++ b/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 FILE_ACCESS_SERVICE_PROXY_FUZZER_H +#define FILE_ACCESS_SERVICE_PROXY_FUZZER_H + +#define FUZZ_PROJECT_NAME "fileaccessserviceproxy_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fileaccessserviceproxy_fuzzer/project.xml b/test/fuzztest/fileaccessserviceproxy_fuzzer/project.xml new file mode 100644 index 00000000..d6679ccc --- /dev/null +++ b/test/fuzztest/fileaccessserviceproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fileaccessservicestub_fuzzer/fileaccessservicemock.h b/test/fuzztest/fileaccessservicestub_fuzzer/fileaccessservicemock.h index 839e7d05..363527a7 100644 --- a/test/fuzztest/fileaccessservicestub_fuzzer/fileaccessservicemock.h +++ b/test/fuzztest/fileaccessservicestub_fuzzer/fileaccessservicemock.h @@ -24,14 +24,14 @@ class FileAccessServiceMock final : public FileAccessServiceStub { public: virtual ~FileAccessServiceMock() = default; - virtual int32_t OnChange(Uri uri, NotifyType notifyType) override { return 0; } - virtual int32_t RegisterNotify(Uri uri, bool notifyForDescendants, const sptr &observer, + int32_t OnChange(Uri uri, NotifyType notifyType) override { return 0; } + int32_t RegisterNotify(Uri uri, bool notifyForDescendants, const sptr &observer, const std::shared_ptr &info) override { return 0; } - virtual int32_t UnregisterNotify(Uri uri, const sptr &observer, + int32_t UnregisterNotify(Uri uri, const sptr &observer, const std::shared_ptr &info) override { return 0; } - virtual int32_t GetExensionProxy(const std::shared_ptr &info, + int32_t GetExensionProxy(const std::shared_ptr &info, sptr &extensionProxy) override { return 0; } - virtual int32_t CleanAllNotify(Uri uri, const std::shared_ptr &info) override { return 0; } + int32_t CleanAllNotify(Uri uri, const std::shared_ptr &info) override { return 0; } }; } // namespace FileAccessFwk } // namespace OHOS diff --git a/test/fuzztest/fileinfosharedmemory_fuzzer/BUILD.gn b/test/fuzztest/fileinfosharedmemory_fuzzer/BUILD.gn new file mode 100644 index 00000000..4dc50a83 --- /dev/null +++ b/test/fuzztest/fileinfosharedmemory_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/filemanagement/user_file_service/filemanagement_aafwk.gni") +ohos_fuzztest("FileInfoSharedMemoryFuzzTest") { + module_out_path = "user_file_service/user_file_service" + fuzz_config_file = + "${user_file_service_path}/test/fuzztest/fileinfosharedmemory_fuzzer" + include_dirs = [ + "${user_file_service_path}/interfaces/inner_api/file_access/include", + "${user_file_service_path}/interfaces/kits/js/src/common", + "${user_file_service_path}/utils", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "${user_file_service_path}/test/fuzztest/fileinfosharedmemory_fuzzer/fileinfosharedmemory_fuzzer.cpp" ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] + + defines = [ "private=public" ] +} diff --git a/test/fuzztest/fileinfosharedmemory_fuzzer/corpus/init b/test/fuzztest/fileinfosharedmemory_fuzzer/corpus/init new file mode 100644 index 00000000..6198079a --- /dev/null +++ b/test/fuzztest/fileinfosharedmemory_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fileinfosharedmemory_fuzzer/fileinfosharedmemory_fuzzer.cpp b/test/fuzztest/fileinfosharedmemory_fuzzer/fileinfosharedmemory_fuzzer.cpp new file mode 100644 index 00000000..306fb6a5 --- /dev/null +++ b/test/fuzztest/fileinfosharedmemory_fuzzer/fileinfosharedmemory_fuzzer.cpp @@ -0,0 +1,121 @@ +/* + * 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 "fileinfosharedmemory_fuzzer.h" + +#include +#include + +#include "file_info_shared_memory.h" + +namespace OHOS { +using namespace std; +using namespace FileAccessFwk; + +template +T TypeCast(const uint8_t *data, int *pos = nullptr) +{ + if (pos) { + *pos += sizeof(T); + } + return *(reinterpret_cast(data)); +} + +bool MarshallingFuzzTest(shared_ptr info, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int) + sizeof(uint64_t)) { + return true; + } + + int pos = 0; + MessageParcel reply; + info->memFd = TypeCast(data, &pos); + info->memSize = TypeCast(data + pos); + info->Marshalling(reply); + + return true; +} + +bool UnmarshallingFuzzTest(shared_ptr info, const uint8_t *data, size_t size) +{ + MessageParcel reply; + info->Unmarshalling(reply); + + return true; +} + +bool CreateSharedMemoryFuzzTest(const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(uint64_t)) { + return true; + } + + int pos = 0; + uint64_t memSize = TypeCast(data, &pos); + string memName(reinterpret_cast(data + pos), size - pos); + SharedMemoryInfo memInfo; + SharedMemoryOperation::CreateSharedMemory(memName.c_str(), memSize, memInfo); + SharedMemoryOperation::DestroySharedMemory(memInfo); + + return true; +} + +bool ExpandSharedMemoryFuzzTest(const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(uint64_t)) { + return true; + } + + int pos = 0; + uint64_t memSize = TypeCast(data, &pos); + string memName(reinterpret_cast(data + pos), size - pos); + SharedMemoryInfo memInfo; + SharedMemoryOperation::CreateSharedMemory(memName.c_str(), memSize, memInfo); + SharedMemoryOperation::ExpandSharedMemory(memInfo); + SharedMemoryOperation::DestroySharedMemory(memInfo); + + return true; +} + +bool WriteFileInfosFuzzTest(const uint8_t *data, size_t size) +{ + FileInfo info; + vector fileInfoVec; + fileInfoVec.emplace_back(); + SharedMemoryInfo memInfo; + SharedMemoryOperation::WriteFileInfos(fileInfoVec, memInfo); + SharedMemoryOperation::ReadFileInfo(info, memInfo); + + return true; +} + +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + auto sharedMemoryInfo = std::make_shared(); + if (sharedMemoryInfo == nullptr) { + return 0; + } + + OHOS::MarshallingFuzzTest(sharedMemoryInfo, data, size); + OHOS::UnmarshallingFuzzTest(sharedMemoryInfo, data, size); + + OHOS::CreateSharedMemoryFuzzTest(data, size); + OHOS::ExpandSharedMemoryFuzzTest(data, size); + OHOS::WriteFileInfosFuzzTest(data, size); + + return 0; +} diff --git a/test/fuzztest/fileinfosharedmemory_fuzzer/fileinfosharedmemory_fuzzer.h b/test/fuzztest/fileinfosharedmemory_fuzzer/fileinfosharedmemory_fuzzer.h new file mode 100644 index 00000000..cce31f54 --- /dev/null +++ b/test/fuzztest/fileinfosharedmemory_fuzzer/fileinfosharedmemory_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 FILE_INFO_SHARED_MEMORY_FUZZER_H +#define FILE_INFO_SHARED_MEMORY_FUZZER_H + +#define FUZZ_PROJECT_NAME "fileinfosharedmemory_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fileinfosharedmemory_fuzzer/project.xml b/test/fuzztest/fileinfosharedmemory_fuzzer/project.xml new file mode 100644 index 00000000..d6679ccc --- /dev/null +++ b/test/fuzztest/fileinfosharedmemory_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/useraccesscommonutils_fuzzer/BUILD.gn b/test/fuzztest/useraccesscommonutils_fuzzer/BUILD.gn new file mode 100644 index 00000000..9e7679bd --- /dev/null +++ b/test/fuzztest/useraccesscommonutils_fuzzer/BUILD.gn @@ -0,0 +1,39 @@ +# 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/filemanagement/user_file_service/filemanagement_aafwk.gni") +ohos_fuzztest("UserAccessCommonUtilsFuzzTest") { + module_out_path = "user_file_service/user_file_service" + fuzz_config_file = + "${user_file_service_path}/test/fuzztest/useraccesscommonutils_fuzzer" + include_dirs = [ "${user_file_service_path}/utils" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "${user_file_service_path}/test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.cpp" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "init:libbegetutil", + "os_account:os_account_innerkits", + ] + + defines = [ "private=public" ] +} diff --git a/test/fuzztest/useraccesscommonutils_fuzzer/corpus/init b/test/fuzztest/useraccesscommonutils_fuzzer/corpus/init new file mode 100644 index 00000000..6198079a --- /dev/null +++ b/test/fuzztest/useraccesscommonutils_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/useraccesscommonutils_fuzzer/project.xml b/test/fuzztest/useraccesscommonutils_fuzzer/project.xml new file mode 100644 index 00000000..d6679ccc --- /dev/null +++ b/test/fuzztest/useraccesscommonutils_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.cpp b/test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.cpp new file mode 100644 index 00000000..9aa5e94c --- /dev/null +++ b/test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * 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 "useraccesscommonutils_fuzzer.h" + +#include + +#include "hilog_wrapper.h" +#include "user_access_common_utils.h" + +namespace OHOS { +using namespace std; +using namespace FileAccessFwk; + +bool GetDeviceTypeFuzzTest(const uint8_t *data, size_t size) +{ + string deviceType; + GetDeviceType(deviceType); + return true; +} + +bool GetUserNameFuzzTest(const uint8_t *data, size_t size) +{ + string userName; + GetUserName(userName); + return true; +} + +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::GetDeviceTypeFuzzTest(data, size); + OHOS::GetUserNameFuzzTest(data, size); + + return 0; +} diff --git a/test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.h b/test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.h new file mode 100644 index 00000000..8f57ce37 --- /dev/null +++ b/test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 USER_ACCESS_COMMON_UTILS_FUZZER_H +#define USER_ACCESS_COMMON_UTILS_FUZZER_H + +#define FUZZ_PROJECT_NAME "useraccesscommonutils_fuzzer" + +#endif \ No newline at end of file