Added check to not copy or create too large packets
This commit is contained in:
parent
a04372adc4
commit
6c86398778
1 changed files with 6 additions and 2 deletions
|
@ -33,7 +33,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: packetbuf.c,v 1.8 2010/04/26 22:05:40 nifi Exp $
|
* $Id: packetbuf.c,v 1.9 2010/05/02 14:59:11 nifi Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,6 +159,10 @@ packetbuf_copyto(void *to)
|
||||||
PRINTF("packetbuf_write: data: %s\n", buffer);
|
PRINTF("packetbuf_write: data: %s\n", buffer);
|
||||||
}
|
}
|
||||||
#endif /* DEBUG_LEVEL */
|
#endif /* DEBUG_LEVEL */
|
||||||
|
if(PACKETBUF_HDR_SIZE - hdrptr + buflen > PACKETBUF_SIZE) {
|
||||||
|
/* Too large packet */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
memcpy(to, packetbuf + hdrptr, PACKETBUF_HDR_SIZE - hdrptr);
|
memcpy(to, packetbuf + hdrptr, PACKETBUF_HDR_SIZE - hdrptr);
|
||||||
memcpy((uint8_t *)to + PACKETBUF_HDR_SIZE - hdrptr, packetbufptr + bufptr,
|
memcpy((uint8_t *)to + PACKETBUF_HDR_SIZE - hdrptr, packetbufptr + bufptr,
|
||||||
buflen);
|
buflen);
|
||||||
|
@ -168,7 +172,7 @@ packetbuf_copyto(void *to)
|
||||||
int
|
int
|
||||||
packetbuf_hdralloc(int size)
|
packetbuf_hdralloc(int size)
|
||||||
{
|
{
|
||||||
if(hdrptr >= size) {
|
if(hdrptr >= size && packetbuf_totlen() + size <= PACKETBUF_SIZE) {
|
||||||
hdrptr -= size;
|
hdrptr -= size;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue