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
This commit is contained in:
George Joseph
2016-03-06 13:38:41 -07:00
parent 6e58f83d8d
commit 530cff5f5f
12 changed files with 71 additions and 29 deletions

View File

@@ -210,7 +210,7 @@ void ast_sip_location_retrieve_contact_and_aor_from_list(const char *aor_list, s
*aor = NULL;
*contact = NULL;
while ((aor_name = strsep(&rest, ","))) {
while ((aor_name = ast_strip(strsep(&rest, ",")))) {
*aor = ast_sip_location_retrieve_aor(aor_name);
if (!(*aor)) {
@@ -382,12 +382,16 @@ static int permanent_uri_handler(const struct aco_option *opt, struct ast_variab
}
contacts = ast_strdupa(var->value);
while ((contact_uri = strsep(&contacts, ","))) {
while ((contact_uri = ast_strip(strsep(&contacts, ",")))) {
struct ast_sip_contact *contact;
struct ast_sip_contact_status *status;
char hash[33];
char contact_id[strlen(aor_id) + sizeof(hash) + 2];
if (ast_strlen_zero(contact_uri)) {
continue;
}
if (!aor->permanent_contacts) {
aor->permanent_contacts = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK,
AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, permanent_uri_sort_fn, NULL);
@@ -447,7 +451,7 @@ int ast_sip_for_each_aor(const char *aors, ao2_callback_fn on_aor, void *arg)
}
copy = ast_strdupa(aors);
while ((name = strsep(&copy, ","))) {
while ((name = ast_strip(strsep(&copy, ",")))) {
RAII_VAR(struct ast_sip_aor *, aor,
ast_sip_location_retrieve_aor(name), ao2_cleanup);
@@ -459,7 +463,6 @@ int ast_sip_for_each_aor(const char *aors, ao2_callback_fn on_aor, void *arg)
return -1;
}
}
ast_free(copy);
return 0;
}