fuzz Rectification

Signed-off-by: xzh457 <xiaozihan4@h-partners.com>
Change-Id: Ibd2461effd952d7f54426d25750ba708258e6e6a
This commit is contained in:
xzh457 2024-11-21 12:45:57 +08:00
parent f974ec46d6
commit bd6f7fed03
19 changed files with 584 additions and 232 deletions

View File

@ -110,7 +110,8 @@ static bool SendRequestByCommand(const uint8_t *data, size_t size, uint32_t comm
bool CreateSessionServerFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + INPUT_NAME_SIZE_MAX) {
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + INPUT_NAME_SIZE_MAX ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -142,7 +143,8 @@ bool CreateSessionServerFuzzTest(const uint8_t *data, size_t size)
bool RemoveSessionServerFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + INPUT_NAME_SIZE_MAX) {
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + INPUT_NAME_SIZE_MAX ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -174,7 +176,7 @@ bool RemoveSessionServerFuzzTest(const uint8_t *data, size_t size)
bool OpenSessionFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr ||
if (object == nullptr || data == nullptr || size >= INT32_MAX - 1 ||
size < INPUT_NAME_SIZE_MAX + INPUT_NAME_SIZE_MAX + NETWORKID_SIZE_MAX + NETWORKID_SIZE_MAX + sizeof(bool) +
sizeof(int32_t)) {
return false;
@ -225,7 +227,8 @@ bool OpenSessionFuzzTest(const uint8_t *data, size_t size)
bool OpenAuthSessionFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < sizeof(ConnectionAddr) + INPUT_NAME_SIZE_MAX) {
if (object == nullptr || data == nullptr || size < sizeof(ConnectionAddr) + INPUT_NAME_SIZE_MAX ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -256,7 +259,8 @@ bool OpenAuthSessionFuzzTest(const uint8_t *data, size_t size)
bool NotifyAuthSuccessFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < sizeof(int32_t) + sizeof(int32_t)) {
if (object == nullptr || data == nullptr || size < sizeof(int32_t) + sizeof(int32_t) ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -279,7 +283,8 @@ bool NotifyAuthSuccessFuzzTest(const uint8_t *data, size_t size)
bool CloseChannelFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < sizeof(int32_t) + sizeof(int32_t) + INPUT_NAME_SIZE_MAX) {
if (object == nullptr || data == nullptr || size < sizeof(int32_t) + sizeof(int32_t) + INPUT_NAME_SIZE_MAX ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -312,7 +317,7 @@ bool SendMessageFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < sizeof(int32_t) * SIZE_NUM_THREE +
INPUT_NAME_SIZE_MAX + INPUT_NAME_SIZE_MAX + sizeof(uint32_t)) {
INPUT_NAME_SIZE_MAX + INPUT_NAME_SIZE_MAX + sizeof(uint32_t) || size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -352,7 +357,8 @@ bool SendMessageFuzzTest(const uint8_t *data, size_t size)
bool QosReportFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < sizeof(int32_t) * SIZE_NUM_FOUR) {
if (object == nullptr || data == nullptr || size < sizeof(int32_t) * SIZE_NUM_FOUR ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -381,7 +387,7 @@ bool GrantPermissionFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < sizeof(int32_t) + sizeof(int32_t) +
INPUT_NAME_SIZE_MAX + INPUT_NAME_SIZE_MAX + sizeof(int32_t)) {
INPUT_NAME_SIZE_MAX + INPUT_NAME_SIZE_MAX + sizeof(int32_t) || size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -420,7 +426,7 @@ bool GrantPermissionFuzzTest(const uint8_t *data, size_t size)
bool RemovePermissionFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX) {
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX || size >= INT32_MAX - 1) {
return false;
}
char sessionName[INPUT_NAME_SIZE_MAX] = "";
@ -443,7 +449,8 @@ bool RemovePermissionFuzzTest(const uint8_t *data, size_t size)
bool StreamStatsFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < sizeof(int32_t) + sizeof(int32_t) + sizeof(StreamSendStats)) {
if (object == nullptr || data == nullptr || size < sizeof(int32_t) + sizeof(int32_t) + sizeof(StreamSendStats) ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -467,13 +474,17 @@ bool StreamStatsFuzzTest(const uint8_t *data, size_t size)
bool GetSoftbusSpecObjectFuzzTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size == 0 || size >= INT32_MAX - 1) {
return false;
}
return SendRequestByCommand(data, size, SERVER_GET_SOFTBUS_SPEC_OBJECT);
}
bool JoinLNNFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(ConnectionAddr)) {
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(ConnectionAddr) ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -512,7 +523,7 @@ bool JoinLNNFuzzTest(const uint8_t *data, size_t size)
bool JoinMetaNodeFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr) {
if (object == nullptr || data == nullptr || size == 0 || size >= INT32_MAX - 1) {
return false;
}
uint32_t addrTypeLen = SOFTBUS_FUZZ_TEST_ADDR_TYPE_LEN;
@ -533,7 +544,8 @@ bool JoinMetaNodeFuzzTest(const uint8_t *data, size_t size)
bool LeaveLNNFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + NETWORKID_SIZE_MAX) {
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + NETWORKID_SIZE_MAX ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -566,13 +578,17 @@ bool LeaveLNNFuzzTest(const uint8_t *data, size_t size)
bool LeaveMetaNodeFuzzTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size == 0 || size >= INT32_MAX - 1) {
return false;
}
return SendRequestByCommand(data, size, SERVER_LEAVE_METANODE);
}
bool GetAllOnlineNodeInfoFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(uint32_t)) {
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(uint32_t) ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -601,7 +617,8 @@ bool GetAllOnlineNodeInfoFuzzTest(const uint8_t *data, size_t size)
bool GetLocalDeviceInfoFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(uint32_t)) {
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(uint32_t) ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -630,7 +647,7 @@ bool GetLocalDeviceInfoFuzzTest(const uint8_t *data, size_t size)
bool GetNodeKeyInfoFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr ||
if (object == nullptr || data == nullptr || size >= INT32_MAX - 1 ||
size < INPUT_NAME_SIZE_MAX + NETWORKID_SIZE_MAX + sizeof(int32_t) + sizeof(uint32_t)) {
return false;
}
@ -671,7 +688,8 @@ bool GetNodeKeyInfoFuzzTest(const uint8_t *data, size_t size)
bool SetNodeDataChangeFlagFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + NETWORKID_SIZE_MAX + sizeof(uint16_t)) {
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + NETWORKID_SIZE_MAX + sizeof(uint16_t) ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -709,7 +727,7 @@ bool StartTimeSyncFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + NETWORKID_SIZE_MAX +
sizeof(int32_t) + sizeof(int32_t)) {
sizeof(int32_t) + sizeof(int32_t) || size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -750,7 +768,7 @@ bool StopTimeSyncFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + NETWORKID_SIZE_MAX +
sizeof(int32_t) + sizeof(int32_t)) {
sizeof(int32_t) + sizeof(int32_t) || size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -832,7 +850,7 @@ bool PublishLNNFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < (INPUT_NAME_SIZE_MAX * SIZE_NUM_THREE) +
(sizeof(int32_t) * SIZE_NUM_FIVE) + sizeof(bool)) {
(sizeof(int32_t) * SIZE_NUM_FIVE) + sizeof(bool) || size >= INT32_MAX - 1) {
return false;
}
MessageParcel datas;
@ -849,7 +867,8 @@ bool PublishLNNFuzzTest(const uint8_t *data, size_t size)
bool StopPublishLNNFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(int32_t)) {
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(int32_t) ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -928,7 +947,7 @@ bool RefreshLNNFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < (INPUT_NAME_SIZE_MAX * SIZE_NUM_THREE) +
(sizeof(int32_t) * SIZE_NUM_FIVE) + sizeof(bool) + sizeof(bool)) {
(sizeof(int32_t) * SIZE_NUM_FIVE) + sizeof(bool) + sizeof(bool) || size >= INT32_MAX - 1) {
return false;
}
MessageParcel datas;
@ -945,7 +964,8 @@ bool RefreshLNNFuzzTest(const uint8_t *data, size_t size)
bool StopRefreshLNNFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(int32_t)) {
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(int32_t) ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -972,7 +992,8 @@ bool StopRefreshLNNFuzzTest(const uint8_t *data, size_t size)
bool ActiveMetaNodeFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < sizeof(MetaNodeConfigInfo)) {
if (object == nullptr || data == nullptr || size < sizeof(MetaNodeConfigInfo) ||
size >= INT32_MAX - 1) {
return false;
}
MetaNodeConfigInfo info;
@ -997,7 +1018,8 @@ bool ActiveMetaNodeFuzzTest(const uint8_t *data, size_t size)
bool DeactiveMetaNodeFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX) {
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX ||
size >= INT32_MAX - 1) {
return false;
}
char metaNodeId[INPUT_NAME_SIZE_MAX] = "";
@ -1020,7 +1042,7 @@ bool DeactiveMetaNodeFuzzTest(const uint8_t *data, size_t size)
bool GetAllMetaNodeInfoFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < sizeof(int32_t)) {
if (object == nullptr || data == nullptr || size < sizeof(int32_t) || size >= INT32_MAX - 1) {
return false;
}
int32_t infoNum = *reinterpret_cast<const int32_t *>(data);
@ -1080,7 +1102,7 @@ bool ShiftLNNGearFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < sizeof(bool) + INPUT_NAME_SIZE_MAX * SIZE_NUM_THREE
+ sizeof(GearMode)) {
+ sizeof(GearMode) || size >= INT32_MAX - 1) {
return false;
}
MessageParcel datas;
@ -1097,7 +1119,8 @@ bool ShiftLNNGearFuzzTest(const uint8_t *data, size_t size)
bool RippleStatsFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < sizeof(int32_t) + sizeof(int32_t) + sizeof(TrafficStats)) {
if (object == nullptr || data == nullptr || size < sizeof(int32_t) + sizeof(int32_t) + sizeof(TrafficStats) ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -1122,7 +1145,8 @@ bool RippleStatsFuzzTest(const uint8_t *data, size_t size)
bool SoftbusRegisterServiceFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(IRemoteObject)) {
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(IRemoteObject) ||
size >= INT32_MAX - 1) {
return false;
}
uint32_t offset = 0;
@ -1156,7 +1180,8 @@ bool CheckOpenSessionPermissionFuzzTest(const uint8_t *data, size_t size)
{
#define SESSION_NAME_SIZE_MAX 256
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < DEVICE_ID_SIZE_MAX + GROUP_ID_SIZE_MAX) {
if (object == nullptr || data == nullptr || size < DEVICE_ID_SIZE_MAX + GROUP_ID_SIZE_MAX ||
size >= INT32_MAX - 1) {
return false;
}
SetAceessTokenPermission("SoftBusServerStubTest");
@ -1197,7 +1222,7 @@ bool CheckOpenSessionPermissionFuzzTest(const uint8_t *data, size_t size)
bool EvaLuateQosInnerFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr) {
if (object == nullptr || size == 0 || size >= INT32_MAX - 1) {
return false;
}
MessageParcel datas;
@ -1222,7 +1247,7 @@ bool EvaLuateQosInnerFuzzTest(const uint8_t *data, size_t size)
bool EvaLuateQosInnerNetworkIdFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr) {
if (object == nullptr || size == 0 || size >= INT32_MAX - 1) {
return false;
}
MessageParcel datas;
@ -1247,7 +1272,7 @@ bool EvaLuateQosInnerNetworkIdFuzzTest(const uint8_t *data, size_t size)
bool EvaLuateQosInnerDataTypeFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr) {
if (object == nullptr || size == 0 || size >= INT32_MAX - 1) {
return false;
}
MessageParcel datas;
@ -1271,7 +1296,7 @@ bool EvaLuateQosInnerDataTypeFuzzTest(const uint8_t *data, size_t size)
bool EvaLuateQosInnerQosCountFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr) {
if (object == nullptr || size == 0 || size >= INT32_MAX - 1) {
return false;
}
MessageParcel datas;
@ -1336,7 +1361,7 @@ bool RunFuzzTestCase(const uint8_t *data, size_t size)
/* Fuzzer entry point */
extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t* ptr, size_t size)
{
if (size == 0 || size >= INT32_MAX - 1) {
if (ptr == nullptr) {
return 0;
}
OHOS::RunFuzzTestCase(ptr, size);

View File

@ -40,7 +40,7 @@ HWTEST_F(TransEventTest, TransEventTest001, TestSize.Level0)
.socketName = "testSocket",
.dataType = 0, // invalid
};
constexpr int32_t VALID_EXTRA_SIZE = 5; //result errcode socketName firstTokenId
constexpr int32_t VALID_EXTRA_SIZE = 4; //result errcode socketName firstTokenId
HiSysEventMock mock;
EXPECT_CALL(mock,

View File

@ -127,12 +127,32 @@ static void InitOnChannelOpenedInnerMsg(int32_t channelType, const uint8_t *data
message.WriteInt32(int32Param);
}
uint8_t *TestDataSwitch(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return nullptr;
}
uint8_t *dataWithEndCharacter = static_cast<uint8_t *>(SoftBusCalloc(size + 1));
if (dataWithEndCharacter == nullptr) {
return nullptr;
}
if (memcpy_s(dataWithEndCharacter, size, data, size) != EOK) {
SoftBusFree(dataWithEndCharacter);
return nullptr;
}
return dataWithEndCharacter;
}
/*
* Due to FileDescriptor is invalid, CHANNEL_TYPE_TCP_DIRECT will read it and crash
* Do not add test case which channel type is CHANNEL_TYPE_TCP_DIRECT
*/
bool OnChannelOpenedInnerTest(const uint8_t *data, size_t size)
{
uint8_t *dataWithEndCharacter = TestDataSwitch(data, size);
if (dataWithEndCharacter == nullptr) {
return false;
}
sptr<OHOS::SoftBusClientStub> softBusClientStub = new OHOS::SoftBusClientStub();
if (softBusClientStub == nullptr) {
return false;
@ -141,18 +161,19 @@ bool OnChannelOpenedInnerTest(const uint8_t *data, size_t size)
MessageParcel reply;
MessageOption option;
MessageParcel dataNomal;
InitOnChannelOpenedInnerMsg(CHANNEL_TYPE_UNDEFINED, data, size, dataNomal);
InitOnChannelOpenedInnerMsg(CHANNEL_TYPE_UNDEFINED, dataWithEndCharacter, size, dataNomal);
MessageParcel dataUdp;
InitOnChannelOpenedInnerMsg(CHANNEL_TYPE_UDP, data, size, dataUdp);
InitOnChannelOpenedInnerMsg(CHANNEL_TYPE_UDP, dataWithEndCharacter, size, dataUdp);
softBusClientStub->OnRemoteRequest(CLIENT_ON_CHANNEL_OPENED, dataUdp, reply, option);
SoftBusFree(dataWithEndCharacter);
return true;
}
bool OnChannelOpenFailedInnerTest(const uint8_t *data, size_t size)
{
sptr<OHOS::SoftBusClientStub> softBusClientStub = new OHOS::SoftBusClientStub();
if (softBusClientStub == nullptr) {
if (softBusClientStub == nullptr || data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
@ -174,13 +195,17 @@ bool OnChannelOpenFailedInnerTest(const uint8_t *data, size_t size)
bool OnChannelLinkDownInnerTest(const uint8_t *data, size_t size)
{
uint8_t *dataWithEndCharacter = TestDataSwitch(data, size);
if (dataWithEndCharacter == nullptr) {
return false;
}
sptr<OHOS::SoftBusClientStub> softBusClientStub = new OHOS::SoftBusClientStub();
if (softBusClientStub == nullptr) {
return false;
}
char *networkId = const_cast<char *>(reinterpret_cast<const char *>(data));
int32_t routeType = *(reinterpret_cast<const int32_t *>(data));
char *networkId = const_cast<char *>(reinterpret_cast<const char *>(dataWithEndCharacter));
int32_t routeType = *(reinterpret_cast<const int32_t *>(dataWithEndCharacter));
MessageParcel datas;
MessageParcel reply;
@ -190,6 +215,7 @@ bool OnChannelLinkDownInnerTest(const uint8_t *data, size_t size)
datas.WriteCString(networkId);
datas.WriteInt32(routeType);
softBusClientStub->OnRemoteRequest(CLIENT_ON_CHANNEL_LINKDOWN, datas, reply, option);
SoftBusFree(dataWithEndCharacter);
return true;
}
@ -197,7 +223,7 @@ bool OnChannelLinkDownInnerTest(const uint8_t *data, size_t size)
bool OnChannelClosedInnerTest(const uint8_t *data, size_t size)
{
sptr<OHOS::SoftBusClientStub> softBusClientStub = new OHOS::SoftBusClientStub();
if (softBusClientStub == nullptr) {
if (softBusClientStub == nullptr || data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
@ -220,7 +246,7 @@ bool OnChannelClosedInnerTest(const uint8_t *data, size_t size)
bool OnChannelMsgReceivedInnerTest(const uint8_t *data, size_t size)
{
sptr<OHOS::SoftBusClientStub> softBusClientStub = new OHOS::SoftBusClientStub();
if (softBusClientStub == nullptr) {
if (softBusClientStub == nullptr || data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
@ -245,7 +271,7 @@ bool OnChannelMsgReceivedInnerTest(const uint8_t *data, size_t size)
bool OnChannelQosEventInnerTest(const uint8_t *data, size_t size)
{
sptr<OHOS::SoftBusClientStub> softBusClientStub = new OHOS::SoftBusClientStub();
if (softBusClientStub == nullptr) {
if (softBusClientStub == nullptr || data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
@ -277,6 +303,9 @@ bool OnChannelQosEventInnerTest(const uint8_t *data, size_t size)
bool OnDeviceFoundInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
MessageParcel datas;
datas.WriteInterfaceToken(SOFTBUS_CLIENT_STUB_INTERFACE_TOKEN);
datas.WriteBuffer(data, size);
@ -293,6 +322,9 @@ bool OnDeviceFoundInnerTest(const uint8_t *data, size_t size)
bool OnJoinLNNResultInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr uint32_t addrTypeLen = 10;
constexpr int32_t retCode = 2;
const char *test = "test";
@ -316,6 +348,9 @@ bool OnJoinLNNResultInnerTest(const uint8_t *data, size_t size)
bool OnJoinMetaNodeResultInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr uint32_t addrTypeLen = 12;
constexpr int32_t retCode = 2;
const char *test = "test";
@ -339,6 +374,9 @@ bool OnJoinMetaNodeResultInnerTest(const uint8_t *data, size_t size)
bool OnLeaveLNNResultInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr int32_t intNum = 2;
MessageParcel datas;
datas.WriteInterfaceToken(SOFTBUS_CLIENT_STUB_INTERFACE_TOKEN);
@ -357,6 +395,9 @@ bool OnLeaveLNNResultInnerTest(const uint8_t *data, size_t size)
bool OnLeaveMetaNodeResultInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr int32_t intNum = 2;
MessageParcel datas;
datas.WriteInterfaceToken(SOFTBUS_CLIENT_STUB_INTERFACE_TOKEN);
@ -375,6 +416,9 @@ bool OnLeaveMetaNodeResultInnerTest(const uint8_t *data, size_t size)
bool OnNodeDeviceTrustedChangeInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
MessageParcel datas;
datas.WriteInterfaceToken(SOFTBUS_CLIENT_STUB_INTERFACE_TOKEN);
datas.WriteBuffer(data, size);
@ -391,6 +435,9 @@ bool OnNodeDeviceTrustedChangeInnerTest(const uint8_t *data, size_t size)
bool OnHichainProofExceptionInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
MessageParcel datas;
datas.WriteInterfaceToken(SOFTBUS_CLIENT_STUB_INTERFACE_TOKEN);
datas.WriteBuffer(data, size);
@ -407,6 +454,9 @@ bool OnHichainProofExceptionInnerTest(const uint8_t *data, size_t size)
bool OnNodeOnlineStateChangedInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr uint32_t infoTypeLen = 10;
bool boolNum = true;
const char *test = "test";
@ -430,6 +480,9 @@ bool OnNodeOnlineStateChangedInnerTest(const uint8_t *data, size_t size)
bool OnNodeBasicInfoChangedInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr int32_t type = 2;
constexpr uint32_t infoTypeLen = 10;
const char *test = "test";
@ -453,6 +506,9 @@ bool OnNodeBasicInfoChangedInnerTest(const uint8_t *data, size_t size)
bool OnTimeSyncResultInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr uint32_t infoTypeLen = 10;
int32_t retCode = *(reinterpret_cast<const char *>(data));
const char *test = "test";
@ -475,7 +531,9 @@ bool OnTimeSyncResultInnerTest(const uint8_t *data, size_t size)
static bool OnClientEventByReasonAndCode(const uint8_t *data, size_t size, int32_t reason, uint32_t code)
{
(void)size;
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
int32_t intNum = *(reinterpret_cast<const int32_t *>(data));
MessageParcel datas;
datas.WriteInterfaceToken(SOFTBUS_CLIENT_STUB_INTERFACE_TOKEN);
@ -494,18 +552,27 @@ static bool OnClientEventByReasonAndCode(const uint8_t *data, size_t size, int32
bool OnPublishLNNResultInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr int32_t reason = 2;
return OnClientEventByReasonAndCode(data, size, reason, CLIENT_ON_PUBLISH_LNN_RESULT);
}
bool OnRefreshLNNResultInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr int32_t reason = 8;
return OnClientEventByReasonAndCode(data, size, reason, CLIENT_ON_REFRESH_LNN_RESULT);
}
bool OnRefreshDeviceFoundInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
uint32_t deviceLen = *(reinterpret_cast<const int32_t *>(data));
const char *test = "test";
MessageParcel datas;
@ -526,13 +593,17 @@ bool OnRefreshDeviceFoundInnerTest(const uint8_t *data, size_t size)
bool OnClientPermissonChangeInnerTest(const uint8_t *data, size_t size)
{
uint8_t *dataWithEndCharacter = TestDataSwitch(data, size);
if (dataWithEndCharacter == nullptr) {
return false;
}
sptr<OHOS::SoftBusClientStub> softBusClientStub = new OHOS::SoftBusClientStub();
if (softBusClientStub == nullptr) {
return false;
}
int32_t state = *(reinterpret_cast<const int32_t *>(data));
char *pkgName = const_cast<char *>(reinterpret_cast<const char *>(data));
int32_t state = *(reinterpret_cast<const int32_t *>(dataWithEndCharacter));
char *pkgName = const_cast<char *>(reinterpret_cast<const char *>(dataWithEndCharacter));
MessageParcel datas;
MessageParcel reply;
@ -541,30 +612,43 @@ bool OnClientPermissonChangeInnerTest(const uint8_t *data, size_t size)
datas.WriteInt32(state);
datas.WriteCString(pkgName);
softBusClientStub->OnRemoteRequest(CLIENT_ON_PERMISSION_CHANGE, datas, reply, option);
SoftBusFree(dataWithEndCharacter);
return true;
}
bool OnDiscoverFailedInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr int32_t reason = 2;
return OnClientEventByReasonAndCode(data, size, reason, CLIENT_ON_PUBLISH_LNN_RESULT);
}
bool OnDiscoverySuccessInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr int32_t reason = 2;
return OnClientEventByReasonAndCode(data, size, reason, CLIENT_ON_PUBLISH_LNN_RESULT);
}
bool OnPublishSuccessInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr int32_t reason = 2;
return OnClientEventByReasonAndCode(data, size, reason, CLIENT_ON_PUBLISH_LNN_RESULT);
}
bool OnPublishFailInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
constexpr int32_t reason = 2;
return OnClientEventByReasonAndCode(data, size, reason, CLIENT_ON_PUBLISH_LNN_RESULT);
}
@ -572,7 +656,7 @@ bool OnPublishFailInnerTest(const uint8_t *data, size_t size)
bool OnClientTransLimitChangeInnerTest(const uint8_t *data, size_t size)
{
sptr<OHOS::SoftBusClientStub> softBusClientStub = new OHOS::SoftBusClientStub();
if (softBusClientStub == nullptr) {
if (softBusClientStub == nullptr || data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
@ -592,15 +676,19 @@ bool OnClientTransLimitChangeInnerTest(const uint8_t *data, size_t size)
bool SetChannelInfoInnerTest(const uint8_t *data, size_t size)
{
uint8_t *dataWithEndCharacter = TestDataSwitch(data, size);
if (dataWithEndCharacter == nullptr) {
return false;
}
sptr<OHOS::SoftBusClientStub> softBusClientStub = new OHOS::SoftBusClientStub();
if (softBusClientStub == nullptr) {
return false;
}
char *sessionName = const_cast<char *>(reinterpret_cast<const char *>(data));
int32_t sessionId = *(reinterpret_cast<const int32_t *>(data));
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
int32_t channelType = *(reinterpret_cast<const int32_t *>(data));
char *sessionName = const_cast<char *>(reinterpret_cast<const char *>(dataWithEndCharacter));
int32_t sessionId = *(reinterpret_cast<const int32_t *>(dataWithEndCharacter));
int32_t channelId = *(reinterpret_cast<const int32_t *>(dataWithEndCharacter));
int32_t channelType = *(reinterpret_cast<const int32_t *>(dataWithEndCharacter));
MessageParcel datas;
MessageParcel reply;
@ -611,6 +699,7 @@ bool SetChannelInfoInnerTest(const uint8_t *data, size_t size)
datas.WriteInt32(channelId);
datas.WriteInt32(channelType);
softBusClientStub->OnRemoteRequest(CLIENT_SET_CHANNEL_INFO, datas, reply, option);
SoftBusFree(dataWithEndCharacter);
return true;
}
@ -618,7 +707,7 @@ bool SetChannelInfoInnerTest(const uint8_t *data, size_t size)
bool OnChannelBindInnerTest(const uint8_t *data, size_t size)
{
sptr<OHOS::SoftBusClientStub> softBusClientStub = new OHOS::SoftBusClientStub();
if (softBusClientStub == nullptr) {
if (softBusClientStub == nullptr || data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return false;
}
@ -640,25 +729,13 @@ bool OnChannelBindInnerTest(const uint8_t *data, size_t size)
/* Fuzzer entry point */
extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
/* Run your code on data */
if (data == nullptr || size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
return 0;
}
uint8_t *dataWithEndCharacter = static_cast<uint8_t *>(SoftBusCalloc(size + 1));
if (dataWithEndCharacter == nullptr) {
return 0;
}
if (memcpy_s(dataWithEndCharacter, size, data, size) != EOK) {
SoftBusFree(dataWithEndCharacter);
return 0;
}
static OHOS::TestEnv env;
if (!env.IsInited()) {
return 0;
}
OHOS::OnChannelOpenedInnerTest(dataWithEndCharacter, size);
OHOS::OnChannelOpenedInnerTest(data, size);
OHOS::OnChannelOpenFailedInnerTest(data, size);
OHOS::OnChannelLinkDownInnerTest(dataWithEndCharacter, size);
OHOS::OnChannelLinkDownInnerTest(data, size);
OHOS::OnChannelClosedInnerTest(data, size);
OHOS::OnChannelMsgReceivedInnerTest(data, size);
OHOS::OnChannelQosEventInnerTest(data, size);
@ -674,14 +751,13 @@ extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
OHOS::OnPublishLNNResultInnerTest(data, size);
OHOS::OnRefreshLNNResultInnerTest(data, size);
OHOS::OnRefreshDeviceFoundInnerTest(data, size);
OHOS::OnClientPermissonChangeInnerTest(dataWithEndCharacter, size);
OHOS::OnClientPermissonChangeInnerTest(data, size);
OHOS::OnDiscoverFailedInnerTest(data, size);
OHOS::OnDiscoverySuccessInnerTest(data, size);
OHOS::OnPublishSuccessInnerTest(data, size);
OHOS::OnPublishFailInnerTest(data, size);
OHOS::OnClientTransLimitChangeInnerTest(data, size);
OHOS::SetChannelInfoInnerTest(dataWithEndCharacter, size);
OHOS::SetChannelInfoInnerTest(data, size);
OHOS::OnChannelBindInnerTest(data, size);
SoftBusFree(dataWithEndCharacter);
return 0;
}

View File

@ -43,7 +43,7 @@ void ClientAddNewSessionTest(const uint8_t* data, size_t size)
if ((data == nullptr) || (size == 0)) {
return;
}
const char* testSessionName = reinterpret_cast<const char*>(data);
const char* testSessionName = reinterpret_cast<const char *>(data);
SessionInfo session;
ClientAddNewSession(testSessionName, &session);
}
@ -54,7 +54,7 @@ void ClientAddAuthSessionTest(const uint8_t* data, size_t size)
if ((data == nullptr) || (size < SESSION_NAME_SIZE_MAX)) {
return;
}
int32_t sessionId;
int32_t sessionId = *(reinterpret_cast<const int32_t *>(data));
ClientAddAuthSession(nullptr, &sessionId);
}
@ -63,7 +63,7 @@ void ClientDeleteSessionTest(const uint8_t* data, size_t size)
if ((data == nullptr) || (size < sizeof(int32_t))) {
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
int32_t sessionId = *(reinterpret_cast<const int32_t *>(data));
ClientDeleteSession(sessionId);
}
@ -72,9 +72,9 @@ void ClientGetSessionDataTest(const uint8_t* data, size_t size)
if ((data == nullptr) || (size < sizeof(int32_t))) {
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
char* testData = const_cast<char*>(reinterpret_cast<const char*>(data));
int* testInt = const_cast<int*>(reinterpret_cast<const int*>(data));
int32_t sessionId = *(reinterpret_cast<const int32_t *>(data));
char* testData = const_cast<char*>(reinterpret_cast<const char *>(data));
int* testInt = const_cast<int*>(reinterpret_cast<const int *>(data));
ClientGetSessionDataById(sessionId, testData, size, KEY_SESSION_NAME);
ClientGetSessionIntegerDataById(sessionId, testInt, KEY_SESSION_NAME);
ClientGetSessionSide(sessionId);
@ -85,7 +85,7 @@ void ClientSetChannelBySessionIdTest(const uint8_t* data, size_t size)
if ((data == nullptr) || (size < sizeof(int32_t))) {
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
int32_t sessionId = *(reinterpret_cast<const int32_t *>(data));
TransInfo transInfo = {
.channelId = 0,
.channelType = 0,
@ -99,8 +99,8 @@ void ClientGetSessionCallbackTest(const uint8_t* data, size_t size)
if ((data == nullptr) || (size < sizeof(int32_t))) {
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
const char* testSessionName = reinterpret_cast<const char*>(data);
int32_t sessionId = *(reinterpret_cast<const int32_t *>(data));
const char* testSessionName = reinterpret_cast<const char *>(data);
ClientGetSessionCallbackById(sessionId, &g_sessionlistener);
ClientGetSessionCallbackByName(testSessionName, &g_sessionlistener);
@ -111,17 +111,16 @@ void ClientTransOnLinkDownTest(const uint8_t* data, size_t size)
if ((data == nullptr) || (size < sizeof(int32_t))) {
return;
}
const char* netWorkId = reinterpret_cast<const char*>(data);
int32_t routeType = *(reinterpret_cast<const int32_t*>(data));
const char* netWorkId = reinterpret_cast<const char *>(data);
int32_t routeType = *(reinterpret_cast<const int32_t *>(data));
ClientTransOnLinkDown(netWorkId, routeType);
}
void ClientRemovePermissionTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
return;
}
(void)data;
(void)size;
ClientRemovePermission(nullptr);
}
@ -130,8 +129,8 @@ void ClientGetFileConfigInfoByIdTest(const uint8_t* data, size_t size)
if ((data == nullptr) || (size < sizeof(int32_t))) {
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
int32_t* fileEncrypt = const_cast<int32_t*>(reinterpret_cast<const int32_t*>(data));
int32_t sessionId = *(reinterpret_cast<const int32_t *>(data));
int32_t* fileEncrypt = const_cast<int32_t*>(reinterpret_cast<const int32_t *>(data));
ClientGetFileConfigInfoById(sessionId, fileEncrypt, fileEncrypt, fileEncrypt);
}
@ -140,8 +139,8 @@ void GetEncryptByChannelIdTest(const uint8_t* data, size_t size)
if ((data == nullptr) || (size < sizeof(int32_t))) {
return;
}
int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
int32_t channelType = *(reinterpret_cast<const int32_t *>(data));
int32_t encryp = 0;
GetEncryptByChannelId(channelId, channelType, &encryp);
}
@ -151,8 +150,8 @@ void ClientGetSessionIdByChannelIdTest(const uint8_t* data, size_t size)
if ((data == nullptr) || (size < sizeof(int32_t))) {
return;
}
int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
int32_t channelType = *(reinterpret_cast<const int32_t *>(data));
int32_t sessionId;
bool isClosing = false;
ClientGetSessionIdByChannelId(channelId, channelType, &sessionId, isClosing);
@ -164,7 +163,7 @@ void ClientEnableSessionByChannelIdTest(const uint8_t* data, size_t size)
return;
}
ChannelInfo channel;
int32_t sessionId;
int32_t sessionId = *(reinterpret_cast<const int32_t *>(data));
ClientEnableSessionByChannelId(&channel, &sessionId);
}

View File

@ -32,7 +32,7 @@ namespace OHOS {
return;
}
unsigned int len = SESSION_KEY_LENGTH;
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
int32_t sessionId = *(reinterpret_cast<const int32_t *>(data));
char tmp[SESSION_KEY_LENGTH + 1] = {0};
if (memcpy_s(tmp, sizeof(tmp) - 1, data, size) != EOK) {
return;
@ -46,7 +46,7 @@ namespace OHOS {
return;
}
int32_t handle = 1;
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
int32_t sessionId = *(reinterpret_cast<const int32_t *>(data));
GetSessionHandle(sessionId, &handle);
}
@ -55,7 +55,7 @@ namespace OHOS {
if ((data == nullptr) || (size < sizeof(int32_t))) {
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
int32_t sessionId = *(reinterpret_cast<const int32_t *>(data));
DisableSessionListener(sessionId);
}
@ -64,16 +64,34 @@ namespace OHOS {
if ((data == nullptr) || (size == 0)) {
return;
}
char *charParam = const_cast<char *>(reinterpret_cast<const char *>(data));
#define SESSION_NAME_SIZE_MAX 256
#define DEVICE_ID_SIZE_MAX 65
#define GROUP_ID_SIZE_MAX 65
char mySessionName[SESSION_NAME_SIZE_MAX] = "ohos.fuzz.dms.test";
char peerSessionName[SESSION_NAME_SIZE_MAX] = "ohos.fuzz.dms.test";
char peerNetworkId[DEVICE_ID_SIZE_MAX] = "ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00";
SessionAttribute attr = {
.dataType = TYPE_BYTES,
};
char groupId[GROUP_ID_SIZE_MAX] = "TEST_GROUP_ID";
OpenSessionSync(nullptr, peerSessionName, peerNetworkId, groupId, &attr);
if (memcpy_s(mySessionName, SESSION_NAME_SIZE_MAX, charParam, SESSION_NAME_SIZE_MAX - 1) != EOK) {
return;
}
if (memcpy_s(peerSessionName, SESSION_NAME_SIZE_MAX, charParam, SESSION_NAME_SIZE_MAX - 1) != EOK) {
return;
}
if (memcpy_s(peerNetworkId, DEVICE_ID_SIZE_MAX, charParam, DEVICE_ID_SIZE_MAX - 1) != EOK) {
return;
}
if (memcpy_s(groupId, GROUP_ID_SIZE_MAX, charParam, GROUP_ID_SIZE_MAX - 1) != EOK) {
return;
}
mySessionName[SESSION_NAME_SIZE_MAX - 1] = '\0';
peerSessionName[SESSION_NAME_SIZE_MAX - 1] = '\0';
peerNetworkId[DEVICE_ID_SIZE_MAX - 1] = '\0';
groupId[GROUP_ID_SIZE_MAX - 1] = '\0';
OpenSessionSync(mySessionName, peerSessionName, peerNetworkId, groupId, &attr);
}
} // namespace OHOS

View File

@ -15,38 +15,71 @@
#include "clienttransstream_fuzzer.h"
#include <securec.h>
#include "client_trans_stream.h"
#include "softbus_adapter_mem.h"
namespace OHOS {
void TransOnstreamChannelOpenedTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
ChannelInfo *channel = nullptr;
int32_t streamPort = *(reinterpret_cast<const int32_t *>(data));
TransOnstreamChannelOpened(channel, (int32_t *)size);
TransOnstreamChannelOpened(channel, &streamPort);
}
void TransSendStreamTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int64_t)) {
return;
}
StreamData *streamdata = nullptr;
StreamData *ext = nullptr;
StreamFrameInfo *param = nullptr;
uint8_t *ptr = static_cast<uint8_t *>(SoftBusCalloc(size + 1));
if (ptr == nullptr) {
return;
}
if (memcpy_s(ptr, size, data, size) != EOK) {
SoftBusFree(ptr);
return;
}
int32_t channelId = *(reinterpret_cast<const int32_t *>(ptr));
StreamData streamdata = {
.buf = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
.bufLen = size,
};
StreamData ext = {
.buf = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
.bufLen = size,
};
TV tv = {
.type = *(reinterpret_cast<const int32_t *>(ptr)),
.value = *(reinterpret_cast<const int64_t *>(ptr)),
};
StreamFrameInfo param = {
.frameType = *(reinterpret_cast<const int32_t *>(ptr)),
.timeStamp = *(reinterpret_cast<const int32_t *>(ptr)),
.seqNum = *(reinterpret_cast<const int32_t *>(ptr)),
.seqSubNum = *(reinterpret_cast<const int32_t *>(ptr)),
.level = *(reinterpret_cast<const int32_t *>(ptr)),
.bitMap = *(reinterpret_cast<const int32_t *>(ptr)),
.tvCount = 1,
.tvList = &tv,
};
TransSendStream(size, streamdata, ext, param);
TransSendStream(channelId, &streamdata, &ext, &param);
SoftBusFree(ptr);
}
void TransCloseStreamChannelTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
TransCloseStreamChannel(size);
TransCloseStreamChannel(channelId);
}
} // namespace OHOS
@ -57,6 +90,5 @@ extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
OHOS::TransOnstreamChannelOpenedTest(data, size);
OHOS::TransSendStreamTest(data, size);
OHOS::TransCloseStreamChannelTest(data, size);
return 0;
}

View File

@ -55,18 +55,20 @@ namespace OHOS {
void TransTdcCreateListenerTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
TransTdcCreateListener((int32_t)size);
int32_t fd = *(reinterpret_cast<const int32_t *>(data));
TransTdcCreateListener(fd);
}
void TransTdcStopReadTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
TransTdcStopRead((int32_t)size);
int32_t fd = *(reinterpret_cast<const int32_t *>(data));
TransTdcStopRead(fd);
}
void TransTdcSendBytesTest(const uint8_t* data, size_t size)
@ -74,7 +76,7 @@ namespace OHOS {
if ((data == nullptr) || (size == 0)) {
return;
}
char tmp = *(reinterpret_cast<const char*>(data));
char tmp = *(reinterpret_cast<const char *>(data));
TransTdcSendBytes((int32_t)size, &tmp, (uint32_t)size);
}
@ -83,69 +85,77 @@ namespace OHOS {
if ((data == nullptr) || (size == 0)) {
return;
}
char tmp = *(reinterpret_cast<const char*>(data));
char tmp = *(reinterpret_cast<const char *>(data));
TransTdcSendMessage((int32_t)size, &tmp, (uint32_t)size);
}
void TransAddDataBufNodeTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
TransAddDataBufNode((int32_t)size, (int32_t)size);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
int32_t fd = *(reinterpret_cast<const int32_t *>(data));
TransAddDataBufNode(channelId, fd);
}
void TransDelDataBufNodeTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
TransDelDataBufNode((int32_t)size);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
TransDelDataBufNode(channelId);
}
void TransTdcRecvDataTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
TransTdcRecvData((int32_t)size);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
TransTdcRecvData(channelId);
}
void TransTdcGetInfoByIdTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
TransTdcGetInfoById((int32_t)size, NULL);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
TransTdcGetInfoById(channelId, NULL);
}
void TransTdcGetInfoByIdWithIncSeqTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
TransTdcGetInfoByIdWithIncSeq((int32_t)size, NULL);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
TransTdcGetInfoByIdWithIncSeq(channelId, NULL);
}
void TransTdcGetInfoByFdTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
TransTdcGetInfoByFd((int32_t)size, NULL);
int32_t fd = *(reinterpret_cast<const int32_t *>(data));
TransTdcGetInfoByFd(fd, NULL);
}
void TransTdcCloseChannelTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
TransTdcCloseChannel((int32_t)size);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
TransTdcCloseChannel(channelId);
}
void ClientTransTdcOnChannelOpenedTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size < SESSION_NAME_SIZE_MAX)) {
if (data == nullptr || size < SESSION_NAME_SIZE_MAX) {
return;
}
char tmp[SESSION_NAME_SIZE_MAX] = {0};
@ -157,10 +167,11 @@ namespace OHOS {
void TransDisableSessionListenerTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
TransDisableSessionListener((int32_t)size);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
TransDisableSessionListener(channelId);
}
static void ClientFillSessionCallBack(IClientSessionCallBack *cb)
@ -175,7 +186,7 @@ namespace OHOS {
}
void ClientTransTdcOnSessionOpenedTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size < SESSION_NAME_SIZE_MAX)) {
if (data == nullptr || size < SESSION_NAME_SIZE_MAX) {
return;
}
ChannelInfo channel = {0};
@ -193,7 +204,7 @@ namespace OHOS {
void ClientTransTdcOnSessionClosedTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
IClientSessionCallBack cb;
@ -201,12 +212,13 @@ namespace OHOS {
if (ClientTransTdcSetCallBack(&cb) != SOFTBUS_OK) {
return;
}
ClientTransTdcOnSessionClosed((int32_t)size, SHUTDOWN_REASON_UNKNOWN);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
ClientTransTdcOnSessionClosed(channelId, SHUTDOWN_REASON_UNKNOWN);
}
void ClientTransTdcOnSessionOpenFailedTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
IClientSessionCallBack cb;
@ -214,13 +226,15 @@ namespace OHOS {
if (ClientTransTdcSetCallBack(&cb) != SOFTBUS_OK) {
return;
}
ClientTransTdcOnSessionOpenFailed((int32_t)size, (int32_t)size);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
int32_t errCode = *(reinterpret_cast<const int32_t *>(data));
ClientTransTdcOnSessionOpenFailed(channelId, errCode);
}
void ClientTransTdcOnDataReceivedTest(const uint8_t* data, size_t size)
{
#define PROXY_MAX_MESSAGE_LEN (1 * 1024)
if ((data == nullptr) || (size < PROXY_MAX_MESSAGE_LEN)) {
if (data == nullptr || size < PROXY_MAX_MESSAGE_LEN) {
return;
}
char tmp[PROXY_MAX_MESSAGE_LEN] = {0};

View File

@ -19,6 +19,7 @@
#include "session.h"
#include "client_trans_udp_manager.h"
#include "softbus_adapter_mem.h"
#define STR_LEN 100000
#define TEST_TMP_STR_LEN 50
@ -26,71 +27,99 @@
namespace OHOS {
void TransOnUdpChannelOpenedTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
ChannelInfo channel = {0};
channel.channelType = CHANNEL_TYPE_UDP;
channel.businessType = BUSINESS_TYPE_STREAM;
int32_t udpPort = size;
int32_t udpPort = *(reinterpret_cast<const int32_t *>(data));
TransOnUdpChannelOpened((char *)data, &channel, &udpPort);
}
void TransOnUdpChannelOpenFailedTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
TransOnUdpChannelOpenFailed((int32_t)size, (int32_t)size);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
int32_t errCode = *(reinterpret_cast<const int32_t *>(data));
TransOnUdpChannelOpenFailed(channelId, errCode);
}
void TransOnUdpChannelClosedTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
TransOnUdpChannelClosed((int32_t)size, SHUTDOWN_REASON_UNKNOWN);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
TransOnUdpChannelClosed(channelId, SHUTDOWN_REASON_UNKNOWN);
}
void TransOnUdpChannelQosEventTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
int32_t eventId = *(reinterpret_cast<const int32_t *>(data));
int32_t tvCount = *(reinterpret_cast<const int32_t *>(data));
QosTv tvList;
TransOnUdpChannelQosEvent((int32_t)size, (int32_t)size, (int32_t)size, &tvList);
TransOnUdpChannelQosEvent(channelId, eventId, tvCount, &tvList);
}
void ClientTransCloseUdpChannelTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
ClientTransCloseUdpChannel((int32_t)size, SHUTDOWN_REASON_UNKNOWN);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
ClientTransCloseUdpChannel(channelId, SHUTDOWN_REASON_UNKNOWN);
}
void TransUdpChannelSendStreamTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int64_t)) {
return;
}
char sendStringData[STR_LEN] = {0};
StreamData streamdata1 = {
sendStringData,
100000,
uint8_t *ptr = static_cast<uint8_t *>(SoftBusCalloc(size + 1));
if (ptr == nullptr) {
return;
}
if (memcpy_s(ptr, size, data, size) != EOK) {
SoftBusFree(ptr);
return;
}
int32_t channelId = *(reinterpret_cast<const int32_t *>(ptr));
StreamData streamdata = {
.buf = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
.bufLen = size,
};
char str[TEST_TMP_STR_LEN] = TEST_TMP_STR;
StreamData streamdata2 = {
str,
10,
StreamData ext = {
.buf = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
.bufLen = size,
};
StreamFrameInfo ext = {};
TransUdpChannelSendStream((int32_t)size, &streamdata1, &streamdata2, &ext);
TV tv = {
.type = *(reinterpret_cast<const int32_t *>(ptr)),
.value = *(reinterpret_cast<const int64_t *>(ptr)),
};
StreamFrameInfo param = {
.frameType = *(reinterpret_cast<const int32_t *>(ptr)),
.timeStamp = *(reinterpret_cast<const int32_t *>(ptr)),
.seqNum = *(reinterpret_cast<const int32_t *>(ptr)),
.seqSubNum = *(reinterpret_cast<const int32_t *>(ptr)),
.level = *(reinterpret_cast<const int32_t *>(ptr)),
.bitMap = *(reinterpret_cast<const int32_t *>(ptr)),
.tvCount = 1,
.tvList = &tv,
};
TransUdpChannelSendStream(channelId, &streamdata, &ext, &param);
SoftBusFree(ptr);
}
void TransUdpChannelSendFileTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
const char *sfileList[] = {
@ -99,21 +128,24 @@ namespace OHOS {
"/data/richu-002.jpg",
"/data/richu-003.jpg",
};
TransUdpChannelSendFile((int32_t)size, sfileList, NULL, (uint32_t)size);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
int32_t fileCnt = *(reinterpret_cast<const int32_t *>(data));
TransUdpChannelSendFile(channelId, sfileList, NULL, fileCnt);
}
void TransGetUdpChannelByFileIdTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
int32_t dfileId = *(reinterpret_cast<const int32_t *>(data));
UdpChannel udpChannel;
TransGetUdpChannelByFileId((int32_t)size, &udpChannel);
TransGetUdpChannelByFileId(dfileId, &udpChannel);
}
void TransUdpDeleteFileListenerlTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size < SESSION_NAME_SIZE_MAX)) {
if (data == nullptr || size < SESSION_NAME_SIZE_MAX) {
return;
}
char tmp[SESSION_NAME_SIZE_MAX + 1] = {0};
@ -127,6 +159,7 @@ namespace OHOS {
/* Fuzzer entry point */
extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::TransOnUdpChannelOpenedTest(data, size);
OHOS::TransOnUdpChannelOpenFailedTest(data, size);
OHOS::TransOnUdpChannelClosedTest(data, size);

View File

@ -18,46 +18,114 @@
#include <securec.h>
#include "client_trans_udp_stream_interface.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
namespace OHOS {
void SendVtpStreamTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int64_t)) {
return;
}
StreamData *indata = nullptr;
StreamData *ext = nullptr;
StreamFrameInfo *param = nullptr;
uint8_t *ptr = static_cast<uint8_t *>(SoftBusCalloc(size + 1));
if (ptr == nullptr) {
return;
}
if (memcpy_s(ptr, size, data, size) != EOK) {
SoftBusFree(ptr);
return;
}
int32_t channelId = *(reinterpret_cast<const int32_t *>(ptr));
StreamData streamdata = {
.buf = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
.bufLen = size,
};
StreamData ext = {
.buf = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
.bufLen = size,
};
TV tv = {
.type = *(reinterpret_cast<const int32_t *>(ptr)),
.value = *(reinterpret_cast<const int64_t *>(ptr)),
};
StreamFrameInfo param = {
.frameType = *(reinterpret_cast<const int32_t *>(ptr)),
.timeStamp = *(reinterpret_cast<const int32_t *>(ptr)),
.seqNum = *(reinterpret_cast<const int32_t *>(ptr)),
.seqSubNum = *(reinterpret_cast<const int32_t *>(ptr)),
.level = *(reinterpret_cast<const int32_t *>(ptr)),
.bitMap = *(reinterpret_cast<const int32_t *>(ptr)),
.tvCount = 1,
.tvList = &tv,
};
SendVtpStream(size, indata, ext, param);
SendVtpStream(channelId, &streamdata, &ext, &param);
SoftBusFree(ptr);
}
void StartVtpStreamChannelServerTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int64_t)) {
return;
}
VtpStreamOpenParam *param = nullptr;
uint8_t *ptr = static_cast<uint8_t *>(SoftBusCalloc(size + 1));
if (ptr == nullptr) {
return;
}
if (memcpy_s(ptr, size, data, size) != EOK) {
SoftBusFree(ptr);
return;
}
int32_t channelId = *(reinterpret_cast<const int32_t *>(ptr));
VtpStreamOpenParam param = {
.pkgName = reinterpret_cast<const char *>(ptr),
.myIp = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
.peerIp = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
.peerPort = *(reinterpret_cast<const int32_t *>(ptr)),
.type = *(reinterpret_cast<const StreamType *>(ptr)),
.sessionKey = const_cast<uint8_t *>(ptr),
.keyLen = *(reinterpret_cast<const uint32_t *>(ptr)),
.isRawStreamEncrypt = size % 2,
};
IStreamListener *callback = nullptr;
StartVtpStreamChannelServer(size, param, callback);
StartVtpStreamChannelServer(channelId, &param, callback);
SoftBusFree(ptr);
}
void StartVtpStreamChannelClientTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int64_t)) {
return;
}
VtpStreamOpenParam *param = nullptr;
uint8_t *ptr = static_cast<uint8_t *>(SoftBusCalloc(size + 1));
if (ptr == nullptr) {
return;
}
if (memcpy_s(ptr, size, data, size) != EOK) {
SoftBusFree(ptr);
return;
}
int32_t channelId = *(reinterpret_cast<const int32_t *>(ptr));
VtpStreamOpenParam param = {
.pkgName = reinterpret_cast<const char *>(ptr),
.myIp = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
.peerIp = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
.peerPort = *(reinterpret_cast<const int32_t *>(ptr)),
.type = *(reinterpret_cast<const StreamType *>(ptr)),
.sessionKey = const_cast<uint8_t *>(ptr),
.keyLen = *(reinterpret_cast<const uint32_t *>(ptr)),
.isRawStreamEncrypt = size % 2,
};
IStreamListener *callback = nullptr;
StartVtpStreamChannelClient(size, param, callback);
StartVtpStreamChannelClient(channelId, &param, callback);
SoftBusFree(ptr);
}
void CloseVtpStreamChannelTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size < PKG_NAME_SIZE_MAX)) {
if (data == nullptr || size < PKG_NAME_SIZE_MAX) {
return;
}
char tmp[PKG_NAME_SIZE_MAX + 1] = {0};

View File

@ -22,11 +22,11 @@
namespace OHOS {
void CloseSessionTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int)) {
return;
}
CloseSession(size);
int sessionId = *(reinterpret_cast<const int *>(data));
CloseSession(sessionId);
}
} // namespace OHOS

View File

@ -22,11 +22,12 @@
namespace OHOS {
void GetSessionSideTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int)) {
return;
}
int sessionId = *(reinterpret_cast<const int *>(data));
GetSessionSide(size);
GetSessionSide(sessionId);
}
} // namespace OHOS

View File

@ -23,12 +23,13 @@
namespace OHOS {
void QosReportTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
int32_t appType = 1;
int32_t quality = QOS_RECOVER;
QosReport(size, appType, quality);
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
int32_t appType = *(reinterpret_cast<const int32_t *>(data));
int32_t quality = *(reinterpret_cast<const int32_t *>(data));
QosReport(channelId, appType, quality);
}
} // namespace OHOS

View File

@ -22,13 +22,14 @@
namespace OHOS {
void SendFileTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
const char *sfileList[] = {};
const char *dFileList[] = {};
uint32_t fileCnt = 0;
SendFile(size, sfileList, dFileList, fileCnt);
int32_t sessionId = *(reinterpret_cast<const int32_t *>(data));
int32_t fileCnt = *(reinterpret_cast<const int32_t *>(data));
SendFile(sessionId, sfileList, dFileList, fileCnt);
}
} // namespace OHOS

View File

@ -17,25 +17,56 @@
#include <cstddef>
#include "securec.h"
#include "session.h"
#include "softbus_adapter_mem.h"
namespace OHOS {
void SendStreamTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
if (data == nullptr || size < sizeof(int64_t)) {
return;
}
StreamData streamData = {0};
StreamData ext = {0};
StreamFrameInfo param = {0};
SendStream(size, &streamData, &ext, &param);
uint8_t *ptr = static_cast<uint8_t *>(SoftBusCalloc(size + 1));
if (ptr == nullptr) {
return;
}
if (memcpy_s(ptr, size, data, size) != EOK) {
SoftBusFree(ptr);
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t *>(ptr));
StreamData streamdata = {
.buf = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
.bufLen = size,
};
StreamData ext = {
.buf = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
.bufLen = size,
};
TV tv = {
.type = *(reinterpret_cast<const int32_t *>(ptr)),
.value = *(reinterpret_cast<const int64_t *>(ptr)),
};
StreamFrameInfo param = {
.frameType = *(reinterpret_cast<const int32_t *>(ptr)),
.timeStamp = *(reinterpret_cast<const int32_t *>(ptr)),
.seqNum = *(reinterpret_cast<const int32_t *>(ptr)),
.seqSubNum = *(reinterpret_cast<const int32_t *>(ptr)),
.level = *(reinterpret_cast<const int32_t *>(ptr)),
.bitMap = *(reinterpret_cast<const int32_t *>(ptr)),
.tvCount = 1,
.tvList = &tv,
};
SendStream(sessionId, &streamdata, &ext, &param);
SoftBusFree(ptr);
}
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::SendStreamTest(data, size);
return 0;
}

View File

@ -26,26 +26,28 @@
namespace OHOS {
void InnerOnSessionOpenedTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int)) {
return;
}
int32_t result = SOFTBUS_OK;
int sessionId = *(reinterpret_cast<const int *>(data));
int result = *(reinterpret_cast<const int *>(data));
InnerOnSessionOpened(size, result);
InnerOnSessionOpened(sessionId, result);
}
void InnerOnSessionClosedTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int)) {
return;
}
int sessionId = *(reinterpret_cast<const int *>(data));
InnerOnSessionClosed(size);
InnerOnSessionClosed(sessionId);
}
void InnerOnBytesReceivedTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size == 0) {
return;
}
int32_t sessionId = SESSION_ID;
@ -55,7 +57,7 @@ namespace OHOS {
void InnerOnMessageReceivedTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size == 0) {
return;
}
int32_t sessionId = SESSION_ID;

View File

@ -15,6 +15,7 @@
#include "sessionmock_fuzzer.h"
#include "securec.h"
#include "session.h"
#include "session_mock.h"
#include <cstddef>
@ -26,8 +27,13 @@ void CreateSessionServerInnerTest(const uint8_t *data, size_t size)
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
char *charParam = const_cast<char *>(reinterpret_cast<const char *>(data));
#define SESSION_NAME_SIZE_MAX 256
char mySessionName[SESSION_NAME_SIZE_MAX] = "ohos.fuzz.dms.test";
if (memcpy_s(mySessionName, SESSION_NAME_SIZE_MAX, charParam, SESSION_NAME_SIZE_MAX - 1) != EOK) {
return;
}
mySessionName[SESSION_NAME_SIZE_MAX - 1] = '\0';
CreateSessionServerInner(nullptr, mySessionName);
}
@ -36,8 +42,13 @@ void RemoveSessionServerInnerTest(const uint8_t *data, size_t size)
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
char *charParam = const_cast<char *>(reinterpret_cast<const char *>(data));
#define SESSION_NAME_SIZE_MAX 256
char mySessionName[SESSION_NAME_SIZE_MAX] = "ohos.fuzz.dms.test";
if (memcpy_s(mySessionName, SESSION_NAME_SIZE_MAX, charParam, SESSION_NAME_SIZE_MAX - 1) != EOK) {
return;
}
mySessionName[SESSION_NAME_SIZE_MAX - 1] = '\0';
RemoveSessionServerInner(nullptr, mySessionName);
}
@ -47,6 +58,7 @@ void OpenSessionInnerTest(const uint8_t *data, size_t size)
return;
}
char *charParam = const_cast<char *>(reinterpret_cast<const char *>(data));
#define SESSION_NAME_SIZE_MAX 256
#define DEVICE_ID_SIZE_MAX 65
#define GROUP_ID_SIZE_MAX 65
@ -54,6 +66,22 @@ void OpenSessionInnerTest(const uint8_t *data, size_t size)
char peerSessionName[SESSION_NAME_SIZE_MAX] = "ohos.fuzz.dms.test";
char peerNetworkId[DEVICE_ID_SIZE_MAX] = "ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00";
char groupId[GROUP_ID_SIZE_MAX] = "TEST_GROUP_ID";
if (memcpy_s(mySessionName, SESSION_NAME_SIZE_MAX, charParam, SESSION_NAME_SIZE_MAX - 1) != EOK) {
return;
}
if (memcpy_s(peerSessionName, SESSION_NAME_SIZE_MAX, charParam, SESSION_NAME_SIZE_MAX - 1) != EOK) {
return;
}
if (memcpy_s(peerNetworkId, DEVICE_ID_SIZE_MAX, charParam, DEVICE_ID_SIZE_MAX - 1) != EOK) {
return;
}
if (memcpy_s(groupId, GROUP_ID_SIZE_MAX, charParam, GROUP_ID_SIZE_MAX - 1) != EOK) {
return;
}
mySessionName[SESSION_NAME_SIZE_MAX - 1] = '\0';
peerSessionName[SESSION_NAME_SIZE_MAX - 1] = '\0';
peerNetworkId[DEVICE_ID_SIZE_MAX - 1] = '\0';
groupId[GROUP_ID_SIZE_MAX - 1] = '\0';
OpenSessionInner(mySessionName, peerSessionName, peerNetworkId, groupId, size);
}
@ -80,9 +108,8 @@ void GrantPermissionInnerTest(const uint8_t *data, size_t size)
void RemovePermissionInnerTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size == 0) {
return;
}
(void)data;
(void)size;
RemovePermissionInner(nullptr);
}

View File

@ -26,11 +26,12 @@ using namespace std;
namespace OHOS {
void SetAliveStateDataTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
int32_t cnt = *(reinterpret_cast<const int32_t *>(data));
bool state;
if (size % STANDARD_NUMBER == 0) {
if (cnt % STANDARD_NUMBER == 0) {
state = true;
} else {
state = false;
@ -43,15 +44,26 @@ namespace OHOS {
void InitAdaptorTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(uint32_t)) {
return;
}
VtpStreamOpenParam *param = nullptr;
VtpStreamOpenParam param = {
.pkgName = reinterpret_cast<const char *>(data),
.myIp = const_cast<char *>(reinterpret_cast<const char *>(data)),
.peerIp = const_cast<char *>(reinterpret_cast<const char *>(data)),
.peerPort = *(reinterpret_cast<const int32_t *>(data)),
.type = *(reinterpret_cast<const StreamType *>(data)),
.sessionKey = const_cast<uint8_t *>(data),
.keyLen = *(reinterpret_cast<const uint32_t *>(data)),
.isRawStreamEncrypt = size % 2,
};
int32_t channelId = *(reinterpret_cast<const int32_t *>(data));
IStreamListener *callback = nullptr;
const std::string &pkgName = "ohos.msdp.spatialawareness";
bool isServerSide = size % 2;
OHOS::StreamAdaptor streamadaptor(pkgName);
streamadaptor.InitAdaptor(size, param, true, callback);
streamadaptor.InitAdaptor(channelId, &param, isServerSide, callback);
}
} // namespace OHOS

View File

@ -24,11 +24,14 @@ using namespace std;
namespace OHOS {
void SendTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int)) {
return;
}
Communication::SoftBus::HistoryStats stats;
stats.periodFrameNum = size;
stats.periodFrameNum = *(reinterpret_cast<const int *>(data));
stats.avgFrameInterval = *(reinterpret_cast<const int *>(data));
stats.minFrameInterval = *(reinterpret_cast<const int *>(data));
stats.maxFrameInterval = *(reinterpret_cast<const int *>(data));
Communication::SoftBus::StreamMsgManager streamMsgManager;
streamMsgManager.Send((const Communication::SoftBus::HistoryStats &)stats);
@ -36,11 +39,14 @@ namespace OHOS {
void RecvTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int)) {
return;
}
Communication::SoftBus::HistoryStats stats;
stats.periodFrameNum = size;
stats.periodFrameNum = *(reinterpret_cast<const int *>(data));
stats.avgFrameInterval = *(reinterpret_cast<const int *>(data));
stats.minFrameInterval = *(reinterpret_cast<const int *>(data));
stats.maxFrameInterval = *(reinterpret_cast<const int *>(data));
Communication::SoftBus::StreamMsgManager streamMsgManager;
streamMsgManager.Recv((const Communication::SoftBus::HistoryStats &)stats);
@ -48,11 +54,14 @@ namespace OHOS {
void UpdateTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int)) {
return;
}
Communication::SoftBus::HistoryStats stats;
stats.periodFrameNum = size;
stats.periodFrameNum = *(reinterpret_cast<const int *>(data));
stats.avgFrameInterval = *(reinterpret_cast<const int *>(data));
stats.minFrameInterval = *(reinterpret_cast<const int *>(data));
stats.maxFrameInterval = *(reinterpret_cast<const int *>(data));
Communication::SoftBus::StreamMsgManager streamMsgManager;
streamMsgManager.Update((const Communication::SoftBus::HistoryStats &)stats);

View File

@ -27,11 +27,11 @@ namespace OHOS {
void VtpCreateClientTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size < sizeof(int))) {
if (data == nullptr || size < sizeof(int)) {
return;
}
int32_t streamType = *(reinterpret_cast<const int*>(data));
int32_t streamType = *(reinterpret_cast<const int *>(data));
Communication::SoftBus::IpAndPort ipPort;
std::pair<uint8_t*, uint32_t> sessionKey = std::make_pair(nullptr, 0);
@ -41,11 +41,11 @@ namespace OHOS {
void VtpCreateServerTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size < sizeof(int))) {
if (data == nullptr || size < sizeof(int)) {
return;
}
int32_t streamType = *(reinterpret_cast<const int*>(data));
int32_t streamType = *(reinterpret_cast<const int *>(data));
Communication::SoftBus::IpAndPort ipPort;
std::pair<uint8_t*, uint32_t> sessionKey = std::make_pair(nullptr, 0);
@ -54,30 +54,31 @@ namespace OHOS {
void VtpDestroyStreamSocketTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
return;
}
(void)data;
(void)size;
vtpStreamSocket.DestroyStreamSocket();
}
void VtpConnectTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
if (data == nullptr || size < sizeof(int32_t)) {
return;
}
Communication::SoftBus::IpAndPort ipPort;
ipPort.ip = const_cast<char *>(reinterpret_cast<const char *>(data));
ipPort.port = *(reinterpret_cast<const int32_t *>(data));
vtpStreamSocket.Connect(ipPort);
}
void VtpSetOptionTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size < sizeof(int))) {
if (data == nullptr || size < sizeof(int)) {
return;
}
int32_t type = *(reinterpret_cast<const int*>(data));
int32_t type = *(reinterpret_cast<const int *>(data));
Communication::SoftBus::StreamAttr tmp;
vtpStreamSocket.SetOption(type, tmp);
@ -85,20 +86,19 @@ namespace OHOS {
void VtpGetOptionTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size < sizeof(int))) {
if (data == nullptr || size < sizeof(int)) {
return;
}
int32_t type = *(reinterpret_cast<const int*>(data));
int32_t type = *(reinterpret_cast<const int *>(data));
vtpStreamSocket.GetOption(type);
}
void VtpSetStreamListenerTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
return;
}
(void)data;
(void)size;
std::shared_ptr<Communication::SoftBus::IStreamSocketListener> receiver = nullptr;
@ -107,9 +107,8 @@ namespace OHOS {
void VtpGetEncryptOverheadTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
return;
}
(void)data;
(void)size;
vtpStreamSocket.GetEncryptOverhead();
}
@ -119,8 +118,10 @@ namespace OHOS {
if ((data == nullptr) || (size == 0)) {
return;
}
const void *in = reinterpret_cast<const void *>(data);
void *out = const_cast<void *>(reinterpret_cast<const void *>(data));
vtpStreamSocket.Encrypt(nullptr, size, nullptr, size);
vtpStreamSocket.Encrypt(in, size, out, size);
}
void VtpDecrypt(const uint8_t* data, size_t size)
@ -128,8 +129,10 @@ namespace OHOS {
if ((data == nullptr) || (size == 0)) {
return;
}
const void *in = reinterpret_cast<const void *>(data);
void *out = const_cast<void *>(reinterpret_cast<const void *>(data));
vtpStreamSocket.Decrypt(nullptr, size, nullptr, size);
vtpStreamSocket.Decrypt(in, size, out, size);
}
}