aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_macro.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-09-07 20:39:20 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-09-07 20:39:20 +0000
commitea962f4f08926197721c265f9c982380bd42f489 (patch)
tree08d251dfc7b27cc0915144eaf5365ea5edb92913 /apps/app_macro.c
parentd893a6b73947793a14007e94690c5712dd717b7f (diff)
put a limit on Macro depth (to combat recursion) (issue #5114)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6535 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_macro.c')
-rwxr-xr-xapps/app_macro.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/apps/app_macro.c b/apps/app_macro.c
index a8065f6ed..05e8c8d33 100755
--- a/apps/app_macro.c
+++ b/apps/app_macro.c
@@ -87,10 +87,10 @@ static int macro_exec(struct ast_channel *chan, void *data)
int res=0;
char oldexten[256]="";
int oldpriority;
- char pc[80];
+ char pc[80], depthc[12];
char oldcontext[AST_MAX_CONTEXT] = "";
char *offsets;
- int offset;
+ int offset, depth;
int setmacrocontext=0;
int autoloopflag;
@@ -105,6 +105,21 @@ static int macro_exec(struct ast_channel *chan, void *data)
return 0;
}
+ /* Count how many levels deep the rabbit hole goes */
+ tmp = pbx_builtin_getvar_helper(chan, "MACRO_DEPTH");
+ if (tmp) {
+ sscanf(tmp, "%d", &depth);
+ } else {
+ depth = 0;
+ }
+
+ if (depth >= 7) {
+ ast_log(LOG_ERROR, "Macro(): possible infinite loop detected. Returning early.\n");
+ return 0;
+ }
+ snprintf(depthc, sizeof(depthc), "%d", depth + 1);
+ pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
+
tmp = ast_strdupa((char *) data);
rest = tmp;
macro = strsep(&rest, "|");
@@ -174,6 +189,8 @@ static int macro_exec(struct ast_channel *chan, void *data)
autoloopflag = ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP);
ast_set_flag(chan, AST_FLAG_IN_AUTOLOOP);
while(ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
+ /* Reset the macro depth, if it was changed in the last iteration */
+ pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
if ((res = ast_spawn_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num))) {
/* Something bad happened, or a hangup has been requested. */
if (((res >= '0') && (res <= '9')) || ((res >= 'A') && (res <= 'F')) ||
@@ -215,6 +232,10 @@ static int macro_exec(struct ast_channel *chan, void *data)
chan->priority++;
}
out:
+ /* Reset the depth back to what it was when the routine was entered (like if we called Macro recursively) */
+ snprintf(depthc, sizeof(depthc), "%d", depth);
+ pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
+
ast_set2_flag(chan, autoloopflag, AST_FLAG_IN_AUTOLOOP);
for (x=1; x<argc; x++) {
/* Restore old arguments and delete ours */