From 718252b253049f84fefa14e212cf560838e6607c Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 20 Jul 2011 13:16:06 -0400 Subject: [PATCH] Check return value in fmt_addr Previously, if tor_addr_to_str() returned NULL, we would reuse the last value returned by fmt_addr(). (This could happen if we were erroneously asked to format an AF_UNSPEC address.) Now instead we return "???". --- changes/fmt_addr | 4 ++++ src/common/address.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changes/fmt_addr diff --git a/changes/fmt_addr b/changes/fmt_addr new file mode 100644 index 0000000000..b88c9e1bf4 --- /dev/null +++ b/changes/fmt_addr @@ -0,0 +1,4 @@ + o Minor bugfixes: + - When unable to format an address as a string, report its value + as "???" rather than reusing the last formatted address. Bugfix + on 0.2.1.5-alpha. diff --git a/src/common/address.c b/src/common/address.c index 1c725393d9..7fc7301051 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -958,8 +958,10 @@ fmt_addr(const tor_addr_t *addr) { static char buf[TOR_ADDR_BUF_LEN]; if (!addr) return ""; - tor_addr_to_str(buf, addr, sizeof(buf), 0); - return buf; + if (tor_addr_to_str(buf, addr, sizeof(buf), 0)) + return buf; + else + return "???"; } /** Convert the string in src to a tor_addr_t addr. The string