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 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) {