Add NULL pointer checks to IsStableUpdated(). (#1412)

This commit is contained in:
Jonathan Hui
2017-03-02 09:55:16 -08:00
committed by GitHub
parent 1babb7d379
commit b0085c3d92
+20 -14
View File
@@ -491,38 +491,44 @@ bool Leader::IsStableUpdated(uint16_t aRloc16, uint8_t *aTlvs, uint8_t aTlvsLeng
bool rval = false;
NetworkDataTlv *cur = reinterpret_cast<NetworkDataTlv *>(aTlvs);
NetworkDataTlv *end = reinterpret_cast<NetworkDataTlv *>(aTlvs + aTlvsLength);
PrefixTlv *prefix;
PrefixTlv *prefixBase;
BorderRouterTlv *borderRouter;
HasRouteTlv *hasRoute;
ContextTlv *context;
while (cur < end)
{
if (cur->GetType() == NetworkDataTlv::kTypePrefix)
{
prefix = static_cast<PrefixTlv *>(cur);
context = FindContext(*prefix);
borderRouter = FindBorderRouter(*prefix);
hasRoute = FindHasRoute(*prefix);
PrefixTlv *prefix = static_cast<PrefixTlv *>(cur);
ContextTlv *context = FindContext(*prefix);
BorderRouterTlv *borderRouter = FindBorderRouter(*prefix);
HasRouteTlv *hasRoute = FindHasRoute(*prefix);
if (cur->IsStable() && (!context || borderRouter))
{
prefixBase = FindPrefix(prefix->GetPrefix(), prefix->GetPrefixLength(), aTlvsBase, aTlvsBaseLength);
PrefixTlv *prefixBase = FindPrefix(prefix->GetPrefix(), prefix->GetPrefixLength(),
aTlvsBase, aTlvsBaseLength);
if (!prefixBase)
{
ExitNow(rval = true);
}
if (borderRouter && memcmp(borderRouter, FindBorderRouter(*prefixBase), borderRouter->GetLength()) != 0)
if (borderRouter)
{
ExitNow(rval = true);
BorderRouterTlv *borderRouterBase = FindBorderRouter(*prefixBase);
if (!borderRouterBase || memcmp(borderRouter, borderRouterBase, borderRouter->GetLength()) != 0)
{
ExitNow(rval = true);
}
}
if (hasRoute && (memcmp(hasRoute, FindHasRoute(*prefixBase), hasRoute->GetLength()) != 0))
if (hasRoute)
{
ExitNow(rval = true);
HasRouteTlv *hasRouteBase = FindHasRoute(*prefixBase);
if (!hasRouteBase || (memcmp(hasRoute, hasRouteBase, hasRoute->GetLength()) != 0))
{
ExitNow(rval = true);
}
}
}
}