- 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.
This commit is contained in:
Hiroki Sato 2015-09-02 16:50:49 +00:00
parent 4253ea5083
commit 34e38a56b0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=287404

View File

@ -394,26 +394,22 @@ getnameinfo_link(const struct sockaddr *sa, socklen_t salen,
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) {