diff options
author | deraadt <> | 1996-09-27 18:37:11 +0000 |
---|---|---|
committer | deraadt <> | 1996-09-27 18:37:11 +0000 |
commit | 2331d13ae5c6c8de49aeae1cb23a7c23f3a71b62 (patch) | |
tree | 178be3569fbdd3ee59f72772c997f7e9eaff7e5f /src/lib | |
parent | 255d8c1d1e511fecaedde35a1157c60b1ee9f55e (diff) | |
download | openbsd-2331d13ae5c6c8de49aeae1cb23a7c23f3a71b62.tar.gz openbsd-2331d13ae5c6c8de49aeae1cb23a7c23f3a71b62.tar.bz2 openbsd-2331d13ae5c6c8de49aeae1cb23a7c23f3a71b62.zip |
use INADDRSZ, more careful length checking
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libc/net/gethostnamadr.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c index 29fbedc594..3830e52cc6 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) |
55 | static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.9 1996/09/26 09:13:21 deraadt Exp $"; | 55 | static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.10 1996/09/27 18:37:11 deraadt 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> |
@@ -212,6 +212,8 @@ getanswer(answer, anslen, iquery) | |||
212 | continue; | 212 | continue; |
213 | *ap++ = bp; | 213 | *ap++ = bp; |
214 | n = strlen(bp) + 1; | 214 | n = strlen(bp) + 1; |
215 | if (n > MAXHOSTNAMELEN) | ||
216 | bp[MAXHOSTNAMELEN-1] = '\0'; | ||
215 | bp += n; | 217 | bp += n; |
216 | buflen -= n; | 218 | buflen -= n; |
217 | continue; | 219 | continue; |
@@ -237,6 +239,7 @@ getanswer(answer, anslen, iquery) | |||
237 | cp += n; | 239 | cp += n; |
238 | continue; | 240 | continue; |
239 | } | 241 | } |
242 | |||
240 | if (haveanswer) { | 243 | if (haveanswer) { |
241 | if (n != host.h_length) { | 244 | if (n != host.h_length) { |
242 | cp += n; | 245 | cp += n; |
@@ -251,12 +254,12 @@ getanswer(answer, anslen, iquery) | |||
251 | getclass = class; | 254 | getclass = class; |
252 | host.h_addrtype = (class == C_IN) ? AF_INET : AF_UNSPEC; | 255 | host.h_addrtype = (class == C_IN) ? AF_INET : AF_UNSPEC; |
253 | if (host.h_addrtype == AF_INET) | 256 | if (host.h_addrtype == AF_INET) |
254 | host.h_length = sizeof(struct in_addr); | 257 | host.h_length = INADDRSZ; |
255 | if (!iquery) { | 258 | if (!iquery) { |
256 | host.h_name = bp; | 259 | host.h_name = bp; |
257 | if (strlen(bp) >= MAXHOSTNAMELEN) | ||
258 | host.h_name[MAXHOSTNAMELEN-1] = '\0'; | ||
259 | bp += strlen(bp) + 1; | 260 | bp += strlen(bp) + 1; |
261 | if (strlen(host.h_name) >= MAXHOSTNAMELEN) | ||
262 | host.h_name[MAXHOSTNAMELEN-1] = '\0'; | ||
260 | } | 263 | } |
261 | } | 264 | } |
262 | 265 | ||
@@ -270,8 +273,6 @@ getanswer(answer, anslen, iquery) | |||
270 | break; | 273 | break; |
271 | } | 274 | } |
272 | bcopy(cp, *hap++ = bp, n); | 275 | bcopy(cp, *hap++ = bp, n); |
273 | if (n >= MAXHOSTNAMELEN) | ||
274 | bp[MAXHOSTNAMELEN-1] = '\0'; | ||
275 | bp +=n; | 276 | bp +=n; |
276 | cp += n; | 277 | cp += n; |
277 | haveanswer++; | 278 | haveanswer++; |
@@ -577,7 +578,7 @@ _yphostent(line) | |||
577 | 578 | ||
578 | host.h_name = NULL; | 579 | host.h_name = NULL; |
579 | host.h_addr_list = h_addr_ptrs; | 580 | host.h_addr_list = h_addr_ptrs; |
580 | host.h_length = sizeof(u_int32_t); | 581 | host.h_length = INADDRSZ; |
581 | host.h_addrtype = AF_INET; | 582 | host.h_addrtype = AF_INET; |
582 | hap = h_addr_ptrs; | 583 | hap = h_addr_ptrs; |
583 | buf = host_addrs; | 584 | buf = host_addrs; |