From ba6fd5d712b374074d962ce0158862be9e2146da Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Mon, 22 Aug 2016 14:50:18 +0000 Subject: [PATCH] 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. --- jbsockets.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/jbsockets.c b/jbsockets.c index c1a40809..7b20fa38 100644 --- a/jbsockets.c +++ b/jbsockets.c @@ -1,4 +1,4 @@ -const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.135 2016/01/16 12:33:35 fabiankeil Exp $"; +const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.136 2016/05/25 10:50:55 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jbsockets.c,v $ @@ -1221,6 +1221,7 @@ int accept_connection(struct client_state * csp, jb_socket fds[]) int max_selected_socket; fd_set selected_fds; jb_socket fd; + const char *host_addr; size_t listen_addr_size; c_length = sizeof(client); @@ -1355,16 +1356,17 @@ int accept_connection(struct client_state * csp, jb_socket fds[]) * The string needs space for strlen(...) + 7 characters: * strlen(haddr[i]) + 1 (':') + 5 (port digits) + 1 ('\0') */ - listen_addr_size = strlen(csp->config->haddr[i]) + 7; + 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", csp->config->haddr[i], csp->config->hport[i]); + "%s:%d", host_addr, csp->config->hport[i]); if ((-1 == retval) || listen_addr_size <= retval) { log_error(LOG_LEVEL_ERROR, "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); + host_addr, csp->config->hport[i], listen_addr_size); return 0; } -- 2.39.2