[tor-commits] [tor/release-0.2.2] Detect tor_addr_to_str failure in tor_dup_addr.

arma at torproject.org arma at torproject.org
Thu Dec 8 22:24:17 UTC 2011


commit 3ebe960f3f734322ea3ea471ca6abceb245ca322
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Nov 23 23:04:10 2011 -0500

    Detect tor_addr_to_str failure in tor_dup_addr.
    
    This avoids a possible strdup of an uninitialized buffer.
    
    Fixes 4529; fix on 0.2.1.3-alpha; reported by troll_un.
---
 changes/bug4529      |    5 +++++
 src/common/address.c |    7 +++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/changes/bug4529 b/changes/bug4529
new file mode 100644
index 0000000..89d10b2
--- /dev/null
+++ b/changes/bug4529
@@ -0,0 +1,5 @@
+  o Minor bufixes:
+    - If we had ever tried to call tor_addr_to_str on an address of
+      unknown type, we would have done a strdup on an uninitialized
+      buffer. Now we won't. Fixes bug 4529; bugfix on 0.2.1.3-alpha.
+      Reported by "troll_un".
diff --git a/src/common/address.c b/src/common/address.c
index 7fc7301..46ccb1f 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -945,8 +945,11 @@ char *
 tor_dup_addr(const tor_addr_t *addr)
 {
   char buf[TOR_ADDR_BUF_LEN];
-  tor_addr_to_str(buf, addr, sizeof(buf), 0);
-  return tor_strdup(buf);
+  if (tor_addr_to_str(buf, addr, sizeof(buf), 0)) {
+    return tor_strdup(buf);
+  } else {
+    return tor_strdup("<unknown address type>");
+  }
 }
 
 /** Return a string representing the address <b>addr</b>.  This string is





More information about the tor-commits mailing list