]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Merge pull request #7450 from omoerbeek/avoid-unaligned-access
authorRemi Gacogne <rgacogne@users.noreply.github.com>
Tue, 5 Feb 2019 15:18:32 +0000 (16:18 +0100)
committerGitHub <noreply@github.com>
Tue, 5 Feb 2019 15:18:32 +0000 (16:18 +0100)
Avoid unaligned access, it hurts on e.g. sparc64

pdns/iputils.hh
pdns/nameserver.cc

index 90ecdad281cfe9165a95b2d5d615d85b446de563..490e45ac436665556dd77f7e545187cb810ca9a2 100644 (file)
 union ComboAddress {
   struct sockaddr_in sin4;
   struct sockaddr_in6 sin6;
+  // struct sockaddr_in6 is *not* defined as containing two uint64_t for the
+  // address , but we like to read or write it like that.
+  // Force alignment by adding an uint64_t in the union. This makes sure
+  // the start of the struct and s6_addr gets aligned.
+  // This works because of the spot of s6_addr in struct sockaddr_in6.
+  // Needed for strict alignment architectures like sparc64.
+  uint64_t     force_align;
 
   bool operator==(const ComboAddress& rhs) const
   {
index 60e2e72ed536aeab0327778bd89c42619932fccc..99542014416e013172b315de32bc043e3bbb8d2b 100644 (file)
@@ -242,7 +242,7 @@ void UDPNameserver::bindIPv6()
 
     if( !d_additional_socket )
         g_localaddresses.push_back(locala);
-    if(::bind(s, (sockaddr*)&locala, sizeof(locala))<0) {
+    if(::bind(s, (sockaddr*)&locala, locala.getSocklen())<0) {
       close(s);
       if( errno == EADDRNOTAVAIL && ! ::arg().mustDo("local-ipv6-nonexist-fail") ) {
         g_log<<Logger::Error<<"IPv6 Address " << localname << " does not exist on this server - skipping UDP bind" << endl;