Skip to content

Commit

Permalink
drouting: allow do_routing to set an empty user
Browse files Browse the repository at this point in the history
Before this fix, if the strip was larger than the username, do_routing
function would return negative. This commit fixes this and strips the
username entirely.

Closes #1044
  • Loading branch information
razvancrainea committed Feb 8, 2017
1 parent 9a0279e commit e7f0396
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions modules/drouting/drouting.c
Expand Up @@ -1931,16 +1931,20 @@ static inline str* build_ruri(struct sip_uri *uri, int strip, str *pri,
str *hostport)
{
static str uri_str;
int user_len;
char *p;

if (uri->user.len<=strip) {
LM_ERR("stripping %d makes "
"username <%.*s> null\n",strip,uri->user.len,uri->user.s);
return 0;
}
if (uri->user.len<=strip)
strip = uri->user.len;
user_len = uri->user.len - strip + pri->len;

uri_str.len = 4 /*sip:*/ + user_len;
if (uri->passwd.s && uri->passwd.len)
uri_str.len += uri->passwd.len+1;
if ((uri->passwd.s && uri->passwd.len) || user_len > 0)
uri_str.len++; /*@*/

uri_str.len = 4 /*sip:*/ + uri->user.len - strip +pri->len +
(uri->passwd.s?(uri->passwd.len+1):0) + 1/*@*/ + hostport->len +
uri_str.len += hostport->len +
(uri->params.s?(uri->params.len+1):0) +
(uri->headers.s?(uri->headers.len+1):0);

Expand All @@ -1965,7 +1969,8 @@ static inline str* build_ruri(struct sip_uri *uri, int strip, str *pri,
memcpy(p, uri->passwd.s, uri->passwd.len);
p += uri->passwd.len;
}
*(p++)='@';
if ((uri->passwd.s && uri->passwd.len) || user_len > 0)
*(p++)='@';
memcpy(p, hostport->s, hostport->len);
p += hostport->len;
if (uri->params.s && uri->params.len) {
Expand Down

0 comments on commit e7f0396

Please sign in to comment.