summaryrefslogtreecommitdiff
path: root/lib/libc/net/res_query.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-03-16 05:07:03 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-03-16 05:07:03 +0000
commitc6e6ff6ba816fbfd8168fcaa11020351a56bb992 (patch)
tree047c2ff5a5b9e94a0b77d503884e64395d8ca0cc /lib/libc/net/res_query.c
parent9e9d3110171c8c9544bf65a861f4261fed7219ef (diff)
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 'lib/libc/net/res_query.c')
-rw-r--r--lib/libc/net/res_query.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/libc/net/res_query.c b/lib/libc/net/res_query.c
index 2e245b78cc6..a2a8fe000b5 100644
--- a/lib/libc/net/res_query.c
+++ b/lib/libc/net/res_query.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_query.c,v 1.10 1997/07/09 01:08:53 millert Exp $ */
+/* $OpenBSD: res_query.c,v 1.11 1998/03/16 05:07:02 millert Exp $ */
/*
* ++Copyright++ 1988, 1993
@@ -60,7 +60,7 @@
static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $";
#else
-static char rcsid[] = "$OpenBSD: res_query.c,v 1.10 1997/07/09 01:08:53 millert Exp $";
+static char rcsid[] = "$OpenBSD: res_query.c,v 1.11 1998/03/16 05:07:02 millert Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -359,6 +359,7 @@ hostalias(name)
char *file;
char buf[BUFSIZ];
static char abuf[MAXDNAME];
+ size_t len;
if (_res.options & RES_NOALIASES)
return (NULL);
@@ -366,8 +367,14 @@ hostalias(name)
if (issetugid() != 0 || file == NULL || (fp = fopen(file, "r")) == NULL)
return (NULL);
setbuf(fp, NULL);
- buf[sizeof(buf) - 1] = '\0';
- while (fgets(buf, sizeof(buf), fp)) {
+ while ((cp1 = fgetln(fp, &len)) != NULL) {
+ if (cp1[len-1] == '\n')
+ len--;
+ if (len >= sizeof(buf) || len == 0)
+ continue;
+ (void)memcpy(buf, cp1, len);
+ buf[len] = '\0';
+
for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1)
;
if (!*cp1)