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

George Joseph asteriskteam at digium.com
Sun Mar 6 14:58:32 CST 2016


George Joseph has uploaded a new change for review.

  https://gerrit.asterisk.org/2359

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/59/2359/1

diff --git a/channels/pjsip/dialplan_functions.c b/channels/pjsip/dialplan_functions.c
index b86cfad..fe87eea 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 c070e7d..51cd3b0 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -205,7 +205,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)) {
@@ -377,7 +377,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];
@@ -442,7 +442,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);
 
@@ -454,7 +454,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 2a81cfd..1e14775 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -410,11 +410,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;
@@ -477,7 +473,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 73f12a0..83df1d6 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -270,7 +270,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;
 
@@ -795,7 +795,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;
 
@@ -899,7 +899,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;
 
@@ -1087,7 +1087,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 f73bdae..481262e 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 e1eea6f..6f8a409 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 6d52415..e3bd020 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 03cbe50..f0a5026 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 0da4319..d639f1f 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 accb161..f28981b 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/2359
To unsubscribe, visit https://gerrit.asterisk.org/settings

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



More information about the asterisk-code-review mailing list