Merged revisions 287895 via svnmerge from
authorRussell Bryant <russell@russellbryant.com>
Tue, 21 Sep 2010 15:45:46 +0000 (15:45 +0000)
committerRussell Bryant <russell@russellbryant.com>
Tue, 21 Sep 2010 15:45:46 +0000 (15:45 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.8

........
  r287895 | russell | 2010-09-21 10:43:33 -0500 (Tue, 21 Sep 2010) | 10 lines

  Don't use ast_strdupa() from within the arguments to a function.

  (closes issue #17902)
  Reported by: afried
  Patches:
        issue_17902.rev1.txt uploaded by russell (license 2)
  Tested by: russell

  Review: https://reviewboard.asterisk.org/r/927/
........

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

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

index 31bfc1d..5c833b7 100644 (file)
@@ -13864,6 +13864,8 @@ static enum check_auth_result register_verify(struct sip_pvt *p, struct ast_sock
                        /* Wrong password in authentication. Go away, don't try again until you fixed it */
                        transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq);
                        if (global_authfailureevents) {
+                               const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr));
+                               const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
                                manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
                                              "ChannelType: SIP\r\n"
                                              "Peer: SIP/%s\r\n"
@@ -13871,8 +13873,7 @@ 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_strdupa(ast_sockaddr_stringify_addr(addr)),
-                                             ast_strdupa(ast_sockaddr_stringify_port(addr)));
+                                             name, peer_addr, peer_port);
                        }
                        break;
                case AUTH_USERNAME_MISMATCH:
@@ -13886,6 +13887,8 @@ static enum check_auth_result register_verify(struct sip_pvt *p, struct ast_sock
                        if (sip_cfg.alwaysauthreject) {
                                transmit_fake_auth_response(p, SIP_REGISTER, &p->initreq, XMIT_UNRELIABLE);
                                if (global_authfailureevents) {
+                                       const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr));
+                                       const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
                                        manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
                                                      "ChannelType: SIP\r\n"
                                                      "Peer: SIP/%s\r\n"
@@ -13895,14 +13898,15 @@ 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_strdupa(ast_sockaddr_stringify_addr(addr)),
-                                                     ast_strdupa(ast_sockaddr_stringify_port(addr)));
+                                                     peer_addr, peer_port);
                                }
                        } else {
                                /* URI not found */
                                if (res == AUTH_PEER_NOT_DYNAMIC) {
                                        transmit_response(p, "403 Forbidden", &p->initreq);
                                        if (global_authfailureevents) {
+                                               const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr));
+                                               const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
                                                manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
                                                        "ChannelType: SIP\r\n"
                                                        "Peer: SIP/%s\r\n"
@@ -13910,13 +13914,13 @@ static enum check_auth_result register_verify(struct sip_pvt *p, struct ast_sock
                                                        "Cause: AUTH_PEER_NOT_DYNAMIC\r\n"
                                                        "Address: %s\r\n"
                                                        "Port: %s\r\n",
-                                                       name,
-                                                       ast_strdupa(ast_sockaddr_stringify_addr(addr)),
-                                                       ast_strdupa(ast_sockaddr_stringify_port(addr)));
+                                                       name, peer_addr, peer_port);
                                        }
                                } else {
                                        transmit_response(p, "404 Not found", &p->initreq);
                                        if (global_authfailureevents) {
+                                               const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr));
+                                               const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
                                                manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
                                                        "ChannelType: SIP\r\n"
                                                        "Peer: SIP/%s\r\n"
@@ -13926,8 +13930,7 @@ 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_strdupa(ast_sockaddr_stringify_addr(addr)),
-                                                       ast_strdupa(ast_sockaddr_stringify_port(addr)));
+                                                       peer_addr, peer_port);
                                        }
                                }
                        }
@@ -16937,9 +16940,9 @@ static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_
                const char *prefix = "Localnet:";
 
                for (d = localaddr; d ; prefix = "", d = d->next) {
-                       ast_cli(a->fd, "  %-24s%s/%s\n",
-                           prefix, ast_strdupa(ast_sockaddr_stringify_addr(&d->addr)),
-                           ast_strdupa(ast_sockaddr_stringify_addr(&d->netmask)));
+                       const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&d->addr));
+                       const char *mask = ast_strdupa(ast_sockaddr_stringify_addr(&d->netmask));
+                       ast_cli(a->fd, "  %-24s%s/%s\n", prefix, addr, mask);
                }
        }
        ast_cli(a->fd, "\nGlobal Signalling Settings:\n");
@@ -27332,8 +27335,11 @@ static int apply_directmedia_ha(struct sip_pvt *p, const char *op)
        ast_rtp_instance_get_local_address(p->rtp, &us);
 
        if ((res = ast_apply_ha(p->directmediaha, &them)) == AST_SENSE_DENY) {
+               const char *us_addr = ast_strdupa(ast_sockaddr_stringify(&us));
+               const char *them_addr = ast_strdupa(ast_sockaddr_stringify(&them));
+
                ast_debug(3, "Reinvite %s to %s denied by directmedia ACL on %s\n",
-                       op, ast_strdupa(ast_sockaddr_stringify(&them)), ast_strdupa(ast_sockaddr_stringify(&us)));
+                       op, them_addr, us_addr);
        }
 
        return res;
index 278647b..fa028dc 100644 (file)
@@ -488,7 +488,12 @@ struct ast_ha *ast_append_ha(const char *sense, const char *stuff, struct ast_ha
                ret = ha;
        }
 
-       ast_debug(1, "%s/%s sense %d appended to acl for peer\n", ast_strdupa(ast_sockaddr_stringify(&ha->addr)), ast_strdupa(ast_sockaddr_stringify(&ha->netmask)), ha->sense);
+       {
+               const char *addr = ast_strdupa(ast_sockaddr_stringify(&ha->addr));
+               const char *mask = ast_strdupa(ast_sockaddr_stringify(&ha->netmask));
+
+               ast_debug(1, "%s/%s sense %d appended to acl for peer\n", addr, mask, ha->sense);
+       }
 
        return ret;
 }
@@ -701,9 +706,14 @@ int ast_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us)
                return -1;
        }
        close(s);
-       ast_debug(3, "For destination '%s', our source address is '%s'.\n",
-                 ast_strdupa(ast_sockaddr_stringify_addr(them)),
-                 ast_strdupa(ast_sockaddr_stringify_addr(us)));
+
+       {
+               const char *them_addr = ast_strdupa(ast_sockaddr_stringify_addr(them));
+               const char *us_addr = ast_strdupa(ast_sockaddr_stringify_addr(us));
+
+               ast_debug(3, "For destination '%s', our source address is '%s'.\n",
+                               them_addr, us_addr);
+       }
 
        ast_sockaddr_set_port(us, port);
 
index 7036708..7fb5f88 100644 (file)
@@ -151,22 +151,26 @@ int ast_dnsmgr_lookup(const char *name, struct ast_sockaddr *result, struct ast_
  */
 static int dnsmgr_refresh(struct ast_dnsmgr_entry *entry, int verbose)
 {
-       struct ast_sockaddr tmp;
+       struct ast_sockaddr tmp = { .len = 0, };
        int changed = 0;
 
        ast_mutex_lock(&entry->lock);
-       if (verbose)
-               ast_verb(3, "refreshing '%s'\n", entry->name);
 
-       memset(&tmp, 0, sizeof(tmp));
+       if (verbose) {
+               ast_verb(3, "refreshing '%s'\n", entry->name);
+       }
 
        if (!ast_get_ip_or_srv(&tmp, entry->name, entry->service)) {
-               if (!ast_sockaddr_port(&tmp))
+               if (!ast_sockaddr_port(&tmp)) {
                        ast_sockaddr_set_port(&tmp, ast_sockaddr_port(entry->result));
+               }
+
                if (ast_sockaddr_cmp(&tmp, entry->result)) {
+                       const char *old_addr = ast_strdupa(ast_sockaddr_stringify(entry->result));
+                       const char *new_addr = ast_strdupa(ast_sockaddr_stringify(&tmp));
+
                        ast_log(LOG_NOTICE, "dnssrv: host '%s' changed from %s to %s\n",
-                                       entry->name, ast_strdupa(ast_sockaddr_stringify(entry->result)),
-                                       ast_strdupa(ast_sockaddr_stringify(&tmp)));
+                                       entry->name, old_addr, new_addr);
 
                        ast_sockaddr_copy(entry->result, &tmp);
                        changed = entry->changed = 1;
@@ -174,6 +178,7 @@ static int dnsmgr_refresh(struct ast_dnsmgr_entry *entry, int verbose)
        }
 
        ast_mutex_unlock(&entry->lock);
+
        return changed;
 }
 
index 6ddd339..6437948 100644 (file)
@@ -2012,9 +2012,12 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
                                ast_sockaddr_copy(&rtp->strict_rtp_address,
                                                  &addr);
                        } else  {
+                               const char *real_addr = ast_strdupa(ast_sockaddr_stringify(&addr));
+                               const char *expected_addr = ast_strdupa(ast_sockaddr_stringify(&rtp->strict_rtp_address));
+
                                ast_debug(1, "Received RTP packet from %s, dropping due to strict RTP protection. Expected it to be from %s\n",
-                                         ast_strdupa(ast_sockaddr_stringify(&addr)),
-                                         ast_strdupa(ast_sockaddr_stringify(&rtp->strict_rtp_address)));
+                                               real_addr, expected_addr);
+
                                return &ast_null_frame;
                        }
                }