mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Consistently format addresses in node_get_address_string
Also, don't write to a buffer with length zero.
This commit is contained in:
+5
-5
@@ -863,13 +863,13 @@ node_get_prim_addr_ipv4h(const node_t *node)
|
||||
void
|
||||
node_get_address_string(const node_t *node, char *buf, size_t len)
|
||||
{
|
||||
if (node->ri) {
|
||||
strlcpy(buf, fmt_addr32(node->ri->addr), len);
|
||||
} else if (node->rs) {
|
||||
uint32_t ipv4_addr = node_get_prim_addr_ipv4h(node);
|
||||
|
||||
if (tor_addr_is_valid_ipv4h(ipv4_addr, 0)) {
|
||||
tor_addr_t addr;
|
||||
tor_addr_from_ipv4h(&addr, node->rs->addr);
|
||||
tor_addr_from_ipv4h(&addr, ipv4_addr);
|
||||
tor_addr_to_str(buf, &addr, len, 0);
|
||||
} else {
|
||||
} else if (len > 0) {
|
||||
buf[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user