From 6c3c94357c196681ceda773425e18161da8cfdef Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 6 May 2020 10:24:21 -0400 Subject: Add a fallthrough macro. This macro defers to __attribute__((fallthrough)) on GCC (and clang). Previously we had been using GCC's magic /* fallthrough */ comments, but clang very sensibly doesn't accept those. Since not all compiler recognize it, we only define it when our configure script detects that it works. Part of a fix for 34078. --- configure.ac | 16 ++++++++++++++++ src/lib/cc/compat_compiler.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/configure.ac b/configure.ac index bc434ed836..a441162f4c 100644 --- a/configure.ac +++ b/configure.ac @@ -356,6 +356,22 @@ if test "$tor_cv_c_c99_designated_init" != "yes"; then AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x]) fi +saved_CFLAGS="$CFLAGS" +CFLAGS="$CFLAGS -Werror" +AC_CACHE_CHECK([for __attribute__((fallthrough))], + tor_cv_c_attr_fallthrough, + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([extern int x; void fn(void) ;], + [[ switch (x) { case 1: fn(); __attribute__((fallthrough)); + case 2: fn(); break; } ]])], + [tor_cv_c_attr_fallthrough=yes], + [tor_cv_c_attr_fallthrough=no] )]) +CFLAGS="$saved_CFLAGS" + +if test "$tor_cv_c_attr_fallthrough" == "yes"; then + AC_DEFINE(HAVE_ATTR_FALLTHROUGH, [1], [defined if we have the fallthrough attribute.]) +fi + TORUSER=_tor AC_ARG_WITH(tor-user, AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]), diff --git a/src/lib/cc/compat_compiler.h b/src/lib/cc/compat_compiler.h index 3a0f307186..fbe6a38f1f 100644 --- a/src/lib/cc/compat_compiler.h +++ b/src/lib/cc/compat_compiler.h @@ -50,6 +50,12 @@ #define CHECK_SCANF(formatIdx, firstArg) #endif /* defined(__GNUC__) */ +#if defined(HAVE_ATTR_FALLTHROUGH) +#define FALLTHROUGH __attribute__((fallthrough)) +#else +#define FALLTHROUGH +#endif + /* What GCC do we have? */ #ifdef __GNUC__ #define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) -- cgit v1.2.3-54-g00ecf From 75547c01a37c65398f8d31ee9cb38d865119cd28 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 6 May 2020 10:32:35 -0400 Subject: Replace a "fall through" comment that was outside a switch. --- src/feature/dirauth/keypin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/feature/dirauth/keypin.c b/src/feature/dirauth/keypin.c index 667feb2c03..06cb9ba1ff 100644 --- a/src/feature/dirauth/keypin.c +++ b/src/feature/dirauth/keypin.c @@ -267,7 +267,7 @@ keypin_add_or_replace_entry_in_map(keypin_ent_t *ent) } tor_free(ent2); r = -1; - /* Fall through */ + /* Note lack of return here: we fall through to the next line. */ } keypin_add_entry_to_map(ent); -- cgit v1.2.3-54-g00ecf From 9fe23b8672fdc4da64a99acf55b47193375b9562 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 6 May 2020 10:35:36 -0400 Subject: Replace some "fall through" comments not at the end of a case. --- src/core/proto/proto_socks.c | 5 ++++- src/feature/relay/dns.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/proto/proto_socks.c b/src/core/proto/proto_socks.c index 8b78ed44c2..a6493366e6 100644 --- a/src/core/proto/proto_socks.c +++ b/src/core/proto/proto_socks.c @@ -1067,7 +1067,10 @@ parse_socks_client(const uint8_t *data, size_t datalen, log_info(LD_NET, "SOCKS 5 client: need authentication."); *drain_out = -1; return 2; - /* fall through */ + default: + /* This wasn't supposed to be exhaustive; there are other + * authentication methods too. */ + ; } *reason = tor_strdup("server doesn't support any of our available " diff --git a/src/feature/relay/dns.c b/src/feature/relay/dns.c index cc9f4cf490..38395862c3 100644 --- a/src/feature/relay/dns.c +++ b/src/feature/relay/dns.c @@ -546,7 +546,7 @@ send_resolved_cell,(edge_connection_t *conn, uint8_t answer_type, break; } else { answer_type = RESOLVED_TYPE_ERROR; - /* fall through. */ + /* We let this fall through and treat it as an error. */ } /* Falls through. */ case RESOLVED_TYPE_ERROR_TRANSIENT: -- cgit v1.2.3-54-g00ecf From 37b8324ed3147e184567ab23ac507ba68837093d Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 6 May 2020 10:38:59 -0400 Subject: include compat_compiler for ed25519_donna --- src/ext/ed25519/donna/ed25519_tor.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ext/ed25519/donna/ed25519_tor.c b/src/ext/ed25519/donna/ed25519_tor.c index 7f5ab398d8..a5bb6f4e21 100644 --- a/src/ext/ed25519/donna/ed25519_tor.c +++ b/src/ext/ed25519/donna/ed25519_tor.c @@ -35,6 +35,9 @@ #define ED25519_FN(fn) ED25519_FN2(fn,ED25519_SUFFIX) #include "orconfig.h" + +#include "lib/cc/compat_compiler.h" + #include "ed25519-donna.h" #include "ed25519_donna_tor.h" #include "ed25519-randombytes.h" @@ -366,4 +369,3 @@ ed25519_donna_scalarmult_with_group_order(unsigned char *out, } #include "test-internals.c" - -- cgit v1.2.3-54-g00ecf From 8798c0a94a9cd5ac24fed349da37f8e8dc8f64fd Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 6 May 2020 10:42:17 -0400 Subject: address.c: add a single (harmless) missing break; --- src/lib/net/address.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/net/address.c b/src/lib/net/address.c index a2d234b742..076ca3eb34 100644 --- a/src/lib/net/address.c +++ b/src/lib/net/address.c @@ -926,6 +926,7 @@ tor_addr_copy_tight(tor_addr_t *dest, const tor_addr_t *src) break; case AF_INET6: memcpy(dest->addr.in6_addr.s6_addr, src->addr.in6_addr.s6_addr, 16); + break; case AF_UNSPEC: break; // LCOV_EXCL_START -- cgit v1.2.3-54-g00ecf From 3d3641152b5d8a4bf8587dec640bda3d440b7c36 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 6 May 2020 14:47:38 -0400 Subject: Remove an incorrect "Fall through" comment. --- src/lib/crypt_ops/crypto_digest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypt_ops/crypto_digest.c b/src/lib/crypt_ops/crypto_digest.c index 26f06c6c79..1b2724b2aa 100644 --- a/src/lib/crypt_ops/crypto_digest.c +++ b/src/lib/crypt_ops/crypto_digest.c @@ -100,7 +100,7 @@ library_supports_digest(digest_algorithm_t alg) switch (alg) { case DIGEST_SHA1: /* Fall through */ case DIGEST_SHA256: /* Fall through */ - case DIGEST_SHA512: /* Fall through */ + case DIGEST_SHA512: return true; case DIGEST_SHA3_256: /* Fall through */ case DIGEST_SHA3_512: /* Fall through */ -- cgit v1.2.3-54-g00ecf