sys/shell/commands/gnrc_icmpv6_echo: Fix alignment

Fix unaligned memory access in `ping6` shell command
This commit is contained in:
Marian Buschsieweke 2020-09-25 08:50:38 +02:00
parent ad9e35c445
commit 5a04f48238
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F

View File

@ -42,6 +42,7 @@
#include "net/icmpv6.h" #include "net/icmpv6.h"
#include "net/ipv6.h" #include "net/ipv6.h"
#include "timex.h" #include "timex.h"
#include "unaligned.h"
#include "utlist.h" #include "utlist.h"
#include "xtimer.h" #include "xtimer.h"
@ -323,7 +324,8 @@ static void _pinger(_ping_data_t *data)
LL_PREPEND(pkt, tmp); LL_PREPEND(pkt, tmp);
} }
if (data->datalen >= sizeof(uint32_t)) { if (data->datalen >= sizeof(uint32_t)) {
*((uint32_t *)databuf) = xtimer_now_usec(); uint32_t now = xtimer_now_usec();
memcpy(databuf, &now, sizeof(now));
} }
if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_IPV6, if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_IPV6,
GNRC_NETREG_DEMUX_CTX_ALL, GNRC_NETREG_DEMUX_CTX_ALL,
@ -366,7 +368,7 @@ static void _print_reply(_ping_data_t *data, gnrc_pktsnip_t *icmpv6,
recv_seq = byteorder_ntohs(icmpv6_hdr->seq); recv_seq = byteorder_ntohs(icmpv6_hdr->seq);
ipv6_addr_to_str(&from_str[0], from, sizeof(from_str)); ipv6_addr_to_str(&from_str[0], from, sizeof(from_str));
if (data->datalen >= sizeof(uint32_t)) { if (data->datalen >= sizeof(uint32_t)) {
triptime = xtimer_now_usec() - *((uint32_t *)(icmpv6_hdr + 1)); triptime = xtimer_now_usec() - unaligned_get_u32(icmpv6_hdr + 1);
data->tsum += triptime; data->tsum += triptime;
if (triptime < data->tmin) { if (triptime < data->tmin) {
data->tmin = triptime; data->tmin = triptime;