[asterisk-commits] rmudgett: branch 11 r428570 - /branches/11/main/manager.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 21 12:47:19 CST 2014


Author: rmudgett
Date: Fri Nov 21 12:47:12 2014
New Revision: 428570

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=428570
Log:
manager: Fix could not extend string messages.

When shutting down Asterisk that has an active AMI connection, you get
several "failed to extend from %d to %d" messages because use of the
EVENT_FLAG_SHUTDOWN attempts to add all AMI permission strings to the
event.

* Created MAX_AUTH_PERM_STRING to use when creating stack based struct
ast_str variables used with the authority_to_str() and
user_authority_to_str() functions instead of a variety of magic numbers
that could be too small.

* Added a special check for EVENT_FLAG_SHUTDOWN to authority_to_str() so
it will not attempt to add all permission level strings.

Review: https://reviewboard.asterisk.org/r/4200/

Modified:
    branches/11/main/manager.c

Modified: branches/11/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/manager.c?view=diff&rev=428570&r1=428569&r2=428570
==============================================================================
--- branches/11/main/manager.c (original)
+++ branches/11/main/manager.c Fri Nov 21 12:47:12 2014
@@ -1337,6 +1337,9 @@
 	{ 0, "none" },
 };
 
+/*! Maximum string length of the AMI authority permission string buildable from perms[]. */
+#define MAX_AUTH_PERM_STRING	150
+
 /*! \brief Checks to see if a string which can be used to evaluate functions should be rejected */
 static int function_capable_string_allowed_with_auths(const char *evaluating, int writepermlist)
 {
@@ -1365,8 +1368,10 @@
 		}
 	}
 
-	if (ast_str_strlen(*res) == 0)	/* replace empty string with something sensible */
+	if (ast_str_strlen(*res) == 0) {
+		/* replace empty string with something sensible */
 		ast_str_append(res, 0, "<none>");
+	}
 
 	return ast_str_buffer(*res);
 }
@@ -1380,15 +1385,19 @@
 	char *sep = "";
 
 	ast_str_reset(*res);
-	for (i = 0; i < ARRAY_LEN(perms) - 1; i++) {
-		if (authority & perms[i].num) {
-			ast_str_append(res, 0, "%s%s", sep, perms[i].label);
-			sep = ",";
-		}
-	}
-
-	if (ast_str_strlen(*res) == 0)	/* replace empty string with something sensible */
+	if (authority != EVENT_FLAG_SHUTDOWN) {
+		for (i = 0; i < ARRAY_LEN(perms) - 1; i++) {
+			if (authority & perms[i].num) {
+				ast_str_append(res, 0, "%s%s", sep, perms[i].label);
+				sep = ",";
+			}
+		}
+	}
+
+	if (ast_str_strlen(*res) == 0) {
+		/* replace empty string with something sensible */
 		ast_str_append(res, 0, "<none>");
+	}
 
 	return ast_str_buffer(*res);
 }
@@ -1653,7 +1662,7 @@
 		AST_RWLIST_UNLOCK(&actions);
 		return ret;
 	}
-	authority = ast_str_alloca(80);
+	authority = ast_str_alloca(MAX_AUTH_PERM_STRING);
 	if (a->argc < 4) {
 		return CLI_SHOWUSAGE;
 	}
@@ -1735,8 +1744,8 @@
 	struct ast_manager_user *user = NULL;
 	int l, which;
 	char *ret = NULL;
-	struct ast_str *rauthority = ast_str_alloca(128);
-	struct ast_str *wauthority = ast_str_alloca(128);
+	struct ast_str *rauthority = ast_str_alloca(MAX_AUTH_PERM_STRING);
+	struct ast_str *wauthority = ast_str_alloca(MAX_AUTH_PERM_STRING);
 	struct ast_variable *v;
 
 	switch (cmd) {
@@ -1857,7 +1866,7 @@
 	case CLI_GENERATE:
 		return NULL;
 	}
-	authority = ast_str_alloca(80);
+	authority = ast_str_alloca(MAX_AUTH_PERM_STRING);
 	ast_cli(a->fd, HSMC_FORMAT, "Action", "Privilege", "Synopsis");
 	ast_cli(a->fd, HSMC_FORMAT, "------", "---------", "--------");
 
@@ -3237,7 +3246,7 @@
 static int action_listcommands(struct mansession *s, const struct message *m)
 {
 	struct manager_action *cur;
-	struct ast_str *temp = ast_str_alloca(256);
+	struct ast_str *temp = ast_str_alloca(MAX_AUTH_PERM_STRING);
 
 	astman_start_ack(s, m);
 	AST_RWLIST_RDLOCK(&actions);
@@ -3326,8 +3335,9 @@
 	if ((s->session->send_events & EVENT_FLAG_SYSTEM)
 		&& (s->session->readperm & EVENT_FLAG_SYSTEM)
 		&& ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)) {
-		struct ast_str *auth = ast_str_alloca(80);
+		struct ast_str *auth = ast_str_alloca(MAX_AUTH_PERM_STRING);
 		const char *cat_str = authority_to_str(EVENT_FLAG_SYSTEM, &auth);
+
 		astman_append(s, "Event: FullyBooted\r\n"
 			"Privilege: %s\r\n"
 			"Status: Fully Booted\r\n\r\n", cat_str);
@@ -5732,7 +5742,7 @@
 	RAII_VAR(struct ao2_container *, sessions, ao2_global_obj_ref(mgr_sessions), ao2_cleanup);
 	struct mansession_session *session;
 	struct manager_custom_hook *hook;
-	struct ast_str *auth = ast_str_alloca(80);
+	struct ast_str *auth = ast_str_alloca(MAX_AUTH_PERM_STRING);
 	const char *cat_str;
 	va_list ap;
 	struct timeval now;




More information about the asterisk-commits mailing list