summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2000-07-30 14:07:15 +0000
committerJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2000-07-30 14:07:15 +0000
commit144b8babf339d0d54fd7112b6194ffc77b073dd8 (patch)
treebb76e08787b134e2b9e029fcfc1b899d1b13660a
parent72b615ee4693fbf100d77fc0dda678dc352a1806 (diff)
avoid buffer overrun on too-long reply for NIS hostname lookup.
-rw-r--r--lib/libc/net/gethostnamadr.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c
index 47570f4a025..33c9643f700 100644
--- a/lib/libc/net/gethostnamadr.c
+++ b/lib/libc/net/gethostnamadr.c
@@ -52,7 +52,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.41 2000/01/06 08:24:17 d Exp $";
+static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.42 2000/07/30 14:07:14 itojun Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -954,14 +954,14 @@ _yphostent(line)
q = host.h_aliases = host_aliases;
nextline:
+ /* check for host_addrs overflow */
+ if (buf >= &host_addrs[sizeof(host_addrs) / sizeof(host_addrs[0])])
+ goto done;
+
more = 0;
cp = strpbrk(p, " \t");
- if (cp == NULL) {
- if (host.h_name == NULL)
- return (NULL);
- else
- goto done;
- }
+ if (cp == NULL)
+ goto done;
*cp++ = '\0';
*hap++ = (char *)buf;
@@ -1002,6 +1002,8 @@ nextline:
*cp++ = '\0';
}
done:
+ if (host.h_name == NULL)
+ return (NULL);
*q = NULL;
*hap = NULL;
return (&host);