netresolv/inet: Merge remaining patches from 2013 to current HEAD.
Commits merged from the semi-official Git mirror of NetBSD trunk (https://github.com/IIJ-NetBSD/netbsd-src/ - inet is in the tree at lib/libc/inet/). Commit authors/messages in chronological order follow: --------------------------------------- From: christos <[email protected]> Date: Mon, 10 Feb 2014 16:29:30 +0000 Subject: PR/48585: Henning Petersen: Always set errno when returning NULL. From: christos <[email protected]> Date: Mon, 10 Feb 2014 16:30:54 +0000 Subject: remove unneeded code, and kill parens from return
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $ */
|
/* $NetBSD: inet_ntop.c,v 1.11 2014/02/10 16:30:54 christos Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp";
|
static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $");
|
__RCSID("$NetBSD: inet_ntop.c,v 1.11 2014/02/10 16:30:54 christos Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
@@ -69,12 +69,12 @@ inet_ntop(int af, const void *src, char *dst, socklen_t size)
|
|||||||
|
|
||||||
switch (af) {
|
switch (af) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
return (inet_ntop4(src, dst, size));
|
return inet_ntop4(src, dst, size);
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
return (inet_ntop6(src, dst, size));
|
return inet_ntop6(src, dst, size);
|
||||||
default:
|
default:
|
||||||
errno = EAFNOSUPPORT;
|
errno = EAFNOSUPPORT;
|
||||||
return (NULL);
|
return NULL;
|
||||||
}
|
}
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
@@ -101,12 +101,10 @@ inet_ntop4(const u_char *src, char *dst, socklen_t size)
|
|||||||
|
|
||||||
l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u",
|
l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u",
|
||||||
src[0], src[1], src[2], src[3]);
|
src[0], src[1], src[2], src[3]);
|
||||||
if (l <= 0 || (socklen_t) l >= size) {
|
if (l <= 0 || (socklen_t) l >= size)
|
||||||
errno = ENOSPC;
|
return NULL;
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
strlcpy(dst, tmp, size);
|
strlcpy(dst, tmp, size);
|
||||||
return (dst);
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* const char *
|
/* const char *
|
||||||
@@ -184,7 +182,7 @@ inet_ntop6(const u_char *src, char *dst, socklen_t size)
|
|||||||
/* Are we following an initial run of 0x00s or any real hex? */
|
/* Are we following an initial run of 0x00s or any real hex? */
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
if (tp + 1 >= ep)
|
if (tp + 1 >= ep)
|
||||||
return (NULL);
|
goto out;
|
||||||
*tp++ = ':';
|
*tp++ = ':';
|
||||||
}
|
}
|
||||||
/* Is this address an encapsulated IPv4? */
|
/* Is this address an encapsulated IPv4? */
|
||||||
@@ -192,36 +190,37 @@ inet_ntop6(const u_char *src, char *dst, socklen_t size)
|
|||||||
(best.len == 6 ||
|
(best.len == 6 ||
|
||||||
(best.len == 7 && words[7] != 0x0001) ||
|
(best.len == 7 && words[7] != 0x0001) ||
|
||||||
(best.len == 5 && words[5] == 0xffff))) {
|
(best.len == 5 && words[5] == 0xffff))) {
|
||||||
if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp)))
|
if (!inet_ntop4(src + 12, tp, (socklen_t)(ep - tp)))
|
||||||
return (NULL);
|
goto out;
|
||||||
tp += strlen(tp);
|
tp += strlen(tp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]);
|
advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]);
|
||||||
if (advance <= 0 || advance >= ep - tp)
|
if (advance <= 0 || advance >= ep - tp)
|
||||||
return (NULL);
|
goto out;
|
||||||
tp += advance;
|
tp += advance;
|
||||||
}
|
}
|
||||||
/* Was it a trailing run of 0x00's? */
|
/* Was it a trailing run of 0x00's? */
|
||||||
if (best.base != -1 && (best.base + best.len) ==
|
if (best.base != -1 && (best.base + best.len) ==
|
||||||
(NS_IN6ADDRSZ / NS_INT16SZ)) {
|
(NS_IN6ADDRSZ / NS_INT16SZ)) {
|
||||||
if (tp + 1 >= ep)
|
if (tp + 1 >= ep)
|
||||||
return (NULL);
|
goto out;
|
||||||
*tp++ = ':';
|
*tp++ = ':';
|
||||||
}
|
}
|
||||||
if (tp + 1 >= ep)
|
if (tp + 1 >= ep)
|
||||||
return (NULL);
|
goto out;
|
||||||
*tp++ = '\0';
|
*tp++ = '\0';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for overflow, copy, and we're done.
|
* Check for overflow, copy, and we're done.
|
||||||
*/
|
*/
|
||||||
if ((size_t)(tp - tmp) > size) {
|
if ((size_t)(tp - tmp) > size)
|
||||||
errno = ENOSPC;
|
goto out;
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
strlcpy(dst, tmp, size);
|
strlcpy(dst, tmp, size);
|
||||||
return (dst);
|
return dst;
|
||||||
|
out:
|
||||||
|
errno = ENOSPC;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef inet_ntop
|
#undef inet_ntop
|
||||||
|
|||||||
Reference in New Issue
Block a user