int main(int argc, char *argv[]) { otInstance *instance; #if OPENTHREAD_EXAMPLES_POSIX if (setjmp(gResetJump)) { alarm(0); #if OPENTHREAD_ENABLE_COVERAGE __gcov_flush(); #endif execvp(argv[0], argv); } #endif #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES size_t otInstanceBufferLength = 0; uint8_t *otInstanceBuffer = NULL; #endif pseudo_reset: otSysInit(argc, argv); #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES // Call to query the buffer size (void)otInstanceInit(NULL, &otInstanceBufferLength); // Call to allocate the buffer otInstanceBuffer = (uint8_t *)malloc(otInstanceBufferLength); assert(otInstanceBuffer); // Initialize OpenThread with the buffer instance = otInstanceInit(otInstanceBuffer, &otInstanceBufferLength); #else instance = otInstanceInitSingle(); #endif assert(instance); otCliUartInit(instance); #if OPENTHREAD_ENABLE_DIAG otDiagInit(instance); #endif while (!otSysPseudoResetWasRequested()) { otTaskletsProcess(instance); otSysProcessDrivers(instance); } otInstanceFinalize(instance); #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES free(otInstanceBuffer); #endif goto pseudo_reset; return 0; }
int main(int argc, char *argv[]) { otInstance *sInstance; #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES size_t otInstanceBufferLength = 0; uint8_t *otInstanceBuffer = NULL; #endif pseudo_reset: PlatformInit(argc, argv); #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES // Call to query the buffer size (void)otInstanceInit(NULL, &otInstanceBufferLength); // Call to allocate the buffer otInstanceBuffer = (uint8_t *)malloc(otInstanceBufferLength); assert(otInstanceBuffer); // Initialize OpenThread with the buffer sInstance = otInstanceInit(otInstanceBuffer, &otInstanceBufferLength); #else sInstance = otInstanceInitSingle(); #endif assert(sInstance); otNcpInit(sInstance); #if OPENTHREAD_ENABLE_DIAG otDiagInit(sInstance); #endif while (!PlatformPseudoResetWasRequested()) { otTaskletsProcess(sInstance); PlatformProcessDrivers(sInstance); } otInstanceFinalize(sInstance); #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES free(otInstanceBuffer); #endif goto pseudo_reset; return 0; }
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { const otPanId panId = 0xdead; otInstance * instance = NULL; otMessage * message = NULL; otError error = OT_ERROR_NONE; otMessageSettings settings; VerifyOrExit(size > 0); FuzzerPlatformInit(); instance = otInstanceInitSingle(); otLinkSetPanId(instance, panId); otIp6SetEnabled(instance, true); otThreadSetEnabled(instance, true); otThreadBecomeLeader(instance); settings.mLinkSecurityEnabled = (data[0] & 0x1) != 0; settings.mPriority = OT_MESSAGE_PRIORITY_NORMAL; message = otIp6NewMessage(instance, &settings); VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); error = otMessageAppend(message, data + 1, static_cast<uint16_t>(size - 1)); SuccessOrExit(error); error = otIp6Send(instance, message); message = NULL; exit: if (message != NULL) { otMessageFree(message); } if (instance != NULL) { otInstanceFinalize(instance); } return 0; }