<p>If I do a substring operation where I extract the middle of a string, I occasionally get results that are not correct. Example code:<br>
$var(x) = $(var(y){s.substr,1,5});</p>
<p>This seems to be the same issue as: <a href="http://sip-router.1086192.n5.nabble.com/PATCH-Memory-corruption-using-s-substr-transformation-td118002.html" rel="nofollow">http://sip-router.1086192.n5.nabble.com/PATCH-Memory-corruption-using-s-substr-transformation-td118002.html</a></p>
<p>This issue had a fix which added "tr_string_clone_result" in numerous exit points in pv_trans.c: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/kamailio/kamailio/commit/fe7e4a5152674aa9c81c09dd2fc9938d9e9e762e/hovercard" href="https://github.com/kamailio/kamailio/commit/fe7e4a5152674aa9c81c09dd2fc9938d9e9e762e"><tt>fe7e4a5</tt></a></p>
<p>It seemed to be missing at the exit path for the substring operation which may explain my observation. See:<br>
<a href="https://github.com/kamailio/kamailio/blob/master/src/modules/pv/pv_trans.c#L617">https://github.com/kamailio/kamailio/blob/master/src/modules/pv/pv_trans.c#L617</a></p>
<p>I also notice that this is not used in some other string operations which leads me to wonder if this problem is more prevalent (likely, since I've heard reports of similar symptoms with the replace).</p>
<p>Suggestion:<br>
Investigate if we can have this "tr_string_clone_result" called here and remove all other occurrences in the switch clause.</p>
<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/1937">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZOUXTOSKM4JN6FCSM3PSEND5ANCNFSM4HIJLLTQ">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABO7UZKYP2TZKXMLBBEYHETPSEND5ANCNFSM4HIJLLTQ.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://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"In-place string transform having occasionally corrupted results (#1937)"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1937"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/1937",
"url": "https://github.com/kamailio/kamailio/issues/1937",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>