[tor-commits] [torsocks/master] Fix: set loopback check in host byte order

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


commit c5a7493bbdff681ba6be440d39891c090a5b1345
Author: David Goulet <dgoulet at ev0ke.net>
Date:   Thu Nov 7 20:37:11 2013 -0500

    Fix: set loopback check in host byte order
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 src/common/compat.h |    5 +++--
 src/lib/connect.c   |    2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/common/compat.h b/src/common/compat.h
index faadfdb..f8e241e 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -103,10 +103,11 @@ void tsocks_mutex_unlock(tsocks_mutex_t *m);
 
 /*
  * Shamelessly taken from linux/in.h of the libc. This is consider trivial code
- * by the GPL license thus copying it as is should be OK.
+ * by the GPL license thus copying it as is should be OK. Slight modification
+ * was made to make the check in host byte order.
  */
 #ifndef IN_LOOPBACK
-#define IN_LOOPBACK(a)      ((((long int) (a)) & 0xff000000) == 0x7f000000)
+#define IN_LOOPBACK(a)      ((((long int) (a)) & 0x000000ff) == 0x0000007f)
 #endif
 
 #endif /* TORSOCKS_COMPAT_H */
diff --git a/src/lib/connect.c b/src/lib/connect.c
index 09d3be6..ab2e082 100644
--- a/src/lib/connect.c
+++ b/src/lib/connect.c
@@ -73,7 +73,7 @@ LIBC_CONNECT_RET_TYPE tsocks_connect(LIBC_CONNECT_SIG)
 
 	/* Check if address is local IPv4. */
 	if (__addr->sa_family == AF_INET &&
-			utils_is_ipv4_local(be32toh(inet_addr->sin_addr.s_addr))) {
+			utils_is_ipv4_local(inet_addr->sin_addr.s_addr)) {
 		WARN("[connect] Connection to a local address are denied since it "
 				"might be a TCP DNS query to a local DNS server. "
 				"Rejecting it for safety reasons.");





More information about the tor-commits mailing list