[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r17849: {tor} Try harder to make sure we zero-out the extraneous sockaddr (in tor/trunk/src: common or)



Author: nickm
Date: 2009-01-02 15:39:38 -0500 (Fri, 02 Jan 2009)
New Revision: 17849

Modified:
   tor/trunk/src/common/address.c
   tor/trunk/src/or/eventdns.c
Log:
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.

Modified: tor/trunk/src/common/address.c
===================================================================
--- tor/trunk/src/common/address.c	2009-01-02 19:48:55 UTC (rev 17848)
+++ tor/trunk/src/common/address.c	2009-01-02 20:39:38 UTC (rev 17849)
@@ -68,6 +68,8 @@
     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 @@
       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));

Modified: tor/trunk/src/or/eventdns.c
===================================================================
--- tor/trunk/src/or/eventdns.c	2009-01-02 19:48:55 UTC (rev 17848)
+++ tor/trunk/src/or/eventdns.c	2009-01-02 20:39:38 UTC (rev 17849)
@@ -2300,6 +2300,9 @@
 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 @@
 	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 @@
 										  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,