[fuzz] enable Thread protocols and set state to Leader (#2067)

This commit:

- Enables Thread-related protocols and sets the device role state to Leader
  in fuzz tests.

- Bypasses AES-CCM decryption and authentication in fuzz tests.
This commit is contained in:
Jonathan Hui
2017-08-04 16:06:59 -07:00
committed by GitHub
parent 97e957b14a
commit 71d40a5c83
3 changed files with 20 additions and 6 deletions
+4
View File
@@ -2073,13 +2073,17 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn
{
length = aMessage.Read(aMessage.GetOffset(), sizeof(buf), buf);
aesCcm.Payload(buf, buf, length, false);
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
aMessage.Write(aMessage.GetOffset(), length, buf);
#endif
aMessage.MoveOffset(length);
}
tagLength = sizeof(tag);
aesCcm.Finalize(tag, &tagLength);
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
VerifyOrExit(messageTagLength == tagLength && memcmp(messageTag, tag, tagLength) == 0);
#endif
if (keySequence > netif.GetKeyManager().GetCurrentKeySequence())
{
+8 -3
View File
@@ -33,6 +33,7 @@
#include <openthread/link.h>
#include <openthread/message.h>
#include <openthread/thread.h>
#include <openthread/thread_ftd.h>
#include <openthread/types.h>
#include "common/code_utils.hpp"
@@ -41,12 +42,16 @@ static otInstance *sInstance;
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
{
(void)argc;
(void)argv;
const otPanId panId = 0xdead;
sInstance = otInstanceInitSingle();
otLinkSetPanId(sInstance, (otPanId)0xdead);
otLinkSetPanId(sInstance, panId);
otIp6SetEnabled(sInstance, true);
otThreadSetEnabled(sInstance, true);
otThreadBecomeLeader(sInstance);
(void)argc;
(void)argv;
return 0;
}
+8 -3
View File
@@ -33,6 +33,7 @@
#include <openthread/ip6.h>
#include <openthread/link.h>
#include <openthread/thread.h>
#include <openthread/thread_ftd.h>
#include <openthread/types.h>
#include <openthread/platform/radio.h>
@@ -42,12 +43,16 @@ static otInstance *sInstance;
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
{
(void)argc;
(void)argv;
const otPanId panId = 0xdead;
sInstance = otInstanceInitSingle();
otLinkSetPanId(sInstance, (otPanId)0xdead);
otLinkSetPanId(sInstance, panId);
otIp6SetEnabled(sInstance, true);
otThreadSetEnabled(sInstance, true);
otThreadBecomeLeader(sInstance);
(void)argc;
(void)argv;
return 0;
}