aboutsummaryrefslogtreecommitdiff
path: root/src/lib/net/resolve.c
diff options
context:
space:
mode:
authorteor <teor@torproject.org>2019-06-13 21:14:36 +1000
committerNick Mathewson <nickm@torproject.org>2019-06-26 09:55:37 -0400
commit308d3002130cfb5b9ad2100dab25b0c4c83162f6 (patch)
tree00ec6e3c6bf975198933da0e0d87be39e55fb5fa /src/lib/net/resolve.c
parentfb93646c1c2e97a978045019403d9cfb43f55cbc (diff)
downloadtor-308d3002130cfb5b9ad2100dab25b0c4c83162f6.tar.gz
tor-308d3002130cfb5b9ad2100dab25b0c4c83162f6.zip
address/resolve: try harder to avoid returning uninitialised data
Cleanup after 30721.
Diffstat (limited to 'src/lib/net/resolve.c')
-rw-r--r--src/lib/net/resolve.c11
1 files changed, 10 insertions, 1 deletions
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;
}