Replace calls to strtok() with strtok_r()

strtok() uses a static buffer, making it not thread safe.

Change-Id: Icce265153e1e65adafa8849334438ab6d190e541
13.26
Sean Bright 7 years ago
parent 856f3e6895
commit 1cb6466268

@ -11583,15 +11583,16 @@ static int process_sdp_a_text(const char *a, struct sip_pvt *p, struct ast_rtp_c
ast_verbose("Discarded description format %s for ID %u\n", mimeSubtype, codec); ast_verbose("Discarded description format %s for ID %u\n", mimeSubtype, codec);
} }
} else if (!strncmp(a, red_fmtp, strlen(red_fmtp))) { } else if (!strncmp(a, red_fmtp, strlen(red_fmtp))) {
char *rest;
/* count numbers of generations in fmtp */ /* count numbers of generations in fmtp */
red_cp = &red_fmtp[strlen(red_fmtp)]; red_cp = &red_fmtp[strlen(red_fmtp)];
strncpy(red_fmtp, a, 100); strncpy(red_fmtp, a, 100);
sscanf(red_cp, "%30u", (unsigned *)&red_data_pt[*red_num_gen]); sscanf(red_cp, "%30u", (unsigned *)&red_data_pt[*red_num_gen]);
red_cp = strtok(red_cp, "/"); red_cp = strtok_r(red_cp, "/", &rest);
while (red_cp && (*red_num_gen)++ < AST_RED_MAX_GENERATION) { while (red_cp && (*red_num_gen)++ < AST_RED_MAX_GENERATION) {
sscanf(red_cp, "%30u", (unsigned *)&red_data_pt[*red_num_gen]); sscanf(red_cp, "%30u", (unsigned *)&red_data_pt[*red_num_gen]);
red_cp = strtok(NULL, "/"); red_cp = strtok_r(NULL, "/", &rest);
} }
red_cp = red_fmtp; red_cp = red_fmtp;
found = TRUE; found = TRUE;

@ -2955,6 +2955,8 @@ static char *dundi_show_cache(struct ast_cli_entry *e, int cmd, struct ast_cli_a
db_tree = ast_db_gettree("dundi/cache", NULL); db_tree = ast_db_gettree("dundi/cache", NULL);
ast_cli(a->fd, FORMAT2, "Number", "Context", "Expiration", "From", "Weight", "Destination (Flags)"); ast_cli(a->fd, FORMAT2, "Number", "Context", "Expiration", "From", "Weight", "Destination (Flags)");
for (db_entry = db_tree; db_entry; db_entry = db_entry->next) { for (db_entry = db_tree; db_entry; db_entry = db_entry->next) {
char *rest;
if ((strncmp(db_entry->key, "/dundi/cache/hint/", 18) == 0) || ast_get_time_t(db_entry->data, &ts, 0, &length)) { if ((strncmp(db_entry->key, "/dundi/cache/hint/", 18) == 0) || ast_get_time_t(db_entry->data, &ts, 0, &length)) {
continue; continue;
} }
@ -2966,10 +2968,10 @@ static char *dundi_show_cache(struct ast_cli_entry *e, int cmd, struct ast_cli_a
} }
ptr = db_entry->key + sizeof("/dundi/cache"); ptr = db_entry->key + sizeof("/dundi/cache");
strtok(ptr, "/"); strtok_r(ptr, "/", &rest);
number = strtok(NULL, "/"); number = strtok_r(NULL, "/", &rest);
context = strtok(NULL, "/"); context = strtok_r(NULL, "/", &rest);
ptr = strtok(NULL, "/"); ptr = strtok_r(NULL, "/", &rest);
if (*ptr != 'e') { if (*ptr != 'e') {
continue; continue;
@ -3047,6 +3049,8 @@ static char *dundi_show_hints(struct ast_cli_entry *e, int cmd, struct ast_cli_a
ast_cli(a->fd, FORMAT2, "Prefix", "Context", "Expiration", "From"); ast_cli(a->fd, FORMAT2, "Prefix", "Context", "Expiration", "From");
for (db_entry = db_tree; db_entry; db_entry = db_entry->next) { for (db_entry = db_tree; db_entry; db_entry = db_entry->next) {
char *rest;
if (ast_get_time_t(db_entry->data, &ts, 0, &length)) { if (ast_get_time_t(db_entry->data, &ts, 0, &length)) {
continue; continue;
} }
@ -3058,10 +3062,10 @@ static char *dundi_show_hints(struct ast_cli_entry *e, int cmd, struct ast_cli_a
} }
ptr = db_entry->key + sizeof("/dundi/cache/hint"); ptr = db_entry->key + sizeof("/dundi/cache/hint");
src = strtok(ptr, "/"); src = strtok_r(ptr, "/", &rest);
number = strtok(NULL, "/"); number = strtok_r(NULL, "/", &rest);
context = strtok(NULL, "/"); context = strtok_r(NULL, "/", &rest);
ptr = strtok(NULL, "/"); ptr = strtok_r(NULL, "/", &rest);
if (*ptr != 'e') { if (*ptr != 'e') {
continue; continue;

@ -809,17 +809,17 @@ unsigned int ast_fax_minrate(void)
static int update_modem_bits(enum ast_fax_modems *bits, const char *value) static int update_modem_bits(enum ast_fax_modems *bits, const char *value)
{ {
char *m[5], *tok, *v = (char *)value; char *m[5], *tok, *v = (char *) value, *rest;
int i = 0, j; int i = 0, j;
if (!strchr(v, ',')) { if (!strchr(v, ',')) {
m[i++] = v; m[i++] = v;
m[i] = NULL; m[i] = NULL;
} else { } else {
tok = strtok(v, ", "); tok = strtok_r(v, ", ", &rest);
while (tok && i < ARRAY_LEN(m) - 1) { while (tok && i < ARRAY_LEN(m) - 1) {
m[i++] = tok; m[i++] = tok;
tok = strtok(NULL, ", "); tok = strtok_r(NULL, ", ", &rest);
} }
m[i] = NULL; m[i] = NULL;
} }

Loading…
Cancel
Save