]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
app_if: Fix faulty EndIf branching.
authorNaveen Albert <asterisk@phreaknet.org>
Sat, 23 Dec 2023 16:26:13 +0000 (16:26 +0000)
committerAsterisk Development Team <asteriskteam@digium.com>
Fri, 12 Jan 2024 18:32:13 +0000 (18:32 +0000)
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
(cherry picked from commit 1bf4493371b8cf515e0094a6a7efe6003ff43dae)

apps/app_if.c

index bc04ffd71bb570c53cb3f1e744b8285f80d697b6..94bb1f12733ac81731f7f4748ebd55adfb54a663 100644 (file)
@@ -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);