DFX: add new fuzz branch for wantparams

Signed-off-by: z00838083 <zhuhuixuan@huawei.com>
This commit is contained in:
z00838083 2024-07-20 16:11:46 +08:00
parent f1aa3ff6e9
commit d22fbe48fe

View File

@ -19,11 +19,15 @@
#include <cstdint>
#include <iostream>
#include "array_wrapper.h"
#include "bool_wrapper.h"
#include "byte_wrapper.h"
#include "distributed_want_params.h"
#include "distributed_want_params_wrapper.h"
#include "double_wrapper.h"
#include "float_wrapper.h"
#include "int_wrapper.h"
#include "long_wrapper.h"
#include "securec.h"
#include "short_wrapper.h"
#include "string_wrapper.h"
@ -52,20 +56,24 @@ uint32_t GetU32Data(const char* ptr)
bool DoSomethingInterestingWithMyAPI_DistributedWantParams_001(const char* data, size_t size)
{
UnsupportedData other;
std::shared_ptr<UnsupportedData> unsupportedData = std::make_shared<UnsupportedData>(other);
DistributedWantParams wantOther;
std::shared_ptr<DistributedWantParams> wantParams = std::make_shared<DistributedWantParams>(wantOther);
std::string key(data, size);
int8_t byteValue = static_cast<int8_t>(GetU32Data(data));
std::shared_ptr<DistributedWantParams> wantParams = std::make_shared<DistributedWantParams>(wantOther);
sptr<AAFwk::IArray> array = new (std::nothrow) AAFwk::Array(0, DistributedSchedule::g_IID_IDistributedWantParams);
wantParams->SetParam(key, array);
IArray *iarray = IArray::Query(array);
sptr<IArray> destAO = nullptr;
wantParams->NewArrayData(iarray, destAO);
sptr<IInterface> stringIt = String::Box(key);
wantParams->Remove(key);
wantParams->SetParam(key, stringIt);
wantParams->KeySet();
wantParams->HasParam(key);
wantParams->IsEmpty();
wantParams->GetParams();
Parcel parcel;
sptr<IInterface> byteIt = Byte::Box(byteValue);
wantParams->WriteToParcelByte(parcel, byteIt);
return true;
}
@ -77,20 +85,35 @@ bool DoSomethingInterestingWithMyAPI_DistributedWantParams_002(const char* data,
IArray* ao = nullptr;
wantParams->WriteArrayToParcelChar(parcel, ao);
wantParams->WriteArrayToParcelShort(parcel, ao);
wantParams->WriteToParcelFD(parcel, wantOther);
wantParams->WriteToParcelRemoteObject(parcel, wantOther);
float floatValue = 0.0;
wantParams->WriteArrayToParcelString(parcel, ao);
wantParams->WriteArrayToParcelBool(parcel, ao);
wantParams->WriteArrayToParcelByte(parcel, ao);
wantParams->WriteArrayToParcelInt(parcel, ao);
wantParams->WriteArrayToParcelLong(parcel, ao);
wantParams->WriteArrayToParcelFloat(parcel, ao);
wantParams->WriteArrayToParcelDouble(parcel, ao);
long longValue = static_cast<long>(GetU32Data(data));
sptr<IInterface> longIt = Long::Box(longValue);
wantParams->WriteToParcelLong(parcel, longIt);
float floatValue = static_cast<float>(GetU32Data(data));
sptr<IInterface> floatIt = Float::Box(floatValue);
wantParams->WriteToParcelFloat(parcel, floatIt);
sptr<IArray> array;
wantParams->ReadFromParcelArrayChar(parcel, array);
wantParams->ReadFromParcelArrayShort(parcel, array);
wantParams->ReadFromParcelArrayString(parcel, array);
wantParams->ReadFromParcelArrayBool(parcel, array);
wantParams->ReadFromParcelArrayByte(parcel, array);
wantParams->ReadFromParcelArrayInt(parcel, array);
wantParams->ReadFromParcelArrayLong(parcel, array);
wantParams->ReadFromParcelArrayFloat(parcel, array);
wantParams->ReadFromParcelArrayDouble(parcel, array);
std::string key(data, size);
int type = static_cast<int>(GetU32Data(data));
wantParams->ReadFromParcelWantParamWrapper(parcel, key, type);
wantParams->ReadFromParcelFD(parcel, key);
wantParams->ReadFromParcelRemoteObject(parcel, key);
wantParams->ReadFromParcelLong(parcel, key);
wantParams->ReadFromParcelFloat(parcel, key);
wantParams->ReadArrayToParcel(parcel, GetU32Data(data) % OFFSET_16, array);
return true;
}
@ -99,23 +122,70 @@ bool DoSomethingInterestingWithMyAPI_DistributedWantParams_003(const char* data,
DistributedWantParams wantOther;
std::shared_ptr<DistributedWantParams> wantParams = std::make_shared<DistributedWantParams>(wantOther);
Parcel parcel;
std::string key(data, size);
int8_t byteValue = static_cast<int8_t>(GetU32Data(data));
sptr<IInterface> byteIt = Byte::Box(byteValue);
wantParams->WriteToParcelByte(parcel, byteIt);
sptr<IInterface> stringIt = String::Box(key);
wantParams->WriteToParcelString(parcel, stringIt);
bool boolValue = static_cast<bool>(GetU32Data(data) > FOO_MAX_LEN);
sptr<IInterface> boolIt = Boolean::Box(boolValue);
wantParams->WriteToParcelBool(parcel, boolIt);
char charValue = *data;
sptr<IInterface> charIt = Char::Box(charValue);
wantParams->WriteToParcelChar(parcel, charIt);
short shortValue = 0;
short shortValue = static_cast<short>(GetU32Data(data));
sptr<IInterface> shortIt = Short::Box(shortValue);
wantParams->WriteToParcelShort(parcel, shortIt);
double doubleValue = 0.0;
double doubleValue = static_cast<double>(GetU32Data(data));
sptr<IInterface> doubleIt = Double::Box(doubleValue);
wantParams->WriteToParcelDouble(parcel, doubleIt);
IArray* ao = nullptr;
wantParams->WriteArrayToParcelString(parcel, ao);
wantParams->WriteArrayToParcelBool(parcel, ao);
wantParams->WriteArrayToParcelByte(parcel, ao);
wantParams->WriteArrayToParcelInt(parcel, ao);
wantParams->WriteArrayToParcelLong(parcel, ao);
wantParams->WriteArrayToParcelFloat(parcel, ao);
wantParams->WriteArrayToParcelDouble(parcel, ao);
int32_t intValue = static_cast<int32_t>(GetU32Data(data));
sptr<IInterface> intIt = Integer::Box(intValue);
wantParams->WriteToParcelInt(parcel, intIt);
wantParams->WriteToParcelFD(parcel, wantOther);
wantParams->WriteToParcelRemoteObject(parcel, wantOther);
int type = static_cast<int>(GetU32Data(data));
wantParams->ReadFromParcelInt8(parcel, key);
wantParams->ReadFromParcelString(parcel, key);
wantParams->ReadFromParcelBool(parcel, key);
wantParams->ReadFromParcelChar(parcel, key);
wantParams->ReadFromParcelShort(parcel, key);
wantParams->ReadFromParcelDouble(parcel, key);
wantParams->ReadFromParcelInt(parcel, key);
wantParams->ReadFromParcelFD(parcel, key);
wantParams->ReadFromParcelRemoteObject(parcel, key);
wantParams->ReadFromParcelWantParamWrapper(parcel, key, type);
wantParams->WriteToParcelByte(parcel, byteIt);
wantParams->ReadFromParcel(parcel);
DistributedUnsupportedData uData;
std::shared_ptr<DistributedUnsupportedData> unsupportedData = std::make_shared<DistributedUnsupportedData>(uData);
wantParams->cachedUnsupportedData_.emplace_back(std::move(uData));
wantParams->DoMarshalling(parcel);
wantParams->cachedUnsupportedData_.clear();
return true;
}
bool DoSomethingInterestingWithMyAPI_DistributedWantParams_004(const char* data, size_t size)
{
DistributedWantParams wantOther;
std::shared_ptr<DistributedWantParams> wantParams = std::make_shared<DistributedWantParams>(wantOther);
std::string value(data, size);
sptr<IInterface> stringObj =
DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_STRING, value);
wantParams->CompareInterface(stringObj, stringObj, DistributedWantParams::VALUE_TYPE_STRING);
std::string keyStr = "12345667";
wantParams->SetParam(keyStr, String::Box(value));
Parcel in;
wantParams->Marshalling(in);
std::shared_ptr<DistributedWantParams> wantParamsNew(DistributedWantParams::Unmarshalling(in));
wantParams->ToWantParams();
return true;
}
}
@ -151,6 +221,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
OHOS::DoSomethingInterestingWithMyAPI_DistributedWantParams_001(ch, size);
OHOS::DoSomethingInterestingWithMyAPI_DistributedWantParams_002(ch, size);
OHOS::DoSomethingInterestingWithMyAPI_DistributedWantParams_003(ch, size);
OHOS::DoSomethingInterestingWithMyAPI_DistributedWantParams_004(ch, size);
free(ch);
ch = nullptr;
return 0;