]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
bridge_channel: don't set cause code on channel during bridge delete if already set
authorMike Bradeen <mbradeen@sangoma.com>
Tue, 18 Feb 2025 22:17:07 +0000 (15:17 -0700)
committerAsterisk Development Team <asteriskteam@digium.com>
Thu, 20 Mar 2025 18:29:21 +0000 (18:29 +0000)
Due to a potential race condition via ARI when hanging up a channel hangup with cause
while also deleting a bridge containing that channel, the bridge delete can over-write
the hangup cause code resulting in Normal Call Clearing instead of the set value.

With this change, bridge deletion will only set the hangup code if it hasn't been
previously set.

Resolves: #1124
(cherry picked from commit 4a563b6b8d0357202762610642e827db7c21a282)

main/bridge_channel.c

index 4aebb01b5e3ad2639a2b76d100cd608b1c83867e..e2175959bf482030edfa6925941177876c7eeaa5 100644 (file)
@@ -278,13 +278,23 @@ static void bridge_channel_poke(struct ast_bridge_channel *bridge_channel)
  */
 static int channel_set_cause(struct ast_channel *chan, int cause)
 {
+       int current_cause;
        ast_channel_lock(chan);
+       current_cause = ast_channel_hangupcause(chan);
+
+       /* if the hangupcause is already set, leave it */
+       if (current_cause > 0) {
+               ast_channel_unlock(chan);
+               return current_cause;
+       }
+
        if (cause <= 0) {
                cause = ast_channel_hangupcause(chan);
                if (cause <= 0) {
                        cause = AST_CAUSE_NORMAL_CLEARING;
                }
        }
+
        ast_channel_hangupcause_set(chan, cause);
        ast_channel_unlock(chan);
        return cause;