mirror of
https://gitee.com/openharmony/filemanagement_user_file_service
synced 2024-11-23 15:29:42 +00:00
!810 add fuzz testcases to improve cover
Merge pull request !810 from wangpggg/master
This commit is contained in:
commit
450fb37b2d
@ -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",
|
||||
]
|
||||
}
|
||||
|
56
test/fuzztest/fileaccessserviceproxy_fuzzer/BUILD.gn
Normal file
56
test/fuzztest/fileaccessserviceproxy_fuzzer/BUILD.gn
Normal file
@ -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" ]
|
||||
}
|
16
test/fuzztest/fileaccessserviceproxy_fuzzer/corpus/init
Normal file
16
test/fuzztest/fileaccessserviceproxy_fuzzer/corpus/init
Normal file
@ -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
|
@ -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<IFileAccessObserver> &observer,
|
||||
const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
|
||||
int32_t UnregisterNotify(Uri uri, const sptr<IFileAccessObserver> &observer,
|
||||
const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
|
||||
int32_t GetExensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
|
||||
sptr<IFileAccessExtBase> &extensionProxy) override { return 0; }
|
||||
int32_t CleanAllNotify(Uri uri, const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
|
||||
};
|
||||
} // namespace FileAccessFwk
|
||||
} // namespace OHOS
|
||||
#endif // FILE_ACCESS_SERVICE_MOCK_H
|
@ -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 <cstring>
|
||||
#include <memory>
|
||||
|
||||
#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<ISystemAbilityManager> SystemAbilityManagerClient::GetSystemAbilityManager()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SystemAbilityManagerClient::DestroySystemAbilityManagerObject()
|
||||
{}
|
||||
|
||||
template<class T>
|
||||
T TypeCast(const uint8_t *data, int *pos = nullptr)
|
||||
{
|
||||
if (pos) {
|
||||
*pos += sizeof(T);
|
||||
}
|
||||
return *(reinterpret_cast<const T*>(data));
|
||||
}
|
||||
|
||||
bool OnChangeFuzzTest(shared_ptr<FileAccessServiceProxy> proxy, const uint8_t *data, size_t size)
|
||||
{
|
||||
if (data == nullptr || size < sizeof(NotifyType)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int pos = 0;
|
||||
NotifyType notifyType = TypeCast<NotifyType>(data, &pos);
|
||||
Uri uri(string(reinterpret_cast<const char*>(data + pos), size - pos));
|
||||
|
||||
proxy->OnChange(uri, notifyType);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegisterNotifyFuzzTest(shared_ptr<FileAccessServiceProxy> proxy, const uint8_t *data, size_t size)
|
||||
{
|
||||
if (data == nullptr || size < sizeof(bool)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int pos = 0;
|
||||
auto info = make_shared<ConnectExtensionInfo>();
|
||||
bool notifyForDescendants = TypeCast<bool>(data, &pos);
|
||||
Uri uri(string(reinterpret_cast<const char*>(data + pos), size - pos));
|
||||
|
||||
proxy->RegisterNotify(uri, notifyForDescendants, nullptr, info);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnregisterNotifyFuzzTest(shared_ptr<FileAccessServiceProxy> proxy, const uint8_t *data, size_t size)
|
||||
{
|
||||
auto info = make_shared<ConnectExtensionInfo>();
|
||||
Uri uri(string(reinterpret_cast<const char*>(data), size));
|
||||
|
||||
proxy->UnregisterNotify(uri, nullptr, info);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetExensionProxyFuzzTest(shared_ptr<FileAccessServiceProxy> proxy, const uint8_t *data, size_t size)
|
||||
{
|
||||
auto info = make_shared<ConnectExtensionInfo>();
|
||||
sptr<IFileAccessExtBase> 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<OHOS::FileAccessFwk::FileAccessServiceMock>();
|
||||
auto proxy = std::make_shared<OHOS::FileAccessFwk::FileAccessServiceProxy>(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;
|
||||
}
|
@ -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
|
25
test/fuzztest/fileaccessserviceproxy_fuzzer/project.xml
Normal file
25
test/fuzztest/fileaccessserviceproxy_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
@ -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<IFileAccessObserver> &observer,
|
||||
int32_t OnChange(Uri uri, NotifyType notifyType) override { return 0; }
|
||||
int32_t RegisterNotify(Uri uri, bool notifyForDescendants, const sptr<IFileAccessObserver> &observer,
|
||||
const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
|
||||
virtual int32_t UnregisterNotify(Uri uri, const sptr<IFileAccessObserver> &observer,
|
||||
int32_t UnregisterNotify(Uri uri, const sptr<IFileAccessObserver> &observer,
|
||||
const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
|
||||
virtual int32_t GetExensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
|
||||
int32_t GetExensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
|
||||
sptr<IFileAccessExtBase> &extensionProxy) override { return 0; }
|
||||
virtual int32_t CleanAllNotify(Uri uri, const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
|
||||
int32_t CleanAllNotify(Uri uri, const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
|
||||
};
|
||||
} // namespace FileAccessFwk
|
||||
} // namespace OHOS
|
||||
|
44
test/fuzztest/fileinfosharedmemory_fuzzer/BUILD.gn
Normal file
44
test/fuzztest/fileinfosharedmemory_fuzzer/BUILD.gn
Normal file
@ -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" ]
|
||||
}
|
16
test/fuzztest/fileinfosharedmemory_fuzzer/corpus/init
Normal file
16
test/fuzztest/fileinfosharedmemory_fuzzer/corpus/init
Normal file
@ -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
|
@ -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 <cstring>
|
||||
#include <memory>
|
||||
|
||||
#include "file_info_shared_memory.h"
|
||||
|
||||
namespace OHOS {
|
||||
using namespace std;
|
||||
using namespace FileAccessFwk;
|
||||
|
||||
template<class T>
|
||||
T TypeCast(const uint8_t *data, int *pos = nullptr)
|
||||
{
|
||||
if (pos) {
|
||||
*pos += sizeof(T);
|
||||
}
|
||||
return *(reinterpret_cast<const T*>(data));
|
||||
}
|
||||
|
||||
bool MarshallingFuzzTest(shared_ptr<SharedMemoryInfo> 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<int>(data, &pos);
|
||||
info->memSize = TypeCast<uint64_t>(data + pos);
|
||||
info->Marshalling(reply);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnmarshallingFuzzTest(shared_ptr<SharedMemoryInfo> 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<uint64_t>(data, &pos);
|
||||
string memName(reinterpret_cast<const char*>(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<uint64_t>(data, &pos);
|
||||
string memName(reinterpret_cast<const char*>(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<FileInfo> 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<OHOS::FileAccessFwk::SharedMemoryInfo>();
|
||||
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;
|
||||
}
|
@ -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
|
25
test/fuzztest/fileinfosharedmemory_fuzzer/project.xml
Normal file
25
test/fuzztest/fileinfosharedmemory_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
39
test/fuzztest/useraccesscommonutils_fuzzer/BUILD.gn
Normal file
39
test/fuzztest/useraccesscommonutils_fuzzer/BUILD.gn
Normal file
@ -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" ]
|
||||
}
|
16
test/fuzztest/useraccesscommonutils_fuzzer/corpus/init
Normal file
16
test/fuzztest/useraccesscommonutils_fuzzer/corpus/init
Normal file
@ -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
|
25
test/fuzztest/useraccesscommonutils_fuzzer/project.xml
Normal file
25
test/fuzztest/useraccesscommonutils_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
@ -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 <cstring>
|
||||
|
||||
#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;
|
||||
}
|
@ -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
|
Loading…
Reference in New Issue
Block a user