summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzuul <zuul@gerrit.asterisk.org>2016-09-06 22:47:50 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2016-09-06 22:47:50 -0500
commit7437467d94e5b8e3c794c594bf34051571e25b68 (patch)
tree10bdd46ff7d1ba7576fc1fd34614329a01bca13b
parentd0beb475b4b8922ac304fd5b35883609578c621f (diff)
parent68c7694abbf5a2d4dabd0d5a45678baf8b286e70 (diff)
Merge "res_pjsip_registrar.c: Reduce stack usage in find_aor_name()."
-rw-r--r--res/res_pjsip_registrar.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index 47d5991e4..fd87ef7bb 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -555,6 +555,7 @@ static int match_aor(const char *aor_name, const char *id)
static char *find_aor_name(const char *username, const char *domain, const char *aors)
{
char *configured_aors;
+ char *aors_buf;
char *aor_name;
char *id_domain;
struct ast_sip_domain_alias *alias;
@@ -562,8 +563,10 @@ static char *find_aor_name(const char *username, const char *domain, const char
id_domain = ast_alloca(strlen(username) + strlen(domain) + 2);
sprintf(id_domain, "%s@%s", username, domain);
+ aors_buf = ast_strdupa(aors);
+
/* Look for exact match on username@domain */
- configured_aors = ast_strdupa(aors);
+ configured_aors = aors_buf;
while ((aor_name = ast_strip(strsep(&configured_aors, ",")))) {
if (match_aor(aor_name, id_domain)) {
return ast_strdup(aor_name);
@@ -578,7 +581,7 @@ static char *find_aor_name(const char *username, const char *domain, const char
sprintf(id_domain, "%s@%s", username, alias->domain);
ao2_cleanup(alias);
- configured_aors = ast_strdupa(aors);
+ configured_aors = strcpy(aors_buf, aors);/* Safe */
while ((aor_name = ast_strip(strsep(&configured_aors, ",")))) {
if (match_aor(aor_name, id_domain_alias)) {
return ast_strdup(aor_name);
@@ -586,8 +589,13 @@ static char *find_aor_name(const char *username, const char *domain, const char
}
}
+ if (ast_strlen_zero(username)) {
+ /* No username, no match */
+ return NULL;
+ }
+
/* Look for exact match on username only */
- configured_aors = ast_strdupa(aors);
+ configured_aors = strcpy(aors_buf, aors);/* Safe */
while ((aor_name = ast_strip(strsep(&configured_aors, ",")))) {
if (match_aor(aor_name, username)) {
return ast_strdup(aor_name);