Replace calls to strtok() with strtok_r()

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

Also add a #define to cause a compile failure if strtok is used.

Change-Id: Icce265153e1e65adafa8849334438ab6d190e541
This commit is contained in:
Sean Bright 2019-03-06 16:04:57 -05:00
parent a32f525489
commit 2473b791b9
4 changed files with 19 additions and 13 deletions

View File

@ -11637,15 +11637,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);
}
} else if (!strncmp(a, red_fmtp, strlen(red_fmtp))) {
char *rest;
/* count numbers of generations in fmtp */
red_cp = &red_fmtp[strlen(red_fmtp)];
strncpy(red_fmtp, a, 100);
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) {
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;
found = TRUE;

View File

@ -47,6 +47,7 @@
#define DEFAULT_SAMPLES_PER_MS ((DEFAULT_SAMPLE_RATE)/1000)
#define setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__
#define sched_setscheduler __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
#define strtok __PLEASE_USE_strtok_r_INSTEAD_OF_strtok__
#if defined(DEBUG_FD_LEAKS) && !defined(STANDALONE) && !defined(STANDALONE2) && !defined(STANDALONE_AEL)
/* These includes are all about ordering */

View File

@ -2977,6 +2977,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);
ast_cli(a->fd, FORMAT2, "Number", "Context", "Expiration", "From", "Weight", "Destination (Flags)");
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)) {
continue;
}
@ -2988,10 +2990,10 @@ static char *dundi_show_cache(struct ast_cli_entry *e, int cmd, struct ast_cli_a
}
ptr = db_entry->key + sizeof("/dundi/cache");
strtok(ptr, "/");
number = strtok(NULL, "/");
context = strtok(NULL, "/");
ptr = strtok(NULL, "/");
strtok_r(ptr, "/", &rest);
number = strtok_r(NULL, "/", &rest);
context = strtok_r(NULL, "/", &rest);
ptr = strtok_r(NULL, "/", &rest);
if (*ptr != 'e') {
continue;
@ -3069,6 +3071,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");
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)) {
continue;
}
@ -3080,10 +3084,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");
src = strtok(ptr, "/");
number = strtok(NULL, "/");
context = strtok(NULL, "/");
ptr = strtok(NULL, "/");
src = strtok_r(ptr, "/", &rest);
number = strtok_r(NULL, "/", &rest);
context = strtok_r(NULL, "/", &rest);
ptr = strtok_r(NULL, "/", &rest);
if (*ptr != 'e') {
continue;

View File

@ -807,17 +807,17 @@ unsigned int ast_fax_minrate(void)
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;
if (!strchr(v, ',')) {
m[i++] = v;
m[i] = NULL;
} else {
tok = strtok(v, ", ");
tok = strtok_r(v, ", ", &rest);
while (tok && i < ARRAY_LEN(m) - 1) {
m[i++] = tok;
tok = strtok(NULL, ", ");
tok = strtok_r(NULL, ", ", &rest);
}
m[i] = NULL;
}