<p><a href="https://github.com/linuxmaniac" class="user-mention">@linuxmaniac</a>, <a href="https://github.com/miconda" class="user-mention">@miconda</a>, I work with <a href="https://github.com/davidxbwang" class="user-mention">@davidxbwang</a></p>
<p>I found the issue in modules/pv/pv_core.c. Function pv_get_srcip(). We should substitute the function ip_addr2strz() for ip_addr2a(). ip_addr2strz() correctly inserts the [] in the string when the address is IPv6. Also, I noticed that both of these functions use a static buffer that is one character too small. Since they put a null terminator, if you have a maximum size IPv6 address (no leading zeros) you will overwrite the end of the buffer.</p>
<p>We tested the fix, and, it appears to not affect other parts of the code that might not expect the brackets [] added.</p>
<p>Below the fix is shown with the old line commented out.</p>
<p>int pv_get_srcip(struct sip_msg *msg, pv_param_t *param,<br>
pv_value_t *res)<br>
{<br>
str s;<br>
if(msg==NULL)<br>
return -1;</p>
<pre><code>    //s.s = ip_addr2a(&msg->rcv.src_ip);
    s.s = ip_addr2strz(&msg->rcv.src_ip);
    s.len = strlen(s.s);
    return pv_get_strval(msg, param, res, &s);
</code></pre>
<p>}</p>
<p>Don.</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/1136#issuecomment-310208571">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZUncGHv3wthEPkGrtJi_Sv114Cybks5sGYkFgaJpZM4NkKgo">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZV418OkyZTMBmCYfotB1w_BUbffIks5sGYkFgaJpZM4NkKgo.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/issues/1136#issuecomment-310208571"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>

<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://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"PERSON","message":"@doncarr in #1136: @linuxmaniac, @miconda, I work with @davidxbwang \r\n\r\nI found the issue in modules/pv/pv_core.c. Function pv_get_srcip(). We should substitute the function ip_addr2strz() for ip_addr2a(). ip_addr2strz() correctly inserts the [] in the string when the address is IPv6. Also, I noticed that both of these functions use a static buffer that is one character too small. Since they put a null terminator, if you have a maximum size IPv6 address (no leading zeros) you will overwrite the end of the buffer. \r\n\r\nWe tested the fix, and, it appears to not affect other parts of the code that might not expect the brackets [] added.  \r\n\r\nBelow the fix is shown with the old line commented out.\r\n\r\nint pv_get_srcip(struct sip_msg *msg, pv_param_t *param,\r\n                pv_value_t *res)\r\n{\r\n        str s;\r\n        if(msg==NULL)\r\n                return -1;\r\n \r\n        //s.s = ip_addr2a(\u0026msg-\u003ercv.src_ip);\r\n        s.s = ip_addr2strz(\u0026msg-\u003ercv.src_ip);\r\n        s.len = strlen(s.s);\r\n        return pv_get_strval(msg, param, res, \u0026s);\r\n}\r\n \r\nDon."}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1136#issuecomment-310208571"}}}</script>