INN commit: branches/2.5/innfeed (connection.c)

INN Commit rra at isc.org
Thu May 14 13:39:25 UTC 2015


    Date: Thursday, May 14, 2015 @ 06:39:24
  Author: iulius
Revision: 9863

innfeed/connection.c:  avoid violating C aliasing rules

The object was written as a 'struct sockaddr' but then read as a
'struct sockaddr_storage', which violates C99 s6.5#7.  The fix
is to always access it as a 'struct sockaddr' and use a union to
ensure enough space for any possible address type.

Thanks to Richard Kettlewell for the patch.

Modified:
  branches/2.5/innfeed/connection.c

--------------+
 connection.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Modified: connection.c
===================================================================
--- connection.c	2015-05-14 13:38:42 UTC (rev 9862)
+++ connection.c	2015-05-14 13:39:24 UTC (rev 9863)
@@ -1307,12 +1307,15 @@
  */
 static void connectionIfIpv6DeleteIpv4Addr (Connection cxn)
 {
-  struct sockaddr_storage ss;
-  socklen_t len = sizeof(ss);
+  union {
+    struct sockaddr sa;
+    struct sockaddr_storage ss;
+  } u;
+  socklen_t len = sizeof(u);
 
-  if (getpeername (endPointFd (cxn->myEp), (struct sockaddr *)&ss, &len) < 0)
+  if (getpeername (endPointFd (cxn->myEp), &u.sa, &len) < 0)
     return;
-  if (ss.ss_family == AF_INET)
+  if (u.sa.sa_family == AF_INET)
     return;
 
   hostDeleteIpv4Addr (cxn->myHost);



More information about the inn-committers mailing list