aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-04-15 21:23:24 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-04-15 21:23:24 +0000
commitc3d2ac4126115ed4504ea3ebfc40f9d53f8f2b4f (patch)
tree2b4215e9a5a1608a4a6e241a26a7b6666e0c6a73 /main
parent5f1c004a4c10cffb45e79ba04cff5fcb3fc930d0 (diff)
Allow application options with arguments to contain parentheses, through a variety of escaping techniques.
Fixes SWP-1194 (ABE-2143). Review: https://reviewboard.asterisk.org/r/604/ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@257544 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/app.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/main/app.c b/main/app.c
index 2beee00a3..abf052900 100644
--- a/main/app.c
+++ b/main/app.c
@@ -1438,8 +1438,40 @@ int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags
curarg = *s++ & 0x7f; /* the array (in app.h) has 128 entries */
argloc = options[curarg].arg_index;
if (*s == '(') {
+ int paren = 1, quote = 0;
+ int parsequotes = (s[1] == '"') ? 1 : 0;
+
/* Has argument */
arg = ++s;
+ for (; *s; s++) {
+ if (*s == '(' && !quote) {
+ paren++;
+ } else if (*s == ')' && !quote) {
+ /* Count parentheses, unless they're within quotes (or backslashed, below) */
+ paren--;
+ } else if (*s == '"' && parsequotes) {
+ /* Leave embedded quotes alone, unless they are the first character */
+ quote = quote ? 0 : 1;
+ ast_copy_string(s, s + 1, INT_MAX);
+ s--;
+ } else if (*s == '\\') {
+ if (!quote) {
+ /* If a backslash is found outside of quotes, remove it */
+ ast_copy_string(s, s + 1, INT_MAX);
+ } else if (quote && s[1] == '"') {
+ /* Backslash for a quote character within quotes, remove the backslash */
+ ast_copy_string(s, s + 1, INT_MAX);
+ } else {
+ /* Backslash within quotes, keep both characters */
+ s++;
+ }
+ }
+
+ if (paren == 0) {
+ break;
+ }
+ }
+ /* This will find the closing paren we found above, or none, if the string ended before we found one. */
if ((s = strchr(s, ')'))) {
if (argloc)
args[argloc - 1] = arg;