Author: hrs Date: Wed Sep 2 16:50:49 2015 New Revision: 287404 URL: https://svnweb.freebsd.org/changeset/base/287404
Log: - snprintf() returns at most size-1 of the chars printed into the buffer. (n == hostlen) also means the buffer length was too short. - Use sdl->sdl_data only when (sdl->sdl_nlen > 0 && sdl->sdl_alen == 0) to prevent redundant output. Modified: head/lib/libc/net/getnameinfo.c Modified: head/lib/libc/net/getnameinfo.c ============================================================================== --- head/lib/libc/net/getnameinfo.c Wed Sep 2 16:48:03 2015 (r287403) +++ head/lib/libc/net/getnameinfo.c Wed Sep 2 16:50:49 2015 (r287404) @@ -394,26 +394,22 @@ getnameinfo_link(const struct sockaddr * if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) { n = snprintf(host, hostlen, "link#%d", sdl->sdl_index); - if (n > hostlen) { + if (n >= hostlen) { *host = '\0'; return (EAI_MEMORY); } return (0); } - if (sdl->sdl_nlen > 0) { - if (sdl->sdl_nlen + 1 > hostlen) { + if (sdl->sdl_nlen > 0 && sdl->sdl_alen == 0) { + n = sdl->sdl_nlen; + if (n >= hostlen) { *host = '\0'; return (EAI_MEMORY); } memcpy(host, sdl->sdl_data, sdl->sdl_nlen); - n = sdl->sdl_nlen; - host += n; - if (sdl->sdl_alen > 0) { - *host++ = ':'; - n++; - } - hostlen -= n; + host[n] = '\0'; + return (0); } switch (sdl->sdl_type) { _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"