gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] 16/26: daemon.c: fixed possible unaligned access to 'str


From: gnunet
Subject: [libmicrohttpd] 16/26: daemon.c: fixed possible unaligned access to 'struct sockaddr_in'
Date: Mon, 25 Apr 2022 15:08:40 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit a4036e668134d1ad9637534bac1e0cb55d0a2b36
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Sat Apr 23 19:10:50 2022 +0300

    daemon.c: fixed possible unaligned access to 'struct sockaddr_in'
    
    On some platforms 'struct sockaddr_in' requires increased alignment
    compared to ''struct sockaddr'.
---
 src/microhttpd/daemon.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 17cf8393..6cbd9ad5 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -44,6 +44,7 @@
 #include "mhd_itc.h"
 #include "mhd_compat.h"
 #include "mhd_send.h"
+#include "mhd_align.h"
 
 #if HAVE_SEARCH_H
 #include <search.h>
@@ -342,13 +343,13 @@ MHD_ip_addr_to_key (const struct sockaddr *addr,
   /* IPv4 addresses */
   if (AF_INET == addr->sa_family)
   {
-    const struct sockaddr_in *addr4 = (const struct sockaddr_in *) addr;
     mhd_assert (sizeof (struct sockaddr_in) <= (size_t) addrlen);
 
     key->family = AF_INET;
     memcpy (&key->addr.ipv4,
-            &addr4->sin_addr,
-            sizeof(addr4->sin_addr));
+            ((const uint8_t *) addr)
+            + _MHD_OFFSETOF (struct sockaddr_in, sin_addr),
+            sizeof(((struct sockaddr_in *) NULL)->sin_addr));
     return MHD_YES;
   }
 
@@ -356,13 +357,13 @@ MHD_ip_addr_to_key (const struct sockaddr *addr,
   /* IPv6 addresses */
   if (AF_INET6 == addr->sa_family)
   {
-    const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *) addr;
     mhd_assert (sizeof (struct sockaddr_in6) <= (size_t) addrlen);
 
     key->family = AF_INET6;
     memcpy (&key->addr.ipv6,
-            &addr6->sin6_addr,
-            sizeof(addr6->sin6_addr));
+            ((const uint8_t *) addr)
+            + _MHD_OFFSETOF (struct sockaddr_in6, sin6_addr),
+            sizeof(((struct sockaddr_in6 *) NULL)->sin6_addr));
     return MHD_YES;
   }
 #endif

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]