[git] Assuan - branch, master, updated. libassuan-2.5.1-23-gea69c71
by NIIBE Yutaka
cvs at cvs.gnupg.org
Thu Nov 8 10:39:21 CET 2018
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "IPC library used by GnuPG".
The branch, master has been updated
via ea69c7126ff25d7d44950bf4a70467d577989a34 (commit)
from 50ed4f7d5b68e94464df7c0646c3424cee2f47de (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ea69c7126ff25d7d44950bf4a70467d577989a34
Author: NIIBE Yutaka <gniibe at fsij.org>
Date: Thu Nov 8 18:21:23 2018 +0900
socket: Use union for sockaddr access.
* src/assuan-socket.c (socks5_connect, use_socks): Use union
to access, instead of using cast to the pointer.
--
In some machine like 32-bit ARM, alignment requirement of struct
sockaddr and struct sockaddr_in (or struct sockaddr_in6) is different.
Although it is completely valid to use the value of the address by
cast here, because the object should be allocated by struct
sockaddr_in or struct sockaddr_in6 to be referred by struct
sockaddr *. But compiler doesn't assume such a usage, thus, emits
warnings.
The API with struct sockaddr * is a bit difficult thing. I examined
GNU C library for the implementation of the connect function, it uses
transparent union, the GCC feature. It would be too much, if we do
same thing here.
Signed-off-by: NIIBE Yutaka <gniibe at fsij.org>
diff --git a/src/assuan-socket.c b/src/assuan-socket.c
index 7fb2201..7644ada 100644
--- a/src/assuan-socket.c
+++ b/src/assuan-socket.c
@@ -703,14 +703,19 @@ socks5_connect (assuan_context_t ctx, assuan_fd_t sock,
struct sockaddr_in proxyaddr_in;
struct sockaddr *proxyaddr;
size_t proxyaddrlen;
- struct sockaddr_in6 *addr_in6;
- struct sockaddr_in *addr_in;
+ union {
+ struct sockaddr *addr;
+ struct sockaddr_in *addr_in;
+ struct sockaddr_in6 *addr_in6;
+ } addru;
unsigned char buffer[22+512]; /* The extra 512 gives enough space
for username/password or the
hostname. */
size_t buflen, hostnamelen;
int method;
+ addru.addr = addr;
+
/* memset (&proxyaddr_in6, 0, sizeof proxyaddr_in6); */
memset (&proxyaddr_in, 0, sizeof proxyaddr_in);
@@ -848,20 +853,16 @@ socks5_connect (assuan_context_t ctx, assuan_fd_t sock,
}
else if (addr->sa_family == AF_INET6)
{
- addr_in6 = (struct sockaddr_in6 *)addr;
-
buffer[3] = 4; /* ATYP = IPv6 */
- memcpy (buffer+ 4, &addr_in6->sin6_addr.s6_addr, 16); /* DST.ADDR */
- memcpy (buffer+20, &addr_in6->sin6_port, 2); /* DST.PORT */
+ memcpy (buffer+ 4, &addru.addr_in6->sin6_addr.s6_addr, 16); /* DST.ADDR */
+ memcpy (buffer+20, &addru.addr_in6->sin6_port, 2); /* DST.PORT */
buflen = 22;
}
else
{
- addr_in = (struct sockaddr_in *)addr;
-
buffer[3] = 1; /* ATYP = IPv4 */
- memcpy (buffer+4, &addr_in->sin_addr.s_addr, 4); /* DST.ADDR */
- memcpy (buffer+8, &addr_in->sin_port, 2); /* DST.PORT */
+ memcpy (buffer+4, &addru.addr_in->sin_addr.s_addr, 4); /* DST.ADDR */
+ memcpy (buffer+8, &addru.addr_in->sin_port, 2); /* DST.PORT */
buflen = 10;
}
ret = do_writen (ctx, sock, buffer, buflen);
@@ -931,15 +932,22 @@ socks5_connect (assuan_context_t ctx, assuan_fd_t sock,
static int
use_socks (struct sockaddr *addr)
{
+ union {
+ struct sockaddr *addr;
+ struct sockaddr_in *addr_in;
+ struct sockaddr_in6 *addr_in6;
+ } addru;
+
+ addru.addr = addr;
+
if (!tor_mode)
return 0;
else if (addr->sa_family == AF_INET6)
{
- struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)addr;
const unsigned char *s;
int i;
- s = (unsigned char *)&addr_in6->sin6_addr.s6_addr;
+ s = (unsigned char *)&addru.addr_in6->sin6_addr.s6_addr;
if (s[15] != 1)
return 1; /* Last octet is not 1 - not the loopback address. */
for (i=0; i < 15; i++, s++)
@@ -950,9 +958,7 @@ use_socks (struct sockaddr *addr)
}
else if (addr->sa_family == AF_INET)
{
- struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
-
- if (*(unsigned char*)&addr_in->sin_addr.s_addr == 127)
+ if (*(unsigned char*)&addru.addr_in->sin_addr.s_addr == 127)
return 0; /* Loopback (127.0.0.0/8) */
return 1;
-----------------------------------------------------------------------
Summary of changes:
src/assuan-socket.c | 36 +++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
hooks/post-receive
--
IPC library used by GnuPG
http://git.gnupg.org
More information about the Gnupg-commits
mailing list