--- a/sys/libkern/inet_ntop.c +++ b/sys/libkern/inet_ntop.c @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -49,6 +50,7 @@ case AF_INET6: return (inet_ntop6(src, dst, size)); default: + errno = EAFNOSUPPORT; return (NULL); } /* NOTREACHED */ @@ -74,6 +76,7 @@ l = ksnprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]); if (l <= 0 || (socklen_t) l >= size) { + errno = ENOSPC; return (NULL); } strlcpy(dst, tmp, size); @@ -155,8 +158,10 @@ if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 7 && words[7] != 0x0001) || (best.len == 5 && words[5] == 0xffff))) { - if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) + if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) { + errno = ENOSPC; return (NULL); + } tp += strlen(tp); break; } @@ -172,6 +177,7 @@ * Check for overflow, copy, and we're done. */ if ((socklen_t)(tp - tmp) > size) { + errno = ENOSPC; return (NULL); } strcpy(dst, tmp);