diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-01-02 20:39:38 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-01-02 20:39:38 +0000 |
commit | 48f2ce298b617f00775fb07af7936a09b5d675c6 (patch) | |
tree | 12bac3c13694a4b96be25bb64655ebc408bc138a /src | |
parent | 6ded0249148745bbce46937faba1eedf9bfb2450 (diff) | |
download | tor-48f2ce298b617f00775fb07af7936a09b5d675c6.tar.gz tor-48f2ce298b617f00775fb07af7936a09b5d675c6.zip |
Try harder to make sure we zero-out the extraneous sockaddr fields and that we set sockaddr_len. Conceivably a backport candidate, though nothing has yet been sen to break.
svn:r17849
Diffstat (limited to 'src')
-rw-r--r-- | src/common/address.c | 3 | ||||
-rw-r--r-- | src/or/eventdns.c | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/common/address.c b/src/common/address.c index a47b1228f9..1abd1a7dfb 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -68,6 +68,8 @@ tor_addr_to_sockaddr(const tor_addr_t *a, if (len < (int)sizeof(struct sockaddr_in)) return -1; sin = (struct sockaddr_in *)sa_out; + memset(sin, 0, sizeof(struct sockaddr_in)); + sin->sin_len = sizeof(struct sockaddr_in); sin->sin_family = AF_INET; sin->sin_port = htons(port); sin->sin_addr.s_addr = tor_addr_to_ipv4n(a); @@ -78,6 +80,7 @@ tor_addr_to_sockaddr(const tor_addr_t *a, return -1; sin6 = (struct sockaddr_in6 *)sa_out; memset(sin6, 0, sizeof(struct sockaddr_in6)); + sin6->sin6_len = sizeof(struct sockaddr_in6); sin6->sin6_family = AF_INET6; sin6->sin6_port = htons(port); memcpy(&sin6->sin6_addr, tor_addr_to_in6(a), sizeof(struct in6_addr)); diff --git a/src/or/eventdns.c b/src/or/eventdns.c index 3ecc795ed8..248422d22a 100644 --- a/src/or/eventdns.c +++ b/src/or/eventdns.c @@ -2300,6 +2300,9 @@ out1: int evdns_nameserver_add(unsigned long int address) { struct sockaddr_in sin; + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_len = sizeof(sin); sin.sin_addr.s_addr = htonl(address); sin.sin_port = 53; return _evdns_nameserver_add_impl((struct sockaddr*) &sin, sizeof(sin)); @@ -2377,6 +2380,8 @@ evdns_nameserver_ip_add(const char *ip_as_string) { assert(addr_part); if (is_ipv6) { struct sockaddr_in6 sin6; + memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_len = sizeof(sin6); sin6.sin6_family = AF_INET6; sin6.sin6_port = htons(port); if (1 != tor_inet_pton(AF_INET6, addr_part, &sin6.sin6_addr)) { @@ -2387,10 +2392,12 @@ evdns_nameserver_ip_add(const char *ip_as_string) { sizeof(sin6)); } else { struct sockaddr_in sin; + memset(&sin, 0, sizeof(sin)); + sin.sin_len = sizeof(sin); sin.sin_family = AF_INET; sin.sin_port = htons(port); if (!inet_aton(addr_part, &sin.sin_addr)) { - log(EVDNS_LOG_DEBUG, "anet_pton(%s) failed", addr_part); + log(EVDNS_LOG_DEBUG, "inet_pton(%s) failed", addr_part); return 4; } return _evdns_nameserver_add_impl((struct sockaddr*)&sin, |