Bugfix: must copy the sender and receiver addresses from the packetbuf buffer, otherwise an application program may overwrite them

This commit is contained in:
adamdunkels 2009-05-10 21:10:02 +00:00
parent fe5a1f1068
commit 02734c9806

View file

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: multihop.c,v 1.5 2009/04/28 14:01:46 adamdunkels Exp $ * $Id: multihop.c,v 1.6 2009/05/10 21:10:02 adamdunkels Exp $
*/ */
/** /**
@ -70,6 +70,13 @@ data_packet_received(struct unicast_conn *uc, rimeaddr_t *from)
{ {
struct multihop_conn *c = (struct multihop_conn *)uc; struct multihop_conn *c = (struct multihop_conn *)uc;
rimeaddr_t *nexthop; rimeaddr_t *nexthop;
rimeaddr_t sender, receiver;
/* Copy the packet attributes to avoid them being overwritten or
cleared by an application program that uses the packet buffer for
its own needs. */
rimeaddr_copy(&sender, packetbuf_addr(PACKETBUF_ADDR_ESENDER));
rimeaddr_copy(&receiver, packetbuf_addr(PACKETBUF_ADDR_ERECEIVER));
PRINTF("data_packet_received from %d.%d towards %d.%d len %d\n", PRINTF("data_packet_received from %d.%d towards %d.%d len %d\n",
from->u8[0], from->u8[1], from->u8[0], from->u8[1],
@ -81,15 +88,13 @@ data_packet_received(struct unicast_conn *uc, rimeaddr_t *from)
&rimeaddr_node_addr)) { &rimeaddr_node_addr)) {
PRINTF("for us!\n"); PRINTF("for us!\n");
if(c->cb->recv) { if(c->cb->recv) {
c->cb->recv(c, packetbuf_addr(PACKETBUF_ADDR_ESENDER), from, c->cb->recv(c, &sender, from,
packetbuf_attr(PACKETBUF_ATTR_HOPS)); packetbuf_attr(PACKETBUF_ATTR_HOPS));
} }
} else { } else {
nexthop = NULL; nexthop = NULL;
if(c->cb->forward) { if(c->cb->forward) {
nexthop = c->cb->forward(c, nexthop = c->cb->forward(c, &sender, &receiver,
packetbuf_addr(PACKETBUF_ADDR_ESENDER),
packetbuf_addr(PACKETBUF_ADDR_ERECEIVER),
from, packetbuf_attr(PACKETBUF_ATTR_HOPS)); from, packetbuf_attr(PACKETBUF_ATTR_HOPS));
packetbuf_set_attr(PACKETBUF_ATTR_HOPS, packetbuf_set_attr(PACKETBUF_ATTR_HOPS,