Date: Sun, 13 Sep 2015 03:15:38 +0000 (UTC) From: Hiroki Sato <hrs@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r287736 - stable/10/lib/libc/net Message-ID: <201509130315.t8D3Fcn8000472@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hrs Date: Sun Sep 13 03:15:37 2015 New Revision: 287736 URL: https://svnweb.freebsd.org/changeset/base/287736 Log: MFC 287349,287404: - Print sdl->sdl_data when sdl->sdl_nlen > 0 && sdl->sdl_alen == 0 as link_ntoa(3) does. - snprintf() returns at most size-1 of the chars printed into the buffer. (n == hostlen) also means the buffer length was too short. Modified: stable/10/lib/libc/net/getnameinfo.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/net/getnameinfo.c ============================================================================== --- stable/10/lib/libc/net/getnameinfo.c Sun Sep 13 03:09:21 2015 (r287735) +++ stable/10/lib/libc/net/getnameinfo.c Sun Sep 13 03:15:37 2015 (r287736) @@ -390,11 +390,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 (EAI_MEMORY); + } + return (0); + } + + if (sdl->sdl_nlen > 0 && sdl->sdl_alen == 0) { + n = sdl->sdl_nlen; + if (n >= hostlen) { + *host = '\0'; + return (EAI_MEMORY); } - return 0; + memcpy(host, sdl->sdl_data, sdl->sdl_nlen); + host[n] = '\0'; + return (0); } switch (sdl->sdl_type) { @@ -437,10 +448,7 @@ getnameinfo_link(const struct sockaddr * } static int -hexname(cp, len, host, hostlen) - const u_int8_t *cp; - char *host; - size_t len, hostlen; +hexname(const u_int8_t *cp, size_t len, char *host, size_t hostlen) { int i, n; char *outp = host;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201509130315.t8D3Fcn8000472>