Avoid calling rpl_lock_parent for uninitialized memory. Renamed p to parent to make reading easier.

This commit is contained in:
Nicolas Tsiftes 2014-03-27 15:55:38 +01:00
parent 1c560fb9db
commit 7f4d3e3d7b

View File

@ -583,10 +583,11 @@ dao_input(void)
int len; int len;
int i; int i;
int learned_from; int learned_from;
rpl_parent_t *p; rpl_parent_t *parent;
uip_ds6_nbr_t *nbr; uip_ds6_nbr_t *nbr;
prefixlen = 0; prefixlen = 0;
parent = NULL;
uip_ipaddr_copy(&dao_sender_addr, &UIP_IP_BUF->srcipaddr); 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"); learned_from == RPL_ROUTE_FROM_UNICAST_DAO? "unicast": "multicast");
if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) { if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
/* Check whether this is a DAO forwarding loop. */ /* 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 */ /* check if this is a new DAO registration with an "illegal" rank */
/* if we already route to this node it is likely */ /* if we already route to this node it is likely */
if(p != NULL && if(parent != NULL &&
DAG_RANK(p->rank, instance) < DAG_RANK(dag->rank, instance)) { 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", 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)); DAG_RANK(parent->rank, instance), DAG_RANK(dag->rank, instance));
p->rank = INFINITE_RANK; parent->rank = INFINITE_RANK;
p->updated = 1; parent->updated = 1;
return; return;
} }
/* If we get the DAO from our parent, we also have a loop. */ /* 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"); PRINTF("RPL: Loop detected when receiving a unicast DAO from our parent\n");
p->rank = INFINITE_RANK; parent->rank = INFINITE_RANK;
p->updated = 1; parent->updated = 1;
return; return;
} }
} }
@ -756,7 +757,7 @@ dao_input(void)
PRINTF("RPL: Neighbor already in neighbor cache\n"); 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); rep = rpl_add_route(dag, &prefix, prefixlen, &dao_sender_addr);
if(rep == NULL) { if(rep == NULL) {