From: Jonathan Rose Date: Thu, 19 Jan 2012 21:47:22 +0000 (+0000) Subject: Eliminates doubling the :port part of SIP Notify Message-Account headers. X-Git-Tag: 10.2.0-rc1~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ee1b73567fda12b7142bbd05b5820d7ff338419;p=thirdparty%2Fasterisk.git Eliminates doubling the :port part of SIP Notify Message-Account headers. This patch prevents the domain string from getting mangled during the initreqprep step by moving the initialization to before its immediate use. It also documents this pitfall for the ast_sockaddr_stringify functions. (issue ASTERISK-19057) Reported by: Yuri Review: https://reviewboard.asterisk.org/r/1678/ ........ Merged revisions 351559 from http://svn.asterisk.org/svn/asterisk/branches/1.8 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10@351560 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 90c11076b9..34a72fb4bc 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -12959,7 +12959,7 @@ static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs, struct sip_request req; struct ast_str *out = ast_str_alloca(500); int ourport = (p->fromdomainport) ? p->fromdomainport : ast_sockaddr_port(&p->ourip); - const char *domain = S_OR(p->fromdomain, ast_sockaddr_stringify_host_remote(&p->ourip)); + const char *domain; const char *exten = S_OR(vmexten, default_vmexten); initreqprep(&req, p, SIP_NOTIFY, NULL); @@ -12967,6 +12967,8 @@ static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs, add_header(&req, "Content-Type", default_notifymime); ast_str_append(&out, 0, "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no"); + /* domain initialization occurs here because initreqprep changes ast_sockaddr_stringify string. */ + domain = S_OR(p->fromdomain, ast_sockaddr_stringify_host_remote(&p->ourip)); if (!sip_standard_port(p->socket.type, ourport)) { if (p->socket.type == SIP_TRANSPORT_UDP) { diff --git a/include/asterisk/netsock2.h b/include/asterisk/netsock2.h index 83af23a976..b541b50eba 100644 --- a/include/asterisk/netsock2.h +++ b/include/asterisk/netsock2.h @@ -185,6 +185,14 @@ int ast_sockaddr_cmp_addr(const struct ast_sockaddr *a, const struct ast_sockadd * a.b.c.d for IPv4 * [a:b:c:...:d] for IPv6. * AST_SOCKADDR_STR_PORT: port only + * + * \note The string pointer returned by this function will point to a string that + * will be changed whenever any form of ast_sockaddr_stringify_fmt is called on that + * thread. Because of this, it is important that if you use this function, you use the + * string before another use of this function is made elsewhere in the same thread. + * The easiest way to accomplish this is by immediately copying the string to a buffer + * with something like ast_strdupa. + * * \retval "(null)" \a addr is null * \retval "" An error occurred during processing * \retval string The stringified form of the address