From 7f4d3e3d7b3f4b1557f9f2848081db2b898d2055 Mon Sep 17 00:00:00 2001 From: Nicolas Tsiftes Date: Thu, 27 Mar 2014 15:55:38 +0100 Subject: [PATCH] Avoid calling rpl_lock_parent for uninitialized memory. Renamed p to parent to make reading easier. --- core/net/rpl/rpl-icmp6.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/net/rpl/rpl-icmp6.c b/core/net/rpl/rpl-icmp6.c index c1cc6060b..d1ff56837 100644 --- a/core/net/rpl/rpl-icmp6.c +++ b/core/net/rpl/rpl-icmp6.c @@ -583,10 +583,11 @@ dao_input(void) int len; int i; int learned_from; - rpl_parent_t *p; + rpl_parent_t *parent; uip_ds6_nbr_t *nbr; prefixlen = 0; + parent = NULL; uip_ipaddr_copy(&dao_sender_addr, &UIP_IP_BUF->srcipaddr); @@ -634,23 +635,23 @@ dao_input(void) learned_from == RPL_ROUTE_FROM_UNICAST_DAO? "unicast": "multicast"); if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) { /* Check whether this is a DAO forwarding loop. */ - p = rpl_find_parent(dag, &dao_sender_addr); + parent = rpl_find_parent(dag, &dao_sender_addr); /* check if this is a new DAO registration with an "illegal" rank */ /* if we already route to this node it is likely */ - if(p != NULL && - DAG_RANK(p->rank, instance) < DAG_RANK(dag->rank, instance)) { + if(parent != NULL && + DAG_RANK(parent->rank, instance) < DAG_RANK(dag->rank, instance)) { PRINTF("RPL: Loop detected when receiving a unicast DAO from a node with a lower rank! (%u < %u)\n", - DAG_RANK(p->rank, instance), DAG_RANK(dag->rank, instance)); - p->rank = INFINITE_RANK; - p->updated = 1; + DAG_RANK(parent->rank, instance), DAG_RANK(dag->rank, instance)); + parent->rank = INFINITE_RANK; + parent->updated = 1; return; } /* If we get the DAO from our parent, we also have a loop. */ - if(p != NULL && p == dag->preferred_parent) { + if(parent != NULL && parent == dag->preferred_parent) { PRINTF("RPL: Loop detected when receiving a unicast DAO from our parent\n"); - p->rank = INFINITE_RANK; - p->updated = 1; + parent->rank = INFINITE_RANK; + parent->updated = 1; return; } } @@ -756,7 +757,7 @@ dao_input(void) PRINTF("RPL: Neighbor already in neighbor cache\n"); } - rpl_lock_parent(p); + rpl_lock_parent(parent); rep = rpl_add_route(dag, &prefix, prefixlen, &dao_sender_addr); if(rep == NULL) {