From 01d81a035111b7a0794c70aea8c9df14e7fc06e9 Mon Sep 17 00:00:00 2001 From: Yoshinobu Inoue Date: Thu, 27 Jan 2000 17:24:53 +0000 Subject: [PATCH] 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 --- lib/libutil/realhostname.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/libutil/realhostname.c b/lib/libutil/realhostname.c index 7236890dab0b..2c9c5c52a902 100644 --- a/lib/libutil/realhostname.c +++ b/lib/libutil/realhostname.c @@ -122,8 +122,10 @@ realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen) port = ((struct sockinet *)addr)->si_port; ((struct sockinet *)addr)->si_port = 0; if (!memcmp(sa, addr, sa->sa_len)) { - strncpy(host, res->ai_canonname, - hsize); + if (res->ai_canonname != 0) + strncpy(host, + res->ai_canonname, + hsize); result = HOSTNAME_FOUND; ((struct sockinet *)addr)->si_port = port; @@ -146,8 +148,10 @@ realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen) if (IN6_IS_ADDR_V4MAPPED(in6) && !memcmp(&in6->s6_addr[12], in, sizeof(*in))) { - strncpy(host, res->ai_canonname, - hsize); + if (res->ai_canonname != 0) + strncpy(host, + res->ai_canonname, + hsize); result = HOSTNAME_FOUND; break; }