current jbsockets.c,1.136,1.137

Fabian Keil <[email protected]> Mon, 22 Aug 2016 14:50:20 +0000
Newsgroups gmane.comp.web.privoxy.cvs
Message-ID <[email protected]>
Update of /cvsroot/ijbswa/current
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv18537

Modified Files:
	jbsockets.c 
Log Message:
accept_connection(): Fix crashes with "listen-addr :8118"

After jbsockets.c v1.136 a valid text representation of
the host address is required for the $listen-address
variable. If no host address has been specified, use an
empty string to prevent NULL pointer dereferences.

The problem was reported by Marvin Renich in Debian bug #834941,
the offending commit was tracked down by Roland in SF Bug #902.


Index: jbsockets.c
===================================================================
RCS file: /cvsroot/ijbswa/current/jbsockets.c,v
retrieving revision 1.136
retrieving revision 1.137
diff -C2 -d -r1.136 -r1.137
*** jbsockets.c	25 May 2016 10:50:55 -0000	1.136
--- jbsockets.c	22 Aug 2016 14:50:18 -0000	1.137
***************
*** 1222,1225 ****
--- 1222,1226 ----
     fd_set selected_fds;
     jb_socket fd;
+    const char *host_addr;
     size_t listen_addr_size;
  
***************
*** 1356,1363 ****
      * strlen(haddr[i]) + 1 (':') + 5 (port digits) + 1 ('\0')
      */
!    listen_addr_size = strlen(csp->config->haddr[i]) + 7;
     csp->listen_addr_str = malloc_or_die(listen_addr_size);
     retval = snprintf(csp->listen_addr_str, listen_addr_size,
!       "%s:%d", csp->config->haddr[i], csp->config->hport[i]);
     if ((-1 == retval) || listen_addr_size <= retval)
     {
--- 1357,1365 ----
      * strlen(haddr[i]) + 1 (':') + 5 (port digits) + 1 ('\0')
      */
!    host_addr = (csp->config->haddr[i] != NULL) ? csp->config->haddr[i] : "";
!    listen_addr_size = strlen(host_addr) + 7;
     csp->listen_addr_str = malloc_or_die(listen_addr_size);
     retval = snprintf(csp->listen_addr_str, listen_addr_size,
!       "%s:%d", host_addr, csp->config->hport[i]);
     if ((-1 == retval) || listen_addr_size <= retval)
     {
***************
*** 1365,1369 ****
           "Server name (%s) and port number (%d) ASCII decimal representation"
           "don't fit into %d bytes",
!          csp->config->haddr[i], csp->config->hport[i], listen_addr_size);
        return 0;
     }
--- 1367,1371 ----
           "Server name (%s) and port number (%d) ASCII decimal representation"
           "don't fit into %d bytes",
!          host_addr, csp->config->hport[i], listen_addr_size);
        return 0;
     }


------------------------------------------------------------------------------