From 3658f74d179365e3d6990e684e0040887251a42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C3=85berg?= Date: Mon, 16 Nov 2020 13:35:16 +0100 Subject: [PATCH] net: ipv6: fixed endian issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A cast made assumption on how data is stored. This commit makes the following test pass on qemu_leon3: - net.udp Signed-off-by: Martin Ã…berg --- subsys/net/ip/ipv6.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/subsys/net/ip/ipv6.c b/subsys/net/ip/ipv6.c index 2e699886e85..61d83080459 100644 --- a/subsys/net/ip/ipv6.c +++ b/subsys/net/ip/ipv6.c @@ -172,11 +172,15 @@ static inline int ipv6_handle_ext_hdr_options(struct net_pkt *pkt, uint16_t exthdr_len = 0U; uint16_t length = 0U; - if (net_pkt_read_u8(pkt, (uint8_t *)&exthdr_len)) { - return -ENOBUFS; + { + uint8_t val = 0U; + + if (net_pkt_read_u8(pkt, &val)) { + return -ENOBUFS; + } + exthdr_len = val * 8U + 8; } - exthdr_len = exthdr_len * 8U + 8; if (exthdr_len > pkt_len) { NET_DBG("Corrupted packet, extension header %d too long " "(max %d bytes)", exthdr_len, pkt_len);