!3397 Init Fuzz用例告警修改

Merge pull request !3397 from 陈其文/HM_FuzzTestWarningDeal
This commit is contained in:
openharmony_ci 2024-11-23 03:43:58 +00:00 committed by Gitee
commit 3178a19c39
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 88 additions and 7 deletions

View File

@ -15,15 +15,42 @@
#include "buildcontrolmessage_fuzzer.h"
#include <string>
#include "securec.h"
#include "fd_holder_internal.h"
namespace OHOS {
const uint8_t* BASE_DATA = nullptr;
size_t g_baseSize = 0;
size_t g_basePos;
template <class T> T GetData()
{
T object{};
size_t objectSize = sizeof(object);
if ((BASE_DATA == nullptr) || (objectSize > g_baseSize - g_basePos)) {
return object;
}
errno_t ret = memcpy_s(&object, objectSize, BASE_DATA + g_basePos, objectSize);
if (ret != EOK) {
return {};
}
g_basePos += objectSize;
return object;
}
bool FuzzBuildControlMessage(const uint8_t* data, size_t size)
{
bool result = false;
if (!BuildControlMessage(nullptr, nullptr, 1, false)) {
result = true;
BASE_DATA = data;
g_baseSize = size;
g_basePos = 0;
if (size > sizeof(struct msghdr) + sizeof(int)) {
struct msghdr msghdr = GetData<struct msghdr>();
int fd = GetData<int>();
if (!BuildControlMessage(&msghdr, &fd, 1, false)) {
result = true;
}
}
return result;
}

View File

@ -15,12 +15,38 @@
#include "cmdserviceprocessdelclient_fuzzer.h"
#include <string>
#include "securec.h"
#include "control_fd.h"
namespace OHOS {
const uint8_t *BASE_DATA = nullptr;
size_t g_baseSize = 0;
size_t g_basePos;
template <class T> T GetData()
{
T object{};
size_t objectSize = sizeof(object);
if ((BASE_DATA == nullptr) || (objectSize > g_baseSize - g_basePos)) {
return object;
}
errno_t ret = memcpy_s(&object, objectSize, BASE_DATA + g_basePos, objectSize);
if (ret != EOK) {
return {};
}
g_basePos += objectSize;
return object;
}
bool FuzzCmdServiceProcessDelClient(const uint8_t* data, size_t size)
{
CmdServiceProcessDelClient(1);
BASE_DATA = data;
g_baseSize = size;
g_basePos = 0;
if (size > sizeof(pid_t)) {
pid_t pid = GetData<pid_t>();
CmdServiceProcessDelClient(pid);
}
return true;
}
}

View File

@ -14,12 +14,15 @@
*/
#include "modulemgrdestroy_fuzzer.h"
#include <string>
#include "modulemgr.h"
namespace OHOS {
bool FuzzModuleMgrDestroy(const uint8_t* data, size_t size)
{
ModuleMgrDestroy(nullptr);
std::string name(reinterpret_cast<const char*>(data), size);
MODULE_MGR *moduleMgr = ModuleMgrCreate(name.c_str());
ModuleMgrDestroy(moduleMgr);
return true;
}
}

View File

@ -15,15 +15,40 @@
#include "receivefds_fuzzer.h"
#include <string>
#include "securec.h"
#include "fd_holder_internal.h"
namespace OHOS {
const uint8_t* BASE_DATA = nullptr;
size_t g_baseSize = 0;
size_t g_basePos;
template <class T> T GetData()
{
T object{};
size_t objectSize = sizeof(object);
if ((BASE_DATA == nullptr) || (objectSize > g_baseSize - g_basePos)) {
return object;
}
errno_t ret = memcpy_s(&object, objectSize, BASE_DATA + g_basePos, objectSize);
if (ret != EOK) {
return {};
}
g_basePos += objectSize;
return object;
}
bool FuzzReceiveFds(const uint8_t* data, size_t size)
{
bool result = false;
struct iovec iovec = {};
if (!ReceiveFds(1, iovec, nullptr, false, nullptr)) {
result = true;
BASE_DATA = data;
g_baseSize = size;
g_basePos = 0;
if (size > sizeof(struct iovec)) {
struct iovec iovec = GetData<struct iovec>();
if (!ReceiveFds(1, iovec, nullptr, false, nullptr)) {
result = true;
}
}
return result;
}