INN commit: trunk/innfeed (connection.c)

INN Commit rra at isc.org
Sun May 3 15:11:06 UTC 2015


    Date: Sunday, May 3, 2015 @ 08:11:05
  Author: iulius
Revision: 9849

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:
  trunk/innfeed/connection.c

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

Modified: connection.c
===================================================================
--- connection.c	2015-05-03 15:05:45 UTC (rev 9848)
+++ connection.c	2015-05-03 15:11:05 UTC (rev 9849)
@@ -1312,12 +1312,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