summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libc/net/ethers.c30
-rw-r--r--src/lib/libc/net/gethostnamadr.c18
-rw-r--r--src/lib/libc/net/getnetent.314
-rw-r--r--src/lib/libc/net/getnetent.c21
-rw-r--r--src/lib/libc/net/getprotoent.c20
-rw-r--r--src/lib/libc/net/getservent.c20
-rw-r--r--src/lib/libc/net/res_init.c17
-rw-r--r--src/lib/libc/net/res_query.c15
8 files changed, 101 insertions, 54 deletions
diff --git a/src/lib/libc/net/ethers.c b/src/lib/libc/net/ethers.c
index 71163515a4..b2d18e9932 100644
--- a/src/lib/libc/net/ethers.c
+++ b/src/lib/libc/net/ethers.c
@@ -6,7 +6,7 @@
6 */ 6 */
7 7
8#if defined(LIBC_SCCS) && !defined(lint) 8#if defined(LIBC_SCCS) && !defined(lint)
9static char rcsid[] = "$OpenBSD: ethers.c,v 1.3 1996/08/19 08:28:36 tholo Exp $"; 9static char rcsid[] = "$OpenBSD: ethers.c,v 1.4 1998/03/16 05:06:53 millert Exp $";
10#endif /* LIBC_SCCS and not lint */ 10#endif /* LIBC_SCCS and not lint */
11 11
12#include <sys/types.h> 12#include <sys/types.h>
@@ -64,7 +64,8 @@ ether_ntohost(hostname, e)
64 struct ether_addr *e; 64 struct ether_addr *e;
65{ 65{
66 FILE *f; 66 FILE *f;
67 char buf[BUFSIZ]; 67 char buf[BUFSIZ+1], *p;
68 size_t len;
68 struct ether_addr try; 69 struct ether_addr try;
69 70
70#ifdef YP 71#ifdef YP
@@ -79,9 +80,16 @@ ether_ntohost(hostname, e)
79#endif 80#endif
80 81
81 f = fopen(_PATH_ETHERS, "r"); 82 f = fopen(_PATH_ETHERS, "r");
82 if (f==NULL) 83 if (f == NULL)
83 return -1; 84 return -1;
84 while (fgets(buf, sizeof buf, f)) { 85 while ((p = fgetln(f, &len)) != NULL) {
86 if (p[len-1] == '\n')
87 len--;
88 if (len > sizeof(buf) - 2)
89 continue;
90 memcpy(buf, p, len);
91 buf[len] = '\n'; /* code assumes newlines later on */
92 buf[len+1] = '\0';
85#ifdef YP 93#ifdef YP
86 /* A + in the file means try YP now. */ 94 /* A + in the file means try YP now. */
87 if (!strncmp(buf, "+\n", sizeof buf)) { 95 if (!strncmp(buf, "+\n", sizeof buf)) {
@@ -103,7 +111,7 @@ ether_ntohost(hostname, e)
103 } 111 }
104#endif 112#endif
105 if (ether_line(buf, &try, hostname) == 0 && 113 if (ether_line(buf, &try, hostname) == 0 &&
106 bcmp((char *)&try, (char *)e, sizeof try) == 0) { 114 memcmp((char *)&try, (char *)e, sizeof try) == 0) {
107 (void)fclose(f); 115 (void)fclose(f);
108 return 0; 116 return 0;
109 } 117 }
@@ -119,8 +127,9 @@ ether_hostton(hostname, e)
119 struct ether_addr *e; 127 struct ether_addr *e;
120{ 128{
121 FILE *f; 129 FILE *f;
122 char buf[BUFSIZ]; 130 char buf[BUFSIZ+1], *p;
123 char try[MAXHOSTNAMELEN]; 131 char try[MAXHOSTNAMELEN];
132 size_t len;
124#ifdef YP 133#ifdef YP
125 int hostlen = strlen(hostname); 134 int hostlen = strlen(hostname);
126#endif 135#endif
@@ -129,7 +138,14 @@ ether_hostton(hostname, e)
129 if (f==NULL) 138 if (f==NULL)
130 return -1; 139 return -1;
131 140
132 while (fgets(buf, sizeof buf, f)) { 141 while ((p = fgetln(f, &len)) != NULL) {
142 if (p[len-1] == '\n')
143 len--;
144 if (len > sizeof(buf) - 2)
145 continue;
146 memcpy(buf, p, len);
147 buf[len] = '\n'; /* code assumes newlines later on */
148 buf[len+1] = '\0';
133#ifdef YP 149#ifdef YP
134 /* A + in the file means try YP now. */ 150 /* A + in the file means try YP now. */
135 if (!strncmp(buf, "+\n", sizeof buf)) { 151 if (!strncmp(buf, "+\n", sizeof buf)) {
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';
diff --git a/src/lib/libc/net/getnetent.3 b/src/lib/libc/net/getnetent.3
index a33ac0fac5..5864b75839 100644
--- a/src/lib/libc/net/getnetent.3
+++ b/src/lib/libc/net/getnetent.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: getnetent.3,v 1.4 1997/04/05 21:13:07 millert Exp $ 1.\" $OpenBSD: getnetent.3,v 1.5 1998/03/16 05:06:56 millert Exp $
2.\" 2.\"
3.\" Copyright (c) 1983, 1991, 1993 3.\" Copyright (c) 1983, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
@@ -141,10 +141,8 @@ and
141functions appeared in 141functions appeared in
142.Bx 4.2 . 142.Bx 4.2 .
143.Sh BUGS 143.Sh BUGS
144The data space used by 144The data space used by these functions is static; if future use
145these functions is static; if future use requires the data, it should be 145requires the data, it should be copied before any subsequent calls
146copied before any subsequent calls to these functions overwrite it. 146to these functions overwrite it. Only Internet network numbers
147Only Internet network 147are currently understood. Expecting network numbers to fit in no
148numbers are currently understood. 148more than 32 bits is naive.
149Expecting network numbers to fit
150in no more than 32 bits is naive.
diff --git a/src/lib/libc/net/getnetent.c b/src/lib/libc/net/getnetent.c
index e40fb50c0f..8f618a1d5e 100644
--- a/src/lib/libc/net/getnetent.c
+++ b/src/lib/libc/net/getnetent.c
@@ -32,7 +32,7 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35static char rcsid[] = "$OpenBSD: getnetent.c,v 1.7 1997/04/24 08:37:09 tholo Exp $"; 35static char rcsid[] = "$OpenBSD: getnetent.c,v 1.8 1998/03/16 05:06:57 millert Exp $";
36#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
37 37
38#include <sys/types.h> 38#include <sys/types.h>
@@ -75,21 +75,24 @@ endnetent()
75struct netent * 75struct netent *
76getnetent() 76getnetent()
77{ 77{
78 char *p; 78 char *p, *cp, **q;
79 register char *cp, **q; 79 size_t len;
80 80
81 if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) 81 if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
82 return (NULL); 82 return (NULL);
83again: 83again:
84 p = fgets(line, BUFSIZ, netf); 84 if ((p = fgetln(netf, &len)) == NULL)
85 if (p == NULL)
86 return (NULL); 85 return (NULL);
87 if (*p == '#') 86 if (p[len-1] == '\n')
87 len--;
88 if (len >= sizeof(line) || len == 0)
88 goto again; 89 goto again;
89 cp = strpbrk(p, "#\n"); 90 p = memcpy(line, p, len);
90 if (cp == NULL) 91 line[len] = '\0';
92 if (*p == '#')
91 goto again; 93 goto again;
92 *cp = '\0'; 94 if ((cp = strchr(p, '#')) != NULL)
95 *cp = '\0';
93 net.n_name = p; 96 net.n_name = p;
94 if (strlen(net.n_name) >= MAXHOSTNAMELEN-1) 97 if (strlen(net.n_name) >= MAXHOSTNAMELEN-1)
95 net.n_name[MAXHOSTNAMELEN-1] = '\0'; 98 net.n_name[MAXHOSTNAMELEN-1] = '\0';
diff --git a/src/lib/libc/net/getprotoent.c b/src/lib/libc/net/getprotoent.c
index 381feb6faf..2bef526e7a 100644
--- a/src/lib/libc/net/getprotoent.c
+++ b/src/lib/libc/net/getprotoent.c
@@ -32,7 +32,7 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.2 1996/08/19 08:28:52 tholo Exp $"; 35static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.3 1998/03/16 05:06:59 millert Exp $";
36#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
37 37
38#include <sys/types.h> 38#include <sys/types.h>
@@ -74,20 +74,24 @@ endprotoent()
74struct protoent * 74struct protoent *
75getprotoent() 75getprotoent()
76{ 76{
77 char *p; 77 char *p, *cp, **q;
78 register char *cp, **q; 78 size_t len;
79 79
80 if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) 80 if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL)
81 return (NULL); 81 return (NULL);
82again: 82again:
83 if ((p = fgets(line, BUFSIZ, protof)) == NULL) 83 if ((p = fgetln(protof, &len)) == NULL)
84 return (NULL); 84 return (NULL);
85 if (*p == '#') 85 if (p[len-1] == '\n')
86 len--;
87 if (len >= sizeof(line) || len == 0)
86 goto again; 88 goto again;
87 cp = strpbrk(p, "#\n"); 89 p = memcpy(line, p, len);
88 if (cp == NULL) 90 line[len] = '\0';
91 if (*p == '#')
89 goto again; 92 goto again;
90 *cp = '\0'; 93 if ((cp = strchr(p, '#')) != NULL)
94 *cp = '\0';
91 proto.p_name = p; 95 proto.p_name = p;
92 cp = strpbrk(p, " \t"); 96 cp = strpbrk(p, " \t");
93 if (cp == NULL) 97 if (cp == NULL)
diff --git a/src/lib/libc/net/getservent.c b/src/lib/libc/net/getservent.c
index feb97aa129..7d8cb6d8ca 100644
--- a/src/lib/libc/net/getservent.c
+++ b/src/lib/libc/net/getservent.c
@@ -32,7 +32,7 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35static char rcsid[] = "$OpenBSD: getservent.c,v 1.3 1997/04/05 21:13:09 millert Exp $"; 35static char rcsid[] = "$OpenBSD: getservent.c,v 1.4 1998/03/16 05:07:00 millert Exp $";
36#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
37 37
38#include <sys/types.h> 38#include <sys/types.h>
@@ -74,20 +74,24 @@ endservent()
74struct servent * 74struct servent *
75getservent() 75getservent()
76{ 76{
77 char *p; 77 char *p, *cp, **q;
78 register char *cp, **q; 78 size_t len;
79 79
80 if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) 80 if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL)
81 return (NULL); 81 return (NULL);
82again: 82again:
83 if ((p = fgets(line, BUFSIZ, servf)) == NULL) 83 if ((p = fgetln(servf, &len)) == NULL)
84 return (NULL); 84 return (NULL);
85 if (*p == '#') 85 if (p[len-1] == '\n')
86 len--;
87 if (len >= sizeof(line) || len == 0)
86 goto again; 88 goto again;
87 cp = strpbrk(p, "#\n"); 89 p = memcpy(line, p, len);
88 if (cp == NULL) 90 line[len] = '\0';
91 if (*p == '#')
89 goto again; 92 goto again;
90 *cp = '\0'; 93 if ((cp = strchr(p, '#')) != NULL)
94 *cp = '\0';
91 serv.s_name = p; 95 serv.s_name = p;
92 p = strpbrk(p, " \t"); 96 p = strpbrk(p, " \t");
93 if (p == NULL) 97 if (p == NULL)
diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c
index b4cee1d307..df176b7fa1 100644
--- a/src/lib/libc/net/res_init.c
+++ b/src/lib/libc/net/res_init.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: res_init.c,v 1.15 1997/07/15 18:33:50 flipk Exp $ */ 1/* $OpenBSD: res_init.c,v 1.16 1998/03/16 05:07:01 millert Exp $ */
2 2
3/* 3/*
4 * ++Copyright++ 1985, 1989, 1993 4 * ++Copyright++ 1985, 1989, 1993
@@ -60,7 +60,7 @@
60static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; 60static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
61static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; 61static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $";
62#else 62#else
63static char rcsid[] = "$OpenBSD: res_init.c,v 1.15 1997/07/15 18:33:50 flipk Exp $"; 63static char rcsid[] = "$OpenBSD: res_init.c,v 1.16 1998/03/16 05:07:01 millert Exp $";
64#endif 64#endif
65#endif /* LIBC_SCCS and not lint */ 65#endif /* LIBC_SCCS and not lint */
66 66
@@ -151,6 +151,7 @@ res_init()
151 int nserv = 0; /* number of nameserver records read from file */ 151 int nserv = 0; /* number of nameserver records read from file */
152 int haveenv = 0; 152 int haveenv = 0;
153 int havesearch = 0; 153 int havesearch = 0;
154 size_t len;
154#ifdef RESOLVSORT 155#ifdef RESOLVSORT
155 int nsort = 0; 156 int nsort = 0;
156 char *net; 157 char *net;
@@ -241,9 +242,17 @@ res_init()
241 strncpy(_res.lookups, "bf", sizeof _res.lookups); 242 strncpy(_res.lookups, "bf", sizeof _res.lookups);
242 243
243 /* read the config file */ 244 /* read the config file */
244 while (fgets(buf, sizeof(buf), fp) != NULL) { 245 buf[0] = '\0';
246 while ((cp = fgetln(fp, &len)) != NULL) {
247 /* skip lines that are too long or zero length */
248 if (len >= sizeof(buf) || len == 0)
249 continue;
250 (void)memcpy(buf, cp, len);
251 buf[len] = '\0';
245 /* skip comments */ 252 /* skip comments */
246 if (*buf == ';' || *buf == '#') 253 if ((cp = strpbrk(buf, ";#")) != NULL)
254 *cp = '\0';
255 if (buf[0] == '\0')
247 continue; 256 continue;
248 /* read default domain name */ 257 /* read default domain name */
249 if (MATCH(buf, "domain")) { 258 if (MATCH(buf, "domain")) {
diff --git a/src/lib/libc/net/res_query.c b/src/lib/libc/net/res_query.c
index 2e245b78cc..a2a8fe000b 100644
--- a/src/lib/libc/net/res_query.c
+++ b/src/lib/libc/net/res_query.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: res_query.c,v 1.10 1997/07/09 01:08:53 millert Exp $ */ 1/* $OpenBSD: res_query.c,v 1.11 1998/03/16 05:07:02 millert Exp $ */
2 2
3/* 3/*
4 * ++Copyright++ 1988, 1993 4 * ++Copyright++ 1988, 1993
@@ -60,7 +60,7 @@
60static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; 60static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
61static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $"; 61static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $";
62#else 62#else
63static char rcsid[] = "$OpenBSD: res_query.c,v 1.10 1997/07/09 01:08:53 millert Exp $"; 63static char rcsid[] = "$OpenBSD: res_query.c,v 1.11 1998/03/16 05:07:02 millert Exp $";
64#endif 64#endif
65#endif /* LIBC_SCCS and not lint */ 65#endif /* LIBC_SCCS and not lint */
66 66
@@ -359,6 +359,7 @@ hostalias(name)
359 char *file; 359 char *file;
360 char buf[BUFSIZ]; 360 char buf[BUFSIZ];
361 static char abuf[MAXDNAME]; 361 static char abuf[MAXDNAME];
362 size_t len;
362 363
363 if (_res.options & RES_NOALIASES) 364 if (_res.options & RES_NOALIASES)
364 return (NULL); 365 return (NULL);
@@ -366,8 +367,14 @@ hostalias(name)
366 if (issetugid() != 0 || file == NULL || (fp = fopen(file, "r")) == NULL) 367 if (issetugid() != 0 || file == NULL || (fp = fopen(file, "r")) == NULL)
367 return (NULL); 368 return (NULL);
368 setbuf(fp, NULL); 369 setbuf(fp, NULL);
369 buf[sizeof(buf) - 1] = '\0'; 370 while ((cp1 = fgetln(fp, &len)) != NULL) {
370 while (fgets(buf, sizeof(buf), fp)) { 371 if (cp1[len-1] == '\n')
372 len--;
373 if (len >= sizeof(buf) || len == 0)
374 continue;
375 (void)memcpy(buf, cp1, len);
376 buf[len] = '\0';
377
371 for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1) 378 for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1)
372 ; 379 ;
373 if (!*cp1) 380 if (!*cp1)