<p></p>
<blockquote>
<p>I would rather change pkg_str_dup() and shm_str_dup() to allocate len+1 and add the ending zero</p>
</blockquote>
<p>That was my first approach. I just thought it would provoke more discussion (see below) and I wanted to fix this bug fast, so I just kinda reverted the commits that introduced it.</p>
<p>The problem with adding a zero on every copy is that a <code>str</code> is supposed to be useful without a terminating zero. Lots of <code>str</code> uses are within the parser where <code>str</code> just points into the message buffer and has no terminating 0. Having them mixed will inevitable lead to bugs (just like the one I'm trying to fix). All developers will have to remember that only copies are 0-terminated.</p>
<p>Introducing a separate type for it (<code>strz</code>) will need duplicates for all existing str functions as C doesn't allow type inheritance.</p>
<p>Another option is to create <code>pkg_str_dupz()</code> and <code>shm_str_dupz()</code> which will 0-terminate the copies.</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/pull/2512#issuecomment-712661040">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZPLX63I4F3OZPBKMJLSLU5TZANCNFSM4SWDGBOQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZMDYOBL5UZX6N3DJUDSLU5TZA5CNFSM4SWDGBO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFJ5FQMA.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/pull/2512#issuecomment-712661040",
"url": "https://github.com/kamailio/kamailio/pull/2512#issuecomment-712661040",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>