summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/gethostnamadr.c
diff options
context:
space:
mode:
authormillert <>1998-03-16 05:07:02 +0000
committermillert <>1998-03-16 05:07:02 +0000
commit7cc61258b3b66c62b0828fdaa234ee8ae2fee2dc (patch)
treed54fd8f615df82fffca9638aee76c24acf5b731f /src/lib/libc/net/gethostnamadr.c
parentfcd822203d1ea91b0c87703a36e5819909a8f7f4 (diff)
downloadopenbsd-7cc61258b3b66c62b0828fdaa234ee8ae2fee2dc.tar.gz
openbsd-7cc61258b3b66c62b0828fdaa234ee8ae2fee2dc.tar.bz2
openbsd-7cc61258b3b66c62b0828fdaa234ee8ae2fee2dc.zip
Use fgetln(3) instead of fgets(3) so we can easily recognize lines
that are too long and ignore them instead of corrupting later entries.
Diffstat (limited to 'src/lib/libc/net/gethostnamadr.c')
-rw-r--r--src/lib/libc/net/gethostnamadr.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c
index 7fb148bf52..7321225863 100644
--- a/src/lib/libc/net/gethostnamadr.c
+++ b/src/lib/libc/net/gethostnamadr.c
@@ -52,7 +52,7 @@
52 */ 52 */
53 53
54#if defined(LIBC_SCCS) && !defined(lint) 54#if defined(LIBC_SCCS) && !defined(lint)
55static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.29 1998/01/20 18:28:33 deraadt Exp $"; 55static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.30 1998/03/16 05:06:55 millert Exp $";
56#endif /* LIBC_SCCS and not lint */ 56#endif /* LIBC_SCCS and not lint */
57 57
58#include <sys/param.h> 58#include <sys/param.h>
@@ -721,22 +721,28 @@ _gethtent()
721{ 721{
722 char *p; 722 char *p;
723 register char *cp, **q; 723 register char *cp, **q;
724 int af, len; 724 int af;
725 size_t len;
725 726
726 if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) { 727 if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) {
727 h_errno = NETDB_INTERNAL; 728 h_errno = NETDB_INTERNAL;
728 return (NULL); 729 return (NULL);
729 } 730 }
730 again: 731 again:
731 if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) { 732 if ((p = fgetln(hostf, &len)) == NULL) {
732 h_errno = HOST_NOT_FOUND; 733 h_errno = HOST_NOT_FOUND;
733 return (NULL); 734 return (NULL);
734 } 735 }
735 if (*p == '#') 736 if (p[len-1] == '\n')
737 len--;
738 if (len >= sizeof(hostbuf) || len == 0)
736 goto again; 739 goto again;
737 if (!(cp = strpbrk(p, "#\n"))) 740 p = memcpy(hostbuf, p, len);
741 hostbuf[len] = '\0';
742 if (*p == '#')
738 goto again; 743 goto again;
739 *cp = '\0'; 744 if ((cp = strchr(p, '#')))
745 *cp = '\0';
740 if (!(cp = strpbrk(p, " \t"))) 746 if (!(cp = strpbrk(p, " \t")))
741 goto again; 747 goto again;
742 *cp++ = '\0'; 748 *cp++ = '\0';