mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 06:20:07 +00:00
add dms FUZZ
Signed-off-by: c30051536 <chenbin179@huawei.com>
This commit is contained in:
parent
360c22962a
commit
2dc0efc6be
@ -20,38 +20,114 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
constexpr uint32_t MIN_SIZE = 38;
|
||||
constexpr uint32_t UINT32_T_OFFSET = 4;
|
||||
constexpr uint32_t ENUM_OFFSET = 4;
|
||||
constexpr uint32_t BOOL_OFFSET = 1;
|
||||
constexpr uint32_t INT32_T_OFFSET = 4;
|
||||
constexpr uint32_t CHAR_PONTER_OFFSET = 4;
|
||||
}
|
||||
|
||||
void FuzzApplyAdvanceResource(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(uint32_t))) {
|
||||
if ((data == nullptr) || (size < MIN_SIZE)) {
|
||||
return;
|
||||
}
|
||||
const std::string peerNetworkId(reinterpret_cast<const char*>(data), size);
|
||||
ServiceCollaborationManager_ResourceRequestInfoSets reqInfoSets;
|
||||
|
||||
reqInfoSets.remoteHardwareListSize = *(reinterpret_cast<const uint32_t*>(data));
|
||||
reqInfoSets.localHardwareListSize = *(reinterpret_cast<const uint32_t*>(data));
|
||||
|
||||
ServiceCollaborationManager_HardwareRequestInfo remoteHardwareListTemp;
|
||||
uint32_t offset = UINT32_T_OFFSET;
|
||||
remoteHardwareListTemp.hardWareType =
|
||||
*(reinterpret_cast<const ServiceCollaborationManagerHardwareType*>(data + offset));
|
||||
offset += ENUM_OFFSET;
|
||||
remoteHardwareListTemp.canShare = *(reinterpret_cast<const bool*>(data + offset));
|
||||
offset += BOOL_OFFSET;
|
||||
reqInfoSets.remoteHardwareList = &remoteHardwareListTemp;
|
||||
|
||||
reqInfoSets.localHardwareListSize = *(reinterpret_cast<const uint32_t*>(data + offset));
|
||||
offset += UINT32_T_OFFSET;
|
||||
|
||||
ServiceCollaborationManager_HardwareRequestInfo localHardwareListTemp;
|
||||
localHardwareListTemp.hardWareType =
|
||||
*(reinterpret_cast<const ServiceCollaborationManagerHardwareType*>(data + offset));
|
||||
offset += ENUM_OFFSET;
|
||||
localHardwareListTemp.canShare = *(reinterpret_cast<const bool*>(data + offset));
|
||||
offset += BOOL_OFFSET;
|
||||
reqInfoSets.localHardwareList = &localHardwareListTemp;
|
||||
|
||||
ServiceCollaborationManager_CommunicationRequestInfo communicationRequestTemp;
|
||||
communicationRequestTemp.minBandwidth = *(reinterpret_cast<const int32_t*>(data + offset));
|
||||
offset += INT32_T_OFFSET;
|
||||
communicationRequestTemp.maxLatency = *(reinterpret_cast<const int32_t*>(data + offset));
|
||||
offset += INT32_T_OFFSET;
|
||||
communicationRequestTemp.minLatency = *(reinterpret_cast<const int32_t*>(data + offset));
|
||||
offset += INT32_T_OFFSET;
|
||||
communicationRequestTemp.maxWaitTime = *(reinterpret_cast<const int32_t*>(data + offset));
|
||||
offset += INT32_T_OFFSET;
|
||||
communicationRequestTemp.dataType = reinterpret_cast<const char*>(data + offset);
|
||||
offset += CHAR_PONTER_OFFSET;
|
||||
reqInfoSets.communicationRequest = &communicationRequestTemp;
|
||||
|
||||
const std::string peerNetworkId(reinterpret_cast<const char*>(data + offset), size - MIN_SIZE);
|
||||
DSchedAllConnectManager::GetInstance().ApplyAdvanceResource(peerNetworkId, reqInfoSets);
|
||||
}
|
||||
|
||||
void FuzzGetResourceRequest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(uint32_t))) {
|
||||
if ((data == nullptr) || (size < MIN_SIZE)) {
|
||||
return;
|
||||
}
|
||||
ServiceCollaborationManager_ResourceRequestInfoSets reqInfoSets;
|
||||
|
||||
reqInfoSets.remoteHardwareListSize = *(reinterpret_cast<const uint32_t*>(data));
|
||||
reqInfoSets.localHardwareListSize = *(reinterpret_cast<const uint32_t*>(data));
|
||||
|
||||
ServiceCollaborationManager_HardwareRequestInfo remoteHardwareListTemp;
|
||||
uint32_t offset = UINT32_T_OFFSET;
|
||||
remoteHardwareListTemp.hardWareType =
|
||||
*(reinterpret_cast<const ServiceCollaborationManagerHardwareType*>(data + offset));
|
||||
offset += ENUM_OFFSET;
|
||||
remoteHardwareListTemp.canShare = *(reinterpret_cast<const bool*>(data + offset));
|
||||
offset += BOOL_OFFSET;
|
||||
reqInfoSets.remoteHardwareList = &remoteHardwareListTemp;
|
||||
|
||||
reqInfoSets.localHardwareListSize = *(reinterpret_cast<const uint32_t*>(data + offset));
|
||||
offset += UINT32_T_OFFSET;
|
||||
|
||||
ServiceCollaborationManager_HardwareRequestInfo localHardwareListTemp;
|
||||
localHardwareListTemp.hardWareType =
|
||||
*(reinterpret_cast<const ServiceCollaborationManagerHardwareType*>(data + offset));
|
||||
offset += ENUM_OFFSET;
|
||||
localHardwareListTemp.canShare = *(reinterpret_cast<const bool*>(data + offset));
|
||||
offset += BOOL_OFFSET;
|
||||
reqInfoSets.localHardwareList = &localHardwareListTemp;
|
||||
|
||||
ServiceCollaborationManager_CommunicationRequestInfo communicationRequestTemp;
|
||||
communicationRequestTemp.minBandwidth = *(reinterpret_cast<const int32_t*>(data + offset));
|
||||
offset += INT32_T_OFFSET;
|
||||
communicationRequestTemp.maxLatency = *(reinterpret_cast<const int32_t*>(data + offset));
|
||||
offset += INT32_T_OFFSET;
|
||||
communicationRequestTemp.minLatency = *(reinterpret_cast<const int32_t*>(data + offset));
|
||||
offset += INT32_T_OFFSET;
|
||||
communicationRequestTemp.maxWaitTime = *(reinterpret_cast<const int32_t*>(data + offset));
|
||||
offset += INT32_T_OFFSET;
|
||||
communicationRequestTemp.dataType = reinterpret_cast<const char*>(data + offset);
|
||||
reqInfoSets.communicationRequest = &communicationRequestTemp;
|
||||
DSchedAllConnectManager::GetInstance().GetResourceRequest(reqInfoSets);
|
||||
}
|
||||
|
||||
void FuzzPublishServiceState(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(uint32_t))) {
|
||||
if ((data == nullptr) || (size < sizeof(size_t))) {
|
||||
return;
|
||||
}
|
||||
const std::string peerNetworkId(reinterpret_cast<const char*>(data), size);
|
||||
const std::string extraInfo(reinterpret_cast<const char*>(data), size);
|
||||
uint8_t* temp = const_cast<uint8_t*>(data);
|
||||
ServiceCollaborationManagerBussinessStatus state =
|
||||
*(reinterpret_cast<const ServiceCollaborationManagerBussinessStatus*>(data));
|
||||
*(reinterpret_cast<ServiceCollaborationManagerBussinessStatus*>(temp));
|
||||
DSchedAllConnectManager::GetInstance().PublishServiceState(peerNetworkId, extraInfo, state);
|
||||
}
|
||||
}
|
||||
|
@ -17,23 +17,62 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <securec.h>
|
||||
|
||||
#include "dsched_data_buffer.h"
|
||||
#include "dsched_softbus_session.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
static const uint32_t DSCHED_MAX_BUFFER_SIZE = 80 * 1024 * 1024;
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr int32_t POS_0 = 0;
|
||||
constexpr int32_t POS_1 = 1;
|
||||
constexpr int32_t POS_2 = 2;
|
||||
constexpr int32_t POS_3 = 3;
|
||||
constexpr int32_t OFFSET_24 = 24;
|
||||
constexpr int32_t OFFSET_16 = 16;
|
||||
constexpr int32_t OFFSET_8 = 8;
|
||||
}
|
||||
|
||||
int32_t Get32Data(const uint8_t* ptr, size_t size)
|
||||
{
|
||||
if (size > FOO_MAX_LEN || size < U32_AT_SIZE) {
|
||||
return 0;
|
||||
}
|
||||
char *ch = static_cast<char*>(malloc(size + 1));
|
||||
if (ch == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
(void)memset_s(ch, size + 1, 0x00, size + 1);
|
||||
if (memcpy_s(ch, size + 1, ptr, size) != EOK) {
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
int32_t data = (ch[POS_0] << OFFSET_24) | (ch[POS_1] << OFFSET_16) | (ch[POS_2] << OFFSET_8) | ch[POS_3];
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return data;
|
||||
}
|
||||
|
||||
void FuzzOnBytesReceived(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
if ((data == nullptr) || (size < U32_AT_SIZE)) {
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<DSchedDataBuffer> buffer = std::make_shared<DSchedDataBuffer>(size);
|
||||
size_t intParam = static_cast<size_t>(Get32Data(data, size));
|
||||
if (intParam >= DSCHED_MAX_BUFFER_SIZE) {
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<DSchedDataBuffer> buffer = std::make_shared<DSchedDataBuffer>(intParam);
|
||||
DSchedSoftbusSession dschedSoftbusSession;
|
||||
dschedSoftbusSession.OnBytesReceived(buffer);
|
||||
dschedSoftbusSession.OnConnect();
|
||||
dschedSoftbusSession.GetPeerDeviceId();
|
||||
int32_t dataType = *(reinterpret_cast<const int32_t*>(data));
|
||||
int32_t dataType = Get32Data(data, size);
|
||||
dschedSoftbusSession.SendData(buffer, dataType);
|
||||
dschedSoftbusSession.OnDisconnect();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user