]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_pubsub: Prevent removing subscriptions.
authorNaveen Albert <asterisk@phreaknet.org>
Sun, 16 Oct 2022 20:35:29 +0000 (20:35 +0000)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Wed, 26 Oct 2022 14:07:41 +0000 (09:07 -0500)
pjproject does not provide any mechanism of removing
event packages, which means that once a subscription
handler is registered, it is effectively permanent.

pjproject will assert if the same event package is
ever registered again, so currently unloading and
loading any Asterisk modules that use subscriptions
will cause a crash that is beyond our control.

For that reason, we now prevent users from being
able to unload these modules, to prevent them
from ever being loaded twice.

ASTERISK-30264 #close

Change-Id: I7fdcb1a5e44d38b7ba10c44259fe98f0ae9bc12c

res/res_pjsip_exten_state.c
res/res_pjsip_mwi.c

index 3c7baeeaa910b93d16bf426b7d8f530139c650c0..1b29091849ab0ca2a7d87a5e16c4899657c44c95 100644 (file)
@@ -973,6 +973,7 @@ static int publisher_stop(struct ast_sip_outbound_publish_client *client)
 
 static int unload_module(void)
 {
+#if 0
        ast_sip_unregister_event_publisher_handler(&dialog_publisher);
        ast_sip_unregister_subscription_handler(&dialog_handler);
        ast_sip_unregister_event_publisher_handler(&presence_publisher);
@@ -987,6 +988,18 @@ static int unload_module(void)
        publishers = NULL;
 
        return 0;
+#else
+       /* If we were allowed to unload, the above is what we would do.
+        * pjsip_evsub_register_pkg is called by ast_sip_register_subscription_handler
+        * but there is no corresponding unregister function, so unloading
+        * a module does not remove the event package. If this module is ever
+        * loaded again, then pjproject will assert and cause a crash.
+        * For that reason, we must not be allowed to unload, but if
+        * a pjsip_evsub_unregister_pkg API is added in the future
+        * then we should go back to unloading the module as intended.
+        */
+       return -1;
+#endif
 }
 
 static int load_module(void)
index ba684862b33bed140f3965f8e6b445e4773364ca..dfe5481f334a29e88bd80dfb48f025751f14d14c 100644 (file)
@@ -1524,6 +1524,7 @@ static int reload(void)
 
 static int unload_module(void)
 {
+#if 0
        struct ao2_container *unsolicited_mwi;
 
        ast_sorcery_observer_remove(ast_sip_get_sorcery(), "global", &global_observer);
@@ -1548,6 +1549,18 @@ static int unload_module(void)
        ast_free(default_voicemail_extension);
        default_voicemail_extension = NULL;
        return 0;
+#else
+       /* If we were allowed to unload, the above is what we would do.
+        * pjsip_evsub_register_pkg is called by ast_sip_register_subscription_handler
+        * but there is no corresponding unregister function, so unloading
+        * a module does not remove the event package. If this module is ever
+        * loaded again, then pjproject will assert and cause a crash.
+        * For that reason, we must not be allowed to unload, but if
+        * a pjsip_evsub_unregister_pkg API is added in the future
+        * then we should go back to unloading the module as intended.
+        */
+       return -1;
+#endif
 }
 
 static int load_module(void)