[tor-commits] [torsocks/master] Fix: handle socket creation with multiple types

dgoulet at torproject.org dgoulet at torproject.org
Fri Apr 4 22:40:27 UTC 2014


commit b6d1e19c1bcf14c5c0521d8d431fe09489d03a47
Author: David Goulet <dgoulet at 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 at torproject.org>
    Signed-off-by: David Goulet <dgoulet at 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. */





More information about the tor-commits mailing list