Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib use strtok_r, as strtok can interfere with other callers...



details:   https://anonhg.NetBSD.org/src/rev/5f3a6e32901f
branches:  trunk
changeset: 533136:5f3a6e32901f
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sat Jun 22 11:52:40 2002 +0000

description:
use strtok_r, as strtok can interfere with other callers.  from openbsd

diffstat:

 lib/libskey/skeylogin.c    |  47 ++++++++++++++++++++++++++++-----------------
 lib/libwrap/hosts_access.3 |   5 +---
 lib/libwrap/hosts_access.c |  15 +++++++------
 3 files changed, 38 insertions(+), 29 deletions(-)

diffs (201 lines):

diff -r d0bb1c855d71 -r 5f3a6e32901f lib/libskey/skeylogin.c
--- a/lib/libskey/skeylogin.c   Sat Jun 22 11:46:16 2002 +0000
+++ b/lib/libskey/skeylogin.c   Sat Jun 22 11:52:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: skeylogin.c,v 1.16 2000/07/28 16:35:11 thorpej Exp $   */
+/*     $NetBSD: skeylogin.c,v 1.17 2002/06/22 11:59:12 itojun Exp $    */
 
 /* S/KEY v1.1b (skeylogin.c)
  *
@@ -125,6 +125,7 @@
        int found = 0;
        long recstart = 0;
        const char *ht = NULL;
+       char *last;
 
        if(!(mp->keyfile = openSkey()))
                return(-1);
@@ -141,22 +142,22 @@
                rip(mp->buf);
                if (mp->buf[0] == '#')
                        continue;       /* Comment */
-               if ((mp->logname = strtok(mp->buf, " \t")) == NULL)
+               if ((mp->logname = strtok_r(mp->buf, " \t", &last)) == NULL)
                        continue;
-               if ((cp = strtok(NULL, " \t")) == NULL)
+               if ((cp = strtok_r(NULL, " \t", &last)) == NULL)
                        continue;
                /* Save hash type if specified, else use md4 */
                if (isalpha((u_char) *cp)) {
                        ht = cp;
-                       if ((cp = strtok(NULL, " \t")) == NULL)
+                       if ((cp = strtok_r(NULL, " \t", &last)) == NULL)
                                continue;
                } else {
                        ht = "md4";
                }
                mp->n = atoi(cp);
-               if ((mp->seed = strtok(NULL, " \t")) == NULL)
+               if ((mp->seed = strtok_r(NULL, " \t", &last)) == NULL)
                        continue;
-               if ((mp->val = strtok(NULL, " \t")) == NULL)
+               if ((mp->val = strtok_r(NULL, " \t", &last)) == NULL)
                        continue;
                if (strcmp(mp->logname, name) == 0) {
                        found = 1;
@@ -185,6 +186,7 @@
 int skeygetnext(struct skey *mp)
 {
        long recstart = 0;
+       char *last;
 
        /* Open _PATH_SKEYKEYS if it exists, else return an error */
        if (mp->keyfile == NULL) {
@@ -203,19 +205,19 @@
                rip(mp->buf);
                if (mp->buf[0] == '#')
                        continue;       /* Comment */
-               if ((mp->logname = strtok(mp->buf, " \t")) == NULL)
+               if ((mp->logname = strtok_r(mp->buf, " \t", &last)) == NULL)
                        continue;
-               if ((cp = strtok(NULL, " \t")) == NULL)
+               if ((cp = strtok_r(NULL, " \t", &last)) == NULL)
                        continue;
                /* Save hash type if specified, else use md4 */
                if (isalpha((u_char) *cp)) {
-                       if ((cp = strtok(NULL, " \t")) == NULL)
+                       if ((cp = strtok_r(NULL, " \t", &last)) == NULL)
                                continue;
                }
                mp->n = atoi(cp);
-               if ((mp->seed = strtok(NULL, " \t")) == NULL)
+               if ((mp->seed = strtok_r(NULL, " \t", &last)) == NULL)
                        continue;
-               if ((mp->val = strtok(NULL, " \t")) == NULL)
+               if ((mp->val = strtok_r(NULL, " \t", &last)) == NULL)
                        continue;
                /* Got a real entry */
                break;
@@ -241,7 +243,7 @@
        time_t now;
        struct tm *tm;
        char tbuf[27];
-       char *cp;
+       char *cp, *last;
        int i, rval;
 
        time(&now);
@@ -293,12 +295,17 @@
                return -1;
        }
        rip(mp->buf);
-       mp->logname = strtok(mp->buf, " \t");
-       cp = strtok(NULL, " \t") ;
+       if ((mp->logname = strtok_r(mp->buf, " \t", &last)) == NULL)
+               goto verify_failure;
+       if ((cp = strtok_r(NULL, " \t", &last)) == NULL)
+               goto verify_failure;
        if (isalpha((u_char) *cp))
-               cp = strtok(NULL, " \t") ;
-       mp->seed = strtok(NULL, " \t");
-       mp->val = strtok(NULL, " \t");
+               if ((cp = strtok_r(NULL, " \t", &last)) == NULL)
+                       goto verify_failure;
+       if ((mp->seed = strtok_r(NULL, " \t", &last)) == NULL)
+               goto verify_failure;
+       if ((mp->val = strtok_r(NULL, " \t", &last)) == NULL)
+               goto verify_failure;
        /* And convert file value to hex for comparison */
        atob8(filekey, mp->val);
 
@@ -329,8 +336,12 @@
 
        fclose(mp->keyfile);
        mp->keyfile = NULL;
+       return 0;
 
-       return 0;
+  verify_failure:
+       fclose(mp->keyfile);
+       mp->keyfile = NULL;
+       return -1;
 }
 
 
diff -r d0bb1c855d71 -r 5f3a6e32901f lib/libwrap/hosts_access.3
--- a/lib/libwrap/hosts_access.3        Sat Jun 22 11:46:16 2002 +0000
+++ b/lib/libwrap/hosts_access.3        Sat Jun 22 11:52:40 2002 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: hosts_access.3,v 1.5 2002/01/15 02:54:31 wiz Exp $
+.\"    $NetBSD: hosts_access.3,v 1.6 2002/06/22 11:52:40 itojun Exp $
 .\"
 .TH HOSTS_ACCESS 3
 .SH NAME
@@ -81,9 +81,6 @@
 hosts_options(5), optional extensions to the base language.
 .SH FILES
 /etc/hosts.allow, /etc/hosts.deny, access control tables.
-.SH BUGS
-hosts_access() uses the strtok() library function. This may interfere
-with other code that relies on strtok().
 .SH AUTHOR
 .na
 .nf
diff -r d0bb1c855d71 -r 5f3a6e32901f lib/libwrap/hosts_access.c
--- a/lib/libwrap/hosts_access.c        Sat Jun 22 11:46:16 2002 +0000
+++ b/lib/libwrap/hosts_access.c        Sat Jun 22 11:52:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hosts_access.c,v 1.15 2002/06/06 21:28:49 itojun Exp $ */
+/*     $NetBSD: hosts_access.c,v 1.16 2002/06/22 11:52:40 itojun Exp $ */
 
  /*
   * This module implements a simple access control language that is based on
@@ -24,7 +24,7 @@
 #if 0
 static char sccsid[] = "@(#) hosts_access.c 1.21 97/02/12 02:13:22";
 #else
-__RCSID("$NetBSD: hosts_access.c,v 1.15 2002/06/06 21:28:49 itojun Exp $");
+__RCSID("$NetBSD: hosts_access.c,v 1.16 2002/06/22 11:52:40 itojun Exp $");
 #endif
 #endif
 
@@ -202,7 +202,7 @@
 struct request_info *request;
 int   (*match_fn) __P((char *, struct request_info *));
 {
-    char   *tok;
+    char   *tok, *last;
     int l;
 
     /*
@@ -212,7 +212,8 @@
      * the match is affected by any exceptions.
      */
 
-    for (tok = strtok(list, sep); tok != 0; tok = strtok((char *) 0, sep)) {
+    for (tok = strtok_r(list, sep, &last); tok != 0;
+      tok = strtok_r(NULL, sep, &last)) {
        if (STR_EQ(tok, "EXCEPT"))              /* EXCEPT: give up */
            return (NO);
        l = strlen(tok);
@@ -221,9 +222,9 @@
            tok++;
        }
        if (match_fn(tok, request)) {           /* YES: look for exceptions */
-           while ((tok = strtok((char *) 0, sep)) && STR_NE(tok, "EXCEPT"))
+           while ((tok = strtok_r(NULL, sep, &last)) && STR_NE(tok, "EXCEPT"))
                 /* VOID */ ;
-           return (tok == 0 || list_match((char *) 0, request, match_fn) == 0);
+           return (tok == 0 || list_match(NULL, request, match_fn) == 0);
        }
     }
     return (NO);
@@ -283,7 +284,7 @@
        static char *mydomain = 0;
        if (mydomain == 0)
            yp_get_default_domain(&mydomain);
-       return (innetgr(tok + 1, eval_hostname(host), (char *) 0, mydomain));
+       return (innetgr(tok + 1, eval_hostname(host), NULL, mydomain));
 #else
        tcpd_warn("netgroup support is disabled");      /* not tcpd_jump() */
        return (NO);



Home | Main Index | Thread Index | Old Index