INN commit: trunk (innd/rc.c innfeed/connection.c nnrpd/nnrpd.c)

INN Commit rra at isc.org
Mon Dec 25 20:40:39 UTC 2017


    Date: Monday, December 25, 2017 @ 12:40:38
  Author: eagle
Revision: 10199

Avoid use of SA_LEN in INN code

As part of the original IPv6 work, we adopted the SA_LEN macro to
find the length of a struct sockaddr holding either an IPv4 or an
IPv6 address.  This macro is non-standard, however, and is now
setting off warnings in current versions of GCC.

It doesn't appear to have ever caught on, and we only used it in
three places, two of which were easy to refactor to not use it.
The third requires an if statement because it doesn't pass back the
address length from another function, but it's still simpler than
carrying the SA_LEN macro code.

This prepares INN for a later import of rra-c-util that will drop
the SA_LEN macro and Autoconf probe.

Modified:
  trunk/innd/rc.c
  trunk/innfeed/connection.c
  trunk/nnrpd/nnrpd.c

----------------------+
 innd/rc.c            |   14 +++++++-------
 innfeed/connection.c |   18 +++++++++++++++---
 nnrpd/nnrpd.c        |    8 ++++----
 3 files changed, 26 insertions(+), 14 deletions(-)

Modified: innd/rc.c
===================================================================
--- innd/rc.c	2017-12-10 15:22:43 UTC (rev 10198)
+++ innd/rc.c	2017-12-25 20:40:38 UTC (rev 10199)
@@ -128,7 +128,7 @@
     struct sockaddr *s_local;
     struct sockaddr *s_distant = NULL;
     int ident_fd;
-    socklen_t len;
+    socklen_t local_len, distant_len;
     int port1,port2;
     ssize_t lu;
     char buf[80], *buf2;
@@ -137,14 +137,14 @@
          return true;
 
     s_local = xmalloc(sizeof(struct sockaddr_storage));
-    len = sizeof(struct sockaddr_storage);
-    if ((getsockname(fd, s_local, &len)) < 0) {
+    local_len = sizeof(struct sockaddr_storage);
+    if ((getsockname(fd, s_local, &local_len)) < 0) {
 	syslog(L_ERROR, "can't do getsockname for identd");
         goto fail;
     }
     s_distant = xmalloc(sizeof(struct sockaddr_storage));
-    len = sizeof(struct sockaddr_storage);
-    if ((getpeername(fd, s_distant, &len)) < 0) {
+    distant_len = sizeof(struct sockaddr_storage);
+    if ((getpeername(fd, s_distant, &distant_len)) < 0) {
 	syslog(L_ERROR, "can't do getpeername for identd");
         goto fail;
     }
@@ -174,12 +174,12 @@
 	syslog(L_ERROR, "can't open socket for identd (%m)");
         goto fail;
     }
-    if (bind(ident_fd, s_local, SA_LEN(s_local)) < 0) {
+    if (bind(ident_fd, s_local, local_len) < 0) {
 	syslog(L_ERROR, "can't bind socket for identd (%m)");
         close(ident_fd);
         goto fail;
     }
-    if (connect(ident_fd, s_distant, SA_LEN(s_distant)) < 0) {
+    if (connect(ident_fd, s_distant, distant_len) < 0) {
 	syslog(L_ERROR, "can't connect to identd (%m)");
         close(ident_fd);
         goto fail;

Modified: innfeed/connection.c
===================================================================
--- innfeed/connection.c	2017-12-10 15:22:43 UTC (rev 10198)
+++ innfeed/connection.c	2017-12-25 20:40:38 UTC (rev 10199)
@@ -490,6 +490,7 @@
 bool cxnConnect (Connection cxn)
 {
   struct sockaddr *cxnAddr;
+  socklen_t len;
   int fd, rval;
   const char *src;
   const char *peerName = hostPeerName (cxn->myHost) ;
@@ -524,9 +525,20 @@
     }
 
   if (cxnAddr->sa_family == AF_INET)
-    src = hostBindAddr(cxn->myHost);
+    {
+      src = hostBindAddr(cxn->myHost) ;
+      len = sizeof(struct sockaddr_in) ;
+    }
   else
-    src = hostBindAddr6(cxn->myHost);
+    {
+      src = hostBindAddr6(cxn->myHost) ;
+#if HAVE_INET6
+      len = sizeof(struct sockaddr_in6) ;
+#else
+      /* This should never happen, but the compiler doesn't know that. */
+      len = sizeof(struct sockaddr) ;
+#endif
+    }
   if (src && strcmp(src, "none") == 0)
     src = NULL;
 
@@ -553,7 +565,7 @@
       return false ;
     }
 
-  rval = connect (fd, cxnAddr, SA_LEN(cxnAddr)) ;
+  rval = connect (fd, cxnAddr, len) ;
   if (rval < 0 && errno != EINPROGRESS)
     {
       syswarn ("%s:%d connect", peerName, cxn->ident) ;

Modified: nnrpd/nnrpd.c
===================================================================
--- nnrpd/nnrpd.c	2017-12-10 15:22:43 UTC (rev 10198)
+++ nnrpd/nnrpd.c	2017-12-25 20:40:38 UTC (rev 10199)
@@ -531,7 +531,7 @@
 **  since anyone can fake reverse DNS entries.
 */
 static bool
-Address2Name(struct sockaddr *sa, char *hostname, size_t size)
+Address2Name(struct sockaddr *sa, socklen_t len, char *hostname, size_t size)
 {
     static const char MISMATCH[] = "reverse lookup validation failed";
     struct addrinfo hints, *ai, *host;
@@ -540,7 +540,7 @@
     bool valid = false;
 
     /* Get the official hostname, store it away. */
-    ret = getnameinfo(sa, SA_LEN(sa), hostname, size, NULL, 0, NI_NAMEREQD);
+    ret = getnameinfo(sa, len, hostname, size, NULL, 0, NI_NAMEREQD);
     if (ret != 0) {
 	HostErrorStr = gai_strerror(ret);
 	return false;
@@ -613,7 +613,7 @@
 	}
 	if (GetHostByAddr) {
             HostErrorStr = default_host_error;
-            if (!Address2Name(sac, Client.host, sizeof(Client.host))) {
+            if (!Address2Name(sac, length, Client.host, sizeof(Client.host))) {
                 notice("? reverse lookup for %s failed: %s -- using IP"
                        " address for access", Client.ip, HostErrorStr);
 	        strlcpy(Client.host, Client.ip, sizeof(Client.host));
@@ -641,7 +641,7 @@
 	if (GetHostByAddr) {
 	    HostErrorStr = default_host_error;
             size = sizeof(Client.serverhost);
-            if (!Address2Name(sas, Client.serverhost, size)) {
+            if (!Address2Name(sas, length, Client.serverhost, size)) {
                 notice("? reverse lookup for %s failed: %s -- using IP"
                        " address for access", Client.serverip, HostErrorStr);
 	        strlcpy(Client.serverhost, Client.serverip,



More information about the inn-committers mailing list