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>
This commit is contained in:

committed by
Junio C Hamano

parent
e6aaa39347
commit
eb6c403500
3
daemon.c
3
daemon.c
@ -579,7 +579,7 @@ static void parse_host_arg(char *extra_args, int buflen)
|
|||||||
static char addrbuf[HOST_NAME_MAX + 1];
|
static char addrbuf[HOST_NAME_MAX + 1];
|
||||||
|
|
||||||
hent = gethostbyname(hostname);
|
hent = gethostbyname(hostname);
|
||||||
|
if (hent) {
|
||||||
ap = hent->h_addr_list;
|
ap = hent->h_addr_list;
|
||||||
memset(&sa, 0, sizeof sa);
|
memset(&sa, 0, sizeof sa);
|
||||||
sa.sin_family = hent->h_addrtype;
|
sa.sin_family = hent->h_addrtype;
|
||||||
@ -593,6 +593,7 @@ static void parse_host_arg(char *extra_args, int buflen)
|
|||||||
canon_hostname = xstrdup(hent->h_name);
|
canon_hostname = xstrdup(hent->h_name);
|
||||||
free(ip_address);
|
free(ip_address);
|
||||||
ip_address = xstrdup(addrbuf);
|
ip_address = xstrdup(addrbuf);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user