diff options
author | Mark Michelson <mmichelson@digium.com> | 2012-10-15 21:25:29 +0000 |
---|---|---|
committer | Mark Michelson <mmichelson@digium.com> | 2012-10-15 21:25:29 +0000 |
commit | e9ab568f88b48c1129c79fa2f008b5be72399bc6 (patch) | |
tree | f10049c3dc1174a601f224397b8ed6b04c9f6bab /main/ccss.c | |
parent | e41a591dfc6c199602d2a49ef9a139ec1ad054a7 (diff) |
Fix some potential misuses of ast_str in the code.
Passing an ast_str pointer by value that then calls
ast_str_set(), ast_str_set_va(), ast_str_append(), or
ast_str_append_va() can result in the pointer originally
passed by value being invalidated if the ast_str had
to be reallocated.
This fixes places in the code that do this. Only the
example in ccss.c could result in pointer invalidation
though since the other cases use a stack-allocated ast_str
and cannot be reallocated.
I've also updated the doxygen in strings.h to include
notes about potential misuse of the functions mentioned
previously.
Review: https://reviewboard.asterisk.org/r/2161
........
Merged revisions 375025 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 375026 from http://svn.asterisk.org/svn/asterisk/branches/10
........
Merged revisions 375027 from http://svn.asterisk.org/svn/asterisk/branches/11
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@375044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/ccss.c')
-rw-r--r-- | main/ccss.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/main/ccss.c b/main/ccss.c index 5dd1d70bf..70e16c7a9 100644 --- a/main/ccss.c +++ b/main/ccss.c @@ -3446,7 +3446,7 @@ struct ast_cc_monitor *ast_cc_get_monitor_by_recall_core_id(const int core_id, c * \param dialstring A new dialstring to add * \retval void */ -static void cc_unique_append(struct ast_str *str, const char *dialstring) +static void cc_unique_append(struct ast_str **str, const char *dialstring) { char dialstring_search[AST_CHANNEL_NAME]; @@ -3455,10 +3455,10 @@ static void cc_unique_append(struct ast_str *str, const char *dialstring) return; } snprintf(dialstring_search, sizeof(dialstring_search), "%s%c", dialstring, '&'); - if (strstr(ast_str_buffer(str), dialstring_search)) { + if (strstr(ast_str_buffer(*str), dialstring_search)) { return; } - ast_str_append(&str, 0, "%s", dialstring_search); + ast_str_append(str, 0, "%s", dialstring_search); } /*! @@ -3476,7 +3476,7 @@ static void cc_unique_append(struct ast_str *str, const char *dialstring) * \param str Where we will store CC_INTERFACES * \retval void */ -static void build_cc_interfaces_chanvar(struct ast_cc_monitor *starting_point, struct ast_str *str) +static void build_cc_interfaces_chanvar(struct ast_cc_monitor *starting_point, struct ast_str **str) { struct extension_monitor_pvt *extension_pvt; struct extension_child_dialstring *child_dialstring; @@ -3485,7 +3485,7 @@ static void build_cc_interfaces_chanvar(struct ast_cc_monitor *starting_point, s size_t length; /* Init to an empty string. */ - ast_str_truncate(str, 0); + ast_str_truncate(*str, 0); /* First we need to take all of the is_valid child_dialstrings from * the extension monitor we found and add them to the CC_INTERFACES @@ -3508,9 +3508,9 @@ static void build_cc_interfaces_chanvar(struct ast_cc_monitor *starting_point, s /* str will have an extra '&' tacked onto the end of it, so we need * to get rid of that. */ - length = ast_str_strlen(str); + length = ast_str_strlen(*str); if (length) { - ast_str_truncate(str, length - 1); + ast_str_truncate(*str, length - 1); } if (length <= 1) { /* Nothing to recall? This should not happen. */ @@ -3545,7 +3545,7 @@ int ast_cc_agent_set_interfaces_chanvar(struct ast_channel *chan) AST_LIST_LOCK(interface_tree); monitor = AST_LIST_FIRST(interface_tree); - build_cc_interfaces_chanvar(monitor, str); + build_cc_interfaces_chanvar(monitor, &str); AST_LIST_UNLOCK(interface_tree); pbx_builtin_setvar_helper(chan, "CC_INTERFACES", ast_str_buffer(str)); @@ -3597,7 +3597,7 @@ int ast_set_cc_interfaces_chanvar(struct ast_channel *chan, const char * const e return -1; } - build_cc_interfaces_chanvar(monitor_iter, str); + build_cc_interfaces_chanvar(monitor_iter, &str); AST_LIST_UNLOCK(interface_tree); pbx_builtin_setvar_helper(chan, "CC_INTERFACES", ast_str_buffer(str)); |