Subject: bin/10499: lib/libc/rpc/getnetconfig.c uses strtok(3)
To: None <gnats-bugs@gnats.netbsd.org>
From: IWAMOTO Toshihiro <iwamoto@sat.t.u-tokyo.ac.jp>
List: netbsd-bugs
Date: 07/03/2000 03:44:16
>Number: 10499
>Category: bin
>Synopsis: lib/libc/rpc/getnetconfig.c uses strtok(3)
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jul 03 03:45:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator: IWAMOTO Toshihiro <iwamoto@sat.t.u-tokyo.ac.jp>
>Release: today's current
>Organization:
>Environment:
System: NetBSD een.sat.t.u-tokyo.ac.jp 1.5_ALPHA NetBSD 1.5_ALPHA (EEN) #18: Mon Jul 3 16:29:49 JST 2000 root@:/usr/src/syssrc/sys/arch/i386/compile/EEN i386
>Description:
basesrc/lib/libc/rpc/getnetconfig.c uses strtok(3).
libc functions should not use strtok(3) because this breaks
strtok(3) loops in user programs.
>How-To-Repeat:
For example, mtree -u -def /etc/mtree/NetBSD.dist -p /
fails if one has the line "group: nis files" in /etc/nsswitch.conf,
because _getgrnam() calls strtok.
(gdb) info st
#0 0x16028ef20 in strtok ()
#1 0x16028e948 in parse_ncp ()
#2 0x16028e3b0 in _getnetconfig ()
#3 0x16028c52c in __rpc_getconfip ()
#4 0x160284134 in clnt_com_create ()
#5 0x1602843a4 in _clntudp_bufcreate ()
#6 0x160284434 in _clntudp_create ()
#7 0x16027d444 in _yp_dobind ()
#8 0x160291ba4 in _yp_match ()
#9 0x1602696a0 in _nis_grscan ()
#10 0x1602a4b48 in _nsdispatch ()
#11 0x160269cf8 in grscan ()
#12 0x160268e78 in _getgrnam ()
#13 0x120005594 in set ()
#14 0x1200050f0 in spec ()
#15 0x120005a84 in verify ()
#16 0x120004eb8 in main ()
>Fix:
Apply the following patch:
Index: rpc/getnetconfig.c
===================================================================
RCS file: /public/dpt/NetBSD/NetBSD-CVS/basesrc/lib/libc/rpc/getnetconfig.c,v
retrieving revision 1.1
diff -u -r1.1 getnetconfig.c
--- rpc/getnetconfig.c 2000/06/02 23:11:11 1.1
+++ rpc/getnetconfig.c 2000/07/03 10:18:18
@@ -519,16 +519,17 @@
struct netconfig *ncp; /* where to put results */
{
char *tokenp; /* for processing tokens */
+ char *lasts;
nc_error = NC_BADFILE; /* nearly anything that breaks is for this reason */
stringp[strlen(stringp)-1] = '\0'; /* get rid of newline */
/* netid */
- if ((ncp->nc_netid = strtok(stringp, "\t ")) == NULL) {
+ if ((ncp->nc_netid = strtok_r(stringp, "\t ", &lasts)) == NULL) {
return (-1);
}
/* semantics */
- if ((tokenp = strtok(NULL, "\t ")) == NULL) {
+ if ((tokenp = strtok_r(NULL, "\t ", &lasts)) == NULL) {
return (-1);
}
if (strcmp(tokenp, NC_TPI_COTS_ORD_S) == 0)
@@ -543,7 +544,7 @@
return (-1);
/* flags */
- if ((tokenp = strtok(NULL, "\t ")) == NULL) {
+ if ((tokenp = strtok_r(NULL, "\t ", &lasts)) == NULL) {
return (-1);
}
for (ncp->nc_flag = NC_NOFLAG; *tokenp != '\0';
@@ -562,18 +563,18 @@
}
}
/* protocol family */
- if ((ncp->nc_protofmly = strtok(NULL, "\t ")) == NULL) {
+ if ((ncp->nc_protofmly = strtok_r(NULL, "\t ", &lasts)) == NULL) {
return (-1);
}
/* protocol name */
- if ((ncp->nc_proto = strtok(NULL, "\t ")) == NULL) {
+ if ((ncp->nc_proto = strtok_r(NULL, "\t ", &lasts)) == NULL) {
return (-1);
}
/* network device */
- if ((ncp->nc_device = strtok(NULL, "\t ")) == NULL) {
+ if ((ncp->nc_device = strtok_r(NULL, "\t ", &lasts)) == NULL) {
return (-1);
}
- if ((tokenp = strtok(NULL, "\t ")) == NULL) {
+ if ((tokenp = strtok_r(NULL, "\t ", &lasts)) == NULL) {
return (-1);
}
if (strcmp(tokenp, NC_NOLOOKUP) == 0) {
>Release-Note:
>Audit-Trail:
>Unformatted: