Skip to content

Commit

Permalink
mangler: 0-ending value on deconding uri
Browse files Browse the repository at this point in the history
(cherry picked from commit 3b038ed)
  • Loading branch information
miconda authored and ovidiusas committed Mar 16, 2021
1 parent a9ce71b commit a6fa3de
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/modules/mangler/contact_ops.c
Expand Up @@ -610,28 +610,28 @@ decode_uri (str* uri, char separator, str * result, str* dst_uri)
{
LOG(L_ERR,"ERROR: decode_uri: Unable to decode host address \n");
return -2;/* should I quit or ignore ? */
}
}

if ((format.password.len > 0) && (format.username.len <= 0))
{
LOG(L_ERR,"ERROR: decode_uri: Password decoded but no username available\n");
return -3;
}

/* a complete uri would be sip:username:password@ip:port;transport=protocol goes to
* sip:enc_pref#username#password#ip#port#protocol@public_ip
*/
result->len = format.first + (uri->len - format.second); /* not NULL terminated */
if (format.username.len > 0) result->len += format.username.len + 1; //: or @
if (format.password.len > 0) result->len += format.password.len + 1; //@

/* if (format.ip.len > 0) */ result->len += format.ip.len;

if (format.port.len > 0) result->len += 1 + format.port.len; //:
if (format.protocol.len > 0) result->len += 1 + 10 + format.protocol.len; //;transport=

/* adding one comes from * */
result->s = pkg_malloc (result->len);
result->s = pkg_malloc (result->len + 1); /* NULL termination */
if (result->s == NULL)
{
LOG(L_ERR,"ERROR: decode_contact: Unable to allocate memory\n");
Expand All @@ -640,7 +640,7 @@ decode_uri (str* uri, char separator, str * result, str* dst_uri)
pos = result->s;
memcpy (pos, uri->s, format.first); /* till sip: */
pos = pos + format.first;

if (format.username.len > 0)
{
memcpy (pos, format.username.s, format.username.len);
Expand All @@ -662,7 +662,7 @@ decode_uri (str* uri, char separator, str * result, str* dst_uri)

memcpy (pos, format.ip.s, format.ip.len);
pos = pos + format.ip.len;

if (format.port.len > 0)
{
memcpy (pos, ":", 1);
Expand All @@ -677,9 +677,11 @@ decode_uri (str* uri, char separator, str * result, str* dst_uri)
memcpy (pos, format.protocol.s, format.protocol.len);
pos = pos + format.protocol.len;
}

memcpy (pos, uri->s + format.second, uri->len - format.second); /* till end: */


result->s[result->len] = '\0';

/* dst_uri */
if (dst_uri && format.rcv_ip.s){
dst_uri->len=4 /* sip: */ + format.rcv_ip.len;
Expand Down

0 comments on commit a6fa3de

Please sign in to comment.