From 5169f8cfd543cbce498871527ea8aa454ff2c252 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Thu, 4 Jan 2024 16:48:10 +0100 Subject: [PATCH 1/3] resolve: initialize `r` during OOM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we'd use some garbage value in the error path. ../src/resolve/resolved-dns-query.c: In function ‘dns_query_accept’: ../src/resolve/resolved-dns-query.c:944:27: error: ‘r’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 944 | q->answer_errno = -r; | ^~ cc1: all warnings being treated as errors Follow-up for 9ca133e97a0. --- src/resolve/resolved-dns-query.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c index d94fe1da99..a7bc45838f 100644 --- a/src/resolve/resolved-dns-query.c +++ b/src/resolve/resolved-dns-query.c @@ -902,7 +902,7 @@ static void dns_query_accept(DnsQuery *q, DnsQueryCandidate *c) { if (t->answer_ede_msg) { answer_ede_msg = strdup(t->answer_ede_msg); if (!answer_ede_msg) { - log_oom(); + r = log_oom(); goto fail; } } From 0a87b834972c154b7f03738d165e5459f87a3352 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Thu, 4 Jan 2024 17:50:13 +0100 Subject: [PATCH 2/3] shared: initialize a couple of values explicitly As gcc has trouble figuring this itself with -O2 and -Wmaybe-initialized. --- src/libsystemd/sd-journal/journal-file.c | 2 +- src/login/logind.c | 2 +- src/shared/pkcs11-util.c | 2 +- src/shared/tpm2-util.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index 5e6ff66e3c..c9ff6abca6 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -2757,7 +2757,7 @@ static int generic_array_get( Object **ret_object, /* The found object. */ uint64_t *ret_offset) { /* The offset of the found object. */ - uint64_t a, t = 0, k; + uint64_t a, t = 0, k = 0; /* Explicit initialization of k to appease gcc */ ChainCacheItem *ci; Object *o = NULL; int r; diff --git a/src/login/logind.c b/src/login/logind.c index 030f65da08..4dd89288e7 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -470,7 +470,7 @@ static int deliver_session_leader_fd_consume(Session *s, const char *fdname, int static int manager_attach_session_fd_one_consume(Manager *m, const char *fdname, int fd) { _cleanup_free_ char *id = NULL; - dev_t devno; + dev_t devno = 0; /* Explicit initialization to appease gcc */ Session *s; int r; diff --git a/src/shared/pkcs11-util.c b/src/shared/pkcs11-util.c index 9792f70d42..3ff2e92b01 100644 --- a/src/shared/pkcs11-util.c +++ b/src/shared/pkcs11-util.c @@ -948,7 +948,7 @@ static int pkcs11_token_decrypt_data_ecc( if (mechanism_info.flags & CKF_EC_COMPRESS) { #if HAVE_OPENSSL log_debug("CKM_ECDH1_DERIVE accepts compressed EC points only, trying to convert."); - size_t compressed_point_size; + size_t compressed_point_size = 0; /* Explicit initialization to appease gcc */ r = ecc_convert_to_compressed(m, session, object, encrypted_data, encrypted_data_size, &compressed_point, &compressed_point_size); if (r < 0) return r; diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index 8c683254a2..068921a84c 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -5007,7 +5007,7 @@ static int tpm2_calculate_seal_ecc_seed( size_t bits = (size_t) r * 8; _cleanup_free_ void *seed = NULL; - size_t seed_size; + size_t seed_size = 0; /* Explicit initialization to appease gcc */ r = tpm2_kdfe(parent->publicArea.nameAlg, shared_secret, shared_secret_size, @@ -5044,7 +5044,7 @@ static int tpm2_calculate_seal_seed( log_debug("Calculating encrypted seed for sealed object."); _cleanup_free_ void *seed = NULL, *encrypted_seed = NULL; - size_t seed_size, encrypted_seed_size; + size_t seed_size = 0, encrypted_seed_size = 0; /* Explicit initialization to appease gcc */ if (parent->publicArea.type == TPM2_ALG_RSA) r = tpm2_calculate_seal_rsa_seed(parent, &seed, &seed_size, &encrypted_seed, &encrypted_seed_size); else if (parent->publicArea.type == TPM2_ALG_ECC) From 96e4c6269880c0c6fa03a08f9786e754928bd1d3 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Thu, 4 Jan 2024 17:51:40 +0100 Subject: [PATCH 3/3] ci: build with -O2 and -Wmaybe-uninitialized According to the comment in meson.build this should be a supported configuration, so let's test it in the CI as well. --- .github/workflows/build_test.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_test.sh b/.github/workflows/build_test.sh index c550046761..80f01f09dd 100755 --- a/.github/workflows/build_test.sh +++ b/.github/workflows/build_test.sh @@ -10,9 +10,9 @@ success() { echo >&2 -e "\033[32;1m$1\033[0m"; } ARGS=( "--optimization=0 -Dopenssl=disabled -Dcryptolib=gcrypt -Ddns-over-tls=gnutls -Dtpm=true -Dtpm2=enabled" "--optimization=s -Dutmp=false" + "--optimization=2 -Dc_args=-Wmaybe-uninitialized -Ddns-over-tls=openssl" "--optimization=3 -Db_lto=true -Ddns-over-tls=false" "--optimization=3 -Db_lto=false -Dtpm2=disabled -Dlibfido2=disabled -Dp11kit=disabled" - "--optimization=3 -Ddns-over-tls=openssl" "--optimization=3 -Dfexecve=true -Dstandalone-binaries=true -Dstatic-libsystemd=true -Dstatic-libudev=true" "-Db_ndebug=true" ) @@ -131,6 +131,11 @@ ninja --version for args in "${ARGS[@]}"; do SECONDS=0 + if [[ "$COMPILER" == clang && "$args" =~ Wmaybe-uninitialized ]]; then + # -Wmaybe-uninitialized is not implemented in clang + continue + fi + info "Checking build with $args" # shellcheck disable=SC2086 if ! AR="$AR" \