[Asterisk-code-review] res pjsip registrar.c: Reduce stack usage in find aor name(). (asterisk[13])

Richard Mudgett asteriskteam at digium.com
Fri Sep 2 13:23:47 CDT 2016


Richard Mudgett has uploaded a new change for review.

  https://gerrit.asterisk.org/3807

Change subject: res_pjsip_registrar.c: Reduce stack usage in find_aor_name().
......................................................................

res_pjsip_registrar.c: Reduce stack usage in find_aor_name().

Change-Id: I8aebad1fdcf303bd115b59a4b57fbbd5b2267f09
---
M res/res_pjsip_registrar.c
1 file changed, 11 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/07/3807/1

diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index 5320957..1e0f5ab 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -563,6 +563,7 @@
 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 @@
 	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 at 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 @@
 		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 @@
 		}
 	}
 
+	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);

-- 
To view, visit https://gerrit.asterisk.org/3807
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8aebad1fdcf303bd115b59a4b57fbbd5b2267f09
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-code-review mailing list