From 308d3002130cfb5b9ad2100dab25b0c4c83162f6 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 13 Jun 2019 21:14:36 +1000 Subject: address/resolve: try harder to avoid returning uninitialised data Cleanup after 30721. --- src/lib/net/resolve.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/lib/net/resolve.c') diff --git a/src/lib/net/resolve.c b/src/lib/net/resolve.c index a70fb0a823..9555720883 100644 --- a/src/lib/net/resolve.c +++ b/src/lib/net/resolve.c @@ -47,6 +47,11 @@ tor_lookup_hostname,(const char *name, uint32_t *addr)) tor_addr_t myaddr; int ret; + if (BUG(!addr)) + return -1; + + *addr = 0; + if ((ret = tor_addr_lookup(name, AF_INET, &myaddr))) return ret; @@ -250,7 +255,7 @@ int tor_addr_port_lookup(const char *s, tor_addr_t *addr_out, uint16_t *port_out) { tor_addr_t addr; - uint16_t portval; + uint16_t portval = 0; char *tmp = NULL; int rv = 0; @@ -273,6 +278,10 @@ tor_addr_port_lookup(const char *s, tor_addr_t *addr_out, uint16_t *port_out) return 0; err: + /* Clear the address and port on error */ + memset(addr_out, 0, sizeof(tor_addr_t)); + if (port_out) + *port_out = 0; tor_free(tmp); return -1; } -- cgit v1.2.3-54-g00ecf