INN commit: branches/2.5 (6 files)

INN Commit rra at isc.org
Sat Feb 12 06:50:38 UTC 2011


    Date: Friday, February 11, 2011 @ 22:50:38
  Author: eagle
Revision: 9183

Initialize socket structures and use SUN_LEN properly

>From Bo Lindbergh: innd failed to bind to an unprivileged socket.  I found 
the problem in lib/network.c (a sockaddr_in with uninitialised spare
bits in it).  Then I grepped around and found more instances of the same
problem.  I also found a sockaddr_un problem (SUN_LEN not used).

Modified:
  branches/2.5/CONTRIBUTORS
  branches/2.5/frontends/ovdb_server.c
  branches/2.5/innfeed/imap_connection.c
  branches/2.5/lib/network.c
  branches/2.5/storage/ovdb/ovdb.c
  branches/2.5/tests/lib/network-t.c

---------------------------+
 CONTRIBUTORS              |    2 +-
 frontends/ovdb_server.c   |    3 ++-
 innfeed/imap_connection.c |    1 +
 lib/network.c             |    2 ++
 storage/ovdb/ovdb.c       |    5 ++++-
 tests/lib/network-t.c     |    1 +
 6 files changed, 11 insertions(+), 3 deletions(-)

Modified: CONTRIBUTORS
===================================================================
--- CONTRIBUTORS	2011-02-12 06:50:25 UTC (rev 9182)
+++ CONTRIBUTORS	2011-02-12 06:50:38 UTC (rev 9183)
@@ -273,4 +273,4 @@
 Steve Crook, John F. Morse, Tim Woodall, Jonathan Kamens, Kamil Jonca,
 S.P. Zeidler, Nix, Florian Schlichting, Torsten Jerzembeck, Harald Dunkel,
 Lars Magne Ingebrigtsen, Sam Varshavchik, Matthew Vernon, Ian Jackson,
-Edmund H. Ramm, Raphael Barrois
+Edmund H. Ramm, Raphael Barrois, Bo Lindbergh

Modified: frontends/ovdb_server.c
===================================================================
--- frontends/ovdb_server.c	2011-02-12 06:50:25 UTC (rev 9182)
+++ frontends/ovdb_server.c	2011-02-12 06:50:38 UTC (rev 9183)
@@ -648,13 +648,14 @@
 
     nonblocking(listensock, 1);
 
+    memset(&sa, 0, sizeof sa);
 #ifdef HAVE_UNIX_DOMAIN_SOCKETS
     sa.sun_family = AF_UNIX;
     path = concatpath(innconf->pathrun, OVDB_SERVER_SOCKET);
     strlcpy(sa.sun_path, path, sizeof(sa.sun_path));
     unlink(sa.sun_path);
     free(path);
-    ret = bind(listensock, (struct sockaddr *)&sa, sizeof sa);
+    ret = bind(listensock, (struct sockaddr *)&sa, SUN_LEN(&sa));
 #else
     sa.sin_family = AF_INET;
     sa.sin_port = htons(OVDB_SERVER_PORT);

Modified: innfeed/imap_connection.c
===================================================================
--- innfeed/imap_connection.c	2011-02-12 06:50:25 UTC (rev 9182)
+++ innfeed/imap_connection.c	2011-02-12 06:50:38 UTC (rev 9183)
@@ -1492,6 +1492,7 @@
       return RET_FAIL;	
   }
 
+  memset(&addr, 0, sizeof addr);
   addr.sin_family = AF_INET;
   memcpy(&addr.sin_addr, hp->h_addr, hp->h_length);
   addr.sin_port = htons(port);

Modified: lib/network.c
===================================================================
--- lib/network.c	2011-02-12 06:50:25 UTC (rev 9182)
+++ lib/network.c	2011-02-12 06:50:38 UTC (rev 9183)
@@ -200,6 +200,7 @@
             close(fd);
         return bindfd;
     } else {
+        memset(&server, 0, sizeof server);
         server.sin_family = AF_INET;
         server.sin_port = htons(port);
         if (!inet_aton(address, &addr)) {
@@ -262,6 +263,7 @@
             close(fd);
         return bindfd;
     } else {
+        memset(&server, 0, sizeof server);
         server.sin6_family = AF_INET6;
         server.sin6_port = htons(port);
         if (inet_pton(AF_INET6, address, &addr) < 1) {

Modified: storage/ovdb/ovdb.c
===================================================================
--- storage/ovdb/ovdb.c	2011-02-12 06:50:25 UTC (rev 9182)
+++ storage/ovdb/ovdb.c	2011-02-12 06:50:38 UTC (rev 9183)
@@ -272,19 +272,22 @@
 	return -1;
     }
 
+    memset(&sa, 0, sizeof sa);
 #ifdef HAVE_UNIX_DOMAIN_SOCKETS
     sa.sun_family = AF_UNIX;
     path = concatpath(innconf->pathrun, OVDB_SERVER_SOCKET);
     strlcpy(sa.sun_path, path, sizeof(sa.sun_path));
     free(path);
+    r = connect(clientfd, (struct sockaddr *) &sa, SUN_LEN(&sa))
 #else
     sa.sin_family = AF_INET;
     sa.sin_port = 0;
     sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
     bind(clientfd, (struct sockaddr *) &sa, sizeof sa);
     sa.sin_port = htons(OVDB_SERVER_PORT);
+    r = connect(clientfd, (struct sockaddr *) &sa, sizeof sa);
 #endif
-    if((r = connect(clientfd, (struct sockaddr *) &sa, sizeof sa)) != 0) {
+    if(r != 0) {
         syswarn("OVDB: rc: cant connect to server");
 	close(clientfd);
 	clientfd = -1;

Modified: tests/lib/network-t.c
===================================================================
--- tests/lib/network-t.c	2011-02-12 06:50:25 UTC (rev 9182)
+++ tests/lib/network-t.c	2011-02-12 06:50:38 UTC (rev 9183)
@@ -224,6 +224,7 @@
             fd = network_client_create(PF_INET, SOCK_STREAM, source);
             if (fd < 0)
                 _exit(1);
+            memset(&sin, 0, sizeof sin);
             sin.sin_family = AF_INET;
             sin.sin_port = htons(11119);
             sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);




More information about the inn-committers mailing list