diff --git a/test/fuzztest/externalfileaccess_fuzzer/external_file_access_fuzzer.cpp b/test/fuzztest/externalfileaccess_fuzzer/external_file_access_fuzzer.cpp index 8df82c5b..9c185dff 100644 --- a/test/fuzztest/externalfileaccess_fuzzer/external_file_access_fuzzer.cpp +++ b/test/fuzztest/externalfileaccess_fuzzer/external_file_access_fuzzer.cpp @@ -228,7 +228,8 @@ bool MkdirFuzzTest(const uint8_t* data, size_t size) for (size_t i = 0; i < info.size(); i++) { Uri parentUri(info[i].uri); Uri newDirUri(""); - result = helper->Mkdir(parentUri, "MkdirFuzzTest", newDirUri); + std::string dirName(reinterpret_cast(data), size); + result = helper->Mkdir(parentUri, dirName, newDirUri); if (result != OHOS::FileAccessFwk::ERR_OK) { HILOG_ERROR("Mkdir failed. ret : %{public}d", result); return false; @@ -272,14 +273,18 @@ bool MoveFuzzTest(const uint8_t* data, size_t size) Uri parentUri(info[i].uri); Uri newDirUriTest1(""); Uri newDirUriTest2(""); - int result1 = helper->Mkdir(parentUri, "test1", newDirUriTest1); - int result2 = helper->Mkdir(parentUri, "test2", newDirUriTest2); + size_t len = size >> 2; + std::string test1(reinterpret_cast(data), len); + std::string test2(reinterpret_cast(data + len), len); + int result1 = helper->Mkdir(parentUri, test1, newDirUriTest1); + int result2 = helper->Mkdir(parentUri, test2, newDirUriTest2); if (result1 != OHOS::FileAccessFwk::ERR_OK || result2 != OHOS::FileAccessFwk::ERR_OK) { HILOG_ERROR("Mkdir failed. ret : %{public}d, %{public}d", result1, result2); return false; } Uri testUri(""); - result = helper->CreateFile(newDirUriTest1, "test.txt", testUri); + std::string test(reinterpret_cast(data + len + len), len); + result = helper->CreateFile(newDirUriTest1, test, testUri); if (result != OHOS::FileAccessFwk::ERR_OK) { HILOG_ERROR("CreateFile failed. ret : %{public}d", result); return false; @@ -321,7 +326,8 @@ bool RenameFuzzTest(const uint8_t* data, size_t size) return false; } Uri renameUri(""); - result = helper->Rename(newDirUriTest, "testRename", renameUri); + std::string testRename(reinterpret_cast(data), size); + result = helper->Rename(newDirUriTest, testRename, renameUri); if (result != OHOS::FileAccessFwk::ERR_OK) { HILOG_ERROR("Rename failed. ret : %{public}d", result); return false; diff --git a/test/fuzztest/externalfileaccessaccess_fuzzer/externalfileaccessaccess_fuzzer.cpp b/test/fuzztest/externalfileaccessaccess_fuzzer/externalfileaccessaccess_fuzzer.cpp index 401cb1f4..8ad9d3ea 100644 --- a/test/fuzztest/externalfileaccessaccess_fuzzer/externalfileaccessaccess_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessaccess_fuzzer/externalfileaccessaccess_fuzzer.cpp @@ -37,13 +37,6 @@ using namespace std; using namespace OHOS; using namespace FileAccessFwk; using namespace AbilityRuntime; -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; - - -enum { - TOKEN_INDEX_ONE = 0, -}; void SetNativeToken() { @@ -71,14 +64,14 @@ void SetNativeToken() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } -bool ExternalFileAccessAccessFuzzTest(std::unique_ptr data, size_t size) +bool ExternalFileAccessAccessFuzzTest(const uint8_t *data, size_t size) { SetNativeToken(); // CMD_ACCESS uint32_t code = 14; MessageParcel datas; datas.WriteInterfaceToken(FileAccessExtStub::GetDescriptor()); - datas.WriteBuffer(data.get(), size); + datas.WriteBuffer(reinterpret_cast(data), size); datas.RewindRead(0); MessageParcel reply; MessageOption option; @@ -103,22 +96,6 @@ bool ExternalFileAccessAccessFuzzTest(std::unique_ptr data, size_t size) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { - return 0; - } - - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } - - OHOS::ExternalFileAccessAccessFuzzTest(move(str), size); + OHOS::ExternalFileAccessAccessFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/externalfileaccesscreatefile_fuzzer/externalfileaccesscreatefile_fuzzer.cpp b/test/fuzztest/externalfileaccesscreatefile_fuzzer/externalfileaccesscreatefile_fuzzer.cpp index 52a2ccaf..a030472f 100644 --- a/test/fuzztest/externalfileaccesscreatefile_fuzzer/externalfileaccesscreatefile_fuzzer.cpp +++ b/test/fuzztest/externalfileaccesscreatefile_fuzzer/externalfileaccesscreatefile_fuzzer.cpp @@ -37,13 +37,6 @@ using namespace std; using namespace OHOS; using namespace FileAccessFwk; using namespace AbilityRuntime; -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; - - -enum { - TOKEN_INDEX_ONE = 0, -}; void SetNativeToken() { @@ -71,14 +64,14 @@ void SetNativeToken() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } -bool ExternalFileAccessCreateFileFuzzTest(std::unique_ptr data, size_t size) +bool ExternalFileAccessCreateFileFuzzTest(const uint8_t *data, size_t size) { SetNativeToken(); // CMD_CREATEILE uint32_t code = 2; MessageParcel datas; datas.WriteInterfaceToken(FileAccessExtStub::GetDescriptor()); - datas.WriteBuffer(data.get(), size); + datas.WriteBuffer(reinterpret_cast(data), size); datas.RewindRead(0); MessageParcel reply; MessageOption option; @@ -103,22 +96,6 @@ bool ExternalFileAccessCreateFileFuzzTest(std::unique_ptr data, size_t s /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { - return 0; - } - - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } - - OHOS::ExternalFileAccessCreateFileFuzzTest(move(str), size); + OHOS::ExternalFileAccessCreateFileFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/externalfileaccessdelete_fuzzer/externalfileaccessdelete_fuzzer.cpp b/test/fuzztest/externalfileaccessdelete_fuzzer/externalfileaccessdelete_fuzzer.cpp index 845ed29a..4cd6f7f6 100644 --- a/test/fuzztest/externalfileaccessdelete_fuzzer/externalfileaccessdelete_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessdelete_fuzzer/externalfileaccessdelete_fuzzer.cpp @@ -37,13 +37,6 @@ using namespace std; using namespace OHOS; using namespace FileAccessFwk; using namespace AbilityRuntime; -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; - - -enum { - TOKEN_INDEX_ONE = 0, -}; void SetNativeToken() { @@ -71,14 +64,14 @@ void SetNativeToken() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } -bool ExternalFileAccessDeleteFuzzTest(std::unique_ptr data, size_t size) +bool ExternalFileAccessDeleteFuzzTest(const uint8_t *data, size_t size) { SetNativeToken(); // CMD_DELETE uint32_t code = 4; MessageParcel datas; datas.WriteInterfaceToken(FileAccessExtStub::GetDescriptor()); - datas.WriteBuffer(data.get(), size); + datas.WriteBuffer(reinterpret_cast(data), size); datas.RewindRead(0); MessageParcel reply; MessageOption option; @@ -103,22 +96,6 @@ bool ExternalFileAccessDeleteFuzzTest(std::unique_ptr data, size_t size) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { - return 0; - } - - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } - - OHOS::ExternalFileAccessDeleteFuzzTest(move(str), size); + OHOS::ExternalFileAccessDeleteFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/externalfileaccessgetfileinfofromrelativepath_fuzzer/externalfileaccessgetfileinfofromrelativepath_fuzzer.cpp b/test/fuzztest/externalfileaccessgetfileinfofromrelativepath_fuzzer/externalfileaccessgetfileinfofromrelativepath_fuzzer.cpp index e788cc2a..59180c72 100644 --- a/test/fuzztest/externalfileaccessgetfileinfofromrelativepath_fuzzer/externalfileaccessgetfileinfofromrelativepath_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessgetfileinfofromrelativepath_fuzzer/externalfileaccessgetfileinfofromrelativepath_fuzzer.cpp @@ -37,13 +37,6 @@ using namespace std; using namespace OHOS; using namespace FileAccessFwk; using namespace AbilityRuntime; -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; - - -enum { - TOKEN_INDEX_ONE = 0, -}; void SetNativeToken() { @@ -71,14 +64,14 @@ void SetNativeToken() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } -bool ExternalFileAccessGetFileInfoFromRelativePathFuzzTest(std::unique_ptr data, size_t size) +bool ExternalFileAccessGetFileInfoFromRelativePathFuzzTest(const uint8_t *data, size_t size) { SetNativeToken(); // CMD_GET_FILEINFO_FROM_RELATIVE_PATH uint32_t code = 17; MessageParcel datas; datas.WriteInterfaceToken(FileAccessExtStub::GetDescriptor()); - datas.WriteBuffer(data.get(), size); + datas.WriteBuffer(reinterpret_cast(data), size); datas.RewindRead(0); MessageParcel reply; MessageOption option; @@ -103,22 +96,6 @@ bool ExternalFileAccessGetFileInfoFromRelativePathFuzzTest(std::unique_ptr OHOS::FOO_MAX_LEN) { - return 0; - } - - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } - - OHOS::ExternalFileAccessGetFileInfoFromRelativePathFuzzTest(move(str), size); + OHOS::ExternalFileAccessGetFileInfoFromRelativePathFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/externalfileaccessgetfileinfofromuri_fuzzer/externalfileaccessgetfileinfofromuri_fuzzer.cpp b/test/fuzztest/externalfileaccessgetfileinfofromuri_fuzzer/externalfileaccessgetfileinfofromuri_fuzzer.cpp index b7182894..4a5142d3 100644 --- a/test/fuzztest/externalfileaccessgetfileinfofromuri_fuzzer/externalfileaccessgetfileinfofromuri_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessgetfileinfofromuri_fuzzer/externalfileaccessgetfileinfofromuri_fuzzer.cpp @@ -37,13 +37,6 @@ using namespace std; using namespace OHOS; using namespace FileAccessFwk; using namespace AbilityRuntime; -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; - - -enum { - TOKEN_INDEX_ONE = 0, -}; void SetNativeToken() { @@ -71,14 +64,14 @@ void SetNativeToken() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } -bool ExternalFileAccessGetFileInfoFromUriFuzzTest(std::unique_ptr data, size_t size) +bool ExternalFileAccessGetFileInfoFromUriFuzzTest(const uint8_t *data, size_t size) { SetNativeToken(); // CMD_GET_FILEINFO_FROM_URI uint32_t code = 16; MessageParcel datas; datas.WriteInterfaceToken(FileAccessExtStub::GetDescriptor()); - datas.WriteBuffer(data.get(), size); + datas.WriteBuffer(reinterpret_cast(data), size); datas.RewindRead(0); MessageParcel reply; MessageOption option; @@ -103,22 +96,6 @@ bool ExternalFileAccessGetFileInfoFromUriFuzzTest(std::unique_ptr data, /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { - return 0; - } - - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } - - OHOS::ExternalFileAccessGetFileInfoFromUriFuzzTest(move(str), size); + OHOS::ExternalFileAccessGetFileInfoFromUriFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/externalfileaccessgetroots_fuzzer/externalfileaccessgetroots_fuzzer.cpp b/test/fuzztest/externalfileaccessgetroots_fuzzer/externalfileaccessgetroots_fuzzer.cpp index dd6855b8..028d42ea 100644 --- a/test/fuzztest/externalfileaccessgetroots_fuzzer/externalfileaccessgetroots_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessgetroots_fuzzer/externalfileaccessgetroots_fuzzer.cpp @@ -37,13 +37,6 @@ using namespace std; using namespace OHOS; using namespace FileAccessFwk; using namespace AbilityRuntime; -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; - - -enum { - TOKEN_INDEX_ONE = 0, -}; void SetNativeToken() { @@ -71,14 +64,14 @@ void SetNativeToken() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } -bool ExternalFileAccessGetRootsFuzzTest(std::unique_ptr data, size_t size) +bool ExternalFileAccessGetRootsFuzzTest(const uint8_t *data, size_t size) { SetNativeToken(); // CMD_GET_ROOTS uint32_t code = 13; MessageParcel datas; datas.WriteInterfaceToken(FileAccessExtStub::GetDescriptor()); - datas.WriteBuffer(data.get(), size); + datas.WriteBuffer(reinterpret_cast(data), size); datas.RewindRead(0); MessageParcel reply; MessageOption option; @@ -103,22 +96,6 @@ bool ExternalFileAccessGetRootsFuzzTest(std::unique_ptr data, size_t siz /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { - return 0; - } - - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } - - OHOS::ExternalFileAccessGetRootsFuzzTest(move(str), size); + OHOS::ExternalFileAccessGetRootsFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/externalfileaccesslistfile_fuzzer/externalfileaccesslistfile_fuzzer.cpp b/test/fuzztest/externalfileaccesslistfile_fuzzer/externalfileaccesslistfile_fuzzer.cpp index 54b82d4e..3d60598a 100644 --- a/test/fuzztest/externalfileaccesslistfile_fuzzer/externalfileaccesslistfile_fuzzer.cpp +++ b/test/fuzztest/externalfileaccesslistfile_fuzzer/externalfileaccesslistfile_fuzzer.cpp @@ -37,13 +37,6 @@ using namespace std; using namespace OHOS; using namespace FileAccessFwk; using namespace AbilityRuntime; -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; - - -enum { - TOKEN_INDEX_ONE = 0, -}; void SetNativeToken() { @@ -71,14 +64,14 @@ void SetNativeToken() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } -bool ExternalFileAccessListFileFuzzTest(std::unique_ptr data, size_t size) +bool ExternalFileAccessListFileFuzzTest(const uint8_t *data, size_t size) { SetNativeToken(); // CMD_LISTFILE uint32_t code = 8; MessageParcel datas; datas.WriteInterfaceToken(FileAccessExtStub::GetDescriptor()); - datas.WriteBuffer(data.get(), size); + datas.WriteBuffer(reinterpret_cast(data), size); datas.RewindRead(0); MessageParcel reply; MessageOption option; @@ -103,22 +96,6 @@ bool ExternalFileAccessListFileFuzzTest(std::unique_ptr data, size_t siz /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { - return 0; - } - - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } - - OHOS::ExternalFileAccessListFileFuzzTest(move(str), size); + OHOS::ExternalFileAccessListFileFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/externalfileaccessmkdir_fuzzer/externalfileaccessmkdir_fuzzer.cpp b/test/fuzztest/externalfileaccessmkdir_fuzzer/externalfileaccessmkdir_fuzzer.cpp index a3655318..ce001e69 100644 --- a/test/fuzztest/externalfileaccessmkdir_fuzzer/externalfileaccessmkdir_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessmkdir_fuzzer/externalfileaccessmkdir_fuzzer.cpp @@ -37,13 +37,6 @@ using namespace std; using namespace OHOS; using namespace FileAccessFwk; using namespace AbilityRuntime; -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; - - -enum { - TOKEN_INDEX_ONE = 0, -}; void SetNativeToken() { @@ -71,14 +64,14 @@ void SetNativeToken() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } -bool ExternalFileAccessMkdirFuzzTest(std::unique_ptr data, size_t size) +bool ExternalFileAccessMkdirFuzzTest(const uint8_t *data, size_t size) { SetNativeToken(); // CMD_MKDIR uint32_t code = 3; MessageParcel datas; datas.WriteInterfaceToken(FileAccessExtStub::GetDescriptor()); - datas.WriteBuffer(data.get(), size); + datas.WriteBuffer(reinterpret_cast(data), size); datas.RewindRead(0); MessageParcel reply; MessageOption option; @@ -103,22 +96,6 @@ bool ExternalFileAccessMkdirFuzzTest(std::unique_ptr data, size_t size) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { - return 0; - } - - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } - - OHOS::ExternalFileAccessMkdirFuzzTest(move(str), size); + OHOS::ExternalFileAccessMkdirFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/externalfileaccessmove_fuzzer/externalfileaccessmove_fuzzer.cpp b/test/fuzztest/externalfileaccessmove_fuzzer/externalfileaccessmove_fuzzer.cpp index 4803ca79..e52e990e 100644 --- a/test/fuzztest/externalfileaccessmove_fuzzer/externalfileaccessmove_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessmove_fuzzer/externalfileaccessmove_fuzzer.cpp @@ -37,13 +37,6 @@ using namespace std; using namespace OHOS; using namespace FileAccessFwk; using namespace AbilityRuntime; -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; - - -enum { - TOKEN_INDEX_ONE = 0, -}; void SetNativeToken() { @@ -71,14 +64,14 @@ void SetNativeToken() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } -bool ExternalFileAccessMoveFuzzTest(std::unique_ptr data, size_t size) +bool ExternalFileAccessMoveFuzzTest(const uint8_t *data, size_t size) { SetNativeToken(); // CMD_MOVE uint32_t code = 5; MessageParcel datas; datas.WriteInterfaceToken(FileAccessExtStub::GetDescriptor()); - datas.WriteBuffer(data.get(), size); + datas.WriteBuffer(reinterpret_cast(data), size); datas.RewindRead(0); MessageParcel reply; MessageOption option; @@ -103,22 +96,6 @@ bool ExternalFileAccessMoveFuzzTest(std::unique_ptr data, size_t size) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { - return 0; - } - - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } - - OHOS::ExternalFileAccessMoveFuzzTest(move(str), size); + OHOS::ExternalFileAccessMoveFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/externalfileaccessopenfile_fuzzer/externalfileaccessopenfile_fuzzer.cpp b/test/fuzztest/externalfileaccessopenfile_fuzzer/externalfileaccessopenfile_fuzzer.cpp index 2b0b82ad..7065efb5 100644 --- a/test/fuzztest/externalfileaccessopenfile_fuzzer/externalfileaccessopenfile_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessopenfile_fuzzer/externalfileaccessopenfile_fuzzer.cpp @@ -37,13 +37,6 @@ using namespace std; using namespace OHOS; using namespace FileAccessFwk; using namespace AbilityRuntime; -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; - - -enum { - TOKEN_INDEX_ONE = 0, -}; void SetNativeToken() { @@ -71,14 +64,14 @@ void SetNativeToken() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } -bool ExternalFileAccessOpenFileFuzzTest(std::unique_ptr data, size_t size) +bool ExternalFileAccessOpenFileFuzzTest(const uint8_t *data, size_t size) { SetNativeToken(); // CMD_OPENFILE uint32_t code = 1; MessageParcel datas; datas.WriteInterfaceToken(FileAccessExtStub::GetDescriptor()); - datas.WriteBuffer(data.get(), size); + datas.WriteBuffer(reinterpret_cast(data), size); datas.RewindRead(0); MessageParcel reply; MessageOption option; @@ -103,22 +96,6 @@ bool ExternalFileAccessOpenFileFuzzTest(std::unique_ptr data, size_t siz /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { - return 0; - } - - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } - - OHOS::ExternalFileAccessOpenFileFuzzTest(move(str), size); + OHOS::ExternalFileAccessOpenFileFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/externalfileaccessrename_fuzzer/externalfileaccessrename_fuzzer.cpp b/test/fuzztest/externalfileaccessrename_fuzzer/externalfileaccessrename_fuzzer.cpp index c72424bf..5b7489ca 100644 --- a/test/fuzztest/externalfileaccessrename_fuzzer/externalfileaccessrename_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessrename_fuzzer/externalfileaccessrename_fuzzer.cpp @@ -37,13 +37,6 @@ using namespace std; using namespace OHOS; using namespace FileAccessFwk; using namespace AbilityRuntime; -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; - - -enum { - TOKEN_INDEX_ONE = 0, -}; void SetNativeToken() { @@ -71,14 +64,14 @@ void SetNativeToken() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } -bool ExternalFileAccessRenameFuzzTest(std::unique_ptr data, size_t size) +bool ExternalFileAccessRenameFuzzTest(const uint8_t *data, size_t size) { SetNativeToken(); // CMD_RENAME uint32_t code = 7; MessageParcel datas; datas.WriteInterfaceToken(FileAccessExtStub::GetDescriptor()); - datas.WriteBuffer(data.get(), size); + datas.WriteBuffer(reinterpret_cast(data), size); datas.RewindRead(0); MessageParcel reply; MessageOption option; @@ -103,22 +96,6 @@ bool ExternalFileAccessRenameFuzzTest(std::unique_ptr data, size_t size) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { - return 0; - } - - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } - - OHOS::ExternalFileAccessRenameFuzzTest(move(str), size); + OHOS::ExternalFileAccessRenameFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/externalfileaccessscanfile_fuzzer/externalfileaccessscanfile_fuzzer.cpp b/test/fuzztest/externalfileaccessscanfile_fuzzer/externalfileaccessscanfile_fuzzer.cpp index d5724785..b9954568 100644 --- a/test/fuzztest/externalfileaccessscanfile_fuzzer/externalfileaccessscanfile_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessscanfile_fuzzer/externalfileaccessscanfile_fuzzer.cpp @@ -37,13 +37,6 @@ using namespace std; using namespace OHOS; using namespace FileAccessFwk; using namespace AbilityRuntime; -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; - - -enum { - TOKEN_INDEX_ONE = 0, -}; void SetNativeToken() { @@ -71,14 +64,14 @@ void SetNativeToken() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } -bool ExternalFileAccessScanFileFuzzTest(std::unique_ptr data, size_t size) +bool ExternalFileAccessScanFileFuzzTest(const uint8_t *data, size_t size) { SetNativeToken(); // CMD_SCANFILE uint32_t code = 9; MessageParcel datas; datas.WriteInterfaceToken(FileAccessExtStub::GetDescriptor()); - datas.WriteBuffer(data.get(), size); + datas.WriteBuffer(reinterpret_cast(data), size); datas.RewindRead(0); MessageParcel reply; MessageOption option; @@ -103,22 +96,6 @@ bool ExternalFileAccessScanFileFuzzTest(std::unique_ptr data, size_t siz /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { - return 0; - } - - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } - - OHOS::ExternalFileAccessScanFileFuzzTest(move(str), size); + OHOS::ExternalFileAccessScanFileFuzzTest(data, size); return 0; } diff --git a/test/unittest/external_notify_test.cpp b/test/unittest/external_notify_test.cpp index b8893980..1579d2d0 100644 --- a/test/unittest/external_notify_test.cpp +++ b/test/unittest/external_notify_test.cpp @@ -1125,8 +1125,6 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0017, testing::ext Uri fileUri(""); result = g_fah->CreateFile(newFileDir1, "uri_file", fileUri); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); - usleep(SLEEP_TIME / 10); - EXPECT_NE(g_notifyEvent, ADD_EVENT); usleep(SLEEP_TIME); EXPECT_EQ(g_notifyEvent, ADD_EVENT);