[Asterisk-code-review] res pjsip: Add " " as a separator in comma-separated parame... (asterisk[13])

George Joseph asteriskteam at digium.com
Sun Mar 6 14:57:41 CST 2016


George Joseph has uploaded a new change for review.

  https://gerrit.asterisk.org/2358

Change subject: res_pjsip:  Add " " as a separator in comma-separated parameter lists
......................................................................

res_pjsip:  Add " " as a separator in comma-separated parameter lists

Configurations like "aors = a, b, c" were ignoring everything after "a"
because a space isn't considered a valid separator.  Same for mailboxes,
ciphers, contacts and a few others.

To fix, all the strsep(&copy, ",") calls have been changed to
strtok_r(NULL, ", ", &copy).  The change from strsep to strtok_r was necessary
because strtok_r collapses consecutive separators where strsep doesn't.

There was also an attempt to ast_free an ast_strdupa'd string in
ast_sip_for_each_aor which was causing a SEGV.  I removed it.

Although this issue was reported for realtime, the issue was in the res_pjsip
modules so all config mechanisms were affected.

ASTERISK-25829 #close
Reported-by: Mateusz Kowalski

Change-Id: I0b22a2cf22a7c1c50d4ecacbfa540155bec0e7a2
---
M channels/pjsip/dialplan_functions.c
M res/res_pjsip/config_transport.c
M res/res_pjsip/location.c
M res/res_pjsip/pjsip_configuration.c
M res/res_pjsip/pjsip_options.c
M res/res_pjsip_endpoint_identifier_ip.c
M res/res_pjsip_mwi.c
M res/res_pjsip_notify.c
M res/res_pjsip_path.c
M res/res_pjsip_pubsub.c
M res/res_pjsip_registrar.c
11 files changed, 21 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/58/2358/1

diff --git a/channels/pjsip/dialplan_functions.c b/channels/pjsip/dialplan_functions.c
index eb6def6..10c9024 100644
--- a/channels/pjsip/dialplan_functions.c
+++ b/channels/pjsip/dialplan_functions.c
@@ -819,7 +819,7 @@
 		return -1;
 	}
 
-	while ((aor_name = strsep(&rest, ","))) {
+	while ((aor_name = strtok_r(NULL, ", ", &rest))) {
 		RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
 		RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
 		struct ao2_iterator it_contacts;
diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c
index 61a979c..81bdcb5 100644
--- a/res/res_pjsip/config_transport.c
+++ b/res/res_pjsip/config_transport.c
@@ -985,7 +985,7 @@
 	}
 
 	parse = ast_strdupa(S_OR(var->value, ""));
-	while ((name = strsep(&parse, ","))) {
+	while ((name = strtok_r(NULL, ", ", &parse))) {
 		name = ast_strip(name);
 		if (ast_strlen_zero(name)) {
 			continue;
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c
index 2908f6f..84d4018 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -210,7 +210,7 @@
 	*aor = NULL;
 	*contact = NULL;
 
-	while ((aor_name = strsep(&rest, ","))) {
+	while ((aor_name = strtok_r(NULL, ", ", &rest))) {
 		*aor = ast_sip_location_retrieve_aor(aor_name);
 
 		if (!(*aor)) {
@@ -382,7 +382,7 @@
 	}
 
 	contacts = ast_strdupa(var->value);
-	while ((contact_uri = strsep(&contacts, ","))) {
+	while ((contact_uri = strtok_r(NULL, ", ", &contacts))) {
 		struct ast_sip_contact *contact;
 		struct ast_sip_contact_status *status;
 		char hash[33];
@@ -447,7 +447,7 @@
 	}
 
 	copy = ast_strdupa(aors);
-	while ((name = strsep(&copy, ","))) {
+	while ((name = strtok_r(NULL, ", ", &copy))) {
 		RAII_VAR(struct ast_sip_aor *, aor,
 			 ast_sip_location_retrieve_aor(name), ao2_cleanup);
 
@@ -459,7 +459,6 @@
 			return -1;
 		}
 	}
-	ast_free(copy);
 	return 0;
 }
 
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index 1eed928..e0a5936 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -413,11 +413,7 @@
 		return -1;
 	}
 
-	while ((val = strsep(&auth_names, ","))) {
-		if (ast_strlen_zero(val)) {
-			continue;
-		}
-
+	while ((val = strtok_r(NULL, ", ", &auth_names))) {
 		val = ast_strdup(val);
 		if (!val) {
 			goto failure;
@@ -480,7 +476,7 @@
 	char *idents = ast_strdupa(var->value);
 	char *val;
 
-	while ((val = strsep(&idents, ","))) {
+	while ((val = strtok_r(NULL, ", ", &idents))) {
 		if (!strcasecmp(val, "username")) {
 			endpoint->ident_method |= AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME;
 		} else {
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index f3c0737..0661420 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -281,7 +281,7 @@
 	}
 
 	aors = ast_strdupa(endpoint->aors);
-	while ((aor_name = strsep(&aors, ","))) {
+	while ((aor_name = strtok_r(NULL, ", ", &aors))) {
 		struct ast_sip_aor *aor;
 		struct ao2_container *contacts;
 
@@ -806,7 +806,7 @@
 	}
 
 	aors = ast_strdupa(endpoint->aors);
-	while ((aor_name = strsep(&aors, ","))) {
+	while ((aor_name = strtok_r(NULL, ", ", &aors))) {
 		struct ast_sip_aor *aor;
 		struct ao2_container *contacts;
 
@@ -910,7 +910,7 @@
 	}
 
 	aors = ast_strdupa(endpoint->aors);
-	while ((aor_name = strsep(&aors, ","))) {
+	while ((aor_name = strtok_r(NULL, ", ", &aors))) {
 		struct ast_sip_aor *aor;
 		struct ao2_container *contacts;
 
@@ -1098,7 +1098,7 @@
 	}
 
 	aors = ast_strdupa(endpoint->aors);
-	while ((aor_name = strsep(&aors, ","))) {
+	while ((aor_name = strtok_r(NULL, ", ", &aors))) {
 		struct ast_sip_aor *aor;
 		struct ao2_container *contacts;
 
diff --git a/res/res_pjsip_endpoint_identifier_ip.c b/res/res_pjsip_endpoint_identifier_ip.c
index 11559ad..f26bf7b 100644
--- a/res/res_pjsip_endpoint_identifier_ip.c
+++ b/res/res_pjsip_endpoint_identifier_ip.c
@@ -164,7 +164,7 @@
 		return 0;
 	}
 
-	while ((current_string = strsep(&input_string, ","))) {
+	while ((current_string = strtok_r(NULL, ", ", &input_string))) {
 		struct ast_sockaddr *addrs;
 		int num_addrs = 0, error = 0, i;
 		char *mask = strrchr(current_string, '/');
diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c
index 1bc1adf..3f1cb58 100644
--- a/res/res_pjsip_mwi.c
+++ b/res/res_pjsip_mwi.c
@@ -432,7 +432,7 @@
 	ast_debug(5, "Sending unsolicited MWI NOTIFY to endpoint %s, new messages: %d, old messages: %d\n",
 			sub->id, counter->new_msgs, counter->old_msgs);
 
-	while ((aor_name = strsep(&endpoint_aors, ","))) {
+	while ((aor_name = strtok_r(NULL, ", ", &endpoint_aors))) {
 		RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
 		RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
 		struct unsolicited_mwi_data mwi_data = {
@@ -598,7 +598,7 @@
 	}
 
 	mailboxes = ast_strdupa(aor->mailboxes);
-	while ((mailbox = strsep(&mailboxes, ","))) {
+	while ((mailbox = strtok_r(NULL, ", ", &mailboxes))) {
 		if (endpoint_receives_unsolicited_mwi_for_mailbox(endpoint, mailbox)) {
 			ast_debug(1, "Endpoint '%s' already configured for unsolicited MWI for mailbox '%s'. "
 					"Denying MWI subscription to %s\n", ast_sorcery_object_get_id(endpoint), mailbox,
@@ -622,7 +622,7 @@
 	}
 
 	mailboxes = ast_strdupa(aor->mailboxes);
-	while ((mailbox = strsep(&mailboxes, ","))) {
+	while ((mailbox = strtok_r(NULL, ", ", &mailboxes))) {
 		struct mwi_stasis_subscription *mwi_stasis_sub;
 
 		mwi_stasis_sub = mwi_stasis_subscription_alloc(mailbox, sub);
@@ -890,7 +890,7 @@
 
 	endpoint_aors = ast_strdupa(endpoint->aors);
 
-	while ((aor_name = strsep(&endpoint_aors, ","))) {
+	while ((aor_name = strtok_r(NULL, ", ", &endpoint_aors))) {
 		RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
 
 		if (!aor) {
@@ -921,7 +921,7 @@
 	}
 
 	mailboxes = ast_strdupa(endpoint->subscription.mwi.mailboxes);
-	while ((mailbox = strsep(&mailboxes, ","))) {
+	while ((mailbox = strtok_r(NULL, ", ", &mailboxes))) {
 		struct mwi_subscription *sub = aggregate_sub ?:
 			mwi_subscription_alloc(endpoint, 0, NULL);
 		struct mwi_stasis_subscription *mwi_stasis_sub;
diff --git a/res/res_pjsip_notify.c b/res/res_pjsip_notify.c
index 96367cf..433e4a5 100644
--- a/res/res_pjsip_notify.c
+++ b/res/res_pjsip_notify.c
@@ -615,7 +615,7 @@
 
 	aors = ast_strdupa(data->endpoint->aors);
 
-	while ((aor_name = strsep(&aors, ","))) {
+	while ((aor_name = strtok_r(NULL, ", ", &aors))) {
 		RAII_VAR(struct ast_sip_aor *, aor,
 			 ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
 		RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
diff --git a/res/res_pjsip_path.c b/res/res_pjsip_path.c
index d0ee5a4..b27cded 100644
--- a/res/res_pjsip_path.c
+++ b/res/res_pjsip_path.c
@@ -53,7 +53,7 @@
 	configured_aors = ast_strdupa(endpoint->aors);
 
 	/* Iterate the configured AORs to see if the user or the user+domain match */
-	while ((aor_name = strsep(&configured_aors, ","))) {
+	while ((aor_name = strtok_r(NULL, ", ", &configured_aors))) {
 		struct ast_sip_domain_alias *alias = NULL;
 
 		if (!pj_strcmp2(&sip_uri->user, aor_name)) {
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index 643ed85..a2b1e62 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -3654,7 +3654,7 @@
 	char *items = ast_strdupa(var->value);
 	char *item;
 
-	while ((item = strsep(&items, ","))) {
+	while ((item = strtok_r(NULL, ", ", &items))) {
 		if (item_in_vector(list, item)) {
 			ast_log(LOG_WARNING, "Ignoring duplicated list item '%s'\n", item);
 			continue;
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index b0f8d66..69b629d 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -651,7 +651,7 @@
 	configured_aors = ast_strdupa(endpoint->aors);
 
 	/* Iterate the configured AORs to see if the user or the user+domain match */
-	while ((aor_name = strsep(&configured_aors, ","))) {
+	while ((aor_name = strtok_r(NULL, ", ", &configured_aors))) {
 		struct ast_sip_domain_alias *alias = NULL;
 
 		if (!pj_strcmp2(&uri->user, aor_name)) {

-- 
To view, visit https://gerrit.asterisk.org/2358
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0b22a2cf22a7c1c50d4ecacbfa540155bec0e7a2
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: George Joseph <george.joseph at fairview5.com>



More information about the asterisk-code-review mailing list