mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-22 10:30:13 +00:00
Merge pull request #1090 from rajithr/patch-1
Protection against possible buffer overflow
This commit is contained in:
commit
d65b3e1ab6
@ -141,6 +141,7 @@ packetbuf_copyto(void *to)
|
|||||||
int i;
|
int i;
|
||||||
char buffer[1000];
|
char buffer[1000];
|
||||||
char *bufferptr = buffer;
|
char *bufferptr = buffer;
|
||||||
|
int bufferlen = 0;
|
||||||
|
|
||||||
bufferptr[0] = 0;
|
bufferptr[0] = 0;
|
||||||
for(i = hdrptr; i < PACKETBUF_HDR_SIZE; ++i) {
|
for(i = hdrptr; i < PACKETBUF_HDR_SIZE; ++i) {
|
||||||
@ -149,8 +150,8 @@ packetbuf_copyto(void *to)
|
|||||||
PRINTF("packetbuf_write: header: %s\n", buffer);
|
PRINTF("packetbuf_write: header: %s\n", buffer);
|
||||||
bufferptr = buffer;
|
bufferptr = buffer;
|
||||||
bufferptr[0] = 0;
|
bufferptr[0] = 0;
|
||||||
for(i = bufptr; i < buflen + bufptr; ++i) {
|
for(i = bufptr; ((i < buflen + bufptr) && (bufferlen < (sizeof(buffer) - 10))); ++i) {
|
||||||
bufferptr += sprintf(bufferptr, "0x%02x, ", packetbufptr[i]);
|
bufferlen += sprintf(bufferptr + bufferlen, "0x%02x, ", packetbufptr[i]);
|
||||||
}
|
}
|
||||||
PRINTF("packetbuf_write: data: %s\n", buffer);
|
PRINTF("packetbuf_write: data: %s\n", buffer);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user