diff options
Diffstat (limited to 'src/lib/libc/net/getservent.c')
| -rw-r--r-- | src/lib/libc/net/getservent.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/lib/libc/net/getservent.c b/src/lib/libc/net/getservent.c index 316891450e..ff6bf1e57f 100644 --- a/src/lib/libc/net/getservent.c +++ b/src/lib/libc/net/getservent.c | |||
| @@ -1,5 +1,3 @@ | |||
| 1 | /* $NetBSD: getservent.c,v 1.4 1995/02/25 06:20:38 cgd Exp $ */ | ||
| 2 | |||
| 3 | /* | 1 | /* |
| 4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
| 5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
| @@ -34,11 +32,7 @@ | |||
| 34 | */ | 32 | */ |
| 35 | 33 | ||
| 36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: getservent.c,v 1.5 1999/09/03 16:23:19 millert Exp $"; |
| 38 | static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93"; | ||
| 39 | #else | ||
| 40 | static char rcsid[] = "$NetBSD: getservent.c,v 1.4 1995/02/25 06:20:38 cgd Exp $"; | ||
| 41 | #endif | ||
| 42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 43 | 37 | ||
| 44 | #include <sys/types.h> | 38 | #include <sys/types.h> |
| @@ -80,20 +74,25 @@ endservent() | |||
| 80 | struct servent * | 74 | struct servent * |
| 81 | getservent() | 75 | getservent() |
| 82 | { | 76 | { |
| 83 | char *p; | 77 | char *p, *cp, **q, *endp; |
| 84 | register char *cp, **q; | 78 | long l; |
| 79 | size_t len; | ||
| 85 | 80 | ||
| 86 | if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) | 81 | if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) |
| 87 | return (NULL); | 82 | return (NULL); |
| 88 | again: | 83 | again: |
| 89 | if ((p = fgets(line, BUFSIZ, servf)) == NULL) | 84 | if ((p = fgetln(servf, &len)) == NULL) |
| 90 | return (NULL); | 85 | return (NULL); |
| 91 | if (*p == '#') | 86 | if (p[len-1] == '\n') |
| 87 | len--; | ||
| 88 | if (len >= sizeof(line) || len == 0) | ||
| 92 | goto again; | 89 | goto again; |
| 93 | cp = strpbrk(p, "#\n"); | 90 | p = memcpy(line, p, len); |
| 94 | if (cp == NULL) | 91 | line[len] = '\0'; |
| 92 | if (*p == '#') | ||
| 95 | goto again; | 93 | goto again; |
| 96 | *cp = '\0'; | 94 | if ((cp = strchr(p, '#')) != NULL) |
| 95 | *cp = '\0'; | ||
| 97 | serv.s_name = p; | 96 | serv.s_name = p; |
| 98 | p = strpbrk(p, " \t"); | 97 | p = strpbrk(p, " \t"); |
| 99 | if (p == NULL) | 98 | if (p == NULL) |
| @@ -105,7 +104,10 @@ again: | |||
| 105 | if (cp == NULL) | 104 | if (cp == NULL) |
| 106 | goto again; | 105 | goto again; |
| 107 | *cp++ = '\0'; | 106 | *cp++ = '\0'; |
| 108 | serv.s_port = htons((u_short)atoi(p)); | 107 | l = strtol(p, &endp, 10); |
| 108 | if (endp == p || *endp != '\0' || l < 0 || l > USHRT_MAX) | ||
| 109 | goto again; | ||
| 110 | serv.s_port = htons((in_port_t)l); | ||
| 109 | serv.s_proto = cp; | 111 | serv.s_proto = cp; |
| 110 | q = serv.s_aliases = serv_aliases; | 112 | q = serv.s_aliases = serv_aliases; |
| 111 | cp = strpbrk(cp, " \t"); | 113 | cp = strpbrk(cp, " \t"); |
