Commit 11f26b42 authored by Ondřej Surý's avatar Ondřej Surý
Browse files

Replace all usage of non-reentrant strtok() with strtok_r()

parent 921d05dd
......@@ -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);
......
......@@ -31,14 +31,6 @@
#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;
......
......@@ -27,14 +27,6 @@
#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;
......
......@@ -179,14 +179,6 @@
"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;
......
......@@ -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);
......
......@@ -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) !=
......
......@@ -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));
......
......@@ -25,11 +25,12 @@
*/
#if defined(_WIN32) || defined(_WIN64)
/* We are on Windows */
# define strtok_r strtok_s
#ifndef strtoull
#define strtoull _strtoui64
#endif
#endif
/***
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment