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/


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@351559 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Jonathan Rose
2012-01-19 21:46:31 +00:00
parent eb10c11063
commit 5d9b4af4e2
2 changed files with 11 additions and 1 deletions

View 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) {

View 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