]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Make tor_addr_copy() conform to memcpy requirements
authorNick Mathewson <nickm@torproject.org>
Tue, 9 Feb 2010 17:32:10 +0000 (12:32 -0500)
committerNick Mathewson <nickm@torproject.org>
Tue, 9 Feb 2010 17:32:10 +0000 (12:32 -0500)
The src and dest of a memcpy() call aren't supposed to overlap,
but we were sometimes calling tor_addr_copy() as a no-op.

Also, tor_addr_assign was a redundant copy of tor_addr_copy(); this patch
removes it.

src/common/address.c
src/common/address.h
src/or/connection_edge.c
src/or/dns.c

index 2fe013a2cd188af0b776492af101b699fb5d2b0c..7729f29147fb0b9eb7fd1d4cfb8f9414a4e94fd1 100644 (file)
@@ -760,6 +760,8 @@ tor_addr_from_in6(tor_addr_t *dest, const struct in6_addr *in6)
 void
 tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src)
 {
+  if (src == dest)
+    return;
   tor_assert(src);
   tor_assert(dest);
   memcpy(dest, src, sizeof(tor_addr_t));
@@ -912,13 +914,6 @@ tor_dup_addr(const tor_addr_t *addr)
   return tor_strdup(buf);
 }
 
-/** Copy the address in <b>src</b> to <b>dest</b> */
-void
-tor_addr_assign(tor_addr_t *dest, const tor_addr_t *src)
-{
-  memcpy(dest, src, sizeof(tor_addr_t));
-}
-
 /** Return a string representing the address <b>addr</b>.  This string is
  * statically allocated, and must not be freed.  Each call to
  * <b>fmt_addr</b> invalidates the last result of the function.  This
index 9480d6427468261d0669b2ff8589431a622fa50a..4d4c91075b45a992f579898e9ac51203179d428a 100644 (file)
@@ -107,7 +107,6 @@ tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u)
 
 int tor_addr_lookup(const char *name, uint16_t family, tor_addr_t *addr_out);
 char *tor_dup_addr(const tor_addr_t *addr) ATTR_MALLOC;
-void tor_addr_assign(tor_addr_t *dest, const tor_addr_t *src);
 const char *fmt_addr(const tor_addr_t *addr);
 int get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr);
 
index 8447853fc154522ca3e82f31be8838cc05186616..8bb6742dcaeff4013ffc1fae83de79971ed41876 100644 (file)
@@ -2607,7 +2607,7 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
   if (rh.command == RELAY_COMMAND_BEGIN_DIR) {
     tor_assert(or_circ);
     if (or_circ->p_conn && !tor_addr_is_null(&or_circ->p_conn->real_addr))
-      tor_addr_assign(&n_stream->_base.addr, &or_circ->p_conn->real_addr);
+      tor_addr_copy(&n_stream->_base.addr, &or_circ->p_conn->real_addr);
     return connection_exit_connect_dir(n_stream);
   }
 
@@ -2779,7 +2779,7 @@ connection_exit_connect_dir(edge_connection_t *exitconn)
 
   dirconn = dir_connection_new(AF_INET);
 
-  tor_addr_assign(&dirconn->_base.addr, &exitconn->_base.addr);
+  tor_addr_copy(&dirconn->_base.addr, &exitconn->_base.addr);
   dirconn->_base.port = 0;
   dirconn->_base.address = tor_strdup(exitconn->_base.address);
   dirconn->_base.type = CONN_TYPE_DIR;
index 08bff763a349402b9d798bec7d0c8a69fc5e23e4..c055c885b7dfaf5df21c5ed60462e28314175c59 100644 (file)
@@ -655,7 +655,7 @@ dns_resolve_impl(edge_connection_t *exitconn, int is_resolve,
    * know the answer. */
   if (tor_addr_from_str(&addr, exitconn->_base.address) >= 0) {
     if (tor_addr_family(&addr) == AF_INET) {
-      tor_addr_assign(&exitconn->_base.addr, &addr);
+      tor_addr_copy(&exitconn->_base.addr, &addr);
       exitconn->address_ttl = DEFAULT_DNS_TTL;
       return 1;
     } else {