Browse code

Fix an unaligned access on OpenBSD/sparc64

The pointer to the packet content doesn't seem to be word-aligned,
resulting in a SIGBUS when accessing it as a pointer to struct ip that
contains bit fields.

Replace with struct openvpn_iphdr and OPENVPN_IPH_GET_VER, which only
does a one byte access and thus isn't affected by alignement.
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <87ink3vpcs.fsf@ritchie.wxcvbn.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg14769.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>

Jérémie Courrèges-Anglas authored on 2017/06/10 23:48:44
Showing 1 changed files
... ...
@@ -1654,11 +1654,11 @@ write_tun_header(struct tuntap *tt, uint8_t *buf, int len)
1654 1654
     {
1655 1655
         u_int32_t type;
1656 1656
         struct iovec iv[2];
1657
-        struct ip *iph;
1657
+        struct openvpn_iphdr *iph;
1658 1658
 
1659
-        iph = (struct ip *) buf;
1659
+        iph = (struct openvpn_iphdr *) buf;
1660 1660
 
1661
-        if (iph->ip_v == 6)
1661
+        if (OPENVPN_IPH_GET_VER(iph->version_len) == 6)
1662 1662
         {
1663 1663
             type = htonl(AF_INET6);
1664 1664
         }