From 35bbb2e830aeb8181bd4bf6b0ef68929217d97f0 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 28 Feb 2026 22:41:23 +0100 Subject: [PATCH] clang-tidy: fix issues found with build-fuzzing - curl_sha512_256: add missing, drop redundant, parentheses. - doh: drop redundant returns. - url: add missing parentheses. - vtls: fix unused const variables. - tests/unit: fix missing header with clang-tidy and !threaded-resolver. Follow-up to 57ff2d6c918d0bb444e5a8a53405217aec116b1b #20106 Closes #20774 --- lib/curl_sha512_256.c | 24 ++++++++++++------------ lib/doh.c | 2 -- lib/url.c | 8 ++++---- lib/vtls/vtls.c | 2 -- tests/unit/unit1607.c | 1 + tests/unit/unit1609.c | 1 + tests/unit/unit2600.c | 1 + 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/curl_sha512_256.c b/lib/curl_sha512_256.c index 2f51d2a4cd..00f4d1071f 100644 --- a/lib/curl_sha512_256.c +++ b/lib/curl_sha512_256.c @@ -452,14 +452,14 @@ static void Curl_sha512_256_transform(uint64_t H[SHA512_256_HASH_SIZE_WORDS], /* Four 'Sigma' macro functions. See FIPS PUB 180-4 formulae 4.10, 4.11, 4.12, 4.13. */ -#define SIG0(x) \ - (Curl_rotr64((x), 28) ^ Curl_rotr64((x), 34) ^ Curl_rotr64((x), 39)) -#define SIG1(x) \ - (Curl_rotr64((x), 14) ^ Curl_rotr64((x), 18) ^ Curl_rotr64((x), 41)) -#define sig0(x) \ - (Curl_rotr64((x), 1) ^ Curl_rotr64((x), 8) ^ ((x) >> 7)) -#define sig1(x) \ - (Curl_rotr64((x), 19) ^ Curl_rotr64((x), 61) ^ ((x) >> 6)) +#define SIG0(x) \ + (Curl_rotr64(x, 28) ^ Curl_rotr64(x, 34) ^ Curl_rotr64(x, 39)) +#define SIG1(x) \ + (Curl_rotr64(x, 14) ^ Curl_rotr64(x, 18) ^ Curl_rotr64(x, 41)) +#define sig0(x) \ + (Curl_rotr64(x, 1) ^ Curl_rotr64(x, 8) ^ ((x) >> 7)) +#define sig1(x) \ + (Curl_rotr64(x, 19) ^ Curl_rotr64(x, 61) ^ ((x) >> 6)) if(1) { unsigned int t; @@ -520,8 +520,8 @@ static void Curl_sha512_256_transform(uint64_t H[SHA512_256_HASH_SIZE_WORDS], used. */ #define SHA2STEP64(vA, vB, vC, vD, vE, vF, vG, vH, kt, wt) \ do { \ - (vD) += ((vH) += SIG1((vE)) + Sha512_Ch((vE), (vF), (vG)) + (kt) + (wt)); \ - (vH) += SIG0((vA)) + Sha512_Maj((vA), (vB), (vC)); \ + (vD) += ((vH) += SIG1(vE) + Sha512_Ch(vE, vF, vG) + (kt) + (wt)); \ + (vH) += SIG0(vA) + Sha512_Maj(vA, vB, vC); \ } while(0) /* One step of SHA-512/256 computation with working variables rotation, @@ -530,7 +530,7 @@ static void Curl_sha512_256_transform(uint64_t H[SHA512_256_HASH_SIZE_WORDS], #define SHA2STEP64RV(vA, vB, vC, vD, vE, vF, vG, vH, kt, wt) \ do { \ uint64_t tmp_h_ = (vH); \ - SHA2STEP64((vA), (vB), (vC), (vD), (vE), (vF), (vG), tmp_h_, (kt), (wt)); \ + SHA2STEP64(vA, vB, vC, vD, vE, vF, vG, tmp_h_, kt, wt); \ (vH) = (vG); \ (vG) = (vF); \ (vF) = (vE); \ @@ -546,7 +546,7 @@ static void Curl_sha512_256_transform(uint64_t H[SHA512_256_HASH_SIZE_WORDS], Input data must be read in big-endian bytes order, see FIPS PUB 180-4 section 3.1.2. */ #define SHA512_GET_W_FROM_DATA(buf, t) \ - CURL_GET_64BIT_BE(((const uint8_t *)(buf)) + (t) * SHA512_256_BYTES_IN_WORD) + CURL_GET_64BIT_BE((const uint8_t *)(buf) + ((t) * SHA512_256_BYTES_IN_WORD)) /* During first 16 steps, before making any calculation on each step, the W element is read from the input data buffer as a big-endian value and diff --git a/lib/doh.c b/lib/doh.c index 283746cab3..7fe4a06058 100644 --- a/lib/doh.c +++ b/lib/doh.c @@ -201,7 +201,6 @@ static void doh_print_buf(struct Curl_easy *data, infof(data, "%s: len=%d, val=%s", prefix, (int)len, hexstr); else infof(data, "%s: len=%d (truncated)val=%s", prefix, (int)len, hexstr); - return; } #endif @@ -1191,7 +1190,6 @@ UNITTEST void doh_print_httpsrr(struct Curl_easy *data, } else infof(data, "HTTPS RR: no ipv6hints"); - return; } # endif #endif diff --git a/lib/url.c b/lib/url.c index 0e594681ea..495de2297c 100644 --- a/lib/url.c +++ b/lib/url.c @@ -953,7 +953,7 @@ static bool url_match_proxy_use(struct connectdata *conn, return TRUE; } #else -#define url_match_proxy_use(c, m) ((void)c, (void)m, TRUE) +#define url_match_proxy_use(c, m) ((void)(c), (void)(m), TRUE) #endif #ifndef CURL_DISABLE_HTTP @@ -1009,8 +1009,8 @@ static bool url_match_http_version(struct connectdata *conn, return TRUE; } #else -#define url_match_http_multiplex(c, m) ((void)c, (void)m, TRUE) -#define url_match_http_version(c, m) ((void)c, (void)m, TRUE) +#define url_match_http_multiplex(c, m) ((void)(c), (void)(m), TRUE) +#define url_match_http_version(c, m) ((void)(c), (void)(m), TRUE) #endif static bool url_match_proto_config(struct connectdata *conn, @@ -1178,7 +1178,7 @@ static bool url_match_auth_ntlm(struct connectdata *conn, return TRUE; } #else -#define url_match_auth_ntlm(c, m) ((void)c, (void)m, TRUE) +#define url_match_auth_ntlm(c, m) ((void)(c), (void)(m), TRUE) #endif #ifdef USE_SPNEGO diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c index df9bc33a7b..f7201d18d6 100644 --- a/lib/vtls/vtls.c +++ b/lib/vtls/vtls.c @@ -136,7 +136,6 @@ static const struct alpn_spec ALPN_SPEC_H11 = { static const struct alpn_spec ALPN_SPEC_H10_H11 = { { ALPN_HTTP_1_0, ALPN_HTTP_1_1 }, 2 }; -#endif /* !CURL_DISABLE_HTTP || !CURL_DISABLE_PROXY */ #ifdef USE_HTTP2 static const struct alpn_spec ALPN_SPEC_H2 = { { ALPN_H2 }, 1 @@ -149,7 +148,6 @@ static const struct alpn_spec ALPN_SPEC_H11_H2 = { }; #endif /* USE_HTTP2 */ -#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_PROXY) static const struct alpn_spec *alpn_get_spec(http_majors wanted, http_majors preferred, bool only_http_10, diff --git a/tests/unit/unit1607.c b/tests/unit/unit1607.c index 3072130cce..3265df484a 100644 --- a/tests/unit/unit1607.c +++ b/tests/unit/unit1607.c @@ -25,6 +25,7 @@ #include "urldata.h" #include "connect.h" +#include "curl_addrinfo.h" static CURLcode t1607_setup(void) { diff --git a/tests/unit/unit1609.c b/tests/unit/unit1609.c index 366b117abe..a862154176 100644 --- a/tests/unit/unit1609.c +++ b/tests/unit/unit1609.c @@ -25,6 +25,7 @@ #include "urldata.h" #include "connect.h" +#include "curl_addrinfo.h" static CURLcode t1609_setup(void) { diff --git a/tests/unit/unit2600.c b/tests/unit/unit2600.c index 97d4caed96..4bd12313e6 100644 --- a/tests/unit/unit2600.c +++ b/tests/unit/unit2600.c @@ -46,6 +46,7 @@ #include "cf-ip-happy.h" #include "multiif.h" #include "select.h" +#include "curl_addrinfo.h" #include "curl_trc.h" static CURLcode t2600_setup(CURL **easy)