From: Viktor Szakats Date: Tue, 16 Jan 2024 16:30:07 +0000 (+0000) Subject: mbedtls: fix `-Wnull-dereference` and `-Wredundant-decls` X-Git-Tag: curl-8_6_0~71 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=434db995a7566a76f6a16391897816ddd1011adc;p=thirdparty%2Fcurl.git mbedtls: fix `-Wnull-dereference` and `-Wredundant-decls` - Silence warning in mbedTLS v3.5.1 public headers: ``` ./mbedtls/_x64-linux-musl/usr/include/psa/crypto_extra.h:489:14: warning: redundant redeclaration of 'psa_set_key_domain_parameters' [-Wredundant-decls] ./mbedtls/_x64-linux-musl/usr/include/psa/crypto_struct.h:354:14: note: previous declaration of 'psa_set_key_domain_parameters' was here ``` Ref: https://github.com/libssh2/libssh2/commit/ecec68a2c13a9c63fe8c2dc457ae785a513e157c Ref: https://github.com/libssh2/libssh2/pull/1226 - Fix compiler warnings seen with gcc 9.2.0 + cmake unity: ``` ./curl/lib/vtls/mbedtls.c: In function 'mbedtls_bio_cf_read': ./curl/lib/vtls/mbedtls.c:189:11: warning: null pointer dereference [-Wnull-dereference] 189 | nread = Curl_conn_cf_recv(cf->next, data, (char *)buf, blen, &result); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./curl/lib/vtls/mbedtls.c: In function 'mbedtls_bio_cf_write': ./curl/lib/vtls/mbedtls.c:168:14: warning: null pointer dereference [-Wnull-dereference] 168 | nwritten = Curl_conn_cf_send(cf->next, data, (char *)buf, blen, &result); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` - delete stray `#else`. Closes #12720 --- diff --git a/lib/vtls/mbedtls.c b/lib/vtls/mbedtls.c index 159fa6c666..7d70de53bd 100644 --- a/lib/vtls/mbedtls.c +++ b/lib/vtls/mbedtls.c @@ -36,6 +36,13 @@ /* Define this to enable lots of debugging for mbedTLS */ /* #define MBEDTLS_DEBUG */ +#ifdef __GNUC__ +#pragma GCC diagnostic push +/* mbedTLS (as of v3.5.1) has a duplicate function declaration + in its public headers. Disable the warning that detects it. */ +#pragma GCC diagnostic ignored "-Wredundant-decls" +#endif + #include #if MBEDTLS_VERSION_NUMBER >= 0x02040000 #include @@ -56,6 +63,10 @@ # endif #endif +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + #include "urldata.h" #include "sendf.h" #include "inet_pton.h" @@ -154,7 +165,6 @@ static void mbed_debug(void *context, int level, const char *f_name, infof(data, "%s", line); (void) level; } -#else #endif static int mbedtls_bio_cf_write(void *bio, @@ -166,6 +176,9 @@ static int mbedtls_bio_cf_write(void *bio, CURLcode result; DEBUGASSERT(data); + if(!data) + return 0; + nwritten = Curl_conn_cf_send(cf->next, data, (char *)buf, blen, &result); CURL_TRC_CF(data, cf, "mbedtls_bio_cf_out_write(len=%zu) -> %zd, err=%d", blen, nwritten, result); @@ -183,6 +196,8 @@ static int mbedtls_bio_cf_read(void *bio, unsigned char *buf, size_t blen) CURLcode result; DEBUGASSERT(data); + if(!data) + return 0; /* OpenSSL catches this case, so should we. */ if(!buf) return 0;