From 51475aee57523318d0b0a9e47dedad89ef1b578c Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 10 Sep 2019 10:53:39 -0400 Subject: [PATCH 1/2] fp.c: Suppress float-conversion warnings on FreeBSD. We used to do this on Windows only, but it appears to affect multiple platforms when building with certain versions of GCC, and a common pattern for defining the floating-point classifier functions. Fixes part of 31687. I'm calling this a bugfux on 31687, when we started suppressing these warnings on Windows. --- changes/ticket31687_1 | 4 ++++ src/lib/math/fp.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changes/ticket31687_1 diff --git a/changes/ticket31687_1 b/changes/ticket31687_1 new file mode 100644 index 0000000000..2f4d440974 --- /dev/null +++ b/changes/ticket31687_1 @@ -0,0 +1,4 @@ + o Minor bugfixes (compilation): + - Suppress spurious float-conversion warnings from GCC when calling + floating-point classifier functions on FreeBSD. Fixes part of bug + 31687; bugfix on 0.3.1.5-alpha. diff --git a/src/lib/math/fp.c b/src/lib/math/fp.c index 4419635dfe..eafad358c3 100644 --- a/src/lib/math/fp.c +++ b/src/lib/math/fp.c @@ -62,12 +62,16 @@ clamp_double_to_int64(double number) { int exponent; -#if defined(MINGW_ANY) && GCC_VERSION >= 409 +#if (defined(MINGW_ANY)||defined(__FreeBSD__)) && GCC_VERSION >= 409 /* Mingw's math.h uses gcc's __builtin_choose_expr() facility to declare isnan, isfinite, and signbit. But as implemented in at least some versions of gcc, __builtin_choose_expr() can generate type warnings even from branches that are not taken. So, suppress those warnings. + + FreeBSD's math.h uses an __fp_type_select() macro, which dispatches + based on sizeof -- again, this can generate type warnings from + branches that are not taken. */ #define PROBLEMATIC_FLOAT_CONVERSION_WARNING DISABLE_GCC_WARNING(float-conversion) From 97f7efa9e3316e4e8970a87a1ee53fd4fd0075d8 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 10 Sep 2019 11:07:25 -0400 Subject: [PATCH 2/2] pf: when extracting an IPv6 address, make sure we got an IPv6 address Our code assumes that when we're configured to get IPv6 addresses out of a TRANS_PF transparent proxy connection, we actually will. But we didn't check that, and so FreeBSD started warning us about a potential NULL pointer dereference. Fixes part of bug 31687; bugfix on 0.2.3.4-alpha when this code was added. --- changes/ticket31687_2 | 5 +++++ src/core/or/connection_edge.c | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 changes/ticket31687_2 diff --git a/changes/ticket31687_2 b/changes/ticket31687_2 new file mode 100644 index 0000000000..eadc698275 --- /dev/null +++ b/changes/ticket31687_2 @@ -0,0 +1,5 @@ + o Minor bugfixes (FreeBSD, PF-based proxy, IPv6): + - When extracting an IPv6 address from a PF-based proxy, verify + that we are actually configured to receive an IPv6 address, + and log an internal error if not. Fixes part of bug 31687; + bugfix on 0.2.3.4-alpha. diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c index e4b3455d13..7cc67d7f5e 100644 --- a/src/core/or/connection_edge.c +++ b/src/core/or/connection_edge.c @@ -2547,8 +2547,11 @@ destination_from_pf(entry_connection_t *conn, socks_request_t *req) } else if (proxy_sa->sa_family == AF_INET6) { struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)proxy_sa; pnl.af = AF_INET6; - memcpy(&pnl.saddr.v6, tor_addr_to_in6(&ENTRY_TO_CONN(conn)->addr), - sizeof(struct in6_addr)); + const struct in6_addr *dest_in6 = + tor_addr_to_in6(&ENTRY_TO_CONN(conn)->addr); + if (BUG(!dest_in6)) + return -1; + memcpy(&pnl.saddr.v6, dest_in6, sizeof(struct in6_addr)); pnl.sport = htons(ENTRY_TO_CONN(conn)->port); memcpy(&pnl.daddr.v6, &sin6->sin6_addr, sizeof(struct in6_addr)); pnl.dport = sin6->sin6_port;