Skip to content

Commit

Permalink
Fix wrong inheriting of Contact-Length hdr.
Browse files Browse the repository at this point in the history
When moving from multi part to single part, do not inherite the Ct-len hdr of the part.
Fixes #1990

(cherry picked from commit 7dd1151)
  • Loading branch information
bogdan-iancu committed Jun 25, 2020
1 parent 68afb70 commit 775462d
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions msg_translator.c
Expand Up @@ -1261,7 +1261,8 @@ static unsigned int prep_reassemble_body_parts( struct sip_msg* msg,
unsigned int size;
unsigned int len = 0;
unsigned int orig_offs;
char *hdr;
struct hdr_field hf;
char *hdr, *it;

/* set the offset (in the original buffer) at the beginning of the body */
orig_offs = msg->body->part_count ? msg->body->body.s-msg->buf : msg->len ;
Expand Down Expand Up @@ -1366,15 +1367,27 @@ static unsigned int prep_reassemble_body_parts( struct sip_msg* msg,
}
}
} else {
hdr = (char*)pkg_malloc( part->headers.len);
if (hdr==NULL) {
LM_ERR("failed to allocate new ct hdr\n");
} else {
memcpy( hdr, part->headers.s, part->headers.len);
if (insert_new_lump_before(ct, hdr,
part->headers.len, HDR_CONTENTTYPE_T) == NULL) {
LM_ERR("failed to create insert lump\n");
pkg_free(hdr);
/* iterate all the SIP hdrs from this part and keep all
* except the "Content-Length" */
it = part->headers.s;
while ( it<part->headers.s+part->headers.len ) {
memset( &hf, 0, sizeof(struct hdr_field));
it = get_hdr_field( it, part->headers.s+part->headers.len, &hf);
if (hf.type==HDR_ERROR_T || hf.type==HDR_EOH_T)
break;
if (hf.type==HDR_CONTENTLENGTH_T)
continue;
/* add this hdr */
hdr = (char*)pkg_malloc( hf.len);
if (hdr==NULL) {
LM_ERR("failed to allocate new ct hdr\n");
} else {
memcpy( hdr, hf.name.s, hf.len);
if (insert_new_lump_before(ct, hdr,
hf.len, HDR_CONTENTTYPE_T) == NULL) {
LM_ERR("failed to create insert lump\n");
pkg_free(hdr);
}
}
}
}
Expand Down

0 comments on commit 775462d

Please sign in to comment.