]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_pubsub: Prevent crash from AMI command on freed subscription. 96/2096/1
authorMark Michelson <mmichelson@digium.com>
Mon, 25 Jan 2016 22:51:25 +0000 (16:51 -0600)
committerMark Michelson <mmichelson@digium.com>
Tue, 26 Jan 2016 21:00:21 +0000 (15:00 -0600)
A test recently uncovered that running an ill-timed AMI command to show
inbound subscriptions could cause a crash since Asterisk will try to
operate on a freed subscription.

The fix for this is to remove the subscription tree from the list of
subscriptions at the time that we are sending our final NOTIFY request
out. This way, as the subscription is in the process of dying, it is
inaccessible from AMI.

Change-Id: Ic0239003d8d73e04c47c12dd2a7e23867e5b5b23
(cherry picked from commit b073244c511f9634de57ea401ab9dbebcf2390e8)

res/res_pjsip_pubsub.c

index 8d3ea6f5cf11f2f0dee459a0a3e7d01c353b910b..fd0119004f1cc8bb3f058efa749bb05ff1fe6e2e 100644 (file)
@@ -1197,8 +1197,6 @@ static void subscription_tree_destructor(void *obj)
 
        ast_debug(3, "Destroying subscription tree %p\n", sub_tree);
 
-       remove_subscription(sub_tree);
-
        ao2_cleanup(sub_tree->endpoint);
 
        destroy_subscriptions(sub_tree->root);
@@ -3277,6 +3275,7 @@ static void pubsub_on_evsub_state(pjsip_evsub *evsub, pjsip_event *event)
                }
        }
 
+       remove_subscription(sub_tree);
        pjsip_evsub_set_mod_data(evsub, pubsub_module.id, NULL);
        sub_tree->evsub = NULL;
        ast_sip_dialog_set_serializer(sub_tree->dlg, NULL);