summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1995-03-24 15:51:30 +0000
committerache <ache@FreeBSD.org>1995-03-24 15:51:30 +0000
commit522e5e4d534ca03d5c37eee0e66cdff59d100de8 (patch)
treed700b9bbf1ff6c049312a6eb2f10ff374fd01a35 /lib/libc
parent74c984e74d6e85a006418d318d5aa7b26abd8247 (diff)
downloadFreeBSD-src-522e5e4d534ca03d5c37eee0e66cdff59d100de8.zip
FreeBSD-src-522e5e4d534ca03d5c37eee0e66cdff59d100de8.tar.gz
Sicnce this code shares the same fragment as gethostnamaddr:
Change strtok() to strsep(), cause memory corruption for all programs which use strtok() too in the same time. Fix potential NULL reference, depends of /etc/hosts.conf format Fix the bug when service name fetched always from beginning of the line, not from parsed token.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/net/getnetnamadr.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/libc/net/getnetnamadr.c b/lib/libc/net/getnetnamadr.c
index ff44ede..cf0a81a 100644
--- a/lib/libc/net/getnetnamadr.c
+++ b/lib/libc/net/getnetnamadr.c
@@ -24,8 +24,8 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)$Id: getnetnamadr.c,v 1.1 1994/09/25 02:12:29 pst Exp $";
-static char rcsid[] = "$Id: getnetnamadr.c,v 1.1 1994/09/25 02:12:29 pst Exp $";
+static char sccsid[] = "@(#)$Id: getnetnamadr.c,v 1.2 1994/09/26 22:45:10 wollman Exp $";
+static char rcsid[] = "$Id: getnetnamadr.c,v 1.2 1994/09/26 22:45:10 wollman Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -90,7 +90,7 @@ get_service_name(const char *name) {
static void
init_services()
{
- char *cp, buf[BUFSIZ];
+ char *cp, *p, buf[BUFSIZ];
register int cc = 0;
FILE *fd;
@@ -103,14 +103,20 @@ init_services()
if(buf[0] == '#')
continue;
- cp = strtok(buf, "\n \t,:;");
+ p = buf;
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ if (cp == NULL)
+ continue;
do {
- if(!isalpha(cp[0])) continue;
- service_order[cc] = get_service_name(buf);
- if(service_order[cc] != SERVICE_NONE)
- cc++;
- } while((cp = strtok((char *)0, "\n \t,:;"))
- && (cc < SERVICE_MAX));
+ if (isalpha(cp[0])) {
+ service_order[cc] = get_service_name(cp);
+ if(service_order[cc] != SERVICE_NONE)
+ cc++;
+ }
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ } while(cp != NULL && cc < SERVICE_MAX);
}
service_order[cc] = SERVICE_NONE;
fclose(fd);
OpenPOWER on IntegriCloud