commit 506f1dc40cc2f7991f4d27285d050daf2f7ff14e Author: David Goulet dgoulet@ev0ke.net Date: Wed Mar 12 20:08:03 2014 -0400
Fix: strict aliasing in library
Fixes #28
Signed-off-by: David Goulet dgoulet@ev0ke.net --- src/lib/gethostbyname.c | 8 ++++---- src/lib/recv.c | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/lib/gethostbyname.c b/src/lib/gethostbyname.c index 6b4ea21..322f398 100644 --- a/src/lib/gethostbyname.c +++ b/src/lib/gethostbyname.c @@ -94,8 +94,8 @@ LIBC_GETHOSTBYNAME_RET_TYPE tsocks_gethostbyname(LIBC_GETHOSTBYNAME_SIG) tsocks_he.h_addrtype = AF_INET; tsocks_he.h_addr_list = tsocks_he_addr_list;
- DBG("Hostname %s resolved to %s", name, - inet_ntoa(*((struct in_addr *) &ip))); + DBG("[gethostbyname] Hostname %s resolved to %u.%u.%u.%u", name, + ip & 0XFF, (ip >> 8) & 0XFF, (ip >> 16) & 0XFF, (ip >> 24) & 0xFF);
errno = 0; return &tsocks_he; @@ -368,8 +368,8 @@ LIBC_GETHOSTBYNAME_R_RET_TYPE tsocks_gethostbyname_r(LIBC_GETHOSTBYNAME_R_SIG) he->h_length = sizeof(in_addr_t); he->h_addrtype = AF_INET;
- DBG("[gethostbyname_r] Hostname %s resolved to %s", name, - inet_ntoa(*((struct in_addr *) &ip))); + DBG("[gethostbyname_r] Hostname %s resolved to %u.%u.%u.%u", name, + ip & 0XFF, (ip >> 8) & 0XFF, (ip >> 16) & 0XFF, (ip >> 24) & 0xFF);
error: return ret; diff --git a/src/lib/recv.c b/src/lib/recv.c index b041f6d..036fa91 100644 --- a/src/lib/recv.c +++ b/src/lib/recv.c @@ -67,7 +67,7 @@ LIBC_RECVMSG_RET_TYPE tsocks_recvmsg(LIBC_RECVMSG_SIG) * further. */ if (cmsg->cmsg_type == SCM_RIGHTS || cmsg->cmsg_level == SOL_SOCKET) { - struct sockaddr_storage addr; + struct sockaddr addr; socklen_t addrlen; sa_family_t family = AF_UNSPEC;
@@ -75,14 +75,13 @@ LIBC_RECVMSG_RET_TYPE tsocks_recvmsg(LIBC_RECVMSG_SIG)
/* Get socket protocol family. */ addrlen = sizeof(addr); - ret = getsockname(fd, (struct sockaddr *) &addr, &addrlen); + ret = getsockname(fd, &addr, &addrlen); if (ret < 0) { /* Use the getsockname() errno value. */ goto end; }
- family = ((struct sockaddr *) &addr)->sa_family; - + family = addr.sa_family; if (family == AF_INET || family == AF_INET6) { ERR("[recvmsg] Inet socket passing detected. Aborting everything! " "A non Tor socket could be used thus leaking information.");
tor-commits@lists.torproject.org