Skip to content

[bug]: app_if.c : nested EndIf incorrectly exits parent If #341

Description

@asolovjov

Severity

Trivial

Versions

18

Components/Modules

app_if.c

Operating Environment

It doesn't matter.
Asterisk 18.19.0 built by builder @ builder.lo on a x86_64 running Linux on 2023-09-20 09:17:45

Frequency of Occurrence

None

Issue Description

If nested if block condition is true then EndIf exits the parent if block. (BTW, If condition is false, it works correctly. ExitIf also works correctly.)
Example simple dialplan:

exten => _iftest,1,Noop
    same => n,If(1)
        same => n,Noop(inside main if)
        same => n,If(0)
            same => n,Noop()
        same => n,Endif
        same => n,Noop(after nested false if)
        same => n,If(1)
            same => n,Noop(inside true nested if)
        same => n,Endif
        same => n,Noop(after nested true if)
    same => n,Endif
    same => n,Noop(after main if)
    same => n,Hangup

> dialplan show iftest@test                                                                                                                                                                                                
[ Context 'test' created by 'pbx_config' ]
  '_iftest' =>      1. Noop()                                     [extensions_custom.conf:487]
                    2. If(1)                                      [extensions_custom.conf:488]
                    3. Noop(inside main if)                       [extensions_custom.conf:489]
                    4. If(0)                                      [extensions_custom.conf:490]
                    5. Noop()                                     [extensions_custom.conf:491]
                    6. Endif()                                    [extensions_custom.conf:492]
                    7. Noop(after nested false if)                [extensions_custom.conf:493]
                    8. If(1)                                      [extensions_custom.conf:494]
                    9. Noop(inside true nested if)                [extensions_custom.conf:495]
                    10. Endif()                                   [extensions_custom.conf:496]
                    11. Noop(after nested true if)                [extensions_custom.conf:497]
                    12. Endif()                                   [extensions_custom.conf:498]
                    13. Noop(after main if)                       [extensions_custom.conf:499]
                    14. Hangup()                                  [extensions_custom.conf:500]

We should see "inside true nested if" and then "after nested true if". Instead we jump to priority 12:

    -- Executing [iftest@test:1] NoOp("SIP/y1103-00000015", "") in new stack
    -- Executing [iftest@test:2] If("SIP/y1103-00000015", "1") in new stack
    -- Executing [iftest@test:3] NoOp("SIP/y1103-00000015", "inside main if") in new stack
    -- Executing [iftest@test:4] If("SIP/y1103-00000015", "0") in new stack
    -- Exiting conditional, jumping to priority 6
    -- Executing [iftest@test:7] NoOp("SIP/y1103-00000015", "after nested false if") in new stack
    -- Executing [iftest@test:8] If("SIP/y1103-00000015", "1") in new stack
    -- Executing [iftest@test:9] NoOp("SIP/y1103-00000015", "inside true nested if") in new stack
    -- Executing [iftest@test:10] EndIf("SIP/y1103-00000015", "") in new stack
    -- Exiting conditional, jumping to priority 12
    -- Executing [iftest@test:13] NoOp("SIP/y1103-00000015", "after main if") in new stack
    -- Executing [iftest@test:14] Hangup("SIP/y1103-00000015", "") in new stack

Relevant log output

No response

Asterisk Issue Guidelines

  • Yes, I have read the Asterisk Issue Guidelines

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions