<p>Considering the following <em>fallback case</em> :</p>

<ul>
<li>alloc dst->s = pointer sizeof(void*)</li>
<li>dst->len = 0</li>
<li>return <strong>0</strong>
</li>
</ul>

<p>After skimming the code a little more I came to this for the above case(i.e. src->s is NULL):</p>

<ul>
<li>either make dst->s = NULL; dst->len = 0 and return <strong>-1</strong>; this will be caught by shm_str_dup() != 0 and prevent shm_free() a NULL pointer, even though memory managers checks for this and gives L_WARN</li>
<li>or keep the fallback case; further uses of the dst should be done based on the dst->len (i.e. cmp_str() or LM_ERR("%.*s"))</li>
</ul>

<p>I'd go for the second option. What do you think?</p>

<p>Also I've seen that the memory manager allocate and 'unsigned int'. So, if shm/pkg_str_dup() is called with src->len < 0 it will probably fail (depending on the negative value). In this case, I'd also force the fallback case.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/kamailio/kamailio/pull/401#issuecomment-157984715">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZarCAxQbvYpCFNoyubCnzQbyzsiJks5pHXqhgaJpZM4Gkk2w.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/kamailio/kamailio/pull/401#issuecomment-157984715"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>