From: Naveen Albert Date: Sat, 23 Dec 2023 16:26:13 +0000 (+0000) Subject: app_if: Fix faulty EndIf branching. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bf4493371b8cf515e0094a6a7efe6003ff43dae;p=thirdparty%2Fasterisk.git app_if: Fix faulty EndIf branching. This fixes faulty branching logic for the EndIf application. Instead of computing the next priority, which should be done for false conditionals or ExitIf, we should simply advance to the next priority. Resolves: #341 --- diff --git a/apps/app_if.c b/apps/app_if.c index bc04ffd71b..94bb1f1273 100644 --- a/apps/app_if.c +++ b/apps/app_if.c @@ -196,6 +196,7 @@ static int find_matching_endif(struct ast_channel *chan, const char *otherapp) if (!ast_rdlock_context(c)) { if (!strcmp(ast_get_context_name(c), ast_channel_context(chan))) { /* This is the matching context we want */ + int cur_priority = ast_channel_priority(chan) + 1, level = 1; for (e = find_matching_priority(c, ast_channel_exten(chan), cur_priority, @@ -203,6 +204,7 @@ static int find_matching_endif(struct ast_channel *chan, const char *otherapp) e; e = find_matching_priority(c, ast_channel_exten(chan), ++cur_priority, S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) { + if (!strcasecmp(ast_get_extension_app(e), "IF")) { level++; } else if (!strcasecmp(ast_get_extension_app(e), "ENDIF")) { @@ -283,7 +285,10 @@ static int if_helper(struct ast_channel *chan, const char *data, int end) pbx_builtin_setvar_helper(chan, my_name, NULL); snprintf(end_varname,sizeof(end_varname),"END_%s",varname); ast_channel_lock(chan); - endifpri = find_matching_endif(chan, NULL); + /* For EndIf, simply go to the next priority. + * For ExitIf or false If() condition, we need to find the end of the current + * If branch (at same indentation) and branch there. */ + endifpri = end == 2 ? ast_channel_priority(chan) + 1 : find_matching_endif(chan, NULL); if ((goto_str = pbx_builtin_getvar_helper(chan, end_varname))) { ast_parseable_goto(chan, goto_str); pbx_builtin_setvar_helper(chan, end_varname, NULL);