tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

commit 34c2daf3ca23a7d8cd31a7757ea5a17aa98aad5b
parent 58248adab617eb240d6d8accd7620a1cabc1a1ff
Author: Nick Mathewson <nickm@torproject.org>
Date:   Mon, 19 May 2025 07:52:22 -0400

Merge branch 'gcc-15-warnings-048' into gcc-15-warnings-049

Diffstat:
Achanges/gcc-15 | 3+++
Mconfigure.ac | 15+++++++++++++++
Msrc/feature/nodelist/networkstatus.c | 4++++
Msrc/lib/cc/compat_compiler.h | 6++++++
Msrc/test/test.c | 3++-
Msrc/test/test_bridges.c | 12++++++------
Msrc/test/test_cell_formats.c | 2+-
Msrc/test/test_circuitlist.c | 10+++++-----
Msrc/test/test_crypto_ope.c | 4++--
Msrc/test/test_dir.c | 11+++++++----
Msrc/test/test_extorport.c | 2+-
Msrc/test/test_relaycrypt.c | 10++++++++--
Msrc/test/test_util_format.c | 2+-
13 files changed, 61 insertions(+), 23 deletions(-)

diff --git a/changes/gcc-15 b/changes/gcc-15 @@ -0,0 +1,3 @@ + o Minor features (portability): + - Fix warnings when compiling with GCC 15. + Closes ticket 41079. diff --git a/configure.ac b/configure.ac @@ -570,6 +570,21 @@ if test "$tor_cv_c_attr_fallthrough" = "yes"; then AC_DEFINE(HAVE_ATTR_FALLTHROUGH, [1], [defined if we have the fallthrough attribute.]) fi +saved_CFLAGS="$CFLAGS" +CFLAGS="$CFLAGS -Werror" +AC_CACHE_CHECK([for __attribute__((nonstring))], + tor_cv_c_attr_nonstring, + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([], + [[ __attribute__((nonstring)) const char foo[5] = "abcde"; ]])], + [tor_cv_c_attr_nonstring=yes], + [tor_cv_c_attr_nonstring=no] )]) +CFLAGS="$saved_CFLAGS" + +if test "$tor_cv_c_attr_nonstring" = "yes"; then + AC_DEFINE(HAVE_ATTR_NONSTRING, [1], [defined if we have the nonstring 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/feature/nodelist/networkstatus.c b/src/feature/nodelist/networkstatus.c @@ -2141,6 +2141,10 @@ networkstatus_set_current_consensus(const char *consensus, } current_md_consensus = c; free_consensus = 0; /* avoid free */ + } else { + tor_assert_nonfatal_unreached(); + result = -2; + goto done; } waiting = &consensus_waiting_for_certs[flav]; diff --git a/src/lib/cc/compat_compiler.h b/src/lib/cc/compat_compiler.h @@ -79,6 +79,12 @@ #define FALLTHROUGH #endif +#if defined(HAVE_ATTR_NONSTRING) +#define NONSTRING __attribute__((nonstring)) +#else +#define NONSTRING +#endif + /* What GCC do we have? */ #ifdef __GNUC__ #define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) diff --git a/src/test/test.c b/src/test/test.c @@ -76,7 +76,8 @@ test_ntor_handshake(void *arg) /* shared */ const curve25519_public_key_t *server_pubkey; - uint8_t node_id[20] = "abcdefghijklmnopqrst"; + + NONSTRING uint8_t node_id[20] = "abcdefghijklmnopqrst"; (void) arg; diff --git a/src/test/test_bridges.c b/src/test/test_bridges.c @@ -253,7 +253,7 @@ test_bridges_get_configured_bridge_by_addr_port_digest_digest_only(void *arg) { char digest[DIGEST_LEN]; bridge_info_t *bridge; - const char fingerprint[HEX_DIGEST_LEN] = + NONSTRING const char fingerprint[HEX_DIGEST_LEN] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; tor_addr_t *addr = tor_malloc(sizeof(tor_addr_t)); char ret_addr[16]; @@ -321,7 +321,7 @@ test_bridges_get_configured_bridge_by_exact_addr_port_digest_donly(void *arg) { char digest[DIGEST_LEN]; bridge_info_t *bridge; - const char fingerprint[HEX_DIGEST_LEN] = + NONSTRING const char fingerprint[HEX_DIGEST_LEN] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; tor_addr_t *addr = tor_malloc(sizeof(tor_addr_t)); uint16_t port = 11111; @@ -353,7 +353,7 @@ test_bridges_get_configured_bridge_by_exact_addr_port_digest_both(void *arg) { char digest[DIGEST_LEN]; bridge_info_t *bridge; - const char fingerprint[HEX_DIGEST_LEN] = + NONSTRING const char fingerprint[HEX_DIGEST_LEN] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; tor_addr_t *addr = tor_malloc(sizeof(tor_addr_t)); uint16_t port = 4444; @@ -419,7 +419,7 @@ test_bridges_find_bridge_by_digest_known(void *arg) { char digest1[DIGEST_LEN]; bridge_info_t *bridge; - const char fingerprint[HEX_DIGEST_LEN] = + NONSTRING const char fingerprint[HEX_DIGEST_LEN] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; helper_add_bridges_to_bridgelist(arg); @@ -616,10 +616,10 @@ test_bridges_node_is_a_configured_bridge(void *arg) node_t node_with_digest; memset(&node_with_digest, 0, sizeof(node_with_digest)); - const char fingerprint[HEX_DIGEST_LEN] = + NONSTRING const char fingerprint[HEX_DIGEST_LEN] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - const char fingerprint2[HEX_DIGEST_LEN] = + NONSTRING const char fingerprint2[HEX_DIGEST_LEN] = "ffffffffffffffffffffffffffffffffffffffff"; base16_decode(node_with_digest.identity, DIGEST_LEN, diff --git a/src/test/test_cell_formats.c b/src/test/test_cell_formats.c @@ -33,7 +33,7 @@ static void test_cfmt_relay_header(void *arg) { relay_header_t rh; - const uint8_t hdr_1[RELAY_HEADER_SIZE_V0] = + NONSTRING const uint8_t hdr_1[RELAY_HEADER_SIZE_V0] = "\x03" "\x00\x00" "\x21\x22" "ABCD" "\x01\x03"; uint8_t hdr_out[RELAY_HEADER_SIZE_V0]; (void)arg; diff --git a/src/test/test_circuitlist.c b/src/test/test_circuitlist.c @@ -187,9 +187,9 @@ test_rend_token_maps(void *arg) { or_circuit_t *c1, *c2, *c3, *c4; origin_circuit_t *c5; - const uint8_t tok1[REND_TOKEN_LEN] = "The cat can't tell y"; - const uint8_t tok2[REND_TOKEN_LEN] = "ou its name, and it "; - const uint8_t tok3[REND_TOKEN_LEN] = "doesn't really care."; + NONSTRING const uint8_t tok1[REND_TOKEN_LEN] = "The cat can't tell y"; + NONSTRING const uint8_t tok2[REND_TOKEN_LEN] = "ou its name, and it "; + NONSTRING const uint8_t tok3[REND_TOKEN_LEN] = "doesn't really care."; /* -- Adapted from a quote by Fredrik Lundh. */ (void)arg; @@ -420,7 +420,7 @@ test_hs_circuitmap_isolation(void *arg) ed25519_public_key_t intro_pk2 = { {2} }; /* Junk, not important. */ { - const uint8_t tok1[REND_TOKEN_LEN] = "bet i got some of th"; + NONSTRING const uint8_t tok1[REND_TOKEN_LEN] = "bet i got some of th"; circ1 = or_circuit_new(0, NULL); tt_assert(circ1); @@ -442,7 +442,7 @@ test_hs_circuitmap_isolation(void *arg) } { - const uint8_t tok2[REND_TOKEN_LEN] = "you dont know anythi"; + NONSTRING const uint8_t tok2[REND_TOKEN_LEN] = "you dont know anythi"; circ2 = origin_circuit_new(); tt_assert(circ2); diff --git a/src/test/test_crypto_ope.c b/src/test/test_crypto_ope.c @@ -28,7 +28,7 @@ test_crypto_ope_consistency(void *arg) const int TEST_VALS[] = { 5, 500, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 10000, OPE_INPUT_MAX }; unsigned i; - const uint8_t key[32] = "A fixed key, chosen arbitrarily."; + NONSTRING const uint8_t key[32] = "A fixed key, chosen arbitrarily."; ope = crypto_ope_new(key); tt_assert(ope); @@ -56,7 +56,7 @@ test_crypto_ope_oob(void *arg) (void)arg; crypto_ope_t *ope = NULL; - const uint8_t key[32] = "A fixed key, chosen arbitrarily."; + NONSTRING const uint8_t key[32] = "A fixed key, chosen arbitrarily."; ope = crypto_ope_new(key); tt_u64_op(UINT64_MAX, OP_EQ, crypto_ope_encrypt(ope,INT_MIN)); diff --git a/src/test/test_dir.c b/src/test/test_dir.c @@ -2641,7 +2641,7 @@ test_dir_dirserv_read_measured_bandwidths(void *arg) smartlist_len(bw_file_headers)); /* force bw_file_headers to be bigger than * MAX_BW_FILE_HEADER_COUNT_IN_VOTE */ - char line[8] = "foo=bar\0"; + NONSTRING char line[8] = "foo=bar\0"; smartlist_add_strdup(bw_file_headers, line); tt_int_op(MAX_BW_FILE_HEADER_COUNT_IN_VOTE, OP_LT, smartlist_len(bw_file_headers)); @@ -4546,14 +4546,17 @@ test_dir_bwauth_bw_file_digest256(void *arg) char *fname = tor_strdup(get_fname("V3BandwidthsFile")); /* Initialize to a wrong digest. */ - uint8_t digest[DIGEST256_LEN] = "01234567890123456789abcdefghijkl"; + NONSTRING + uint8_t digest[DIGEST256_LEN] = "01234567890123456789abcdefghijkl"; /* Digest of an empty string. Initialize to a wrong digest. */ - char digest_empty_str[DIGEST256_LEN] = "01234567890123456789abcdefghijkl"; + NONSTRING + char digest_empty_str[DIGEST256_LEN] = "01234567890123456789abcdefghijkl"; crypto_digest256(digest_empty_str, "", 0, DIGEST_SHA256); /* Digest of the content. Initialize to a wrong digest. */ - char digest_expected[DIGEST256_LEN] = "01234567890123456789abcdefghijkl"; + NONSTRING + char digest_expected[DIGEST256_LEN] = "01234567890123456789abcdefghijkl"; crypto_digest256(digest_expected, content, strlen(content), DIGEST_SHA256); /* When the bandwidth file can not be found. */ diff --git a/src/test/test_extorport.c b/src/test/test_extorport.c @@ -166,7 +166,7 @@ test_ext_or_cookie_auth(void *arg) size_t reply_len=0; char hmac1[32], hmac2[32]; - const char client_nonce[32] = + NONSTRING const char client_nonce[32] = "Who is the third who walks alway"; char server_hash_input[] = "ExtORPort authentication server-to-client hash" diff --git a/src/test/test_relaycrypt.c b/src/test/test_relaycrypt.c @@ -19,11 +19,18 @@ #include "test/test.h" -static const char KEY_MATERIAL[3][CPATH_KEY_MATERIAL_LEN] = { +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wattributes" +#endif +NONSTRING static const char KEY_MATERIAL[3][CPATH_KEY_MATERIAL_LEN] = { " 'My public key is in this signed x509 object', said Tom assertively.", "'Let's chart the pedal phlanges in the tomb', said Tom cryptographically", " 'Segmentation fault bugs don't _just happen_', said Tom seethingly.", }; +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif typedef struct testing_circuitset_t { or_circuit_t *or_circ[3]; @@ -189,4 +196,3 @@ struct testcase_t relaycrypt_tests[] = { TEST(inbound), END_OF_TESTCASES }; - diff --git a/src/test/test_util_format.c b/src/test/test_util_format.c @@ -13,7 +13,7 @@ static void test_util_format_unaligned_accessors(void *ignored) { (void)ignored; - char buf[9] = "onionsoup"; // 6f6e696f6e736f7570 + NONSTRING char buf[9] = "onionsoup"; // 6f6e696f6e736f7570 tt_u64_op(get_uint64(buf+1), OP_EQ, tor_htonll(UINT64_C(0x6e696f6e736f7570)));