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.
This commit is contained in:
Nick Mathewson
2011-11-23 23:04:10 -05:00
parent fbf1c5ee79
commit 3ebe960f3f
2 changed files with 10 additions and 2 deletions
+5 -2
View File
@@ -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