Module: sip-router Branch: master Commit: 262b5880616d8b58cf9b012b460793f9879087b3 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=262b5880...
Author: Juha Heinanen jh@tutpro.com Committer: Juha Heinanen jh@tutpro.com Date: Wed Apr 10 22:42:43 2013 +0300
modules/registrar: fixed bug in un-escaping of path/received
---
modules/registrar/path.c | 30 ++++++++++++++++++++---------- 1 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/modules/registrar/path.c b/modules/registrar/path.c index 63c282c..ef976e0 100644 --- a/modules/registrar/path.c +++ b/modules/registrar/path.c @@ -37,16 +37,17 @@
/*! \brief Unscape all printable ASCII characters */ -int unescape_string(str *sin) +int unescape_string(str *sin, str *sout) { char *at, *p, c;
- if (sin == NULL || sin->s == NULL || sin->len < 0) + if(sin==NULL || sout==NULL || sin->s==NULL || sout->s==NULL + || sin->len<0 || sout->len < sin->len+1) return -1;
- at = sin->s; + at = sout->s; p = sin->s; - while(p < sin->s + sin->len) + while(p < sin->s+sin->len) { if (*p == '%') { @@ -129,11 +130,13 @@ int unescape_string(str *sin) } else { *at++ = *p; } - p++; + p++; }
- sin->len = at - sin->s; + *at = 0; + sout->len = at - sout->s; + LM_DBG("unescaped string is <%s>\n", sout->s); return 0; }
@@ -143,6 +146,8 @@ int unescape_string(str *sin) int build_path_vector(struct sip_msg *_m, str *path, str *received) { static char buf[MAX_PATH_SIZE]; + static char uri_buf[MAX_URI_SIZE]; + static str uri_str; char *p; struct hdr_field *hdr; struct sip_uri puri; @@ -196,10 +201,14 @@ int build_path_vector(struct sip_msg *_m, str *path, str *received) }
if (hooks.contact.received) { - *received = hooks.contact.received->body; - if (unescape_string(received) < 0) - LM_ERR("unescaping received value <%.*s> failed\n", - received->len, received->s); + uri_str.s = uri_buf; + uri_str.len = MAX_URI_SIZE; + if (unescape_string(&(hooks.contact.received->body), &uri_str) < 0) { + LM_ERR("unescaping received failed\n"); + goto error; + } + *received = uri_str; + LM_DBG("received is <%.*s>\n", received->len, received->s); } /*for (;params; params = params->next) { @@ -215,6 +224,7 @@ int build_path_vector(struct sip_msg *_m, str *path, str *received)
path->s = buf; path->len = p-buf; + LM_DBG("path is <%.*s>\n", path->len, path->s); return 0; error: if(route) free_rr(&route);