Mpl Static Global was uninitialzed. (#359)

This resulted in a crash when pinging the mesh local address.
This commit is contained in:
MatthewCoppola4
2016-08-10 11:07:48 -07:00
committed by Jonathan Hui
parent ba813c2ac3
commit c7f62aa235
3 changed files with 18 additions and 3 deletions
+11 -3
View File
@@ -35,6 +35,7 @@
#include <common/debug.hpp>
#include <common/logging.hpp>
#include <common/message.hpp>
#include <common/new.hpp>
#include <net/icmp6.hpp>
#include <net/ip6.hpp>
#include <net/ip6_address.hpp>
@@ -46,7 +47,9 @@
namespace Thread {
namespace Ip6 {
static Mpl sMpl;
static otDEFINE_ALIGNED_VAR(sMplBuf, sizeof(Mpl), uint64_t);
static Mpl *sMpl;
static otReceiveIp6DatagramCallback sReceiveIp6DatagramCallback = NULL;
static ThreadError ForwardMessage(Message &message, MessageInfo &messageInfo);
@@ -57,6 +60,11 @@ Message *Ip6::NewMessage(uint16_t reserved)
sizeof(Header) + sizeof(HopByHopHeader) + sizeof(OptionMpl) + reserved);
}
void Ip6::Init(void)
{
sMpl = new(&sMplBuf) Mpl;
}
uint16_t Ip6::UpdateChecksum(uint16_t checksum, uint16_t val)
{
uint16_t result = checksum + val;
@@ -105,7 +113,7 @@ ThreadError AddMplOption(Message &message, Header &header, IpProto nextHeader, u
hbhHeader.SetNextHeader(nextHeader);
hbhHeader.SetLength(0);
sMpl.InitOption(mplOption, HostSwap16(header.GetSource().mFields.m16[7]));
sMpl->InitOption(mplOption, HostSwap16(header.GetSource().mFields.m16[7]));
SuccessOrExit(error = message.Prepend(&mplOption, sizeof(mplOption)));
SuccessOrExit(error = message.Prepend(&hbhHeader, sizeof(hbhHeader)));
header.SetPayloadLength(sizeof(hbhHeader) + sizeof(mplOption) + payloadLength);
@@ -198,7 +206,7 @@ ThreadError HandleOptions(Message &message)
switch (optionHeader.GetType())
{
case OptionMpl::kType:
SuccessOrExit(error = sMpl.ProcessOption(message));
SuccessOrExit(error = sMpl->ProcessOption(message));
break;
default: