From: Sean Bright Date: Thu, 28 Feb 2019 16:01:15 +0000 (-0500) Subject: res_pjsip_diversion: Use static pj_str_t for Diversion header names X-Git-Tag: 16.3.0-rc1~37^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ffe07772e688e79e31e3a5873bc7a2977b29e304;p=thirdparty%2Fasterisk.git res_pjsip_diversion: Use static pj_str_t for Diversion header names 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 --- diff --git a/res/res_pjsip_diversion.c b/res/res_pjsip_diversion.c index e82140b723..04f5964404 100644 --- a/res/res_pjsip_diversion.c +++ b/res/res_pjsip_diversion.c @@ -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; }