mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-09 11:28:25 +00:00
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(©, ",") 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:
@@ -819,7 +819,7 @@ int pjsip_acf_dial_contacts_read(struct ast_channel *chan, const char *cmd, char
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((aor_name = strsep(&rest, ","))) {
|
while ((aor_name = ast_strip(strsep(&rest, ",")))) {
|
||||||
RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
|
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);
|
RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
|
||||||
struct ao2_iterator it_contacts;
|
struct ao2_iterator it_contacts;
|
||||||
|
|||||||
@@ -145,8 +145,12 @@ static int force_inline attribute_pure ast_ends_with(const char *str, const char
|
|||||||
AST_INLINE_API(
|
AST_INLINE_API(
|
||||||
char * attribute_pure ast_skip_blanks(const char *str),
|
char * attribute_pure ast_skip_blanks(const char *str),
|
||||||
{
|
{
|
||||||
while (*str && ((unsigned char) *str) < 33)
|
if (str) {
|
||||||
str++;
|
while (*str && ((unsigned char) *str) < 33) {
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (char *) str;
|
return (char *) str;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -184,8 +188,12 @@ char *ast_trim_blanks(char *str),
|
|||||||
AST_INLINE_API(
|
AST_INLINE_API(
|
||||||
char * attribute_pure ast_skip_nonblanks(const char *str),
|
char * attribute_pure ast_skip_nonblanks(const char *str),
|
||||||
{
|
{
|
||||||
while (*str && ((unsigned char) *str) > 32)
|
if (str) {
|
||||||
str++;
|
while (*str && ((unsigned char) *str) > 32) {
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (char *) str;
|
return (char *) str;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -985,8 +985,7 @@ static int transport_tls_cipher_handler(const struct aco_option *opt, struct ast
|
|||||||
}
|
}
|
||||||
|
|
||||||
parse = ast_strdupa(S_OR(var->value, ""));
|
parse = ast_strdupa(S_OR(var->value, ""));
|
||||||
while ((name = strsep(&parse, ","))) {
|
while ((name = ast_strip(strsep(&parse, ",")))) {
|
||||||
name = ast_strip(name);
|
|
||||||
if (ast_strlen_zero(name)) {
|
if (ast_strlen_zero(name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ void ast_sip_location_retrieve_contact_and_aor_from_list(const char *aor_list, s
|
|||||||
*aor = NULL;
|
*aor = NULL;
|
||||||
*contact = NULL;
|
*contact = NULL;
|
||||||
|
|
||||||
while ((aor_name = strsep(&rest, ","))) {
|
while ((aor_name = ast_strip(strsep(&rest, ",")))) {
|
||||||
*aor = ast_sip_location_retrieve_aor(aor_name);
|
*aor = ast_sip_location_retrieve_aor(aor_name);
|
||||||
|
|
||||||
if (!(*aor)) {
|
if (!(*aor)) {
|
||||||
@@ -382,12 +382,16 @@ static int permanent_uri_handler(const struct aco_option *opt, struct ast_variab
|
|||||||
}
|
}
|
||||||
|
|
||||||
contacts = ast_strdupa(var->value);
|
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 *contact;
|
||||||
struct ast_sip_contact_status *status;
|
struct ast_sip_contact_status *status;
|
||||||
char hash[33];
|
char hash[33];
|
||||||
char contact_id[strlen(aor_id) + sizeof(hash) + 2];
|
char contact_id[strlen(aor_id) + sizeof(hash) + 2];
|
||||||
|
|
||||||
|
if (ast_strlen_zero(contact_uri)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!aor->permanent_contacts) {
|
if (!aor->permanent_contacts) {
|
||||||
aor->permanent_contacts = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK,
|
aor->permanent_contacts = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK,
|
||||||
AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, permanent_uri_sort_fn, NULL);
|
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);
|
copy = ast_strdupa(aors);
|
||||||
while ((name = strsep(©, ","))) {
|
while ((name = ast_strip(strsep(©, ",")))) {
|
||||||
RAII_VAR(struct ast_sip_aor *, aor,
|
RAII_VAR(struct ast_sip_aor *, aor,
|
||||||
ast_sip_location_retrieve_aor(name), ao2_cleanup);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast_free(copy);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -413,7 +413,7 @@ int ast_sip_auth_vector_init(struct ast_sip_auth_vector *auths, const char *valu
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((val = strsep(&auth_names, ","))) {
|
while ((val = ast_strip(strsep(&auth_names, ",")))) {
|
||||||
if (ast_strlen_zero(val)) {
|
if (ast_strlen_zero(val)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -480,7 +480,11 @@ static int ident_handler(const struct aco_option *opt, struct ast_variable *var,
|
|||||||
char *idents = ast_strdupa(var->value);
|
char *idents = ast_strdupa(var->value);
|
||||||
char *val;
|
char *val;
|
||||||
|
|
||||||
while ((val = strsep(&idents, ","))) {
|
while ((val = ast_strip(strsep(&idents, ",")))) {
|
||||||
|
if (ast_strlen_zero(val)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!strcasecmp(val, "username")) {
|
if (!strcasecmp(val, "username")) {
|
||||||
endpoint->ident_method |= AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME;
|
endpoint->ident_method |= AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ static int on_endpoint(void *obj, void *arg, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
aors = ast_strdupa(endpoint->aors);
|
aors = ast_strdupa(endpoint->aors);
|
||||||
while ((aor_name = strsep(&aors, ","))) {
|
while ((aor_name = ast_strip(strsep(&aors, ",")))) {
|
||||||
struct ast_sip_aor *aor;
|
struct ast_sip_aor *aor;
|
||||||
struct ao2_container *contacts;
|
struct ao2_container *contacts;
|
||||||
|
|
||||||
@@ -806,7 +806,7 @@ static int cli_qualify_contacts(void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
aors = ast_strdupa(endpoint->aors);
|
aors = ast_strdupa(endpoint->aors);
|
||||||
while ((aor_name = strsep(&aors, ","))) {
|
while ((aor_name = ast_strip(strsep(&aors, ",")))) {
|
||||||
struct ast_sip_aor *aor;
|
struct ast_sip_aor *aor;
|
||||||
struct ao2_container *contacts;
|
struct ao2_container *contacts;
|
||||||
|
|
||||||
@@ -910,7 +910,7 @@ static int ami_sip_qualify(struct mansession *s, const struct message *m)
|
|||||||
}
|
}
|
||||||
|
|
||||||
aors = ast_strdupa(endpoint->aors);
|
aors = ast_strdupa(endpoint->aors);
|
||||||
while ((aor_name = strsep(&aors, ","))) {
|
while ((aor_name = ast_strip(strsep(&aors, ",")))) {
|
||||||
struct ast_sip_aor *aor;
|
struct ast_sip_aor *aor;
|
||||||
struct ao2_container *contacts;
|
struct ao2_container *contacts;
|
||||||
|
|
||||||
@@ -1098,7 +1098,7 @@ static int qualify_and_schedule_all_cb(void *obj, void *arg, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
aors = ast_strdupa(endpoint->aors);
|
aors = ast_strdupa(endpoint->aors);
|
||||||
while ((aor_name = strsep(&aors, ","))) {
|
while ((aor_name = ast_strip(strsep(&aors, ",")))) {
|
||||||
struct ast_sip_aor *aor;
|
struct ast_sip_aor *aor;
|
||||||
struct ao2_container *contacts;
|
struct ao2_container *contacts;
|
||||||
|
|
||||||
|
|||||||
@@ -164,11 +164,15 @@ static int ip_identify_match_handler(const struct aco_option *opt, struct ast_va
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((current_string = strsep(&input_string, ","))) {
|
while ((current_string = ast_strip(strsep(&input_string, ",")))) {
|
||||||
struct ast_sockaddr *addrs;
|
struct ast_sockaddr *addrs;
|
||||||
int num_addrs = 0, error = 0, i;
|
int num_addrs = 0, error = 0, i;
|
||||||
char *mask = strrchr(current_string, '/');
|
char *mask = strrchr(current_string, '/');
|
||||||
|
|
||||||
|
if (ast_strlen_zero(current_string)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (mask) {
|
if (mask) {
|
||||||
identify->matches = ast_append_ha("d", current_string, identify->matches, &error);
|
identify->matches = ast_append_ha("d", current_string, identify->matches, &error);
|
||||||
|
|
||||||
|
|||||||
@@ -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",
|
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);
|
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 ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
|
||||||
RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
|
RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
|
||||||
struct unsolicited_mwi_data mwi_data = {
|
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);
|
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)) {
|
if (endpoint_receives_unsolicited_mwi_for_mailbox(endpoint, mailbox)) {
|
||||||
ast_debug(1, "Endpoint '%s' already configured for unsolicited MWI for mailbox '%s'. "
|
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,
|
"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);
|
mailboxes = ast_strdupa(aor->mailboxes);
|
||||||
while ((mailbox = strsep(&mailboxes, ","))) {
|
while ((mailbox = ast_strip(strsep(&mailboxes, ",")))) {
|
||||||
struct mwi_stasis_subscription *mwi_stasis_sub;
|
struct mwi_stasis_subscription *mwi_stasis_sub;
|
||||||
|
|
||||||
|
if (ast_strlen_zero(mailbox)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
mwi_stasis_sub = mwi_stasis_subscription_alloc(mailbox, sub);
|
mwi_stasis_sub = mwi_stasis_subscription_alloc(mailbox, sub);
|
||||||
if (!mwi_stasis_sub) {
|
if (!mwi_stasis_sub) {
|
||||||
continue;
|
continue;
|
||||||
@@ -890,7 +898,7 @@ static int create_mwi_subscriptions_for_endpoint(void *obj, void *arg, int flags
|
|||||||
|
|
||||||
endpoint_aors = ast_strdupa(endpoint->aors);
|
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);
|
RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
|
||||||
|
|
||||||
if (!aor) {
|
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);
|
mailboxes = ast_strdupa(endpoint->subscription.mwi.mailboxes);
|
||||||
while ((mailbox = strsep(&mailboxes, ","))) {
|
while ((mailbox = ast_strip(strsep(&mailboxes, ",")))) {
|
||||||
struct mwi_subscription *sub = aggregate_sub ?:
|
struct mwi_subscription *sub;
|
||||||
mwi_subscription_alloc(endpoint, 0, NULL);
|
|
||||||
struct mwi_stasis_subscription *mwi_stasis_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);
|
mwi_stasis_sub = mwi_stasis_subscription_alloc(mailbox, sub);
|
||||||
if (mwi_stasis_sub) {
|
if (mwi_stasis_sub) {
|
||||||
ao2_link(sub->stasis_subs, mwi_stasis_sub);
|
ao2_link(sub->stasis_subs, mwi_stasis_sub);
|
||||||
|
|||||||
@@ -615,7 +615,7 @@ static int notify_endpoint(void *obj)
|
|||||||
|
|
||||||
aors = ast_strdupa(data->endpoint->aors);
|
aors = ast_strdupa(data->endpoint->aors);
|
||||||
|
|
||||||
while ((aor_name = strsep(&aors, ","))) {
|
while ((aor_name = ast_strip(strsep(&aors, ",")))) {
|
||||||
RAII_VAR(struct ast_sip_aor *, aor,
|
RAII_VAR(struct ast_sip_aor *, aor,
|
||||||
ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
|
ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
|
||||||
RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
|
RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
|
||||||
|
|||||||
@@ -53,9 +53,13 @@ static struct ast_sip_aor *find_aor(struct ast_sip_endpoint *endpoint, pjsip_uri
|
|||||||
configured_aors = ast_strdupa(endpoint->aors);
|
configured_aors = ast_strdupa(endpoint->aors);
|
||||||
|
|
||||||
/* Iterate the configured AORs to see if the user or the user+domain match */
|
/* Iterate the configured AORs to see if the user or the user+domain match */
|
||||||
while ((aor_name = strsep(&configured_aors, ","))) {
|
while ((aor_name = ast_strip(strsep(&configured_aors, ",")))) {
|
||||||
struct ast_sip_domain_alias *alias = NULL;
|
struct ast_sip_domain_alias *alias = NULL;
|
||||||
|
|
||||||
|
if (ast_strlen_zero(aor_name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!pj_strcmp2(&sip_uri->user, aor_name)) {
|
if (!pj_strcmp2(&sip_uri->user, aor_name)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3654,7 +3654,11 @@ static int list_item_handler(const struct aco_option *opt,
|
|||||||
char *items = ast_strdupa(var->value);
|
char *items = ast_strdupa(var->value);
|
||||||
char *item;
|
char *item;
|
||||||
|
|
||||||
while ((item = strsep(&items, ","))) {
|
while ((item = ast_strip(strsep(&items, ",")))) {
|
||||||
|
if (ast_strlen_zero(item)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (item_in_vector(list, item)) {
|
if (item_in_vector(list, item)) {
|
||||||
ast_log(LOG_WARNING, "Ignoring duplicated list item '%s'\n", item);
|
ast_log(LOG_WARNING, "Ignoring duplicated list item '%s'\n", item);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -651,9 +651,13 @@ static pj_bool_t registrar_on_rx_request(struct pjsip_rx_data *rdata)
|
|||||||
configured_aors = ast_strdupa(endpoint->aors);
|
configured_aors = ast_strdupa(endpoint->aors);
|
||||||
|
|
||||||
/* Iterate the configured AORs to see if the user or the user+domain match */
|
/* Iterate the configured AORs to see if the user or the user+domain match */
|
||||||
while ((aor_name = strsep(&configured_aors, ","))) {
|
while ((aor_name = ast_strip(strsep(&configured_aors, ",")))) {
|
||||||
struct ast_sip_domain_alias *alias = NULL;
|
struct ast_sip_domain_alias *alias = NULL;
|
||||||
|
|
||||||
|
if (ast_strlen_zero(aor_name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!pj_strcmp2(&uri->user, aor_name)) {
|
if (!pj_strcmp2(&uri->user, aor_name)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user