mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-27 02:10:33 +00:00
!3397 Init Fuzz用例告警修改
Merge pull request !3397 from 陈其文/HM_FuzzTestWarningDeal
This commit is contained in:
commit
3178a19c39
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user