[Asterisk-code-review] Replace calls to strtok() with strtok_r() (...asterisk[16])
Friendly Automation
asteriskteam at digium.com
Fri Mar 8 12:33:24 CST 2019
Friendly Automation has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/11104 )
Change subject: Replace calls to strtok() with strtok_r()
......................................................................
Replace calls to strtok() with strtok_r()
strtok() uses a static buffer, making it not thread safe.
Change-Id: Icce265153e1e65adafa8849334438ab6d190e541
---
M channels/chan_sip.c
M pbx/pbx_dundi.c
M res/res_fax.c
3 files changed, 18 insertions(+), 13 deletions(-)
Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index e632a43..1bce57c 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -11637,15 +11637,16 @@
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;
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index f196721..f0d586d 100644
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -2977,6 +2977,8 @@
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 @@
}
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 @@
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 @@
}
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;
diff --git a/res/res_fax.c b/res/res_fax.c
index 39a7a64..7338507 100644
--- a/res/res_fax.c
+++ b/res/res_fax.c
@@ -807,17 +807,17 @@
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;
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11104
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Icce265153e1e65adafa8849334438ab6d190e541
Gerrit-Change-Number: 11104
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190308/d086bf29/attachment-0001.html>
More information about the asterisk-code-review
mailing list