Package: libnanohttp1
Version: 1.1.0-13
Severity: important

The library call inet_ntoa() is not thread safe.  With glibc in Lenny if you
call it from multiple threads then you can get a SEGV.  Even if it didn't get
a SEGV then it would still result in race conditions and incorrect data.

The following patch removes both instances of inet_ntoa().  The first one was
simply a mistake (doing things the hard way), the second can be done in a
thread-safe manner.

Note that I have not exercised the code path for the inet_ntop() use.

I am in the middle of a significant stress-test of the first patch, it's had
40 threads running for the last 20 minutes without finding a problem yet.

diff -ru libcsoap-1.1.0.bak/nanohttp/nanohttp-socket.c 
libcsoap-1.1.0/nanohttp/nanohttp-socket.c
--- libcsoap-1.1.0.bak/nanohttp/nanohttp-socket.c       2009-04-07 
15:19:25.000000000 +1000
+++ libcsoap-1.1.0/nanohttp/nanohttp-socket.c   2009-04-07 15:31:53.000000000 
+1000
@@ -176,7 +176,6 @@
 {
   struct sockaddr_in address;
   struct hostent *host;
-  char *ip;
 
   if ((dsock->sock = socket(AF_INET, SOCK_STREAM, 0)) <= 0)
     return herror_new("hsocket_open", HSOCKET_ERROR_CREATE,
@@ -187,8 +186,7 @@
     return herror_new("hsocket_open", HSOCKET_ERROR_GET_HOSTNAME,
                       "Socket error (%s)", strerror(errno));
 
-  ip = inet_ntoa(*(struct in_addr *) *host->h_addr_list);
-  address.sin_addr.s_addr = inet_addr(ip);
+  address.sin_addr = *(struct in_addr *) *host->h_addr_list;
 
   /* set server addresss */
   address.sin_family = host->h_addrtype;
@@ -308,6 +306,7 @@
 hsocket_accept(hsocket_t * sock, hsocket_t * dest)
 {
   herror_t status;
+  char ntop_buf[16];
 
   if (sock->sock < 0)
     return herror_new("hsocket_accept", HSOCKET_ERROR_NOT_INITIALIZED,
@@ -323,7 +322,7 @@
   }
 
   log_verbose3("accepting connection from '%s' socket=%d",
-               SAVE_STR(((char *) inet_ntoa(dest->addr.sin_addr))),
+               SAVE_STR(((char *) inet_ntop(AF_INET, &dest->addr.sin_addr, 
ntop_buf, sizeof(dest->addr.sin_addr)))),
                dest->sock);
 
   return H_OK;


-- System Information:
Debian Release: 5.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-1-686 (SMP w/1 CPU core)
Locale: LANG=en_AU.UTF-8, LC_CTYPE=en_AU.UTF-8 (charmap=ANSI_X3.4-1968) 
(ignored: LC_ALL set to C)
Shell: /bin/sh linked to /bin/bash

Versions of packages libnanohttp1 depends on:
ii  libc6                      2.7-18        GNU C Library: Shared libraries
ii  libssl0.9.8                0.9.8g-15     SSL shared libraries
ii  libxml2                    2.6.32.dfsg-5 GNOME XML library

libnanohttp1 recommends no packages.

libnanohttp1 suggests no packages.

-- no debconf information



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to