!463 fuzz告警清理

Merge pull request !463 from 王静/master
This commit is contained in:
openharmony_ci 2024-11-22 08:46:53 +00:00 committed by Gitee
commit 82c2439317
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -21,17 +21,42 @@
#include "blob.h"
#include "rand.h"
#include "result.h"
#include "securec.h"
const uint8_t* g_baseFuzzData = nullptr;
size_t g_baseFuzzSize = 0;
size_t g_baseFuzzPos = 0;
template<class T>
T GetDate()
{
T object{};
size_t objectSize = sizeof(T);
if (g_baseFuzzData == nullptr || objectSize > g_baseFuzzSize - g_baseFuzzPos) {
return object;
}
errno_t ret = memcpy_s(&object, objectSize, g_baseFuzzData + g_baseFuzzPos, objectSize);
if (ret != EOK) {
return {};
}
g_baseFuzzPos += objectSize;
return object;
}
namespace OHOS {
bool HcfRandCreateFuzzTest(const uint8_t* data, size_t size)
{
g_baseFuzzData = data;
g_baseFuzzSize = size;
g_baseFuzzPos = 0;
int32_t numBytes = GetDate<int32_t>();
HcfRand *randObj = nullptr;
HcfResult res = HcfRandCreate(&randObj);
if (res != HCF_SUCCESS) {
return false;
}
struct HcfBlob randomBlob = { 0 };
(void)randObj->generateRandom(randObj, size, &randomBlob);
(void)randObj->generateRandom(randObj, numBytes, &randomBlob);
struct HcfBlob seedBlob = { 0 };
(void)randObj->setSeed(randObj, &seedBlob);
(void)randObj->getAlgoName(randObj);