commit 1e3c81ef2471bf3bfde2701107f9c099c08f1dbf
Author: David Goulet <dgoulet(a)ev0ke.net>
Date: Sat Feb 8 15:15:43 2014 -0500
Fix: socks5 connect use connection domain and correct len
The connection we are trying to do tells us if we need to connect to Tor
in ipv6 or ipv4 since the socket that we send back needs to be connected
with the right socket family.
Signed-off-by: David Goulet <dgoulet(a)ev0ke.net>
---
src/common/socks5.c | 12 ++++++++++--…
[View More]
src/lib/torsocks.c | 2 ++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/common/socks5.c b/src/common/socks5.c
index ede3594..81806c6 100644
--- a/src/common/socks5.c
+++ b/src/common/socks5.c
@@ -123,17 +123,25 @@ ATTR_HIDDEN
int socks5_connect(struct connection *conn)
{
int ret;
+ socklen_t len;
struct sockaddr *socks5_addr = NULL;
assert(conn);
assert(conn->fd >= 0);
- switch (tsocks_config.socks5_addr.domain) {
+ /*
+ * We use the connection domain here since the connect() call MUST match
+ * the right socket family. Thus, trying to establish a connection to a
+ * remote IPv6, we have to connect to the Tor daemon in v6.
+ */
+ switch (conn->dest_addr.domain) {
case CONNECTION_DOMAIN_INET:
socks5_addr = (struct sockaddr *) &tsocks_config.socks5_addr.u.sin;
+ len = sizeof(tsocks_config.socks5_addr.u.sin);
break;
case CONNECTION_DOMAIN_INET6:
socks5_addr = (struct sockaddr *) &tsocks_config.socks5_addr.u.sin6;
+ len = sizeof(tsocks_config.socks5_addr.u.sin6);
break;
default:
ERR("Socks5 connect domain unknown %d",
@@ -145,7 +153,7 @@ int socks5_connect(struct connection *conn)
do {
/* Use the original libc connect() to the Tor. */
- ret = tsocks_libc_connect(conn->fd, socks5_addr, sizeof(*socks5_addr));
+ ret = tsocks_libc_connect(conn->fd, socks5_addr, len);
} while (ret < 0 &&
(errno == EINTR || errno == EINPROGRESS || errno == EALREADY));
if (ret < 0) {
diff --git a/src/lib/torsocks.c b/src/lib/torsocks.c
index fbb091e..8d83bcd 100644
--- a/src/lib/torsocks.c
+++ b/src/lib/torsocks.c
@@ -398,6 +398,7 @@ int tsocks_tor_resolve(const char *hostname, uint32_t *ip_addr)
ret = -errno;
goto error;
}
+ conn.dest_addr.domain = CONNECTION_DOMAIN_INET;
ret = setup_tor_connection(&conn);
if (ret < 0) {
@@ -446,6 +447,7 @@ int tsocks_tor_resolve_ptr(const char *addr, char **ip, int af)
ret = -errno;
goto error;
}
+ conn.dest_addr.domain = CONNECTION_DOMAIN_INET;
ret = setup_tor_connection(&conn);
if (ret < 0) {
[View Less]
commit b6d1e19c1bcf14c5c0521d8d431fe09489d03a47
Author: David Goulet <dgoulet(a)ev0ke.net>
Date: Thu Feb 20 11:23:12 2014 +0000
Fix: handle socket creation with multiple types
The switch case failed to handle extra type such as SOCK_NONBLOCK or/and
SOCK_CLOEXEC that are possible on Linux. This patch changes the code to
use a if/else statement to handle multiple flags.
Reported-by: Nick Mathewson <nickm(a)torproject.org>
Signed-off-by: David …
[View More]Goulet <dgoulet(a)ev0ke.net>
---
src/lib/socket.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/src/lib/socket.c b/src/lib/socket.c
index cae47ec..36d2a90 100644
--- a/src/lib/socket.c
+++ b/src/lib/socket.c
@@ -32,16 +32,14 @@ LIBC_SOCKET_RET_TYPE tsocks_socket(LIBC_SOCKET_SIG)
DBG("[socket] Creating socket with domain %d, type %d and protocol %d",
domain, type, protocol);
- switch (type) {
- case SOCK_STREAM:
+ if (type & SOCK_STREAM) {
if (domain == AF_INET6) {
/* Tor does not handle IPv6 at the moment. Reject it. */
ERR("Socket is IPv6. Tor does not handle AF_INET6 connection.");
errno = EINVAL;
return -1;
}
- break;
- default:
+ } else {
if (domain == AF_INET || domain == AF_INET6) {
/*
* Print this message only in debug mode. Very often, applications
@@ -56,7 +54,6 @@ LIBC_SOCKET_RET_TYPE tsocks_socket(LIBC_SOCKET_SIG)
errno = EINVAL;
return -1;
}
- break;
}
/* Stream socket for INET/INET6 is good so open it. */
[View Less]