summaryrefslogtreecommitdiff
path: root/res/res_pjsip_mwi.c
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2016-03-06 13:38:41 -0700
committerGeorge Joseph <george.joseph@fairview5.com>2016-03-07 13:16:41 -0600
commitd2eb65f71e9347c15d469579bbb20c47501d924b (patch)
tree7146e406d5ab4a30eebbf6b62161a9d219f98cca /res/res_pjsip_mwi.c
parentee5a9442a295eedf05b998ef1b5c101832d6673f (diff)
res_pjsip: Strip spaces from items parsed from comma-separated lists
Configurations like "aors = a, b, c" were either ignoring everything after "a" or trying to look up " b". Same for mailboxes, ciphers, contacts and a few others. To fix, all the strsep(&copy, ",") calls have been wrapped in ast_strip. To facilitate this, ast_strip, ast_skip_blanks and ast_skip_nonblanks were updated to handle null pointers. In some cases, an ast_strlen_zero() test was added to skip consecutive commas. 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
Diffstat (limited to 'res/res_pjsip_mwi.c')
-rw-r--r--res/res_pjsip_mwi.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c
index e1eea6f2a..c9d1b743e 100644
--- a/res/res_pjsip_mwi.c
+++ b/res/res_pjsip_mwi.c
@@ -432,7 +432,7 @@ static void send_unsolicited_mwi_notify(struct mwi_subscription *sub,
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 = ast_strip(strsep(&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,11 @@ static int mwi_validate_for_aor(void *obj, void *arg, int flags)
}
mailboxes = ast_strdupa(aor->mailboxes);
- while ((mailbox = strsep(&mailboxes, ","))) {
+ while ((mailbox = ast_strip(strsep(&mailboxes, ",")))) {
+ if (ast_strlen_zero(mailbox)) {
+ continue;
+ }
+
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,9 +626,13 @@ static int mwi_on_aor(void *obj, void *arg, int flags)
}
mailboxes = ast_strdupa(aor->mailboxes);
- while ((mailbox = strsep(&mailboxes, ","))) {
+ while ((mailbox = ast_strip(strsep(&mailboxes, ",")))) {
struct mwi_stasis_subscription *mwi_stasis_sub;
+ if (ast_strlen_zero(mailbox)) {
+ continue;
+ }
+
mwi_stasis_sub = mwi_stasis_subscription_alloc(mailbox, sub);
if (!mwi_stasis_sub) {
continue;
@@ -890,7 +898,7 @@ static int create_mwi_subscriptions_for_endpoint(void *obj, void *arg, int flags
endpoint_aors = ast_strdupa(endpoint->aors);
- while ((aor_name = strsep(&endpoint_aors, ","))) {
+ while ((aor_name = ast_strip(strsep(&endpoint_aors, ",")))) {
RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
if (!aor) {
@@ -921,11 +929,15 @@ static int create_mwi_subscriptions_for_endpoint(void *obj, void *arg, int flags
}
mailboxes = ast_strdupa(endpoint->subscription.mwi.mailboxes);
- while ((mailbox = strsep(&mailboxes, ","))) {
- struct mwi_subscription *sub = aggregate_sub ?:
- mwi_subscription_alloc(endpoint, 0, NULL);
+ while ((mailbox = ast_strip(strsep(&mailboxes, ",")))) {
+ struct mwi_subscription *sub;
struct mwi_stasis_subscription *mwi_stasis_sub;
+ if (ast_strlen_zero(mailbox)) {
+ continue;
+ }
+
+ sub = aggregate_sub ?: mwi_subscription_alloc(endpoint, 0, NULL);
mwi_stasis_sub = mwi_stasis_subscription_alloc(mailbox, sub);
if (mwi_stasis_sub) {
ao2_link(sub->stasis_subs, mwi_stasis_sub);