From 1ac2c28488fb5de80b3ce9aac3500d215cb61728 Mon Sep 17 00:00:00 2001 From: Brian Wellington Date: Thu, 25 Jan 2001 19:39:48 +0000 Subject: [PATCH] 711. [bug] The libisc and liblwres implementations of inet_ntop contained an off by one error. --- CHANGES | 3 +++ lib/isc/inet_ntop.c | 7 ++++--- lib/lwres/lwinetntop.c | 7 ++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 750c42e7b3..967bf1e657 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,7 @@ + 711. [bug] The libisc and liblwres implementations of + inet_ntop contained an off by one error. + 710. [func] The forwarders statement now takes an optional port. 709. [bug] ANY or SIG queries for data with a TTL of 0 diff --git a/lib/isc/inet_ntop.c b/lib/isc/inet_ntop.c index d6e3768c81..b9138954c7 100644 --- a/lib/isc/inet_ntop.c +++ b/lib/isc/inet_ntop.c @@ -17,7 +17,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static char rcsid[] = - "$Id: inet_ntop.c,v 1.10 2001/01/09 21:56:07 bwelling Exp $"; + "$Id: inet_ntop.c,v 1.11 2001/01/25 19:39:48 bwelling Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -86,7 +86,8 @@ 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"]; - if ((size_t)sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) > size) { + if ((size_t)sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) >= size) + { errno = ENOSPC; return (NULL); } @@ -183,7 +184,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size) /* * Check for overflow, copy, and we're done. */ - if ((size_t)(tp - tmp) > size) { + if ((size_t)(tp - tmp) >= size) { errno = ENOSPC; return (NULL); } diff --git a/lib/lwres/lwinetntop.c b/lib/lwres/lwinetntop.c index 00b97a0b7a..cdcb16dfad 100644 --- a/lib/lwres/lwinetntop.c +++ b/lib/lwres/lwinetntop.c @@ -17,7 +17,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static char rcsid[] = - "$Id: lwinetntop.c,v 1.6 2001/01/09 21:59:26 bwelling Exp $"; + "$Id: lwinetntop.c,v 1.7 2001/01/25 19:39:47 bwelling Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -84,7 +84,8 @@ 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"]; - if ((size_t)sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) > size) { + if ((size_t)sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) >= size) + { errno = ENOSPC; return (NULL); } @@ -180,7 +181,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size) { /* * Check for overflow, copy, and we're done. */ - if ((size_t)(tp - tmp) > size) { + if ((size_t)(tp - tmp) >= size) { errno = ENOSPC; return (NULL); }