From eb6c403500dd0b0d78b7b00d7ed0bf6b5daccc4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Wed, 1 Oct 2014 12:16:17 +0200 Subject: daemon: handle gethostbyname() error If the user-supplied hostname can't be found then we should not use it. We already avoid doing that in the non-NO_IPV6 case by checking if the return value of getaddrinfo() is zero (success). Do the same in the NO_IPV6 case and make sure the return value of gethostbyname() isn't NULL before dereferencing this pointer. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- daemon.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'daemon.c') diff --git a/daemon.c b/daemon.c index 13608c07c6..25af533b97 100644 --- a/daemon.c +++ b/daemon.c @@ -579,20 +579,21 @@ static void parse_host_arg(char *extra_args, int buflen) static char addrbuf[HOST_NAME_MAX + 1]; hent = gethostbyname(hostname); + if (hent) { + ap = hent->h_addr_list; + memset(&sa, 0, sizeof sa); + sa.sin_family = hent->h_addrtype; + sa.sin_port = htons(0); + memcpy(&sa.sin_addr, *ap, hent->h_length); + + inet_ntop(hent->h_addrtype, &sa.sin_addr, + addrbuf, sizeof(addrbuf)); - ap = hent->h_addr_list; - memset(&sa, 0, sizeof sa); - sa.sin_family = hent->h_addrtype; - sa.sin_port = htons(0); - memcpy(&sa.sin_addr, *ap, hent->h_length); - - inet_ntop(hent->h_addrtype, &sa.sin_addr, - addrbuf, sizeof(addrbuf)); - - free(canon_hostname); - canon_hostname = xstrdup(hent->h_name); - free(ip_address); - ip_address = xstrdup(addrbuf); + free(canon_hostname); + canon_hostname = xstrdup(hent->h_name); + free(ip_address); + ip_address = xstrdup(addrbuf); + } #endif } } -- cgit v1.2.3 From 9d1b9aa9e10da398f430bc619b361d83bee6df7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Wed, 1 Oct 2014 12:18:15 +0200 Subject: daemon: fix error message after bind() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'daemon.c') diff --git a/daemon.c b/daemon.c index 25af533b97..3be38f4dbc 100644 --- a/daemon.c +++ b/daemon.c @@ -950,7 +950,7 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis } if ( bind(sockfd, (struct sockaddr *)&sin, sizeof sin) < 0 ) { - logerror("Could not listen to %s: %s", + logerror("Could not bind to %s: %s", ip2str(AF_INET, (struct sockaddr *)&sin, sizeof(sin)), strerror(errno)); close(sockfd); -- cgit v1.2.3 From 107efbeb2409ac3fb01560a42067c8cc506aa249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Wed, 1 Oct 2014 12:21:57 +0200 Subject: daemon: remove write-only variable maxfd It became unused when 6573faff (NO_IPV6 support for git daemon) replaced select() with poll(). Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- daemon.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'daemon.c') diff --git a/daemon.c b/daemon.c index 3be38f4dbc..57b1a5783f 100644 --- a/daemon.c +++ b/daemon.c @@ -841,7 +841,6 @@ static const char *ip2str(int family, struct sockaddr *sin, socklen_t len) static int setup_named_sock(char *listen_addr, int listen_port, struct socketlist *socklist) { int socknum = 0; - int maxfd = -1; char pbuf[NI_MAXSERV]; struct addrinfo hints, *ai0, *ai; int gai; @@ -909,9 +908,6 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis ALLOC_GROW(socklist->list, socklist->nr + 1, socklist->alloc); socklist->list[socklist->nr++] = sockfd; socknum++; - - if (maxfd < sockfd) - maxfd = sockfd; } freeaddrinfo(ai0); -- cgit v1.2.3