From cbba00f5d0a5d1edd1e645d72fdcd0829384dd9b Mon Sep 17 00:00:00 2001 From: Mark Michelson Date: Tue, 27 Jul 2010 18:54:07 +0000 Subject: [PATCH] Fix parsing error in sip_sipredirect(). The code was written in a way that did a bad job of parsing the port out of a URI. Specifically, it would do badly when dealing with an IPv6 address. In this particular scenario, there was no value from parsing the port out, so I just removed that logic. And while I was messing around in the function, I changed some variable names to be more descriptive. (closes issue #17661) Reported by: oej Patches: 17661.diff uploaded by mmichelson (license 60) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@279887 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_sip.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/channels/chan_sip.c b/channels/chan_sip.c index b74bc2912c..47b044ba76 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -27462,49 +27462,44 @@ static int sip_removeheader(struct ast_channel *chan, const char *data) static int sip_sipredirect(struct sip_pvt *p, const char *dest) { char *cdest; - char *extension, *host, *port; - char tmp[80]; + char *extension, *domain; cdest = ast_strdupa(dest); extension = strsep(&cdest, "@"); - host = strsep(&cdest, ":"); - port = strsep(&cdest, ":"); + domain = strsep(&cdest, ":"); if (ast_strlen_zero(extension)) { ast_log(LOG_ERROR, "Missing mandatory argument: extension\n"); return 0; } /* we'll issue the redirect message here */ - if (!host) { - char *localtmp; + if (!domain) { + char *local_to_header; + char to_header[256]; - ast_copy_string(tmp, get_header(&p->initreq, "To"), sizeof(tmp)); - if (ast_strlen_zero(tmp)) { + ast_copy_string(to_header, get_header(&p->initreq, "To"), sizeof(to_header)); + if (ast_strlen_zero(to_header)) { ast_log(LOG_ERROR, "Cannot retrieve the 'To' header from the original SIP request!\n"); return 0; } - if ( ( (localtmp = strcasestr(tmp, "sip:")) || (localtmp = strcasestr(tmp, "sips:")) ) - && (localtmp = strchr(localtmp, '@'))) { - char lhost[80], lport[80]; + if (((local_to_header = strcasestr(to_header, "sip:")) || (local_to_header = strcasestr(to_header, "sips:"))) + && (local_to_header = strchr(local_to_header, '@'))) { + char ldomain[256]; - memset(lhost, 0, sizeof(lhost)); - memset(lport, 0, sizeof(lport)); - localtmp++; + memset(ldomain, 0, sizeof(ldomain)); + local_to_header++; /* This is okey because lhost and lport are as big as tmp */ - sscanf(localtmp, "%80[^<>:; ]:%80[^<>:; ]", lhost, lport); - if (ast_strlen_zero(lhost)) { + sscanf(local_to_header, "%256[^<>; ]", ldomain); + if (ast_strlen_zero(ldomain)) { ast_log(LOG_ERROR, "Can't find the host address\n"); return 0; } - host = ast_strdupa(lhost); - if (!ast_strlen_zero(lport)) { - port = ast_strdupa(lport); - } + domain = ast_strdupa(ldomain); } } - ast_string_field_build(p, our_contact, "Transfer ", extension, host, port ? ":" : "", port ? port : ""); + ast_string_field_build(p, our_contact, "Transfer ", extension, domain); transmit_response_reliable(p, "302 Moved Temporarily", &p->initreq); sip_scheddestroy(p, SIP_TRANS_TIMEOUT); /* Make sure we stop send this reply. */