int socketpair_result = 0;
socketpair_result = tor_socketpair_fn(family, SOCK_STREAM, 0, fds);
- if (-socketpair_result == SOCK_ERRNO(EINVAL)) {
+ /* 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.) */
- /* Assume we're on an IPv6-only system, and give up now.
- * (tor_ersatz_socketpair uses IPv4.) */
+ if (ersatz && ERRNO_IS_EPROTO(-socketpair_result)) {
+ /* In my testing, an IPv6-only FreeBSD jail without ::1 returned EINVAL.
+ * Assume we're on a machine without 127.0.0.1 or ::1 and give up now. */
goto done;
}
tt_int_op(0, OP_EQ, socketpair_result);
++
tt_assert(SOCKET_OK(fds[0]));
tt_assert(SOCKET_OK(fds[1]));
tt_int_op(get_n_open_sockets(), OP_EQ, n + 2);