Browse Source

Bugfix: Use strtok_r for parse_config since some options use strtok themselves

Formerly, this led to undefined behaviour as parse_config tried to get the next token of the wrong (finished) strtok session
Luke Dashjr 13 years ago
parent
commit
13cb2c8cd7
1 changed files with 2 additions and 2 deletions
  1. 2 2
      main.c

+ 2 - 2
main.c

@@ -1454,14 +1454,14 @@ static char *parse_config(json_t *config)
 	struct opt_table *opt;
 
 	for (opt = opt_config_table; opt->type != OPT_END; opt++) {
-		char *p, *name;
+		char *p, *name, *sp;
 
 		/* We don't handle subtables. */
 		assert(!(opt->type & OPT_SUBTABLE));
 
 		/* Pull apart the option name(s). */
 		name = strdup(opt->names);
-		for (p = strtok(name, "|"); p; p = strtok(NULL, "|")) {
+		for (p = strtok_r(name, "|", &sp); p; p = strtok_r(NULL, "|", &sp)) {
 			char *err;
 			/* Ignore short options. */
 			if (p[1] != '-')