]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
prevent double masqurading channels when one is been hung up and deadlock avoidance...
authorGregory Nietsky <gregory@distrotech.co.za>
Sat, 30 Jul 2011 15:25:16 +0000 (15:25 +0000)
committerGregory Nietsky <gregory@distrotech.co.za>
Sat, 30 Jul 2011 15:25:16 +0000 (15:25 +0000)
There is a race condition in ast_do_masquerade / ast_hangup (at least)

Reported by me signed off by schmidts with input from David Vossel

Review: https://reviewboard.asterisk.org/r/1323/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@330311 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/channel.c

index fdddd51ce0ebfa243c3ca1f5ecc75b0c651d4524..b77e0f6007880a3e1b5b97fbfd1faa03c906da20 100644 (file)
@@ -6320,10 +6320,18 @@ int ast_do_masquerade(struct ast_channel *original)
         * for deadlock avoidance will not result in any sort of masquerade race condition.
         * If masq is called by a different thread while this happens, it will be stuck waiting
         * until we unlock the container. */
-       while (ast_channel_trylock(clonechan)) {
+       while ((clonechan = original->masq) && ast_channel_trylock(clonechan)) {
                CHANNEL_DEADLOCK_AVOIDANCE(original);
        }
 
+       /* recheck if masq has been done the deadlock avoidance above could cause a double masq
+        * this is posible with at least ast_hangup*/
+       if (!original->masq) {
+               ast_channel_unlock(original);
+               ao2_unlock(channels);
+               return 0; /* masq already completed by another thread, or never needed to be done to begin with */
+       }
+
        /* Get any transfer masquerade connected line exchange data. */
        xfer_ds = ast_channel_datastore_find(original, &xfer_ds_info, NULL);
        if (xfer_ds) {