Skip to content

Commit 58b16a5

Browse files
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
1 parent fa3922a commit 58b16a5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

apps/app_if.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,15 @@ static int find_matching_endif(struct ast_channel *chan, const char *otherapp)
196196
if (!ast_rdlock_context(c)) {
197197
if (!strcmp(ast_get_context_name(c), ast_channel_context(chan))) {
198198
/* This is the matching context we want */
199+
199200
int cur_priority = ast_channel_priority(chan) + 1, level = 1;
200201

201202
for (e = find_matching_priority(c, ast_channel_exten(chan), cur_priority,
202203
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
203204
e;
204205
e = find_matching_priority(c, ast_channel_exten(chan), ++cur_priority,
205206
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
207+
206208
if (!strcasecmp(ast_get_extension_app(e), "IF")) {
207209
level++;
208210
} 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)
283285
pbx_builtin_setvar_helper(chan, my_name, NULL);
284286
snprintf(end_varname,sizeof(end_varname),"END_%s",varname);
285287
ast_channel_lock(chan);
286-
endifpri = find_matching_endif(chan, NULL);
288+
/* For EndIf, simply go to the next priority.
289+
* For ExitIf or false If() condition, we need to find the end of the current
290+
* If branch (at same indentation) and branch there. */
291+
endifpri = end == 2 ? ast_channel_priority(chan) + 1 : find_matching_endif(chan, NULL);
287292
if ((goto_str = pbx_builtin_getvar_helper(chan, end_varname))) {
288293
ast_parseable_goto(chan, goto_str);
289294
pbx_builtin_setvar_helper(chan, end_varname, NULL);

0 commit comments

Comments
 (0)