Avoid core dump when ai_canonname is NULL.

(Now this happens for numeric addrs, as getaddrinfo() 1.3 -> 1.4 change)

Reviewed by: Mark Huizer <xaa@timewasters.nl>
This commit is contained in:
Yoshinobu Inoue 2000-01-27 17:24:53 +00:00
parent 623136a74f
commit 01d81a0351

View File

@ -122,8 +122,10 @@ realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen)
port = ((struct sockinet *)addr)->si_port; port = ((struct sockinet *)addr)->si_port;
((struct sockinet *)addr)->si_port = 0; ((struct sockinet *)addr)->si_port = 0;
if (!memcmp(sa, addr, sa->sa_len)) { if (!memcmp(sa, addr, sa->sa_len)) {
strncpy(host, res->ai_canonname, if (res->ai_canonname != 0)
hsize); strncpy(host,
res->ai_canonname,
hsize);
result = HOSTNAME_FOUND; result = HOSTNAME_FOUND;
((struct sockinet *)addr)->si_port = ((struct sockinet *)addr)->si_port =
port; port;
@ -146,8 +148,10 @@ realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen)
if (IN6_IS_ADDR_V4MAPPED(in6) && if (IN6_IS_ADDR_V4MAPPED(in6) &&
!memcmp(&in6->s6_addr[12], in, !memcmp(&in6->s6_addr[12], in,
sizeof(*in))) { sizeof(*in))) {
strncpy(host, res->ai_canonname, if (res->ai_canonname != 0)
hsize); strncpy(host,
res->ai_canonname,
hsize);
result = HOSTNAME_FOUND; result = HOSTNAME_FOUND;
break; break;
} }