diff options
Diffstat (limited to 'src/lib/libc/net/ethers.c')
-rw-r--r-- | src/lib/libc/net/ethers.c | 30 |
1 files changed, 23 insertions, 7 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) |
9 | static char rcsid[] = "$OpenBSD: ethers.c,v 1.3 1996/08/19 08:28:36 tholo Exp $"; | 9 | static 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)) { |