[fuzz] reset state on each invocation (#2130)

This commit is contained in:
Jonathan Hui
2017-08-23 14:45:26 -07:00
committed by GitHub
parent 7804396588
commit 5c52373c99
3 changed files with 26 additions and 31 deletions
+5
View File
@@ -37,6 +37,11 @@
static uint32_t sRandomState = 1;
void FuzzerPlatformInit(void)
{
sRandomState = 1;
}
uint32_t otPlatAlarmMilliGetNow(void)
{
return 0;
+11 -16
View File
@@ -38,32 +38,27 @@
#include "common/code_utils.hpp"
static otInstance *sInstance;
extern "C" void FuzzerPlatformInit(void);
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
const otPanId panId = 0xdead;
otInstance *sInstance;
otMessage *message = NULL;
otError error = OT_ERROR_NONE;
bool isSecure;
VerifyOrExit(size > 0);
FuzzerPlatformInit();
sInstance = otInstanceInitSingle();
otLinkSetPanId(sInstance, panId);
otIp6SetEnabled(sInstance, true);
otThreadSetEnabled(sInstance, true);
otThreadBecomeLeader(sInstance);
(void)argc;
(void)argv;
return 0;
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
otMessage *message = NULL;
otError error = OT_ERROR_NONE;
bool isSecure;
VerifyOrExit(size > 0);
isSecure = (data[0] & 0x1) != 0;
message = otIp6NewMessage(sInstance, isSecure);
+10 -15
View File
@@ -39,31 +39,26 @@
#include "common/code_utils.hpp"
static otInstance *sInstance;
extern "C" void FuzzerPlatformInit(void);
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
const otPanId panId = 0xdead;
otInstance *sInstance;
otRadioFrame frame;
uint8_t *buf;
VerifyOrExit(size <= OT_RADIO_FRAME_MAX_SIZE);
FuzzerPlatformInit();
sInstance = otInstanceInitSingle();
otLinkSetPanId(sInstance, panId);
otIp6SetEnabled(sInstance, true);
otThreadSetEnabled(sInstance, true);
otThreadBecomeLeader(sInstance);
(void)argc;
(void)argv;
return 0;
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
otRadioFrame frame;
uint8_t *buf;
VerifyOrExit(size <= OT_RADIO_FRAME_MAX_SIZE);
buf = static_cast<uint8_t *>(malloc(size));
memset(&frame, 0, sizeof(frame));