!965 modify fuzz

Merge pull request !965 from wangpggg/master
This commit is contained in:
openharmony_ci 2024-11-23 07:14:42 +00:00 committed by Gitee
commit 9d17a0216d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 48 additions and 13 deletions

View File

@ -14,7 +14,7 @@
*/
#include "fileaccessextconnection_fuzzer.h"
#include <cstring>
#include <string>
#include <memory>
#include "hilog_wrapper.h"
@ -24,17 +24,21 @@ namespace OHOS {
using namespace std;
using namespace FileAccessFwk;
bool OnAbilityConnectDoneFuzzTest(sptr<FileAccessExtConnection> conn)
bool OnAbilityConnectDoneFuzzTest(sptr<FileAccessExtConnection> conn, const uint8_t *data, size_t size)
{
AppExecFwk::ElementName element;
std::string name(reinterpret_cast<const char*>(data), size);
element.SetBundleName(name);
sptr<IRemoteObject> remoteObject = nullptr;
conn->OnAbilityConnectDone(element, remoteObject, 0);
return true;
}
bool OnAbilityDisconnectDoneFuzzTest(sptr<FileAccessExtConnection> conn)
bool OnAbilityDisconnectDoneFuzzTest(sptr<FileAccessExtConnection> conn, const uint8_t *data, size_t size)
{
AppExecFwk::ElementName element;
std::string name(reinterpret_cast<const char*>(data), size);
element.SetBundleName(name);
conn->OnAbilityDisconnectDone(element, 0);
return true;
}
@ -51,9 +55,12 @@ bool GetFileExtProxyFuzzTest(sptr<FileAccessExtConnection> conn)
return true;
}
bool ConnectFileExtAbility(sptr<FileAccessExtConnection> conn)
bool ConnectFileExtAbility(sptr<FileAccessExtConnection> conn, const uint8_t *data, size_t size)
{
int len = size >> 1;
AAFwk::Want want;
want.SetElementName(std::string(reinterpret_cast<const char*>(data), len),
std::string(reinterpret_cast<const char*>(data + len), size - len));
sptr<IRemoteObject> remoteObject = nullptr;
conn->ConnectFileExtAbility(want, remoteObject);
return true;
@ -74,11 +81,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
return 0;
}
OHOS::OnAbilityConnectDoneFuzzTest(conn);
OHOS::OnAbilityDisconnectDoneFuzzTest(conn);
OHOS::OnAbilityConnectDoneFuzzTest(conn, data, size);
OHOS::OnAbilityDisconnectDoneFuzzTest(conn, data, size);
OHOS::IsExtAbilityConnectedFuzzTest(conn);
OHOS::GetFileExtProxyFuzzTest(conn);
OHOS::ConnectFileExtAbility(conn);
OHOS::ConnectFileExtAbility(conn, data, size);
OHOS::DisconnectFileExtAbility(conn);
return 0;

View File

@ -89,7 +89,11 @@ bool UnregisterNotifyFuzzTest(shared_ptr<FileAccessServiceProxy> proxy, const ui
bool GetExensionProxyFuzzTest(shared_ptr<FileAccessServiceProxy> proxy, const uint8_t *data, size_t size)
{
auto info = make_shared<ConnectExtensionInfo>();
int len = size >> 1;
AAFwk::Want want;
want.SetElementName(std::string(reinterpret_cast<const char*>(data), len),
std::string(reinterpret_cast<const char*>(data + len), size - len));
auto info = make_shared<ConnectExtensionInfo>(want, nullptr);
sptr<IFileAccessExtBase> extensionProxy = nullptr;
proxy->GetExtensionProxy(info, extensionProxy);

View File

@ -106,7 +106,10 @@ ErrCode CmdUnregisterNotifyFuzzTest(shared_ptr<FileAccessServiceStub> fileAccess
ErrCode CmdGetExensionProxyFuzzTest(shared_ptr<FileAccessServiceStub> fileAccessServiceStub, const uint8_t *data,
size_t size)
{
AAFwk::Want want = {};
int len = size >> 1;
AAFwk::Want want;
want.SetElementName(std::string(reinterpret_cast<const char*>(data), len),
std::string(reinterpret_cast<const char*>(data + len), size - len));
MessageParcel msg;
MessageParcel reply;
msg.WriteParcelable(&want);

View File

@ -49,7 +49,12 @@ bool MarshallingFuzzTest(shared_ptr<SharedMemoryInfo> info, const uint8_t *data,
bool UnmarshallingFuzzTest(shared_ptr<SharedMemoryInfo> info, const uint8_t *data, size_t size)
{
if (data == nullptr || size < sizeof(uint64_t)) {
return true;
}
MessageParcel reply;
reply.WriteUint64(*reinterpret_cast<const uint64_t*>(data));
info->Unmarshalling(reply);
return true;
@ -90,13 +95,29 @@ bool ExpandSharedMemoryFuzzTest(const uint8_t *data, size_t size)
bool WriteFileInfosFuzzTest(const uint8_t *data, size_t size)
{
FileInfo info;
if (data == nullptr || size < sizeof(int32_t) + sizeof(int64_t) + sizeof(int64_t)) {
return true;
}
int pos = 0;
int32_t mode = TypeCast<int32_t>(data, &pos);
int64_t sz = TypeCast<int64_t>(data + pos, &pos);
int64_t mtime = TypeCast<int64_t>(data + pos, &pos);
int len = (size - pos) >> 2;
std::string uri(*reinterpret_cast<const char*>(data + pos), len);
std::string relativePath(*reinterpret_cast<const char*>(data + pos + len), len);
std::string fileName(*reinterpret_cast<const char*>(data + pos + len + len), len);
std::string mimeType(*reinterpret_cast<const char*>(data + pos + len + len + len), len);
FileInfo info(uri, relativePath, fileName, mode, mimeType);
info.size = sz;
info.mtime = mtime;
vector<FileInfo> fileInfoVec;
fileInfoVec.emplace_back();
fileInfoVec.emplace_back(info);
SharedMemoryInfo memInfo;
SharedMemoryOperation::WriteFileInfos(fileInfoVec, memInfo);
SharedMemoryOperation::ReadFileInfo(info, memInfo);
return true;
}

View File

@ -31,7 +31,7 @@ bool IsFullMountFuzzTest(const uint8_t *data, size_t size)
bool GetUserNameFuzzTest(const uint8_t *data, size_t size)
{
string userName;
string userName(reinterpret_cast<const char*>(data), size);
GetUserName(userName);
return true;
}