summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2014-03-20 16:35:57 +0000
committerRichard Mudgett <rmudgett@digium.com>2014-03-20 16:35:57 +0000
commit1ba13718fc46527587e3dc87e776858c472bb2d2 (patch)
treeee6d210eb73de1a218310149733f99009456e402 /main
parent57239bfe37d61977ef6eec82eca0cb6631e1d4ef (diff)
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/ ........ Merged revisions 410949 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410950 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r--main/channel_internal_api.c4
-rw-r--r--main/core_unreal.c5
-rw-r--r--main/dial.c28
-rw-r--r--main/manager.c22
4 files changed, 31 insertions, 28 deletions
diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c
index d444d7fba..9cc99f3d5 100644
--- a/main/channel_internal_api.c
+++ b/main/channel_internal_api.c
@@ -1485,8 +1485,8 @@ void ast_channel_internal_swap_uniqueid_and_linkedid(struct ast_channel *a, stru
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)
diff --git a/main/core_unreal.c b/main/core_unreal.c
index bc081f5f4..51f03eab3 100644
--- a/main/core_unreal.c
+++ b/main/core_unreal.c
@@ -907,7 +907,10 @@ struct ast_channel *ast_unreal_new_channels(struct ast_unreal_pvt *p,
/* 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;
}
diff --git a/main/dial.c b/main/dial.c
index 246d4f406..bf0d51c5e 100644
--- a/main/dial.c
+++ b/main/dial.c
@@ -266,8 +266,7 @@ int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device,
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)) {
@@ -293,7 +292,10 @@ static int begin_dial_prerun(struct ast_dial_channel *channel, struct ast_channe
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));
@@ -474,14 +476,10 @@ static int handle_call_forward(struct ast_dial *dial, struct ast_dial_channel *c
/* 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);
@@ -1066,12 +1064,8 @@ int ast_dial_destroy(struct ast_dial *dial)
/* 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);
diff --git a/main/manager.c b/main/manager.c
index 3c98185be..328878251 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -4416,7 +4416,10 @@ static void *fast_originate(void *data)
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 @@ static int action_originate(struct mansession *s, const struct message *m)
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,17 +4731,20 @@ static int action_originate(struct mansession *s, const struct message *m)
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");
res = 0;