diff options
author | 1998-03-16 05:06:47 +0000 | |
---|---|---|
committer | 1998-03-16 05:06:47 +0000 | |
commit | aff2b1e41ca918d7aeda7a2263889387c0ad437d (patch) | |
tree | 47be063896e0b666040cd478a501212b86c04a29 /lib/libc/net/res_query.c | |
parent | Add FFS_SOFTUPDATES and change an occurrence of NFS to NFS_CLIENT. (diff) | |
download | wireguard-openbsd-aff2b1e41ca918d7aeda7a2263889387c0ad437d.tar.xz wireguard-openbsd-aff2b1e41ca918d7aeda7a2263889387c0ad437d.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 'lib/libc/net/res_query.c')
-rw-r--r-- | lib/libc/net/res_query.c | 15 |
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) |