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
This commit is contained in:
Richard Mudgett
2014-03-20 16:35:57 +00:00
parent 57239bfe37
commit 1ba13718fc
8 changed files with 77 additions and 45 deletions

View File

@@ -776,12 +776,10 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint,
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);
@@ -789,6 +787,13 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint,
}
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",
"Endpoint must be specified");