size_t hostlen, char *serv, size_t servlen, int flags)
{
struct hostent *hp;
+ int namelen;
if (sa->sa_family != AF_INET)
return (EAI_FAMILY);
else
return (EAI_FAIL);
}
- if (host != NULL) {
- strncpy(host, hp->h_name, hostlen);
- host[hostlen - 1] = '\0';
+ if (host != NULL && hostlen > 0) {
+ /*
+ * Don't exceed buffer
+ */
+ namelen = min(strlen(hp->h_name), hostlen - 1);
+ if (namelen > 0) {
+ strncpy(host, hp->h_name, namelen);
+ host[namelen - 1] = '\0';
+ }
}
return (0);
}