From efa6c6a9bf13c430d5be5146168d1ded4c39dba7 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Mon, 7 Sep 2020 19:35:04 +0200 Subject: [PATCH] uac: restore first display name then uri with dialog callback - same as for rr callback, otherwise the new header can be malformed: the case of initial INVITE with From URI having no angle brackets and goes out with display name and angle brackets, the ACK for 200ok results with From broken when forwarded --- src/modules/uac/replace.c | 56 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/modules/uac/replace.c b/src/modules/uac/replace.c index c64af52999a..3a476a3d82c 100644 --- a/src/modules/uac/replace.c +++ b/src/modules/uac/replace.c @@ -942,26 +942,6 @@ static void replace_callback(struct dlg_cell *dlg, int type, old_uri.len, old_uri.s, new_display->len, new_display->s, new_uri->len, new_uri->s); - /* duplicate the decoded value */ - p = pkg_malloc( new_uri->len); - if (!p) { - PKG_MEM_ERROR; - return; - } - memcpy( p, new_uri->s, new_uri->len); - - /* build del/add lumps */ - l = del_lump( msg, old_uri.s-msg->buf, old_uri.len, 0); - if (l==0) { - LM_ERR("del lump failed\n"); - goto free; - } - - if (insert_new_lump_after( l, p, new_uri->len, 0)==0) { - LM_ERR("insert new lump failed\n"); - goto free; - } - /* deal with display name */ l = 0; /* first remove the existing display */ @@ -972,8 +952,8 @@ static void replace_callback(struct dlg_cell *dlg, int type, l = del_lump(msg, body->display.s-msg->buf, body->display.len, 0); if (l==0) { LM_ERR("display del lump failed\n"); - goto free; - } + return; + } } if (new_display->s && new_display->len > 0) { LM_DBG("inserting display [%.*s]\n", @@ -982,20 +962,40 @@ static void replace_callback(struct dlg_cell *dlg, int type, buf.s = pkg_malloc(new_display->len + 2); if (buf.s==0) { PKG_MEM_ERROR; - goto free; + return; } memcpy( buf.s, new_display->s, new_display->len); buf.len = new_display->len; if (l==0 && (l=get_display_anchor(msg, hdr, body, &buf)) == 0) { LM_ERR("failed to insert anchor\n"); - goto free2; + goto free1; } if (insert_new_lump_after(l, buf.s, buf.len, 0) == 0) { LM_ERR("insert new display lump failed\n"); - goto free2; + goto free1; } } + /* uri update - duplicate the decoded value */ + p = pkg_malloc( new_uri->len); + if (!p) { + PKG_MEM_ERROR; + goto free1; + } + memcpy( p, new_uri->s, new_uri->len); + + /* build del/add lumps */ + l = del_lump( msg, old_uri.s-msg->buf, old_uri.len, 0); + if (l==0) { + LM_ERR("del lump failed\n"); + goto free2; + } + + if (insert_new_lump_after( l, p, new_uri->len, 0)==0) { + LM_ERR("insert new lump failed\n"); + goto free2; + } + /* register tm callback to change replies, * but only if not registered earlier */ if (!(msg->msg_flags & (FL_USE_UAC_FROM|FL_USE_UAC_TO)) && @@ -1009,10 +1009,10 @@ static void replace_callback(struct dlg_cell *dlg, int type, return; free2: - pkg_free(buf.s); - -free: pkg_free(p); + +free1: + pkg_free(buf.s); }