[asterisk-commits] rmudgett: branch 12 r410949 - in /branches/12: include/asterisk/ main/ res/ r...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 20 11:27:59 CDT 2014


Author: rmudgett
Date: Thu Mar 20 11:27:49 2014
New Revision: 410949

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=410949
Log:
assigned-uniqueids: Miscellaneous cleanup and fixes.

* Fix memory leak in ast_unreal_new_channels().  Made it generate the ;2
uniqueid on a stack variable instead of mallocing it.

* Made send error response to ARI and AMI requests instead of just logging
excessive uniqueid length and allowing truncation.  action_originate() and
ari_channels_handle_originate_with_id().

* Fixed minor truncating uniqueid hole when generating the ;2 uniqueid
string length.  Created public and internal lengths of uniqueid.  The
internal length can handle a max public uniqueid plus an appended ;2.

* free() and ast_free() are NULL tolerant so they don't need a NULL test
before calling.

* Made use better struct initialization format instead of the position
dependent initialization format.  Also anything not explicitly initialized
in the struct is initialized to zero by the compiler.

* Made ast_channel_internal_set_fake_ids() use the safer
ast_copy_string() instead of strncpy().

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

Modified:
    branches/12/include/asterisk/channel.h
    branches/12/include/asterisk/rtp_engine.h
    branches/12/main/channel_internal_api.c
    branches/12/main/core_unreal.c
    branches/12/main/dial.c
    branches/12/main/manager.c
    branches/12/res/ari/resource_channels.c
    branches/12/res/res_stasis_snoop.c

Modified: branches/12/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/channel.h?view=diff&rev=410949&r1=410948&r2=410949
==============================================================================
--- branches/12/include/asterisk/channel.h (original)
+++ branches/12/include/asterisk/channel.h Thu Mar 20 11:27:49 2014
@@ -133,12 +133,31 @@
 
 #define AST_MAX_EXTENSION       80  /*!< Max length of an extension */
 #define AST_MAX_CONTEXT         80  /*!< Max length of a context */
-#define AST_MAX_UNIQUEID       150  /*!< Max length of a channel uniqueid */
-/*                                   150 = 127 (max systemname) + "-" + 10 (epoch
- *                                   timestamp) + "." + 10 (monotonically incrementing
- *                                   integer) + NULL. Note that if this value is ever
- *                                   changed, MAX_CHANNEL_ID should be updated in
- *                                   rtp_engine.h */
+
+/*!
+ * Max length of a channel uniqueid reported to the outside world.
+ *
+ * \details
+ * 149 = 127 (max systemname) + "-" + 10 (epoch timestamp)
+ *     + "." + 10 (monotonically incrementing integer).
+ *
+ * \note If this value is ever changed, MAX_CHANNEL_ID should
+ * be updated in rtp_engine.h.
+ */
+#define AST_MAX_PUBLIC_UNIQUEID 149
+
+/*!
+ * Maximum size of an internal Asterisk channel unique ID.
+ *
+ * \details
+ * Add two for the Local;2 channel to append a ';2' if needed
+ * plus nul terminator.
+ *
+ * \note If this value is ever changed, MAX_CHANNEL_ID should
+ * be updated in rtp_engine.h.
+ */
+#define AST_MAX_UNIQUEID        (AST_MAX_PUBLIC_UNIQUEID + 2 + 1)
+
 #define AST_MAX_ACCOUNT_CODE    20  /*!< Max length of an account code */
 #define AST_CHANNEL_NAME        80  /*!< Max length of an ast_channel name */
 #define MAX_LANGUAGE            40  /*!< Max length of the language setting */

Modified: branches/12/include/asterisk/rtp_engine.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/rtp_engine.h?view=diff&rev=410949&r1=410948&r2=410949
==============================================================================
--- branches/12/include/asterisk/rtp_engine.h (original)
+++ branches/12/include/asterisk/rtp_engine.h Thu Mar 20 11:27:49 2014
@@ -86,11 +86,14 @@
 /* Maximum number of generations */
 #define AST_RED_MAX_GENERATION 5
 
-/* Maximum size of an Asterisk channel unique ID. Should match AST_MAX_UNIQUEID.
- * Note that we don't use that defined value directly here to avoid a hard dependency
- * on channel.h
- */
-#define MAX_CHANNEL_ID 150
+/*!
+ * Maximum size of an internal Asterisk channel unique ID.
+ *
+ * \note Must match the AST_MAX_UNIQUEID(AST_MAX_PUBLIC_UNIQUEID) value.
+ * We don't use that defined value directly here to avoid a hard
+ * dependency on channel.h.
+ */
+#define MAX_CHANNEL_ID 152
 
 struct ast_rtp_instance;
 struct ast_rtp_glue;

Modified: branches/12/main/channel_internal_api.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/channel_internal_api.c?view=diff&rev=410949&r1=410948&r2=410949
==============================================================================
--- branches/12/main/channel_internal_api.c (original)
+++ branches/12/main/channel_internal_api.c Thu Mar 20 11:27:49 2014
@@ -1485,8 +1485,8 @@
 
 void ast_channel_internal_set_fake_ids(struct ast_channel *chan, const char *uniqueid, const char *linkedid)
 {
-	strncpy(chan->uniqueid.unique_id, uniqueid, sizeof(chan->uniqueid.unique_id));
-	strncpy(chan->linkedid.unique_id, linkedid, sizeof(chan->linkedid.unique_id));
+	ast_copy_string(chan->uniqueid.unique_id, uniqueid, sizeof(chan->uniqueid.unique_id));
+	ast_copy_string(chan->linkedid.unique_id, linkedid, sizeof(chan->linkedid.unique_id));
 }
 
 void ast_channel_internal_cleanup(struct ast_channel *chan)

Modified: branches/12/main/core_unreal.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/core_unreal.c?view=diff&rev=410949&r1=410948&r2=410949
==============================================================================
--- branches/12/main/core_unreal.c (original)
+++ branches/12/main/core_unreal.c Thu Mar 20 11:27:49 2014
@@ -907,7 +907,10 @@
 	/* if id1 given but not id2, use default of id1;2 */
 	if (id1.uniqueid && ast_strlen_zero(id2.uniqueid)) {
 		char *uniqueid2;
-		ast_asprintf(&uniqueid2, "%s;2", id1.uniqueid);
+
+		uniqueid2 = ast_alloca(strlen(id1.uniqueid) + 2);
+		strcpy(uniqueid2, id1.uniqueid);/* Safe */
+		strcat(uniqueid2, ";2");/* Safe */
 		id2.uniqueid = uniqueid2;
 	}
 

Modified: branches/12/main/dial.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/dial.c?view=diff&rev=410949&r1=410948&r2=410949
==============================================================================
--- branches/12/main/dial.c (original)
+++ branches/12/main/dial.c Thu Mar 20 11:27:49 2014
@@ -249,8 +249,7 @@
 	channel->device = ast_strdup(device);
 
 	/* Store the assigned id */
-	if (assignedids && !ast_strlen_zero(assignedids->uniqueid))
-	{
+	if (assignedids && !ast_strlen_zero(assignedids->uniqueid)) {
 		channel->assignedid1 = ast_strdup(assignedids->uniqueid);
 
 		if (!ast_strlen_zero(assignedids->uniqueid2)) {
@@ -276,7 +275,10 @@
 	char numsubst[AST_MAX_EXTENSION];
 	struct ast_format_cap *cap_all_audio = NULL;
 	struct ast_format_cap *cap_request;
-	struct ast_assigned_ids assignedids = {channel->assignedid1, channel->assignedid2};
+	struct ast_assigned_ids assignedids = {
+		.uniqueid = channel->assignedid1,
+		.uniqueid2 = channel->assignedid2,
+	};
 
 	/* Copy device string over */
 	ast_copy_string(numsubst, channel->device, sizeof(numsubst));
@@ -431,14 +433,10 @@
 	/* Drop old destination information */
 	ast_free(channel->tech);
 	ast_free(channel->device);
-	if (channel->assignedid1) {
-		ast_free(channel->assignedid1);
-		channel->assignedid1 = NULL;
-	}
-	if (channel->assignedid2) {
-		ast_free(channel->assignedid2);
-		channel->assignedid2 = NULL;
-	}
+	ast_free(channel->assignedid1);
+	channel->assignedid1 = NULL;
+	ast_free(channel->assignedid2);
+	channel->assignedid2 = NULL;
 
 	/* Update the dial channel with the new destination information */
 	channel->tech = ast_strdup(tech);
@@ -1023,12 +1021,8 @@
 		/* Free structure */
 		ast_free(channel->tech);
 		ast_free(channel->device);
-		if (channel->assignedid1) {
-			ast_free(channel->assignedid1);
-		}
-		if (channel->assignedid2) {
-			ast_free(channel->assignedid2);
-		}
+		ast_free(channel->assignedid1);
+		ast_free(channel->assignedid2);
 
 		AST_LIST_REMOVE_CURRENT(list);
 		ast_free(channel);

Modified: branches/12/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/manager.c?view=diff&rev=410949&r1=410948&r2=410949
==============================================================================
--- branches/12/main/manager.c (original)
+++ branches/12/main/manager.c Thu Mar 20 11:27:49 2014
@@ -4416,7 +4416,10 @@
 	int reason = 0;
 	struct ast_channel *chan = NULL, *chans[1];
 	char requested_channel[AST_CHANNEL_NAME];
-	struct ast_assigned_ids assignedids = {in->channelid, in->otherchannelid};
+	struct ast_assigned_ids assignedids = {
+		.uniqueid = in->channelid,
+		.uniqueid2 = in->otherchannelid
+	};
 
 	if (!ast_strlen_zero(in->app)) {
 		res = ast_pbx_outgoing_app(in->tech, in->cap, in->data,
@@ -4711,8 +4714,8 @@
 	const char *codecs = astman_get_header(m, "Codecs");
 	const char *early_media = astman_get_header(m, "Earlymedia");
 	struct ast_assigned_ids assignedids = {
-		astman_get_header(m, "ChannelId"),
-		astman_get_header(m, "OtherChannelId")
+		.uniqueid = astman_get_header(m, "ChannelId"),
+		.uniqueid2 = astman_get_header(m, "OtherChannelId"),
 	};
 	struct ast_variable *vars = NULL;
 	char *tech, *data;
@@ -4728,16 +4731,19 @@
 	pthread_t th;
 	int bridge_early = 0;
 
-	if ((!ast_strlen_zero(assignedids.uniqueid) && strlen(assignedids.uniqueid) >= AST_MAX_UNIQUEID) ||
-		(!ast_strlen_zero(assignedids.uniqueid2) && strlen(assignedids.uniqueid2) >= AST_MAX_UNIQUEID)) {
-		ast_log(LOG_WARNING, "Uniqueid length exceeds maximum of %d\n", AST_MAX_UNIQUEID);
-	}
-
 	if (!cap) {
 		astman_send_error(s, m, "Internal Error. Memory allocation failure.");
 		return 0;
 	}
 	ast_format_cap_add(cap, ast_format_set(&tmp_fmt, AST_FORMAT_SLINEAR, 0));
+
+	if ((assignedids.uniqueid && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid))
+		|| (assignedids.uniqueid2 && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid2))) {
+		astman_send_error_va(s, m, "Uniqueid length exceeds maximum of %d\n",
+			AST_MAX_PUBLIC_UNIQUEID);
+		res = 0;
+		goto fast_orig_cleanup;
+	}
 
 	if (ast_strlen_zero(name)) {
 		astman_send_error(s, m, "Channel not specified");

Modified: branches/12/res/ari/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/ari/resource_channels.c?view=diff&rev=410949&r1=410948&r2=410949
==============================================================================
--- branches/12/res/ari/resource_channels.c (original)
+++ branches/12/res/ari/resource_channels.c Thu Mar 20 11:27:49 2014
@@ -776,18 +776,23 @@
 	char *stuff;
 	struct ast_channel *chan;
 	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
-	struct ast_assigned_ids assignedids = {args_channel_id, args_other_channel_id};
-
-	if ((!ast_strlen_zero(assignedids.uniqueid) && strlen(assignedids.uniqueid) >= AST_MAX_UNIQUEID) || 
-		(!ast_strlen_zero(assignedids.uniqueid2) && strlen(assignedids.uniqueid2) >= AST_MAX_UNIQUEID)) {
-		ast_log(LOG_WARNING, "Uniqueid length exceeds maximum of %d\n", AST_MAX_UNIQUEID);
-	}
+	struct ast_assigned_ids assignedids = {
+		.uniqueid = args_channel_id,
+		.uniqueid2 = args_other_channel_id,
+	};
 
 	if (!cap) {
 		ast_ari_response_alloc_failed(response);
 		return;
 	}
 	ast_format_cap_add(cap, ast_format_set(&tmp_fmt, AST_FORMAT_SLINEAR, 0));
+
+	if ((assignedids.uniqueid && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid))
+		|| (assignedids.uniqueid2 && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid2))) {
+		ast_ari_response_error(response, 400, "Bad Request",
+			"Uniqueid length exceeds maximum of %d\n", AST_MAX_PUBLIC_UNIQUEID);
+		return;
+	}
 
 	if (ast_strlen_zero(args_endpoint)) {
 		ast_ari_response_error(response, 400, "Bad Request",

Modified: branches/12/res/res_stasis_snoop.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_stasis_snoop.c?view=diff&rev=410949&r1=410948&r2=410949
==============================================================================
--- branches/12/res/res_stasis_snoop.c (original)
+++ branches/12/res/res_stasis_snoop.c Thu Mar 20 11:27:49 2014
@@ -290,7 +290,9 @@
 {
 	RAII_VAR(struct stasis_app_snoop *, snoop, NULL, ao2_cleanup);
 	pthread_t thread;
-	struct ast_assigned_ids assignedids = {snoop_id, NULL};
+	struct ast_assigned_ids assignedids = {
+		.uniqueid = snoop_id,
+	};
 
 	if (spy == STASIS_SNOOP_DIRECTION_NONE &&
 		whisper == STASIS_SNOOP_DIRECTION_NONE) {




More information about the asterisk-commits mailing list