Index: apps/app_system.c =================================================================== --- apps/app_system.c (revision 168546) +++ apps/app_system.c (working copy) @@ -33,6 +33,8 @@ #include "asterisk/module.h" #include "asterisk/app.h" #include "asterisk/channel.h" /* autoservice */ +#include "asterisk/strings.h" +#include "asterisk/threadstorage.h" /*** DOCUMENTATION @@ -90,6 +92,8 @@ ***/ +AST_THREADSTORAGE(buf_buf); + static char *app = "System"; static char *app2 = "TrySystem"; @@ -99,6 +103,7 @@ static int system_exec_helper(struct ast_channel *chan, void *data, int failmode) { int res = 0; + struct ast_str *buf = ast_str_thread_get(&buf_buf, 16); if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "System requires an argument(command)\n"); @@ -109,7 +114,9 @@ ast_autoservice_start(chan); /* Do our thing here */ - res = ast_safe_system((char *)data); + ast_str_get_encoded_str(&buf, 0, (char *) data); + res = ast_safe_system(ast_str_buffer(buf)); + if ((res < 0) && (errno != ECHILD)) { ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data); pbx_builtin_setvar_helper(chan, chanvar, "FAILURE"); Index: include/asterisk/app.h =================================================================== --- include/asterisk/app.h (revision 168546) +++ include/asterisk/app.h (working copy) @@ -496,6 +496,9 @@ /*! \brief Decode a stream of encoded control or extended ASCII characters */ int ast_get_encoded_str(const char *stream, char *result, size_t result_len); +/*! \brief Decode a stream of encoded control or extended ASCII characters */ +int ast_str_get_encoded_str(struct ast_str **str, int maxlen, const char *stream); + /*! \brief Common routine for child processes, to close all fds prior to exec(2) */ void ast_close_fds_above_n(int n); Index: main/app.c =================================================================== --- main/app.c (revision 168546) +++ main/app.c (working copy) @@ -1832,14 +1832,45 @@ char *cur = result; size_t consumed; - while (cur < result + result_size - 1 && !ast_get_encoded_char(stream, cur, &consumed)) { - cur++; - stream += consumed; + if (strchr(stream, '\\')) { + while (cur < result + result_size - 1 && !ast_get_encoded_char(stream, cur, &consumed)) { + cur++; + stream += consumed; + } + *cur = '\0'; + } else { + ast_copy_string(result, stream, result_size); } - *cur = '\0'; return 0; } +int ast_str_get_encoded_str(struct ast_str **str, int maxlen, const char *stream) +{ + char next, *buf; + size_t offset = 0; + size_t consumed; + + if (strchr(stream, '\\')) { + while (!ast_get_encoded_char(stream, &next, &consumed)) { + if (offset + 2 > ast_str_size(*str) && maxlen > -1) { + ast_str_make_space(str, maxlen > 0 ? maxlen : ast_str_size(*str) * 2); + } + if (offset + 2 > ast_str_size(*str)) { + break; + } + buf = ast_str_buffer(*str); + buf[offset++] = next; + stream += consumed; + } + buf = ast_str_buffer(*str); + buf[offset++] = '\0'; + ast_str_update(*str); + } else { + ast_str_set(str, maxlen, "%s", stream); + } + return 0; +} + void ast_close_fds_above_n(int n) { #ifdef HAVE_CLOSEFROM Index: main/pbx.c =================================================================== --- main/pbx.c (revision 168546) +++ main/pbx.c (working copy) @@ -755,6 +755,7 @@ AST_THREADSTORAGE(switch_data); AST_THREADSTORAGE(extensionstate_buf); +AST_THREADSTORAGE(setvar_buf); /*! \brief ast_exten: An extension @@ -8827,6 +8828,7 @@ int pbx_builtin_setvar(struct ast_channel *chan, void *data) { char *name, *value, *mydata; + struct ast_str *buf = ast_str_thread_get(&setvar_buf, 16); if (ast_compat_app_set) { return pbx_builtin_setvar_multiple(chan, data); @@ -8840,10 +8842,11 @@ mydata = ast_strdupa(data); name = strsep(&mydata, "="); value = mydata; + ast_str_get_encoded_str(&buf, 0, value); if (strchr(name, ' ')) ast_log(LOG_WARNING, "Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n", name, mydata); - pbx_builtin_setvar_helper(chan, name, value); + pbx_builtin_setvar_helper(chan, name, ast_str_buffer(buf)); return(0); } @@ -8851,6 +8854,7 @@ { char *data; int x; + struct ast_str *buf = ast_str_thread_get(&setvar_buf, 16); AST_DECLARE_APP_ARGS(args, AST_APP_ARG(pair)[24]; ); @@ -8870,7 +8874,8 @@ for (x = 0; x < args.argc; x++) { AST_NONSTANDARD_APP_ARGS(pair, args.pair[x], '='); if (pair.argc == 2) { - pbx_builtin_setvar_helper(chan, pair.name, pair.value); + ast_str_get_encoded_str(&buf, 0, pair.value); + pbx_builtin_setvar_helper(chan, pair.name, ast_str_buffer(buf)); if (strchr(pair.name, ' ')) ast_log(LOG_WARNING, "Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n", pair.name, pair.value); } else if (!chan) {