]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Replace usage of strsep with POSIX strtok_r()
authorOndřej Surý <ondrej@sury.org>
Wed, 21 Mar 2018 21:08:29 +0000 (21:08 +0000)
committerOndřej Surý <ondrej@sury.org>
Thu, 12 Apr 2018 08:37:33 +0000 (10:37 +0200)
17 files changed:
bin/delv/delv.c
bin/dig/dig.c
bin/dig/dighost.c
bin/dig/include/dig/dig.h
bin/dig/nslookup.c
bin/named/unix/os.c
bin/tools/mdig.c
configure
configure.in
contrib/dlz/bin/dlzbdb/dlzbdb.c
contrib/dlz/drivers/sdlz_helper.c
contrib/dlz/modules/common/dlz_dbi.c
lib/irs/getaddrinfo.c
lib/isc/include/isc/platform.h.in
lib/isc/include/isc/string.h
lib/isc/string.c
lib/isc/win32/libisc.def.in

index bf1fa104e2216a5c5ac3f7f24df42d7b6ed6a779..1bcc9e7e3b65f60cba912879ed38a7853b1bbf57 100644 (file)
@@ -943,18 +943,6 @@ cleanup:
        return (result);
 }
 
-static char *
-next_token(char **stringp, const char *delim) {
-       char *res;
-
-       do {
-               res = strsep(stringp, delim);
-               if (res == NULL)
-                       break;
-       } while (*res == '\0');
-       return (res);
-}
-
 static isc_result_t
 parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
           const char *desc) {
@@ -974,23 +962,21 @@ parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
 static void
 plus_option(char *option) {
        isc_result_t result;
-       char option_store[256];
-       char *cmd, *value, *ptr;
+       char *cmd, *value, *last;
        isc_boolean_t state = ISC_TRUE;
 
-       strlcpy(option_store, option, sizeof(option_store));
-       ptr = option_store;
-       cmd = next_token(&ptr,"=");
+       cmd = strtok_r(option, "=", &last);
        if (cmd == NULL) {
-               printf(";; Invalid option %s\n", option_store);
+               printf(";; Invalid option %s\n", option);
                return;
-       }
-       value = ptr;
+       }       
        if (strncasecmp(cmd, "no", 2)==0) {
                cmd += 2;
                state = ISC_FALSE;
        }
 
+       value = strtok_r(NULL, "\0", &last);
+
 #define FULLCHECK(A) \
        do { \
                size_t _l = strlen(cmd); \
index 71a00939ac0fbd90205123920c48a912cb5f0c95..dcd11f14fcf99ba25c5f853521bc4d1b0abefb8b 100644 (file)
@@ -729,28 +729,25 @@ printgreeting(int argc, char **argv, dig_lookup_t *lookup) {
  */
 
 static void
-plus_option(const char *option, isc_boolean_t is_batchfile,
+plus_option(char *option, isc_boolean_t is_batchfile,
            dig_lookup_t *lookup)
 {
        isc_result_t result;
-       char option_store[256];
-       char *cmd, *value, *ptr, *code;
+       char *cmd, *value, *last, *code;
        isc_uint32_t num;
        isc_boolean_t state = ISC_TRUE;
        size_t n;
 
-       strlcpy(option_store, option, sizeof(option_store));
-       ptr = option_store;
-       cmd = next_token(&ptr, "=");
-       if (cmd == NULL) {
-               printf(";; Invalid option %s\n", option_store);
+       if ((cmd = strtok_r(option, "=", &last)) == NULL) {
+               printf(";; Invalid option %s\n", option);
                return;
        }
-       value = ptr;
        if (strncasecmp(cmd, "no", 2)==0) {
                cmd += 2;
                state = ISC_FALSE;
        }
+       /* parse the rest of the string */
+       value = strtok_r(NULL, "", &last);
 
 #define FULLCHECK(A) \
        do { \
@@ -1006,8 +1003,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile,
                                                             "specified");
                                                        goto exit_or_usage;
                                                }
-                                               code = next_token(&value, ":");
-                                               save_opt(lookup, code, value);
+                                               char *extra;
+                                               code = strtok_r(value, ":", &last);
+                                               extra = strtok_r(NULL, "\0", &last);
+                                               save_opt(lookup, code, extra);
                                                break;
                                        default:
                                                goto invalid_option;
@@ -1524,7 +1523,7 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
            isc_boolean_t config_only, int argc, char **argv,
            isc_boolean_t *firstarg)
 {
-       char opt, *value, *ptr, *ptr2, *ptr3;
+       char opt, *value, *ptr, *ptr2, *ptr3, *last;
        isc_result_t result;
        isc_boolean_t value_from_next;
        isc_textregion_t tr;
@@ -1738,15 +1737,13 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
                                 value);
                return (value_from_next);
        case 'y':
-               ptr = next_token(&value, ":");  /* hmac type or name */
-               if (ptr == NULL) {
+               if ((ptr = strtok_r(value, ":", &last)) == NULL) {
                        usage();
                }
-               ptr2 = next_token(&value, ":"); /* name or secret */
-               if (ptr2 == NULL)
+               if ((ptr2 = strtok_r(NULL, ":", &last)) == NULL) {      /* name or secret */
                        usage();
-               ptr3 = next_token(&value, ":"); /* secret or NULL */
-               if (ptr3 != NULL) {
+               }
+               if ((ptr3 = strtok_r(NULL, ":", &last)) != NULL) { /* secret or NULL */
                        parse_hmac(ptr);
                        ptr = ptr2;
                        ptr2 = ptr3;
@@ -1758,6 +1755,7 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
 #endif
                        digestbits = 0;
                }
+               /* XXXONDREJ: FIXME */
                strlcpy(keynametext, ptr, sizeof(keynametext));
                strlcpy(keysecret, ptr2, sizeof(keysecret));
                return (value_from_next);
@@ -1859,10 +1857,9 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
        char **rv;
 #ifndef NOPOSIX
        char *homedir;
-       char rcfile[256];
+       char rcfile[PATH_MAX];
 #endif
-       char *input;
-       int i;
+       char *last;
        isc_boolean_t need_clone = ISC_TRUE;
 
        /*
@@ -1892,32 +1889,23 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
                homedir = getenv("HOME");
                if (homedir != NULL) {
                        unsigned int n;
-                       n = snprintf(rcfile, sizeof(rcfile), "%s/.digrc",
-                                    homedir);
-                       if (n < sizeof(rcfile))
+                       n = snprintf(rcfile, sizeof(rcfile), "%s/.digrc", homedir);
+                       if (n < sizeof(rcfile)) {
                                batchfp = fopen(rcfile, "r");
+                       }
                }
                if (batchfp != NULL) {
-                       while (fgets(batchline, sizeof(batchline),
-                                    batchfp) != 0) {
+                       while (fgets(batchline, sizeof(batchline), batchfp) != 0) {
                                debug("config line %s", batchline);
-                               bargc = 1;
-                               input = batchline;
-                               bargv[bargc] = next_token(&input, " \t\r\n");
-                               while ((bargc < 62) && (bargv[bargc] != NULL)) {
-                                       bargc++;
-                                       bargv[bargc] =
-                                               next_token(&input, " \t\r\n");
+                               for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
+                                    bargc < 62 && bargv[bargc];
+                                    bargv[++bargc] = strtok_r(NULL,  " \t\r\n", &last))
+                               {
+                                       debug(".digrc argv %d: %s", bargc, bargv[bargc]);
                                }
-
                                bargv[0] = argv[0];
                                argv0 = argv[0];
-
-                               for(i = 0; i < bargc; i++)
-                                       debug(".digrc argv %d: %s",
-                                             i, bargv[i]);
-                               parse_args(ISC_TRUE, ISC_TRUE, bargc,
-                                          (char **)bargv);
+                               parse_args(ISC_TRUE, ISC_TRUE, bargc, (char **)bargv);
                        }
                        fclose(batchfp);
                }
@@ -1928,8 +1916,9 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
                /* Processing '-f batchfile'. */
                lookup = clone_lookup(default_lookup, ISC_TRUE);
                need_clone = ISC_FALSE;
-       } else
+       } else {
                lookup = default_lookup;
+       }
 
        rc = argc;
        rv = argv;
@@ -2101,18 +2090,15 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
                        if (batchline[0] == '\r' || batchline[0] == '\n'
                            || batchline[0] == '#' || batchline[0] == ';')
                                goto next_line;
-                       input = batchline;
-                       bargv[bargc] = next_token(&input, " \t\r\n");
-                       while ((bargc < 14) && (bargv[bargc] != NULL)) {
-                               bargc++;
-                               bargv[bargc] = next_token(&input, " \t\r\n");
+                       for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
+                            (bargc < 14) && bargv[bargc];
+                            bargc++, bargv[bargc] = strtok_r(NULL, " \t\r\n", &last)) {
+                               debug("batch argv %d: %s", bargc, bargv[bargc]);
                        }
 
                        bargv[0] = argv[0];
                        argv0 = argv[0];
 
-                       for(i = 0; i < bargc; i++)
-                               debug("batch argv %d: %s", i, bargv[i]);
                        parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
                        return;
                }
@@ -2151,8 +2137,6 @@ query_finished(void) {
        char batchline[MXNAME];
        int bargc;
        char *bargv[16];
-       char *input;
-       int i;
 
        if (batchname == NULL) {
                isc_app_shutdown();
@@ -2169,19 +2153,17 @@ query_finished(void) {
        }
 
        if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
+               char *last;
                debug("batch line %s", batchline);
-               bargc = 1;
-               input = batchline;
-               bargv[bargc] = next_token(&input, " \t\r\n");
-               while ((bargc < 14) && (bargv[bargc] != NULL)) {
-                       bargc++;
-                       bargv[bargc] = next_token(&input, " \t\r\n");
+               for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
+                    bargc < 14 && bargv[bargc];
+                    bargc++, bargv[bargc] = strtok_r(NULL, " \t\r\n", &last))
+               {
+                       debug("batch argv %d: %s", bargc, bargv[bargc]);
                }
 
                bargv[0] = argv0;
 
-               for(i = 0; i < bargc; i++)
-                       debug("batch argv %d: %s", i, bargv[i]);
                parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
                start_lookup();
        } else {
index 85f1b01507abc6e66ffe09a7d4d2c0aa00c4ea47..172b94bf1383d06c8c9840e79472ec735e60daa2 100644 (file)
@@ -242,18 +242,6 @@ check_next_lookup(dig_lookup_t *lookup);
 static isc_boolean_t
 next_origin(dig_lookup_t *oldlookup);
 
-char *
-next_token(char **stringp, const char *delim) {
-       char *res;
-
-       do {
-               res = strsep(stringp, delim);
-               if (res == NULL)
-                       break;
-       } while (*res == '\0');
-       return (res);
-}
-
 static int
 count_dots(char *string) {
        char *s;
index 6cf1683f00f9279e4b4071c329ecd7723830cb24..0b6fc460d0794f8468a2c1715ba3df14b16880bc 100644 (file)
@@ -369,9 +369,6 @@ destroy_libs(void);
 void
 set_search_domain(char *domain);
 
-char *
-next_token(char **stringp, const char *delim);
-
 /*
  * Routines to be defined in dig.c, host.c, and nslookup.c. and
  * then assigned to the appropriate function pointer
index ebb850209c8302f6af9a3ef7422244924c7d3d65..16842a239b974f0155fc7317f2f1ea110a809a58 100644 (file)
@@ -813,12 +813,12 @@ addlookup(char *opt) {
 
 static void
 do_next_command(char *input) {
-       char *ptr, *arg;
+       char *ptr, *arg, *last;
 
-       ptr = next_token(&input, " \t\r\n");
-       if (ptr == NULL)
+       if ((ptr = strtok_r(input, " \t\r\n", &last)) == NULL) {
                return;
-       arg = next_token(&input, " \t\r\n");
+       }
+       arg = strtok_r(NULL, " \t\r\n", &last);
        if ((strcasecmp(ptr, "set") == 0) &&
            (arg != NULL))
                setoption(arg);
index d3b2b2215ec6ce6bfb83081a07ec1dedd22e3571..9448c5b997d45c138a8ff12e5028ab0a0a3a15a7 100644 (file)
@@ -1003,36 +1003,24 @@ named_os_gethostname(char *buf, size_t len) {
        return ((n == 0) ? ISC_R_SUCCESS : ISC_R_FAILURE);
 }
 
-static char *
-next_token(char **stringp, const char *delim) {
-       char *res;
-
-       do {
-               res = strsep(stringp, delim);
-               if (res == NULL)
-                       break;
-       } while (*res == '\0');
-       return (res);
-}
-
 void
 named_os_shutdownmsg(char *command, isc_buffer_t *text) {
-       char *input, *ptr;
+       char *last, *ptr;
        pid_t pid;
 
-       input = command;
 
        /* Skip the command name. */
-       ptr = next_token(&input, " \t");
-       if (ptr == NULL)
+       if ((ptr = strtok_r(command, " \t", &last)) == NULL) {
                return;
+       }
 
-       ptr = next_token(&input, " \t");
-       if (ptr == NULL)
+       if ((ptr = strtok_r(NULL, " \t", &last)) == NULL) {
                return;
+       }
 
-       if (strcmp(ptr, "-p") != 0)
+       if (strcmp(ptr, "-p") != 0) {
                return;
+       }
 
 #ifdef HAVE_LINUXTHREADS
        pid = mainpid;
index 5cac77ef64db757bae7ebfe3ecf433d13b211918..e9e0c52ede84c2a68cabfd865b6494a7c1ab7474 100644 (file)
@@ -795,18 +795,6 @@ help(void) {
        stdout);
 }
 
-static char *
-next_token(char **stringp, const char *delim) {
-       char *res;
-
-       do {
-               res = strsep(stringp, delim);
-               if (res == NULL)
-                       break;
-       } while (*res == '\0');
-       return (res);
-}
-
 ISC_PLATFORM_NORETURN_PRE static void
 fatal(const char *format, ...)
 ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST;
@@ -1037,24 +1025,21 @@ static void
 plus_option(char *option, struct query *query, isc_boolean_t global)
 {
        isc_result_t result;
-       char option_store[256];
-       char *cmd, *value, *ptr, *code;
+       char *cmd, *value, *last, *code;
        isc_uint32_t num;
        isc_boolean_t state = ISC_TRUE;
        size_t n;
 
-       strlcpy(option_store, option, sizeof(option_store));
-       ptr = option_store;
-       cmd = next_token(&ptr, "=");
-       if (cmd == NULL) {
-               printf(";; Invalid option %s\n", option_store);
+       if ((cmd = strtok_r(option, "=", &last)) == NULL) {
+               printf(";; Invalid option %s\n", option);
                return;
        }
-       value = ptr;
        if (strncasecmp(cmd, "no", 2) == 0) {
                cmd += 2;
                state = ISC_FALSE;
        }
+       /* parse the rest of the string */
+       value = strtok_r(NULL, "", &last);
 
 #define FULLCHECK(A) \
        do { \
@@ -1279,7 +1264,7 @@ plus_option(char *option, struct query *query, isc_boolean_t global)
                                                        fatal("ednsopt no "
                                                              "code point "
                                                              "specified");
-                                               code = next_token(&value, ":");
+                                               code = strtok_r(value, ":", &last);
                                                save_opt(query, code, value);
                                                break;
                                        default:
@@ -1755,7 +1740,6 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv)
        char *bargv[64];
        int rc;
        char **rv;
-       char *input;
        isc_boolean_t global = ISC_TRUE;
 
        /*
@@ -1868,15 +1852,15 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv)
                        fatal("couldn't open batch file '%s'", batchname);
                }
                while (fgets(batchline, sizeof(batchline), batchfp) != 0) {
-                       bargc = 1;
+                       char *last;
                        if (batchline[0] == '\r' || batchline[0] == '\n'
                            || batchline[0] == '#' || batchline[0] == ';')
                                continue;
-                       input = batchline;
-                       bargv[bargc] = next_token(&input, " \t\r\n");
-                       while ((bargc < 14) && (bargv[bargc] != NULL)) {
-                               bargc++;
-                               bargv[bargc] = next_token(&input, " \t\r\n");
+                       for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
+                            (bargc < 14) && bargv[bargc];
+                            bargc++, bargv[bargc] = strtok_r(NULL, " \t\r\n", &last))
+                       {
+                               /* empty body */
                        }
 
                        bargv[0] = argv[0];
index aac711428c7138301f05814ed084145974cc5c02..ca1af58b3d9f65205e13c1df9a7633b084741afa 100755 (executable)
--- a/configure
+++ b/configure
@@ -747,7 +747,6 @@ ISC_PLATFORM_NEEDSTRLCPY
 GENRANDOMLIB
 ISC_PLATFORM_NEEDSTRTOUL
 ISC_PLATFORM_NEEDMEMMOVE
-ISC_PLATFORM_NEEDSTRSEP
 ISC_IRS_GETNAMEINFOSOCKLEN
 ISC_IRS_NEEDADDRINFO
 ISC_PLATFORM_HAVETFO
@@ -19429,36 +19428,6 @@ esac
 # Check for some other useful functions that are not ever-present.
 #
 
-# We test for strsep() using AC_TRY_LINK instead of AC_CHECK_FUNC
-# because AIX 4.3.3 with patches for bos.adt.include to version 4.3.3.77
-# reportedly defines strsep() without declaring it in <string.h> when
-# -D_LINUX_SOURCE_COMPAT is not defined [RT #2190], and
-# AC_CHECK_FUNC() incorrectly succeeds because it declares
-# the function itself.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for correctly declared strsep()" >&5
-$as_echo_n "checking for correctly declared strsep()... " >&6; }
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <string.h>
-int
-main ()
-{
-char *sp; char *foo = strsep(&sp, ".");
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }; ISC_PLATFORM_NEEDSTRSEP="#undef ISC_PLATFORM_NEEDSTRSEP"
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }; ISC_PLATFORM_NEEDSTRSEP="#define ISC_PLATFORM_NEEDSTRSEP 1"
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-
-
 ac_fn_c_check_func "$LINENO" "memmove" "ac_cv_func_memmove"
 if test "x$ac_cv_func_memmove" = xyes; then :
   ISC_PLATFORM_NEEDMEMMOVE="#undef ISC_PLATFORM_NEEDMEMMOVE"
index 9e8a88dfd89d565cd8b84af18c996ea108f1c025..87136d0e6c79eb83a4617760333bb83baad85b57 100644 (file)
@@ -3492,18 +3492,6 @@ esac
 # Check for some other useful functions that are not ever-present.
 #
 
-# We test for strsep() using AC_TRY_LINK instead of AC_CHECK_FUNC
-# because AIX 4.3.3 with patches for bos.adt.include to version 4.3.3.77
-# reportedly defines strsep() without declaring it in <string.h> when
-# -D_LINUX_SOURCE_COMPAT is not defined [RT #2190], and
-# AC_CHECK_FUNC() incorrectly succeeds because it declares
-# the function itself.
-AC_MSG_CHECKING(for correctly declared strsep())
-AC_TRY_LINK([#include <string.h>], [char *sp; char *foo = strsep(&sp, ".");],
-       [AC_MSG_RESULT(yes); ISC_PLATFORM_NEEDSTRSEP="#undef ISC_PLATFORM_NEEDSTRSEP"],
-       [AC_MSG_RESULT(no); ISC_PLATFORM_NEEDSTRSEP="#define ISC_PLATFORM_NEEDSTRSEP 1"])
-AC_SUBST(ISC_PLATFORM_NEEDSTRSEP)
-
 AC_CHECK_FUNC(memmove,
        [ISC_PLATFORM_NEEDMEMMOVE="#undef ISC_PLATFORM_NEEDMEMMOVE"],
        [ISC_PLATFORM_NEEDMEMMOVE="#define ISC_PLATFORM_NEEDMEMMOVE 1"])
index f4aba743e4f0137d5ca43a6ba752de6ba00673ca..b57f9e8e52fd6a0d688447d3b6a4a1e58d763408 100644 (file)
@@ -286,47 +286,24 @@ quit(1);
 
 int
 getzone(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
-       char *tmp;
-       char *left;
-       char *right;
-       int result=0;
+       char *token, *last;
 
        UNUSED(dbp);
        UNUSED(pkey);
 
-       /* Allocate memory to use in parsing the string */
-       tmp = right = malloc(pdata->size + 1);
-
-       /* verify memory was allocated */
-       if (right == NULL) {
-               result = BDBparseErr;
-               goto getzone_cleanup;
-       }               
-
-       /* copy data string into newly allocated memory */
-       strncpy(right, pdata->data, pdata->size);
-       right[pdata->size] = '\0';
-
-       /* split string at the first space */
-       left = isc_string_separate(&right, " ");
+       if ((token = strtok_r(pdata->data, " ", &last)) == NULL) {
+               return BDBparseErr;
+       }
 
        /* copy string for "zone" secondary index */
-       skey->data = strdup(left);
-       if (skey->data == NULL) {
-               result = BDBparseErr;
-               goto getzone_cleanup;
+       if ((skey->data = strdup(token)) == NULL) {
+               return BDBparseErr;
        }
        /* set required values for BDB */
        skey->size = strlen(skey->data);
        skey->flags = DB_DBT_APPMALLOC;
 
- getzone_cleanup:
-
-       /* cleanup memory */
-       if (tmp != NULL)
-               free(tmp);
-       
-       return result;
+       return 0;
 }
 
 /*%
@@ -335,56 +312,30 @@ getzone(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
 
 int
 gethost(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
-       char *tmp;
-       char *left;
-       char *right;
-       int result=0;
+       char *token, *last;
 
        UNUSED(dbp);
        UNUSED(pkey);
 
-       /* allocate memory to use in parsing the string */
-       tmp = right = malloc(pdata->size + 1);
-
-       /* verify memory was allocated */
-       if (tmp == NULL) {
-               result = BDBparseErr;
-               goto gethost_cleanup;
-       }               
-
-       /* copy data string into newly allocated memory */
-       strncpy(right, pdata->data, pdata->size);
-       right[pdata->size] = '\0';
-
-       /* we don't care about left string. */
-       /* memory of left string will be freed when tmp is freed. */
-       isc_string_separate(&right, " ");
-
-       /* verify right still has some characters left */
-       if (right == NULL) {
-               result = BDBparseErr;
-               goto gethost_cleanup;
+       /* we don't care about first token. */
+       if ((token = strtok_r(right, " ", &last)) == NULL) {
+               return BDBparseErr;
        }
 
        /* get "host" from data string */
-       left = isc_string_separate(&right, " ");
+       if ((token = strtok_r(NULL, " ", &last)) == NULL) {
+               return BDBparseErr;
+       }
+               
        /* copy string for "host" secondary index */
-       skey->data = strdup(left);
-       if (skey->data == NULL) {
-               result = BDBparseErr;
-               goto gethost_cleanup;
+       if ((skey->data = strdup(token)) == NULL) {
+               return BDBparseErr;
        }
        /* set required values for BDB */
        skey->size = strlen(skey->data);
        skey->flags = DB_DBT_APPMALLOC;
 
- gethost_cleanup:
-
-       /* cleanup memory */
-       if (tmp != NULL)
-               free(tmp);
-       
-       return result;
+       return 0;
 }
 
 /*%
index 67f364e90153fa53b02f9f6da96ce3bb7aa85f24..46bb61dcb7f19fe9af7b11c9d12472b6b35b6c16 100644 (file)
@@ -158,9 +158,9 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
                 * split string at the first "$". set query segment to
                 * left portion
                 */
+               char *last = NULL;
                tseg->sql = isc_mem_strdup(mctx,
-                                          isc_string_separate(&right_str,
-                                                              "$"));
+                                          strtok_r(right_str, "$", &last));
                if (tseg->sql == NULL) {
                        /* no memory, clean everything up. */
                        result = ISC_R_NOMEMORY;
index 01d98218dc173cd26bdabb0e112acaec2bb98d16..488baf51b6a3cb02ef827f3b2a737235cddcf30f 100644 (file)
@@ -132,14 +132,16 @@ build_querylist(const char *query_str, char **zone, char **record,
        }
 
        /* loop through the string and chop it up */
-       while (right_str != NULL) {
+       for (token = strtok_r(right_str, "$", &temp_str);
+            token;
+            token = strtok_r(NULL, "$", &temp_str))
+       {
                /* allocate memory for tseg */
                tseg = calloc(1, sizeof(query_segment_t));
                if (tseg  == NULL) {    /* no memory, clean everything up. */
                        result = ISC_R_NOMEMORY;
                        goto cleanup;
                }
-               tseg->cmd = NULL;
                tseg->direct = ISC_FALSE;
                /* initialize the query segment link */
                DLZ_LINK_INIT(tseg, link);
@@ -150,7 +152,7 @@ build_querylist(const char *query_str, char **zone, char **record,
                 * split string at the first "$". set query segment to
                 * left portion
                 */
-               tseg->cmd = strdup(strsep(&right_str, "$"));
+               tseg->cmd = strdup(token);
                if (tseg->cmd == NULL) {
                        /* no memory, clean everything up. */
                        result = ISC_R_NOMEMORY;
@@ -203,7 +205,8 @@ build_querylist(const char *query_str, char **zone, char **record,
        }
 
        /* we don't need temp_str any more */
-       free(temp_str);
+       free(right_str);
+       right_str = NULL;
        /*
         * add checks later to verify zone and record are found if
         * necessary.
@@ -246,8 +249,9 @@ build_querylist(const char *query_str, char **zone, char **record,
 
  cleanup:
        /* get rid of temp_str */
-       if (temp_str != NULL)
-               free(temp_str);
+       if (right_str != NULL) {
+               free(right_str);
+       }
 
  flag_fail:
        /* get rid of what was build of the query list */
index 74fd80f75d613e07222f2f2f56e868e846c9fdf8..2aed01c3157254108474149876e05ac0cffc3d77 100644 (file)
@@ -1051,29 +1051,6 @@ resolve_name(int family, const char *hostname, int flags,
        return (error);
 }
 
-static char *
-irs_strsep(char **stringp, const char *delim) {
-       char *string = *stringp;
-       char *s;
-       const char *d;
-       char sc, dc;
-
-       if (string == NULL)
-               return (NULL);
-
-       for (s = string; *s != '\0'; s++) {
-               sc = *s;
-               for (d = delim; (dc = *d) != '\0'; d++)
-                       if (sc == dc) {
-                               *s++ = '\0';
-                               *stringp = s;
-                               return (string);
-                       }
-       }
-       *stringp = NULL;
-       return (string);
-}
-
 static void
 set_order(int family, int (**net_order)(const char *, int, struct addrinfo **,
                                        int, int))
@@ -1093,19 +1070,21 @@ set_order(int family, int (**net_order)(const char *, int, struct addrinfo **,
        } else {
                order = getenv("NET_ORDER");
                found = 0;
-               while (order != NULL) {
-                       /*
-                        * We ignore any unknown names.
-                        */
-                       tok = irs_strsep(&order, ":");
+               char *last;
+               for (tok = strtok_r(order, ":", &last);
+                    tok;
+                    tok = strtok_r(NULL, ":", &last))
+               {
                        if (strcasecmp(tok, "inet6") == 0) {
-                               if ((found & FOUND_IPV6) == 0)
+                               if ((found & FOUND_IPV6) == 0) {
                                        *net_order++ = add_ipv6;
+                               }
                                found |= FOUND_IPV6;
                        } else if (strcasecmp(tok, "inet") == 0 ||
-                           strcasecmp(tok, "inet4") == 0) {
-                               if ((found & FOUND_IPV4) == 0)
+                                  strcasecmp(tok, "inet4") == 0) {
+                               if ((found & FOUND_IPV4) == 0) {
                                        *net_order++ = add_ipv4;
+                               }
                                found |= FOUND_IPV4;
                        }
                }
index 41613ec33c7aa9bea78db58ff18eaa7295620d04..c511fa99f7327db3ac6944a4861431ce8d0a6c46 100644 (file)
  */
 @ISC_PLATFORM_QUADFORMAT@
 
-/***
- *** String functions.
- ***/
-/*
- * If the system needs strsep(), ISC_PLATFORM_NEEDSTRSEP will be defined.
- */
-@ISC_PLATFORM_NEEDSTRSEP@
-
 /*
  * If the system needs strlcpy(), ISC_PLATFORM_NEEDSTRLCPY will be defined.
  */
index c32abb3aa4ebad2c667b18e83710e42ae674cef9..67ed24e61570d78e5eabc47b1d0f32531eb99944 100644 (file)
 
 ISC_LANG_BEGINDECLS
 
-char *
-isc_string_separate(char **stringp, const char *delim);
-
-#ifdef ISC_PLATFORM_NEEDSTRSEP
-#define strsep isc_string_separate
-#endif
-
 #ifdef ISC_PLATFORM_NEEDMEMMOVE
 #define memmove(a,b,c) bcopy(b,a,c)
 #endif
index 01ceeb1775c5158382bb5c95cbd74d29d4769824..b1b985b6a2f92b3889da4562fc3601f9c32ead4b 100644 (file)
 #include <isc/string.h>
 #include <isc/util.h>
 
-char *
-isc_string_separate(char **stringp, const char *delim) {
-       char *string = *stringp;
-       char *s;
-       const char *d;
-       char sc, dc;
-
-       if (string == NULL)
-               return (NULL);
-
-       for (s = string; (sc = *s) != '\0'; s++)
-               for (d = delim; (dc = *d) != '\0'; d++)
-                       if (sc == dc) {
-                               *s++ = '\0';
-                               *stringp = s;
-                               return (string);
-                       }
-       *stringp = NULL;
-       return (string);
-}
-
 size_t
 isc_string_strlcpy(char *dst, const char *src, size_t size)
 {
index a5f1960e951cdde3c4da044ca19ca9be5b2fa096..fe4a6c2057d6af57df4004cb89e3b453b0c66681 100644 (file)
@@ -645,7 +645,6 @@ isc_stdio_sync
 isc_stdio_tell
 isc_stdio_write
 isc_stdtime_get
-isc_string_separate
 isc_string_strcasestr
 isc_string_strlcat
 isc_string_strlcpy