libmemif: fix segfault and buffer overflow in examples
- Fix buffer overflow caused by strncpy(dst, src, strlen(src)),
use sized buffer to ensure overflow safe.
- Fix test_app getopt usage
When use example/icmp_responder in slave mode
- Fix segfault when buffer size is not specified
- Fix wrong packet send out.
Type: fix
Signed-off-by: Tianyu Li <tianyu.li@arm.com>
Change-Id: I5ed47fd8e630420d7ae0203a2605d2b9abd33d2a
diff --git a/extras/libmemif/examples/common/packet_handler.c b/extras/libmemif/examples/common/packet_handler.c
index 9d3e4d7..1e97e46 100644
--- a/extras/libmemif/examples/common/packet_handler.c
+++ b/extras/libmemif/examples/common/packet_handler.c
@@ -48,7 +48,7 @@
for (i = 0; i < c->tx_buf_num; i++)
{
uint32_t len;
- void *packet = c->rx_bufs[i].data;
+ void *packet = c->tx_bufs[i].data;
memcpy (c->tx_bufs[i].data, c->rx_bufs[i].data, c->rx_bufs[i].len);
c->tx_bufs[i].flags = c->rx_bufs[i].flags;