diff options
Diffstat (limited to 'src/lib/libc/net/getservent.c')
| -rw-r--r-- | src/lib/libc/net/getservent.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/src/lib/libc/net/getservent.c b/src/lib/libc/net/getservent.c index 316891450e..bad3316f6c 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. |
| @@ -12,11 +10,7 @@ | |||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the | 11 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. | 12 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. All advertising materials mentioning features or use of this software | 13 | * 3. Neither the name of the University nor the names of its contributors |
| 16 | * must display the following acknowledgement: | ||
| 17 | * This product includes software developed by the University of | ||
| 18 | * California, Berkeley and its contributors. | ||
| 19 | * 4. Neither the name of the University nor the names of its contributors | ||
| 20 | * may be used to endorse or promote products derived from this software | 14 | * may be used to endorse or promote products derived from this software |
| 21 | * without specific prior written permission. | 15 | * without specific prior written permission. |
| 22 | * | 16 | * |
| @@ -34,11 +28,7 @@ | |||
| 34 | */ | 28 | */ |
| 35 | 29 | ||
| 36 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 37 | #if 0 | 31 | static char rcsid[] = "$OpenBSD: getservent.c,v 1.6 2003/06/02 20:18:35 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 43 | 33 | ||
| 44 | #include <sys/types.h> | 34 | #include <sys/types.h> |
| @@ -80,20 +70,25 @@ endservent() | |||
| 80 | struct servent * | 70 | struct servent * |
| 81 | getservent() | 71 | getservent() |
| 82 | { | 72 | { |
| 83 | char *p; | 73 | char *p, *cp, **q, *endp; |
| 84 | register char *cp, **q; | 74 | long l; |
| 75 | size_t len; | ||
| 85 | 76 | ||
| 86 | if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) | 77 | if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) |
| 87 | return (NULL); | 78 | return (NULL); |
| 88 | again: | 79 | again: |
| 89 | if ((p = fgets(line, BUFSIZ, servf)) == NULL) | 80 | if ((p = fgetln(servf, &len)) == NULL) |
| 90 | return (NULL); | 81 | return (NULL); |
| 91 | if (*p == '#') | 82 | if (p[len-1] == '\n') |
| 83 | len--; | ||
| 84 | if (len >= sizeof(line) || len == 0) | ||
| 92 | goto again; | 85 | goto again; |
| 93 | cp = strpbrk(p, "#\n"); | 86 | p = memcpy(line, p, len); |
| 94 | if (cp == NULL) | 87 | line[len] = '\0'; |
| 88 | if (*p == '#') | ||
| 95 | goto again; | 89 | goto again; |
| 96 | *cp = '\0'; | 90 | if ((cp = strchr(p, '#')) != NULL) |
| 91 | *cp = '\0'; | ||
| 97 | serv.s_name = p; | 92 | serv.s_name = p; |
| 98 | p = strpbrk(p, " \t"); | 93 | p = strpbrk(p, " \t"); |
| 99 | if (p == NULL) | 94 | if (p == NULL) |
| @@ -105,7 +100,10 @@ again: | |||
| 105 | if (cp == NULL) | 100 | if (cp == NULL) |
| 106 | goto again; | 101 | goto again; |
| 107 | *cp++ = '\0'; | 102 | *cp++ = '\0'; |
| 108 | serv.s_port = htons((u_short)atoi(p)); | 103 | l = strtol(p, &endp, 10); |
| 104 | if (endp == p || *endp != '\0' || l < 0 || l > USHRT_MAX) | ||
| 105 | goto again; | ||
| 106 | serv.s_port = htons((in_port_t)l); | ||
| 109 | serv.s_proto = cp; | 107 | serv.s_proto = cp; |
| 110 | q = serv.s_aliases = serv_aliases; | 108 | q = serv.s_aliases = serv_aliases; |
| 111 | cp = strpbrk(cp, " \t"); | 109 | cp = strpbrk(cp, " \t"); |
