]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_header_funcs: Duplicate new header value, don't copy.
authorGitea <gitea@fake.local>
Mon, 10 Jul 2023 15:43:06 +0000 (12:43 -0300)
committerdon't copy. <Gitea|gitea@fake.local|>
Thu, 14 Dec 2023 18:48:42 +0000 (18:48 +0000)
When updating an existing header the 'update' code incorrectly
just copied the new value into the existing buffer. If the
new value exceeded the available buffer size memory outside
of the buffer would be written into, potentially causing
a crash.

This change makes it so that the 'update' now duplicates
the new header value instead of copying it into the existing
buffer.

res/res_pjsip_header_funcs.c

index ac3bea4372a330abb6e85323f0c64b078727b703..43df0a7b04f450bb2be781eca7b46d4f41df04cc 100644 (file)
@@ -501,6 +501,7 @@ static int add_header(void *obj)
 static int update_header(void *obj)
 {
        struct header_data *data = obj;
+       pj_pool_t *pool = data->channel->session->inv_session->dlg->pool;
        pjsip_hdr *hdr = NULL;
        RAII_VAR(struct ast_datastore *, datastore,
                         ast_sip_session_get_datastore(data->channel->session, header_datastore.type),
@@ -519,7 +520,7 @@ static int update_header(void *obj)
                return -1;
        }
 
-       pj_strcpy2(&((pjsip_generic_string_hdr *) hdr)->hvalue, data->header_value);
+       pj_strdup2(pool, &((pjsip_generic_string_hdr *) hdr)->hvalue, data->header_value);
 
        return 0;
 }