diff options
author | teor (Tim Wilson-Brown) <teor2345@gmail.com> | 2015-11-19 19:08:22 +1100 |
---|---|---|
committer | teor (Tim Wilson-Brown) <teor2345@gmail.com> | 2015-11-19 19:08:22 +1100 |
commit | 53ec840bdfa3dfa421b3cecd7a90a3cd5e39d15c (patch) | |
tree | ff4f2d78fcd675db1bd390e8fd2f3750c952077a /src/test | |
parent | 913fbf8f2f9eea36ccef6100608295d8c8ce449a (diff) | |
download | tor-53ec840bdfa3dfa421b3cecd7a90a3cd5e39d15c.tar.gz tor-53ec840bdfa3dfa421b3cecd7a90a3cd5e39d15c.zip |
Make tor_ersatz_socketpair work on IPv6-only systems
(But it won't work on some systems without IPv4/IPv6 localhost
(some BSD jails) by design, to avoid creating sockets on routable
IP addresses. However, those systems likely have the AF_UNIX socketpair,
which tor prefers.)
Fixes bug #17638; bugfix on a very early tor version,
earlier than 22dba27d8dd5 (23 Nov 2004) / svn:r2943.
Patch by "teor".
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test_util.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index 187cb23125..eecc50a287 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -4342,9 +4342,6 @@ fd_is_nonblocking(tor_socket_t fd) } #endif -#define ERRNO_IS_EPROTO(e) (e == SOCK_ERRNO(EPROTONOSUPPORT)) -#define SOCK_ERR_IS_EPROTO(s) ERRNO_IS_EPROTO(tor_socket_errno(s)) - /* Test for tor_open_socket*, using IPv4 or IPv6 depending on arg. */ static void test_util_socket(void *arg) @@ -4361,7 +4358,7 @@ test_util_socket(void *arg) (void)arg; fd1 = tor_open_socket_with_extensions(domain, SOCK_STREAM, 0, 0, 0); - if (SOCK_ERR_IS_EPROTO(fd1)) { + if (tor_socket_errno(fd1) == SOCK_ERRNO(EPROTONOSUPPORT)) { /* Assume we're on an IPv4-only or IPv6-only system, and give up now. */ goto done; } @@ -4424,11 +4421,10 @@ test_util_socketpair(void *arg) int socketpair_result = 0; socketpair_result = tor_socketpair_fn(family, SOCK_STREAM, 0, fds); - if (ersatz && ERRNO_IS_EPROTO(-socketpair_result)) { - /* Assume we're on an IPv6-only system, and give up now. - * (tor_ersatz_socketpair uses IPv4.) */ - goto done; - } + /* If there is no 127.0.0.1 or ::1, tor_ersatz_socketpair will and must fail. + * Otherwise, we risk exposing a socketpair on a routable IP address. (Some + * BSD jails use a routable address for localhost. Fortunately, they have + * the real AF_UNIX socketpair.) */ tt_int_op(0, OP_EQ, socketpair_result); tt_assert(SOCKET_OK(fds[0])); tt_assert(SOCKET_OK(fds[1])); @@ -4449,8 +4445,6 @@ test_util_socketpair(void *arg) tor_close_socket(fds[1]); } -#undef SOCKET_EPROTO - static void test_util_max_mem(void *arg) { |