]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Replace all usage of non-reentrant strtok() with strtok_r()
authorOndřej Surý <ondrej@sury.org>
Wed, 21 Mar 2018 21:16:51 +0000 (21:16 +0000)
committerOndřej Surý <ondrej@sury.org>
Thu, 12 Apr 2018 08:37:33 +0000 (10:37 +0200)
bin/named/main.c
bin/tests/system/dlzexternal/driver.c
contrib/dlz/example/dlz_example.c
contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c
contrib/queryperf/queryperf.c
contrib/sdb/bdb/bdb.c
lib/isc/win32/fsaccess.c
lib/isc/win32/include/isc/platform.h.in

index c19206215e625bce87e83a92855b7cfee26a2776..5307b0837830a44124f399da2921b560f1469861 100644 (file)
@@ -607,14 +607,15 @@ parse_command_line(int argc, char *argv[]) {
                        else if (!strncmp(isc_commandline_argument,
                                          "mkeytimers=", 11))
                        {
-                               p = strtok(isc_commandline_argument + 11, "/");
+                               char *last;
+                               p = strtok_r(isc_commandline_argument + 11, "/", &last);
                                if (p == NULL)
                                        named_main_earlyfatal("bad mkeytimer");
                                dns_zone_mkey_hour = atoi(p);
                                if (dns_zone_mkey_hour == 0)
                                        named_main_earlyfatal("bad mkeytimer");
 
-                               p = strtok(NULL, "/");
+                               p = strtok_r(NULL, "/", &last);
                                if (p == NULL) {
                                        dns_zone_mkey_day =
                                                (24 * dns_zone_mkey_hour);
@@ -626,7 +627,7 @@ parse_command_line(int argc, char *argv[]) {
                                if (dns_zone_mkey_day < dns_zone_mkey_hour)
                                        named_main_earlyfatal("bad mkeytimer");
 
-                               p = strtok(NULL, "/");
+                               p = strtok_r(NULL, "/", &last);
                                if (p == NULL) {
                                        dns_zone_mkey_month =
                                                (30 * dns_zone_mkey_day);
index 71967d86df92e8255df94e28ee8acc55f31561d8..a55189126be517b1e2ab411b1d23e621c1d3faa2 100644 (file)
 
 #include "driver.h"
 
-#ifdef WIN32
-#define STRTOK_R(a, b, c)      strtok_s(a, b, c)
-#elif defined(_REENTRANT)
-#define STRTOK_R(a, b, c)       strtok_r(a, b, c)
-#else
-#define STRTOK_R(a, b, c)       strtok(a, b)
-#endif
-
 #define CHECK(x) \
        do { \
                result = (x); \
@@ -726,23 +718,23 @@ modrdataset(struct dlz_example_data *state, const char *name,
         * for the type used by dig
         */
 
-       full_name = STRTOK_R(buf, "\t", &saveptr);
+       full_name = strtok_r(buf, "\t", &saveptr);
        if (full_name == NULL)
                goto error;
 
-       ttlstr = STRTOK_R(NULL, "\t", &saveptr);
+       ttlstr = strtok_r(NULL, "\t", &saveptr);
        if (ttlstr == NULL)
                goto error;
 
-       dclass = STRTOK_R(NULL, "\t", &saveptr);
+       dclass = strtok_r(NULL, "\t", &saveptr);
        if (dclass == NULL)
                goto error;
 
-       type = STRTOK_R(NULL, "\t", &saveptr);
+       type = strtok_r(NULL, "\t", &saveptr);
        if (type == NULL)
                goto error;
 
-       data = STRTOK_R(NULL, "\t", &saveptr);
+       data = strtok_r(NULL, "\t", &saveptr);
        if (data == NULL)
                goto error;
 
index 3a63dc4b9f7ac344b90b13d49483ec97ba46ea3a..848189903d1f31b0f40c39ea4f033cb6f5a6504d 100644 (file)
 
 #include "../modules/include/dlz_minimal.h"
 
-#ifdef WIN32
-#define STRTOK_R(a, b, c)      strtok_s(a, b, c)
-#elif defined(_REENTRANT)
-#define STRTOK_R(a, b, c)       strtok_r(a, b, c)
-#else
-#define STRTOK_R(a, b, c)       strtok(a, b)
-#endif
-
 #define CHECK(x) \
        do { \
                result = (x); \
@@ -675,23 +667,23 @@ modrdataset(struct dlz_example_data *state, const char *name,
         * for the type used by dig
         */
 
-       full_name = STRTOK_R(buf, "\t", &saveptr);
+       full_name = strtok_r(buf, "\t", &saveptr);
        if (full_name == NULL)
                goto error;
 
-       ttlstr = STRTOK_R(NULL, "\t", &saveptr);
+       ttlstr = strtok_r(NULL, "\t", &saveptr);
        if (ttlstr == NULL)
                goto error;
 
-       dclass = STRTOK_R(NULL, "\t", &saveptr);
+       dclass = strtok_r(NULL, "\t", &saveptr);
        if (dclass == NULL)
                goto error;
 
-       type = STRTOK_R(NULL, "\t", &saveptr);
+       type = strtok_r(NULL, "\t", &saveptr);
        if (type == NULL)
                goto error;
 
-       data = STRTOK_R(NULL, "\t", &saveptr);
+       data = strtok_r(NULL, "\t", &saveptr);
        if (data == NULL)
                goto error;
 
index 1e8cdad2bb2904b792fd7ea8cc82ee5655bace08..7bc5398750ac7fb76ee173d8fe6fe7fd01fbbf5b 100644 (file)
        "DELETE FROM ZoneData WHERE zone_id = %s AND " \
        "LOWER(name) = LOWER('%s') AND UPPER(type) = UPPER('%s')"
 
-#ifdef WIN32
-#define STRTOK_R(a, b, c)       strtok_s(a, b, c)
-#elif defined(_REENTRANT)
-#define STRTOK_R(a, b, c)       strtok_r(a, b, c)
-#else
-#define STRTOK_R(a, b, c)       strtok(a, b)
-#endif
-
 /*
  * Number of concurrent database connections we support
  * - equivalent to maxmium number of concurrent transactions
@@ -837,23 +829,23 @@ makerecord(mysql_data_t *state, const char *name, const char *rdatastr) {
         * The DATA field is space separated, and is in the data format
         * for the type used by dig
         */
-       real_name = STRTOK_R(buf, "\t", &saveptr);
+       real_name = strtok_r(buf, "\t", &saveptr);
        if (real_name == NULL)
                goto error;
 
-       ttlstr = STRTOK_R(NULL, "\t", &saveptr);
+       ttlstr = strtok_r(NULL, "\t", &saveptr);
        if (ttlstr == NULL || sscanf(ttlstr, "%d", &ttlvalue) != 1)
                goto error;
 
-       dclass = STRTOK_R(NULL, "\t", &saveptr);
+       dclass = strtok_r(NULL, "\t", &saveptr);
        if (dclass == NULL)
                goto error;
 
-       type = STRTOK_R(NULL, "\t", &saveptr);
+       type = strtok_r(NULL, "\t", &saveptr);
        if (type == NULL)
                goto error;
 
-       data = STRTOK_R(NULL, "\t", &saveptr);
+       data = strtok_r(NULL, "\t", &saveptr);
        if (data == NULL)
                goto error;
 
index 0738cc2903043edfd155072cab2e287ffa0e38c2..28a62ea019331c63f793c3d90dd9721c92ebff2b 100644 (file)
@@ -1184,7 +1184,7 @@ identify_directive(char *dir) {
  */
 void
 update_config(char *config_change_desc) {
-       char *directive, *config_value, *trailing_garbage;
+       char *directive, *config_value, *trailing_garbage, *last;
        char conf_copy[MAX_INPUT_LEN + 1];
        unsigned int uint_val;
        int directive_number;
@@ -1213,9 +1213,9 @@ update_config(char *config_change_desc) {
                return;
        }
 
-       directive = strtok(config_change_desc, WHITESPACE);
-       config_value = strtok(NULL, WHITESPACE);
-       trailing_garbage = strtok(NULL, WHITESPACE);
+       directive = strtok_r(config_change_desc, WHITESPACE, &last);
+       config_value = strtok_r(NULL, WHITESPACE, &last);
+       trailing_garbage = strtok_r(NULL, WHITESPACE, &last);
 
        if ((directive_number = identify_directive(directive)) == -1) {
                fprintf(stderr, "Invalid config: Bad directive: %s\n",
@@ -1349,7 +1349,7 @@ parse_query(char *input, char *qname, unsigned int qnlen, int *qtype) {
        unsigned int num_types, index;
        int found = FALSE;
        char incopy[MAX_INPUT_LEN + 1];
-       char *domain_str, *type_str;
+       char *domain_str, *type_str, *last;
 
        num_types = sizeof(qtype_strings) / sizeof(qtype_strings[0]);
        if (num_types > (sizeof(qtype_codes) / sizeof(int)))
@@ -1357,8 +1357,8 @@ parse_query(char *input, char *qname, unsigned int qnlen, int *qtype) {
 
        strcpy(incopy, input);
 
-       domain_str = strtok(incopy, WHITESPACE);
-       type_str = strtok(NULL, WHITESPACE);
+       domain_str = strtok_r(incopy, WHITESPACE, &last);
+       type_str = strtok_r(NULL, WHITESPACE, &last);
 
        if ((domain_str == NULL) || (type_str == NULL)) {
                fprintf(stderr, "Invalid query input format: %s\n", input);
index 23594bbe3c6670673b2ac842b67b713c0e0f517a..351bdc8a5407230d3cecb7db658edf387b99c9ef 100644 (file)
@@ -137,12 +137,13 @@ bdb_lookup(const char *zone, const char *name, void *dbdata,
 
        ret = c->c_get(c, &key, &data, DB_SET);
        while (ret == 0) {
+               char *last;
                ((char *)key.data)[key.size] = 0;
                ((char *)data.data)[data.size] = 0;
-               ttltext.base = strtok((char *)data.data, " ");
+               ttltext.base = strtok_r((char *)data.data, " ", &last);
                ttltext.length = strlen(ttltext.base);
                dns_ttl_fromtext((isc_textregion_t *)&ttltext, &ttl);
-               type = strtok(NULL, " ");
+               type = strtok_r(NULL, " ", &last);
                rdata = type + strlen(type) + 1;
 
                if (dns_sdb_putrr(l, type, ttl, rdata) != ISC_R_SUCCESS) {
@@ -185,12 +186,13 @@ bdb_allnodes(const char *zone, void *dbdata, dns_sdballnodes_t *n)
        memset(&data, 0, sizeof(DBT));
 
        while (c->c_get(c, &key, &data, DB_NEXT) == 0) {
+               char *last;
                ((char *)key.data)[key.size] = 0;
                ((char *)data.data)[data.size] = 0;
-               ttltext.base = strtok((char *)data.data, " ");
+               ttltext.base = strtok_r((char *)data.data, " ", &last);
                ttltext.length = strlen(ttltext.base);
                dns_ttl_fromtext((isc_textregion_t *)&ttltext, &ttl);
-               type = strtok(NULL, " ");
+               type = strtok_r(NULL, " ", &last);
                rdata = type + strlen(type) + 1;
 
                if (dns_sdb_putnamedrr(n, key.data, type, ttl, rdata) !=
index 5944f5435509fe255d06747bd3670a49615eef49..9b3a6559ebe94984f91487e5c7cb709db6c92ca5 100644 (file)
@@ -76,10 +76,11 @@ is_ntfs(const char * file) {
                /* Copy 'c:\' or 'c:/' and NUL terminate. */
                strlcpy(drive, filename, ISC_MIN(3 + 1, sizeof(drive)));
        } else if ((filename[0] == '\\') && (filename[1] == '\\')) {
+               char *last;
                /* Find the machine and share name and rebuild the UNC */
                strlcpy(tmpbuf, filename, sizeof(tmpbuf));
-               machinename = strtok(tmpbuf, "\\");
-               sharename = strtok(NULL, "\\");
+               machinename = strtok_r(tmpbuf, "\\", &last);
+               sharename = strtok_r(NULL, "\\", &last);
                strlcpy(drive, "\\\\", sizeof(drive));
                strlcat(drive, machinename, sizeof(drive));
                strlcat(drive, "\\", sizeof(drive));
index e3f534f7b8e37489876f72cf2508d44b2d4066d6..2e79ae450bbbd2270b28a92ef9162de0d770a170 100644 (file)
  */
 
 #if defined(_WIN32) || defined(_WIN64)
+/* We are on Windows */
+# define strtok_r strtok_s
 
 #ifndef strtoull
 #define strtoull _strtoui64
 #endif
-
 #endif
 
 /***