<h3>Description</h3>
<p>I want convert <code>application/sdp</code> body of INVITE message to <code>multipart/mixed</code>. For this used <a href="https://kamailio.org/docs/modules/devel/modules/textops.html#textops.f.set_body_multipart" rel="nofollow">contruction</a></p>
<pre><code>set_body_multipart("test", "text/plain", "delimiter");
msg_apply_changes();
$var(b) = "7e Od 04 55 75 69 20 4d 61 6b 65 43 61 6c 6c"
append_body_part("$var(b)", "application/vnd.cirpack.isdn-ext", "signal;handling=required");
</code></pre>
<p>For some reason <code>msg_apply_changes</code> is not applied and then  <code>append_body_part</code> causes coredump.</p>
<h3>Troubleshooting</h3>
<h4>Reproduction</h4>
<p>On alpine dist or on docker contained <code>kamailio/kamailio-ci</code> need add load <a href="https://github.com/2600hz/kazoo-configs-kamailio">kazoo config</a> and apply this patch</p>
<pre><code>diff --git a/kamailio/default.cfg b/kamailio/default.cfg
index bc4a084..4b85642 100644
--- a/kamailio/default.cfg
+++ b/kamailio/default.cfg
@@ -334,6 +334,13 @@ route
     route(AUTHORIZATION_CHECK);
     #!endif

+    if (is_method("INVITE") && isflagset(FLAG_INTERNALLY_SOURCED)) {
+        set_body_multipart();
+        msg_apply_changes();
+        $var(b) = "7e Od 04 55 75 69 20 4d 61 6b 65 43 61 6c 6c";
+        append_body_part("$var(b)", "application/vnd.cirpack.isdn-ext", "signal;handling=required");
+    }
+
     route(HANDLE_MESSAGE_WRAPPER);

     #!ifdef PRESENCE_ROLE
</code></pre>
<p>Then make call to other phone.</p>
<h4>Debugging Data</h4>
<pre><code>(gdb) bt
#0  0x00007f1235f96f1b in __syscall4 (a4=<optimized out>, a3=<optimized out>, a2=<optimized out>, a1=<optimized out>, n=<optimized out>)
    at ./arch/x86_64/syscall_arch.h:38
#1  __restore_sigs (set=set@entry=0x7ffc151162d0) at src/signal/block.c:43
#2  0x00007f1235f97035 in raise (sig=sig@entry=6) at src/signal/raise.c:13
#3  0x00007f1235f6efb4 in abort () at src/exit/abort.c:9
#4  0x00005598707495a2 in free_lump (lmp=0x7f1235e76478) at core/data_lump.c:464
#5  0x000055987074965d in free_lump_list (l=l@entry=0x7f1235e763d8) at core/data_lump.c:498
#6  0x000055987074983a in del_nonshm_lump (lump_list=lump_list@entry=0x7f1235e737b8) at core/data_lump.c:647
#7  0x0000559870785c43 in replace_body (msg=msg@entry=0x7f1235e73208, txt=...) at core/msg_translator.c:1667
#8  0x000055987078d205 in check_boundaries (msg=msg@entry=0x7f1235e73208, send_info=send_info@entry=0x7f12322d6df8) at core/msg_translator.c:1874
#9  0x000055987078d5d3 in build_req_buf_from_sip_req (msg=msg@entry=0x7f1235e73208, returned_len=returned_len@entry=0x7ffc151166fc, 
    send_info=0x7f12322d6df8, mode=mode@entry=128) at core/msg_translator.c:1979
#10 0x00007f123602a1ec in prepare_new_uac (t=t@entry=0x7f12322d6b90, i_req=i_req@entry=0x7f1235e73208, branch=branch@entry=0, uri=<optimized out>, 
    uri@entry=0x7f1235e73480, path=<optimized out>, next_hop=<optimized out>, fsocket=0x7f1235e5ba50, snd_flags=..., fproto=0, flags=0, 
    instance=<optimized out>, ruid=<optimized out>, location_ua=<optimized out>) at t_fwd.c:474
#11 0x00007f123602b665 in add_uac (t=t@entry=0x7f12322d6b90, request=request@entry=0x7f1235e73208, uri=0x7f1235e73480, next_hop=<optimized out>, 
    path=<optimized out>, proxy=proxy@entry=0x0, fsocket=0x7f1235e5ba50, snd_flags=..., proto=0, flags=0, instance=0x7f1235e73850, ruid=0x7f1235e73868, 
    location_ua=0x7f1235e73878) at t_fwd.c:800
#12 0x00007f12360307b8 in t_forward_nonack (t=0x7f12322d6b90, p_msg=p_msg@entry=0x7f1235e73208, proxy=proxy@entry=0x0, proto=proto@entry=0) at t_fwd.c:1680
#13 0x00007f123603ee65 in t_relay_to (p_msg=0x7f1235e73208, proxy=0x0, proto=0, replicate=0) at t_funcs.c:331
#14 0x000055987076fbb8 in do_action (h=h@entry=0x7ffc15118360, a=a@entry=0x7f1235bbf528, msg=msg@entry=0x7f1235e73208) at core/action.c:1073
#15 0x000055987076ac5d in run_actions (h=h@entry=0x7ffc15118360, a=0x7f1235bb1c28, msg=msg@entry=0x7f1235e73208) at core/action.c:1565
#16 0x000055987076dbb3 in do_action (h=h@entry=0x7ffc15118360, a=a@entry=0x7f1235bad570, msg=msg@entry=0x7f1235e73208) at core/action.c:691
#17 0x000055987076ac5d in run_actions (h=h@entry=0x7ffc15118360, a=0x7f1235bad570, msg=msg@entry=0x7f1235e73208) at core/action.c:1565
#18 0x000055987076fb99 in do_action (h=h@entry=0x7ffc15118360, a=a@entry=0x7f1235baf5c8, msg=msg@entry=0x7f1235e73208) at core/action.c:1062
#19 0x000055987076ac5d in run_actions (h=h@entry=0x7ffc15118360, a=0x7f1235bac9d0, msg=msg@entry=0x7f1235e73208) at core/action.c:1565
#20 0x000055987076dbb3 in do_action (h=h@entry=0x7ffc15118360, a=a@entry=0x7f1235b71db8, msg=msg@entry=0x7f1235e73208) at core/action.c:691
#21 0x000055987076ac5d in run_actions (h=h@entry=0x7ffc15118360, a=a@entry=0x7f1235b69540, msg=msg@entry=0x7f1235e73208) at core/action.c:1565
#22 0x0000559870775dc7 in run_top_route (a=0x7f1235b69540, msg=msg@entry=0x7f1235e73208, c=c@entry=0x0) at core/action.c:1654
#23 0x00005598707660c1 in receive_msg (
    buf=buf@entry=0x559870a51640 <buf> "INVITE sip:safarov2@node1.nga911.com SIP/2.0\r\nVia: SIP/2.0/UDP 10.0.9.35:11000;rport;branch=z9hG4bK69ag32Nr5gFjH\r\nRoute: <sip:10.0.9.39:5060>\r\nMax-Forwards: 48\r\nFrom: \"Sergey Safarov\" <sip:1240@node1."..., len=<optimized out>, 
    rcv_info=rcv_info@entry=0x7ffc151186c0) at core/receive.c:278
#24 0x00005598708131fb in udp_rcv_loop () at core/udp_server.c:554
#25 0x0000559870744fb6 in main_loop () at main.c:1619
#26 0x000055987073d51f in main (argc=<optimized out>, argv=<optimized out>) at main.c:2638
</code></pre>
<p>Full backtrace at <a href="https://github.com/kamailio/kamailio/files/2342768/bt_full.txt">bt_full.txt</a></p>
<h4>Log Messages</h4>
<p>Please look <a href="https://github.com/kamailio/kamailio/files/2342769/kamailio_console.txt">kamailio_console.txt</a></p>
<h4>SIP Traffic</h4>
<p>Crash when started modification of packet 73 of pcap file <a href="https://github.com/kamailio/kamailio/files/2342770/sip.pcap.gz">sip.pcap.gz</a></p>
<h3>Possible Solutions</h3>
<p>Not known</p>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>/ # kamailio -v
version: kamailio 5.1.5 (x86_64/linux) 
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144 MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown 
compiled on 16:32:28 Sep  1 2018 with gcc 6.4.0
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>
<pre><code>/ # cat /etc/os-release 
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.8.0
PRETTY_NAME="Alpine Linux v3.8"
HOME_URL="http://alpinelinux.org"
BUG_REPORT_URL="http://bugs.alpinelinux.org"
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/1631">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36Zf6vtPVKvOyt8hWBUtV_-iFzI016ks5uWveJgaJpZM4WWXtC">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZZArMD330nvvb-Wz_qFJDyKm3bAJks5uWveJgaJpZM4WWXtC.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"coredump when used append_body_part (#1631)"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1631"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/1631",
"url": "https://github.com/kamailio/kamailio/issues/1631",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "coredump when used append_body_part (#1631)",
"sections": [
{
"text": "",
"activityTitle": "**sergey-safarov**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@sergey-safarov",
"facts": [
{
"name": "Repository: ",
"value": "kamailio/kamailio"
},
{
"name": "Issue #: ",
"value": 1631
}
]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1631,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"name": "Close issue",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueClose\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1631\n}"
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/kamailio/kamailio/issues/1631"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 374963010\n}"
}
],
"themeColor": "26292E"
}
]</script>