res_pjsip_diversion: Use static pj_str_t for Diversion header names
authorSean Bright <sean.bright@gmail.com>
Thu, 28 Feb 2019 16:01:15 +0000 (11:01 -0500)
committerSean Bright <sean.bright@gmail.com>
Fri, 1 Mar 2019 22:47:22 +0000 (16:47 -0600)
PJSIP assumes that these header names are not allocated, and does not
clone the name strings when reusing headers.

Block unload of res_pjsip_diversion until shutdown to ensure static
memory stays valid.

ASTERISK-28312 #close

Change-Id: Ibd6ea55ec4a604bbd43ac07f8d0b54da2c39b8b9

res/res_pjsip_diversion.c

index e82140b..04f5964 100644 (file)
@@ -325,8 +325,7 @@ static void add_diversion_header(pjsip_tx_data *tdata, struct ast_party_redirect
 
        hdr = pjsip_from_hdr_create(tdata->pool);
        hdr->type = PJSIP_H_OTHER;
-       pj_strdup(tdata->pool, &hdr->name, &diversion_name);
-       hdr->sname = hdr->name;
+       hdr->sname = hdr->name = diversion_name;
 
        name_addr = pjsip_uri_clone(tdata->pool, base);
        uri = pjsip_uri_get_uri(name_addr->uri);
@@ -411,6 +410,9 @@ static struct ast_sip_session_supplement diversion_supplement = {
 
 static int load_module(void)
 {
+       /* Because we are passing static memory to pjsip, we need to make sure it
+        * stays valid while we potentially have active sessions */
+       ast_module_shutdown_ref(ast_module_info->self);
        ast_sip_session_register_supplement(&diversion_supplement);
        return AST_MODULE_LOAD_SUCCESS;
 }