X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/8f694072a524ab0f7edc4c3402fb5fc41ecbfa5e..0cdb547f5c79506686a67da65edd3ae0b3c581c1:/lib/inet_ntop.c diff --git a/lib/inet_ntop.c b/lib/inet_ntop.c index 9451d23d..7be7368e 100644 --- a/lib/inet_ntop.c +++ b/lib/inet_ntop.c @@ -15,18 +15,8 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ -#include - -#include -#include -#include - -#include +#include "rsync.h" #define NS_INT16SZ 2 #define NS_IN6ADDRSZ 16 @@ -53,7 +43,7 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, * Paul Vixie, 1996. */ const char * -isc_net_ntop(int af, const void *src, char *dst, size_t size) +inet_ntop(int af, const void *src, char *dst, size_t size) { switch (af) { case AF_INET: @@ -85,13 +75,14 @@ inet_ntop4(const unsigned char *src, char *dst, size_t size) { static const char *fmt = "%u.%u.%u.%u"; char tmp[sizeof "255.255.255.255"]; + size_t len; - if ((size_t)sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) >= size) - { + len = snprintf(tmp, sizeof tmp, fmt, src[0], src[1], src[2], src[3]); + if (len >= size) { errno = ENOSPC; return (NULL); } - strcpy(dst, tmp); + memcpy(dst, tmp, len + 1); return (dst); } @@ -116,7 +107,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size) char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; struct { int base, len; } best, cur; unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ]; - int i; + int i, inc; /* * Preprocess: @@ -167,13 +158,14 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size) /* Is this address an encapsulated IPv4? */ if (i == 6 && best.base == 0 && (best.len == 6 || (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))) return (NULL); tp += strlen(tp); break; } - tp += sprintf(tp, "%x", words[i]); + inc = snprintf(tp, 5, "%x", words[i]); + assert(inc < 5); + tp += inc; } /* Was it a trailing run of 0x00's? */ if (best.base != -1 && (best.base + best.len) == @@ -188,7 +180,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size) errno = ENOSPC; return (NULL); } - strcpy(dst, tmp); + memcpy(dst, tmp, tp - tmp); return (dst); } #endif /* AF_INET6 */