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
This commit is contained in:
Naveen Albert 2023-12-23 16:26:13 +00:00
parent bb364fc61f
commit 1bf4493371
1 changed files with 6 additions and 1 deletions

View 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);