Fix errors where incorrect address information was printed.
authorMark Michelson <mmichelson@digium.com>
Wed, 14 Jul 2010 22:32:29 +0000 (22:32 +0000)
committerMark Michelson <mmichelson@digium.com>
Wed, 14 Jul 2010 22:32:29 +0000 (22:32 +0000)
ast_sockaddr_stringiy_fmt (which is call by all ast_sockaddr_stringify* functions)
uses thread-local storage for storing the string that it creates. In cases where
ast_sockaddr_stringify_fmt was being called twice within the same statement, the
result of one call would be overwritten by the result of the other call. This
usually was happening in printf-like statements and was resulting in the same
stringified addressed being printed twice instead of two separate addresses.

I have fixed this by using ast_strdupa on the result of stringify functions if
they are used twice within the same statement. As far as I could tell, there were
no instances where a pointer to the result of such a call were saved anywhere, so
this is the only situation I could see where this error could occur.

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

channels/chan_sip.c
main/acl.c
main/dnsmgr.c
res/res_rtp_asterisk.c

index 6887e81..4189f53 100644 (file)
@@ -13427,8 +13427,8 @@ static enum check_auth_result register_verify(struct sip_pvt *p, struct ast_sock
                                              "Cause: AUTH_SECRET_FAILED\r\n"
                                              "Address: %s\r\n"
                                              "Port: %s\r\n",
-                                             name, ast_sockaddr_stringify_addr(addr),
-                                             ast_sockaddr_stringify_port(addr));
+                                             name, ast_strdupa(ast_sockaddr_stringify_addr(addr)),
+                                             ast_strdupa(ast_sockaddr_stringify_port(addr)));
                        }
                        break;
                case AUTH_USERNAME_MISMATCH:
@@ -13451,8 +13451,8 @@ static enum check_auth_result register_verify(struct sip_pvt *p, struct ast_sock
                                                      "Port: %s\r\n",
                                                      name,
                                                      res == AUTH_PEER_NOT_DYNAMIC ? "AUTH_PEER_NOT_DYNAMIC" : "URI_NOT_FOUND",
-                                                     ast_sockaddr_stringify_addr(addr),
-                                                     ast_sockaddr_stringify_port(addr));
+                                                     ast_strdupa(ast_sockaddr_stringify_addr(addr)),
+                                                     ast_strdupa(ast_sockaddr_stringify_port(addr)));
                                }
                        } else {
                                /* URI not found */
@@ -13467,8 +13467,8 @@ static enum check_auth_result register_verify(struct sip_pvt *p, struct ast_sock
                                                        "Address: %s\r\n"
                                                        "Port: %s\r\n",
                                                        name,
-                                                       ast_sockaddr_stringify_addr(addr),
-                                                       ast_sockaddr_stringify_port(addr));
+                                                       ast_strdupa(ast_sockaddr_stringify_addr(addr)),
+                                                       ast_strdupa(ast_sockaddr_stringify_port(addr)));
                                        }
                                } else {
                                        transmit_response(p, "404 Not found", &p->initreq);
@@ -13482,8 +13482,8 @@ static enum check_auth_result register_verify(struct sip_pvt *p, struct ast_sock
                                                        "Port: %s\r\n",
                                                        name,
                                                        (res == AUTH_USERNAME_MISMATCH) ? "AUTH_USERNAME_MISMATCH" : "URI_NOT_FOUND",
-                                                       ast_sockaddr_stringify_addr(addr),
-                                                       ast_sockaddr_stringify_port(addr));
+                                                       ast_strdupa(ast_sockaddr_stringify_addr(addr)),
+                                                       ast_strdupa(ast_sockaddr_stringify_port(addr)));
                                        }
                                }
                        }
@@ -27009,7 +27009,7 @@ static int apply_directmedia_ha(struct sip_pvt *p, const char *op)
 
        if ((res = ast_apply_ha(p->directmediaha, &them_sin)) == AST_SENSE_DENY) {
                ast_debug(3, "Reinvite %s to %s denied by directmedia ACL on %s\n",
-                       op, ast_sockaddr_stringify(&them), ast_sockaddr_stringify(&us));
+                       op, ast_strdupa(ast_sockaddr_stringify(&them)), ast_strdupa(ast_sockaddr_stringify(&us)));
        }
 
        return res;
index 082048a..663c0b2 100644 (file)
@@ -529,8 +529,8 @@ int ast_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us)
        }
        close(s);
        ast_debug(3, "For destination '%s', our source address is '%s'.\n",
-                 ast_sockaddr_stringify_addr(them),
-                 ast_sockaddr_stringify_addr(us));
+                 ast_strdupa(ast_sockaddr_stringify_addr(them)),
+                 ast_strdupa(ast_sockaddr_stringify_addr(us)));
 
        ast_sockaddr_set_port(us, port);
 
index 29ac4e3..5818c04 100644 (file)
@@ -161,8 +161,8 @@ static int dnsmgr_refresh(struct ast_dnsmgr_entry *entry, int verbose)
                        ast_sockaddr_set_port(&tmp, ast_sockaddr_port(entry->result));
                if (ast_sockaddr_cmp(&tmp, entry->result)) {
                        ast_log(LOG_NOTICE, "dnssrv: host '%s' changed from %s to %s\n",
-                                       entry->name, ast_sockaddr_stringify(entry->result),
-                                       ast_sockaddr_stringify(&tmp));
+                                       entry->name, ast_strdupa(ast_sockaddr_stringify(entry->result)),
+                                       ast_strdupa(ast_sockaddr_stringify(&tmp)));
 
                        ast_sockaddr_copy(entry->result, &tmp);
                        changed = entry->changed = 1;
index 4ab06e4..28f75c8 100644 (file)
@@ -1999,8 +1999,8 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
                                                  &addr);
                        } else  {
                                ast_debug(1, "Received RTP packet from %s, dropping due to strict RTP protection. Expected it to be from %s\n",
-                                         ast_sockaddr_stringify(&addr),
-                                         ast_sockaddr_stringify(&rtp->strict_rtp_address));
+                                         ast_strdupa(ast_sockaddr_stringify(&addr)),
+                                         ast_strdupa(ast_sockaddr_stringify(&rtp->strict_rtp_address)));
                                return &ast_null_frame;
                        }
                }