diff options
author | Richard Mudgett <rmudgett@digium.com> | 2016-08-30 16:40:59 -0500 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2016-09-02 13:23:20 -0500 |
commit | 03fc438f6eaebf736edb2be8cb7314afed6ca689 (patch) | |
tree | 85c16860df2e8e773de07b36e4d28322ba4392b8 /res | |
parent | 1bd571ef75900c78f98b047659de9d2d6c0c51b5 (diff) |
res_pjsip_registrar.c: Reduce stack usage in find_aor_name().
Change-Id: I8aebad1fdcf303bd115b59a4b57fbbd5b2267f09
Diffstat (limited to 'res')
-rw-r--r-- | res/res_pjsip_registrar.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c index 53209575f..1e0f5ab72 100644 --- a/res/res_pjsip_registrar.c +++ b/res/res_pjsip_registrar.c @@ -563,6 +563,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; @@ -570,8 +571,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); @@ -586,7 +589,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); @@ -594,8 +597,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); |