PR/48585: Henning Petersen: Always set errno when returning NULL.
This commit is contained in:
parent
8653615804
commit
72d54c1762
|
@ -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.10 2014/02/10 16:29:30 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||
|
@ -22,7 +22,7 @@
|
|||
#if 0
|
||||
static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp";
|
||||
#else
|
||||
__RCSID("$NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $");
|
||||
__RCSID("$NetBSD: inet_ntop.c,v 1.10 2014/02/10 16:29:30 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
|
@ -189,7 +189,7 @@ inet_ntop6(const u_char *src, char *dst, socklen_t size)
|
|||
/* Are we following an initial run of 0x00s or any real hex? */
|
||||
if (i != 0) {
|
||||
if (tp + 1 >= ep)
|
||||
return (NULL);
|
||||
goto out;
|
||||
*tp++ = ':';
|
||||
}
|
||||
/* Is this address an encapsulated IPv4? */
|
||||
|
@ -197,36 +197,37 @@ inet_ntop6(const u_char *src, char *dst, socklen_t size)
|
|||
(best.len == 6 ||
|
||||
(best.len == 7 && words[7] != 0x0001) ||
|
||||
(best.len == 5 && words[5] == 0xffff))) {
|
||||
if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp)))
|
||||
return (NULL);
|
||||
if (!inet_ntop4(src + 12, tp, (socklen_t)(ep - tp)))
|
||||
goto out;
|
||||
tp += strlen(tp);
|
||||
break;
|
||||
}
|
||||
advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]);
|
||||
if (advance <= 0 || advance >= ep - tp)
|
||||
return (NULL);
|
||||
goto out;
|
||||
tp += advance;
|
||||
}
|
||||
/* Was it a trailing run of 0x00's? */
|
||||
if (best.base != -1 && (best.base + best.len) ==
|
||||
(NS_IN6ADDRSZ / NS_INT16SZ)) {
|
||||
if (tp + 1 >= ep)
|
||||
return (NULL);
|
||||
goto out;
|
||||
*tp++ = ':';
|
||||
}
|
||||
if (tp + 1 >= ep)
|
||||
return (NULL);
|
||||
goto out;
|
||||
*tp++ = '\0';
|
||||
|
||||
/*
|
||||
* Check for overflow, copy, and we're done.
|
||||
*/
|
||||
if ((size_t)(tp - tmp) > size) {
|
||||
errno = ENOSPC;
|
||||
return (NULL);
|
||||
}
|
||||
if ((size_t)(tp - tmp) > size)
|
||||
goto out;
|
||||
strlcpy(dst, tmp, size);
|
||||
return (dst);
|
||||
out:
|
||||
errno = ENOSPC;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*! \file */
|
||||
|
|
Loading…
Reference in New Issue