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
This commit is contained in:
Nick Mathewson 2009-01-02 20:39:38 +00:00
parent 6ded024914
commit 48f2ce298b
2 changed files with 11 additions and 1 deletions

View File

@ -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));

View File

@ -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,