summaryrefslogtreecommitdiff
path: root/daemon.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2014-10-01 12:16:17 +0200
committerJunio C Hamano <gitster@pobox.com>2014-10-01 13:34:53 -0700
commiteb6c403500dd0b0d78b7b00d7ed0bf6b5daccc4e (patch)
tree2c78bb618e28400efd2ef506dcd11eb5ea0d0333 /daemon.c
parente6aaa393478bf3ee9f4cde8d82cd258c034cd335 (diff)
downloadgit-eb6c403500dd0b0d78b7b00d7ed0bf6b5daccc4e.tar.gz
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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'daemon.c')
-rw-r--r--daemon.c27
1 files changed, 14 insertions, 13 deletions
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
}
}