]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Eliminates doubling the :port part of SIP Notify Message-Account headers.
authorJonathan Rose <jrose@digium.com>
Thu, 19 Jan 2012 21:46:31 +0000 (21:46 +0000)
committerJonathan Rose <jrose@digium.com>
Thu, 19 Jan 2012 21:46:31 +0000 (21:46 +0000)
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/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@351559 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c
include/asterisk/netsock2.h

index 9f5e94a5a6ff2b0755832d5dddf484f38a002f81..fabef6ca46383c6562de5f54ca79a9d6a5f8b0bc 100644 (file)
@@ -12680,7 +12680,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);
@@ -12688,6 +12688,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) {
index 556e6235f422488ec68d1d9934b26d25d8543f14..4a6ab2ca3bfbdb64b2bae449e35901109e2ab045 100644 (file)
@@ -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