From 27a7cf40bb7e8771c356fb3b16714f77f1d126d8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 21 Nov 2025 02:14:59 +0000 Subject: [PATCH 001/140] GHA: update dependency wolfSSL/wolfssl to v5.8.4 Closes #19633 --- .github/workflows/http3-linux.yml | 2 +- .github/workflows/linux.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/http3-linux.yml b/.github/workflows/http3-linux.yml index ff32e6c5d9d9..223c6afbf46d 100644 --- a/.github/workflows/http3-linux.yml +++ b/.github/workflows/http3-linux.yml @@ -49,7 +49,7 @@ env: # renovate: datasource=github-tags depName=gnutls/gnutls versioning=semver registryUrl=https://github.com GNUTLS_VERSION: 3.8.10 # renovate: datasource=github-tags depName=wolfSSL/wolfssl versioning=semver extractVersion=^v?(?.+)-stable$ registryUrl=https://github.com - WOLFSSL_VERSION: 5.8.2 + WOLFSSL_VERSION: 5.8.4 # renovate: datasource=github-tags depName=ngtcp2/nghttp3 versioning=semver registryUrl=https://github.com NGHTTP3_VERSION: 1.12.0 # renovate: datasource=github-tags depName=ngtcp2/ngtcp2 versioning=semver registryUrl=https://github.com diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index a6823b4c9da4..0db8ca33b4ec 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -40,7 +40,7 @@ env: # renovate: datasource=github-tags depName=libressl/portable versioning=semver registryUrl=https://github.com LIBRESSL_VERSION: 4.2.1 # renovate: datasource=github-tags depName=wolfSSL/wolfssl versioning=semver extractVersion=^v?(?.+)-stable$ registryUrl=https://github.com - WOLFSSL_VERSION: 5.8.2 + WOLFSSL_VERSION: 5.8.4 # renovate: datasource=github-tags depName=Mbed-TLS/mbedtls versioning=semver registryUrl=https://github.com MBEDTLS_VERSION: 4.0.0 # renovate: datasource=github-tags depName=Mbed-TLS/mbedtls versioning=semver:^3.0.0 registryUrl=https://github.com From fdacf34aaeac79ad14fa48dcafae24a6de68823d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 21 Nov 2025 02:44:08 +0100 Subject: [PATCH 002/140] GHA/codeql: add tweak to successfully build libtests for CodeQL Turns out the cause of CodeQL hangs (or probably just extreme long compile) is the header `curl/typecheck-gcc.h`. By accident I noticed that the preprocessed output of libtests.c is 75 MB (megabytes). This is much higher than the amounf of source code hinted, also compared to e.g. units.c or other build targets. The reason for the extreme size is each easy option call pulling in the large checker logic defined in this header. By compiling with `-DCURL_DISABLE_TYPECHECK`, preprocessed output drops to 2.2 MB (34x), and the libtests target builds without issues. Also build all tests and examples with the Linux HTTP/3 config, covering 3 more files. With these, CodeQL C coverage is 893 out of 930 (96%) (was: 645 69%) Follow-up to 71fc11e6bbf530b90bf6e93a02cb32bdaecc933b #18695 Follow-up to a333fd4411b95fc0c3061b2d675de9287b6123e0 #18557 Follow-up to b4922b1295333dc6679eb1d588ddc2fb6b7fd5b7 #18564 Closes https://github.com/vszakats/curl/pull/11 Closes #19632 --- .github/workflows/codeql.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index c7b6383cf1dc..c42d71773567 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -109,24 +109,24 @@ jobs: # MultiSSL export PKG_CONFIG_PATH; PKG_CONFIG_PATH="$(brew --prefix c-ares)/lib/pkgconfig:$(brew --prefix mbedtls)/lib/pkgconfig:$(brew --prefix rustls-ffi)/lib/pkgconfig:$(brew --prefix gsasl)/lib/pkgconfig" cmake -B _bld1 -G Ninja -DENABLE_DEBUG=ON \ + -DCMAKE_C_FLAGS=-DCURL_DISABLE_TYPECHECK \ -DCURL_USE_GNUTLS=ON -DCURL_USE_MBEDTLS=ON -DCURL_USE_RUSTLS=ON -DCURL_USE_WOLFSSL=ON \ -DUSE_LIBRTMP=ON -DCURL_USE_GSASL=ON -DCURL_USE_GSSAPI=ON -DUSE_SSLS_EXPORT=ON -DUSE_ECH=ON -DENABLE_ARES=ON \ -DCURL_DISABLE_VERBOSE_STRINGS=ON cmake --build _bld1 - cmake --build _bld1 --target curlinfo - cmake --build _bld1 --target servers - cmake --build _bld1 --target tunits - cmake --build _bld1 --target units + cmake --build _bld1 --target testdeps cmake --build _bld1 --target curl-examples-build # HTTP/3 export PKG_CONFIG_PATH; PKG_CONFIG_PATH="$(brew --prefix libnghttp3)/lib/pkgconfig:$(brew --prefix libngtcp2)/lib/pkgconfig:$(brew --prefix gsasl)/lib/pkgconfig" cmake -B _bld2 -G Ninja \ + -DCMAKE_C_FLAGS=-DCURL_DISABLE_TYPECHECK \ -DCURL_USE_OPENSSL=ON -DOPENSSL_ROOT_DIR="$(brew --prefix openssl)" -DUSE_NGTCP2=ON \ -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=ON \ -DUSE_LIBRTMP=ON -DCURL_USE_GSASL=ON -DCURL_USE_GSSAPI=ON -DUSE_SSLS_EXPORT=ON cmake --build _bld2 - cmake --build _bld2 --target servers + cmake --build _bld2 --target testdeps + cmake --build _bld2 --target curl-examples-build _bld1/src/curl --disable --version _bld2/src/curl --disable --version From b4220bde0ba79486c63e60de71037df912134dfb Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 21 Nov 2025 03:52:04 +0100 Subject: [PATCH 003/140] GHA/checksrc: switch xmllint job to Linux (from macOS) macOS was chosen because xmllint comes preinstalled, saving the prereq install step. But, macOS's xmllint jobs sometimes doesn't finish in 1m (instead of under 1 second) and gets cancelled, causing flaky failures. Go with Linux and an install phase (of 15s) instead. Examples: https://github.com/curl/curl/actions/runs/19558021722/job/56004334495 Closes #19634 --- .github/workflows/checksrc.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/checksrc.yml b/.github/workflows/checksrc.yml index 32f825214d6c..2f7b0b0e941c 100644 --- a/.github/workflows/checksrc.yml +++ b/.github/workflows/checksrc.yml @@ -120,9 +120,17 @@ jobs: xmllint: name: 'xmllint' - runs-on: macos-latest + runs-on: ubuntu-latest timeout-minutes: 1 steps: + - name: 'install prereqs' + run: | + sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list + sudo apt-get -o Dpkg::Use-Pty=0 update + sudo rm -f /var/lib/man-db/auto-update + sudo apt-get -o Dpkg::Use-Pty=0 install \ + libxml2-utils + - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 with: persist-credentials: false From fd23d9505c7263814bfb2963e9c406a53b0295a2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 20 Nov 2025 17:39:53 +0100 Subject: [PATCH 004/140] src: move `memdebug.h` to be the last include `memdebug.h` must be included last within each source. This breaks when including it in a header, which ends up being included in the middle of other headers, and `memdebug.h` also ending up in the middle of includes. Follow-up to c255d2fdcbf27b4bfd668ae3784bb657449d6889 #19602 Closes #19629 --- src/tool_cfgable.h | 1 - src/tool_ssls.c | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h index 717d35a1f522..dc78f2db44f6 100644 --- a/src/tool_cfgable.h +++ b/src/tool_cfgable.h @@ -29,7 +29,6 @@ #include "tool_sdecls.h" #include "tool_urlglob.h" #include "var.h" -#include "memdebug.h" /* keep this as LAST include */ /* the type we use for storing a single boolean bit */ #ifndef BIT diff --git a/src/tool_ssls.c b/src/tool_ssls.c index ab78014c0a86..4c9d1ee00857 100644 --- a/src/tool_ssls.c +++ b/src/tool_ssls.c @@ -30,6 +30,8 @@ #include "tool_ssls.h" #include "tool_parsecfg.h" +#include "memdebug.h" /* keep this as LAST include */ + /* The maximum line length for an ecoded session ticket */ #define MAX_SSLS_LINE (64 * 1024) From 529f61388f8c235fc250aa466163396a8965b362 Mon Sep 17 00:00:00 2001 From: Marc Aldorasi Date: Wed, 19 Nov 2025 11:12:31 -0500 Subject: [PATCH 005/140] gnutls: implement CURLOPT_CAINFO_BLOB This adds support for in-memory CA certs using CURLOPT_CAINFO_BLOB to the GnuTLS backend. Closes #19612 --- docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md | 3 ++- lib/vtls/gtls.c | 27 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md b/docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md index 149c9b795f61..99bfaf11e673 100644 --- a/docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md +++ b/docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md @@ -13,6 +13,7 @@ See-also: - CURLOPT_SSL_VERIFYPEER (3) TLS-backend: - OpenSSL + - GnuTLS - mbedTLS - rustls - wolfSSL @@ -80,7 +81,7 @@ int main(void) # HISTORY This option is supported by the mbedTLS (since 7.81.0), Rustls (since 7.82.0), -wolfSSL (since 8.2.0), OpenSSL and Schannel backends. +wolfSSL (since 8.2.0), GnuTLS (since 8.18.0), OpenSSL and Schannel backends. # %AVAILABILITY% diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c index eba5fb36f09f..c0e248642b25 100644 --- a/lib/vtls/gtls.c +++ b/lib/vtls/gtls.c @@ -477,7 +477,31 @@ static CURLcode gtls_populate_creds(struct Curl_cfilter *cf, #endif } - if(config->CAfile) { + if(config->ca_info_blob) { + gnutls_datum_t ca_info_datum; + if(config->ca_info_blob->len > (size_t)UINT_MAX) { + failf(data, "certificate blob too long: %zu bytes", + config->ca_info_blob->len); + return CURLE_SSL_CACERT_BADFILE; + } + ca_info_datum.data = config->ca_info_blob->data; + ca_info_datum.size = (unsigned int)config->ca_info_blob->len; + rc = gnutls_certificate_set_x509_trust_mem(creds, &ca_info_datum, + GNUTLS_X509_FMT_PEM); + creds_are_empty = creds_are_empty && (rc <= 0); + if(rc < 0) { + infof(data, "error reading ca cert blob (%s)%s", gnutls_strerror(rc), + (creds_are_empty ? "" : ", continuing anyway")); + if(creds_are_empty) { + ssl_config->certverifyresult = rc; + return CURLE_SSL_CACERT_BADFILE; + } + } + else + infof(data, " CA Blob: %d certificates", rc); + } + /* CURLOPT_CAINFO_BLOB overrides CURLOPT_CAINFO */ + else if(config->CAfile) { /* set the trusted CA cert bundle file */ gnutls_certificate_set_verify_flags(creds, GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT); @@ -2335,6 +2359,7 @@ const struct Curl_ssl Curl_ssl_gnutls = { SSLSUPP_CERTINFO | SSLSUPP_PINNEDPUBKEY | SSLSUPP_HTTPS_PROXY | + SSLSUPP_CAINFO_BLOB | SSLSUPP_CIPHER_LIST | SSLSUPP_CA_CACHE, From 49ab46c9c50511dcc304a92f3a2e458d4a9fa131 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 Nov 2025 15:05:17 +0100 Subject: [PATCH 006/140] gtls: drop support for GnuTLS < 3.6.5 Release date 2018-12-01. Has TLS 1.3 support. Closes #19609 --- docs/INTERNALS.md | 2 +- lib/vtls/gtls.c | 49 ++--------------------------------------------- 2 files changed, 3 insertions(+), 48 deletions(-) diff --git a/docs/INTERNALS.md b/docs/INTERNALS.md index d957c69ab77a..e9bb82a33d8e 100644 --- a/docs/INTERNALS.md +++ b/docs/INTERNALS.md @@ -26,7 +26,7 @@ versions of libs and build tools. - OpenSSL 3.0.0 (2021-09-07) - LibreSSL 2.9.1 (2019-04-22) - - GnuTLS 3.1.10 (2013-03-22) + - GnuTLS 3.6.5 (2018-12-01) - mbedTLS 3.2.0 (2022-07-11) - zlib 1.2.5.2 (2011-12-11) - libssh2 1.9.0 (2019-06-20) diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c index c0e248642b25..dbb442f36314 100644 --- a/lib/vtls/gtls.c +++ b/lib/vtls/gtls.c @@ -73,7 +73,7 @@ static void tls_log_func(int level, const char *str) } #endif -#if !defined(GNUTLS_VERSION_NUMBER) || (GNUTLS_VERSION_NUMBER < 0x03010a) +#if !defined(GNUTLS_VERSION_NUMBER) || (GNUTLS_VERSION_NUMBER < 0x030605) #error "too old GnuTLS version" #endif @@ -767,10 +767,8 @@ int Curl_glts_get_ietf_proto(gnutls_session_t session) return CURL_IETF_PROTO_TLS1_1; case GNUTLS_TLS1_2: return CURL_IETF_PROTO_TLS1_2; -#if GNUTLS_VERSION_NUMBER >= 0x030603 case GNUTLS_TLS1_3: return CURL_IETF_PROTO_TLS1_3; -#endif default: return CURL_IETF_PROTO_UNKNOWN; } @@ -1841,51 +1839,8 @@ Curl_gtls_verifyserver(struct Curl_cfilter *cf, rc = (int)gnutls_x509_crt_check_hostname(x509_cert, peer->sni ? peer->sni : peer->hostname); -#if GNUTLS_VERSION_NUMBER < 0x030306 - /* Before 3.3.6, gnutls_x509_crt_check_hostname() did not check IP - addresses. */ - if(!rc) { -#ifdef USE_IPV6 - #define use_addr in6_addr -#else - #define use_addr in_addr -#endif - unsigned char addrbuf[sizeof(struct use_addr)]; - size_t addrlen = 0; - - if(curlx_inet_pton(AF_INET, peer->hostname, addrbuf) > 0) - addrlen = 4; -#ifdef USE_IPV6 - else if(curlx_inet_pton(AF_INET6, peer->hostname, addrbuf) > 0) - addrlen = 16; -#endif - - if(addrlen) { - unsigned char certaddr[sizeof(struct use_addr)]; - int i; - - for(i = 0; ; i++) { - size_t certaddrlen = sizeof(certaddr); - int ret = gnutls_x509_crt_get_subject_alt_name(x509_cert, i, certaddr, - &certaddrlen, NULL); - /* If this happens, it was not an IP address. */ - if(ret == GNUTLS_E_SHORT_MEMORY_BUFFER) - continue; - if(ret < 0) - break; - if(ret != GNUTLS_SAN_IPADDRESS) - continue; - if(certaddrlen == addrlen && !memcmp(addrbuf, certaddr, addrlen)) { - rc = 1; - break; - } - } - } - } -#endif - result = (!rc && config->verifyhost) ? - CURLE_PEER_FAILED_VERIFICATION : CURLE_OK; + CURLE_PEER_FAILED_VERIFICATION : CURLE_OK; gtls_msg_verify_result(data, peer, x509_cert, rc, config->verifyhost); if(result) goto out; From de7ee1c96265013c71a367575abbcf97b843fde3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 21 Nov 2025 09:19:21 +0100 Subject: [PATCH 007/140] GHA: disable TLS in the linux-old build There are no supported TLS libraries left in "stretch". --- .github/workflows/linux-old.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linux-old.yml b/.github/workflows/linux-old.yml index f79cee94ac36..64958f4bd61c 100644 --- a/.github/workflows/linux-old.yml +++ b/.github/workflows/linux-old.yml @@ -72,7 +72,7 @@ jobs: dpkg -i freexian-archive-keyring_2022.06.08_all.deb echo 'deb http://deb.freexian.com/extended-lts stretch-lts main contrib non-free' | tee /etc/apt/sources.list.d/extended-lts.list apt-get -o Dpkg::Use-Pty=0 update - apt-get -o Dpkg::Use-Pty=0 install -y --no-install-suggests --no-install-recommends cmake make automake autoconf libtool gcc pkg-config libpsl-dev libzstd-dev zlib1g-dev libgnutls28-dev libc-ares-dev libkrb5-dev libldap2-dev librtmp-dev stunnel4 groff + apt-get -o Dpkg::Use-Pty=0 install -y --no-install-suggests --no-install-recommends cmake make automake autoconf libtool gcc pkg-config libpsl-dev libzstd-dev zlib1g-dev libc-ares-dev libkrb5-dev libldap2-dev librtmp-dev stunnel4 groff # GitHub's actions/checkout needs newer glibc and libstdc++. The latter also depends on # gcc-8-base, but it does not actually seem used in our situation and is not available in # the main repo, so force the install. @@ -89,7 +89,7 @@ jobs: mkdir bld-1 cd bld-1 cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \ - -DCURL_USE_GNUTLS=ON -DENABLE_ARES=OFF -DCURL_ZSTD=OFF -DCURL_USE_GSSAPI=OFF -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=OFF -DUSE_LIBRTMP=ON + -DCURL_ENABLE_SSL=OFF -DENABLE_ARES=OFF -DCURL_ZSTD=OFF -DCURL_USE_GSSAPI=OFF -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=OFF -DUSE_LIBRTMP=ON - name: 'CM build-only build' run: VERBOSE=1 make -C bld-1 install @@ -113,7 +113,7 @@ jobs: mkdir bld-cares cd bld-cares cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \ - -DCURL_USE_GNUTLS=ON -DENABLE_ARES=ON -DCURL_USE_GSSAPI=ON -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=OFF -DUSE_LIBRTMP=ON \ + -DCURL_ENABLE_SSL=OFF -DENABLE_ARES=ON -DCURL_USE_GSSAPI=ON -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=OFF -DUSE_LIBRTMP=ON \ -DCURL_LIBCURL_VERSIONED_SYMBOLS=ON - name: 'CM configure log' @@ -151,7 +151,7 @@ jobs: mkdir bld-am cd bld-am ../configure --disable-dependency-tracking --enable-unity --enable-warnings --enable-werror \ - --with-gnutls --enable-ares --without-libssh2 --with-zstd --with-gssapi --with-librtmp \ + --without-ssl --enable-ares --without-libssh2 --with-zstd --with-gssapi --with-librtmp \ --prefix="$PWD"/../curl-install-am - name: 'AM configure log' From dd36dacd3e1518c1744e233d4aa3ec5a3a1c7bbc Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Thu, 20 Nov 2025 13:17:03 +0100 Subject: [PATCH 008/140] openssl: no verify failf message unless strict If verifypeer and verifyhost are disabled, to not generate a failf() message for failed verifications. Fixes #19615 Reported-by: ncaklovic on github Closes #19625 --- lib/vtls/openssl.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index 80d01c31604b..909c9a135b24 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -4557,7 +4557,7 @@ static CURLcode ossl_check_issuer(struct Curl_cfilter *cf, X509 *issuer = NULL; BIO *fp = NULL; char err_buf[256]=""; - bool strict = (conn_config->verifypeer || conn_config->verifyhost); + bool verify_enabled = (conn_config->verifypeer || conn_config->verifyhost); CURLcode result = CURLE_OK; /* e.g. match issuer name with provided issuer certificate */ @@ -4581,7 +4581,7 @@ static CURLcode ossl_check_issuer(struct Curl_cfilter *cf, } if(BIO_read_filename(fp, conn_config->issuercert) <= 0) { - if(strict) + if(verify_enabled) failf(data, "SSL: Unable to open issuer cert (%s)", conn_config->issuercert); result = CURLE_SSL_ISSUER_ERROR; @@ -4592,7 +4592,7 @@ static CURLcode ossl_check_issuer(struct Curl_cfilter *cf, if(fp) { issuer = PEM_read_bio_X509(fp, NULL, ZERO_NULL, NULL); if(!issuer) { - if(strict) + if(verify_enabled) failf(data, "SSL: Unable to read issuer cert (%s)", conn_config->issuercert); result = CURLE_SSL_ISSUER_ERROR; @@ -4600,7 +4600,7 @@ static CURLcode ossl_check_issuer(struct Curl_cfilter *cf, } if(X509_check_issued(issuer, server_cert) != X509_V_OK) { - if(strict) + if(verify_enabled) failf(data, "SSL: Certificate issuer check failed (%s)", conn_config->issuercert); result = CURLE_SSL_ISSUER_ERROR; @@ -4648,8 +4648,6 @@ static CURLcode ossl_infof_cert(struct Curl_cfilter *cf, struct Curl_easy *data, X509 *server_cert) { - struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); - bool strict = (conn_config->verifypeer || conn_config->verifyhost); BIO *mem = NULL; struct dynbuf dname; char err_buf[256] = ""; @@ -4686,12 +4684,8 @@ static CURLcode ossl_infof_cert(struct Curl_cfilter *cf, (void)BIO_reset(mem); result = x509_name_oneline(X509_get_issuer_name(server_cert), &dname); - if(result) { - if(strict) - failf(data, "SSL: could not get X509-issuer name"); - result = CURLE_PEER_FAILED_VERIFICATION; + if(result) /* should be only fatal stuff like OOM */ goto out; - } infof(data, " issuer: %s", curlx_dyn_ptr(&dname)); out: @@ -4788,7 +4782,6 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); CURLcode result = CURLE_OK; long ossl_verify; - bool strict = (conn_config->verifypeer || conn_config->verifyhost); X509 *server_cert; bool verified = FALSE; #ifdef USE_APPLE_SECTRUST @@ -4805,7 +4798,8 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, server_cert = SSL_get1_peer_certificate(octx->ssl); if(!server_cert) { - if(!strict) + /* no verification at all, this maybe acceptable */ + if(!(conn_config->verifypeer || conn_config->verifyhost)) goto out; failf(data, "SSL: could not get peer certificate"); @@ -4825,6 +4819,7 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, if(result) goto out; } + /* `verifyhost` is either OK or not requested from here on */ ossl_verify = SSL_get_verify_result(octx->ssl); ssl_config->certverifyresult = ossl_verify; @@ -4853,11 +4848,12 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, if(!verified) { /* no trust established, report the OpenSSL status */ - failf(data, "SSL certificate OpenSSL verify result: %s (%ld)", - X509_verify_cert_error_string(ossl_verify), ossl_verify); - result = CURLE_PEER_FAILED_VERIFICATION; - if(conn_config->verifypeer) + if(conn_config->verifypeer) { + failf(data, "SSL certificate OpenSSL verify result: %s (%ld)", + X509_verify_cert_error_string(ossl_verify), ossl_verify); + result = CURLE_PEER_FAILED_VERIFICATION; goto out; + } infof(data, " SSL certificate verification failed, continuing anyway!"); } From 3561f2c7bfe8d6c4d535a038b67d5f731fe0012f Mon Sep 17 00:00:00 2001 From: x2018 Date: Wed, 19 Nov 2025 23:25:57 +0800 Subject: [PATCH 009/140] lib: cleanup some whitespace nits Closes #19588 --- lib/vtls/openssl.c | 2 +- src/tool_operhlp.c | 2 +- src/tool_setopt.c | 2 +- src/tool_ssls.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index 909c9a135b24..5d35ba1a1530 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -277,7 +277,7 @@ static CURLcode X509V3_ext(struct Curl_easy *data, if(asn1_object_dump(obj, namebuf, sizeof(namebuf))) /* make sure the name is null-terminated */ - namebuf [ sizeof(namebuf) - 1] = 0; + namebuf[sizeof(namebuf) - 1] = 0; if(!X509V3_EXT_print(bio_out, ext, 0, 0)) ASN1_STRING_print(bio_out, (ASN1_STRING *)X509_EXTENSION_get_data(ext)); diff --git a/src/tool_operhlp.c b/src/tool_operhlp.c index e17955bec306..0d6c2cb6e0e5 100644 --- a/src/tool_operhlp.c +++ b/src/tool_operhlp.c @@ -92,7 +92,7 @@ CURLcode add_file_name_to_url(CURL *curl, char **inurlp, const char *filename) if(uh) { char *ptr; uerr = curl_url_set(uh, CURLUPART_URL, *inurlp, - CURLU_GUESS_SCHEME|CURLU_NON_SUPPORT_SCHEME); + CURLU_GUESS_SCHEME|CURLU_NON_SUPPORT_SCHEME); if(uerr) { result = urlerr_cvt(uerr); goto fail; diff --git a/src/tool_setopt.c b/src/tool_setopt.c index ccecd3a7e030..b7039fbb4881 100644 --- a/src/tool_setopt.c +++ b/src/tool_setopt.c @@ -623,7 +623,7 @@ CURLcode tool_setopt_offt(CURL *curl, const char *name, CURLoption tag, if(global->libcurl && !ret && lval) { /* we only use this for real if --libcurl was used */ ret = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, (curl_off_t)%" - CURL_FORMAT_CURL_OFF_T ");", name, lval); + CURL_FORMAT_CURL_OFF_T ");", name, lval); } return ret; diff --git a/src/tool_ssls.c b/src/tool_ssls.c index 4c9d1ee00857..40e67a8044c9 100644 --- a/src/tool_ssls.c +++ b/src/tool_ssls.c @@ -156,8 +156,8 @@ static CURLcode tool_ssls_exp(CURL *easy, void *userptr, (void)earlydata_max; if(!ctx->exported) fputs("# Your SSL session cache. https://curl.se/docs/ssl-sessions.html\n" - "# This file was generated by libcurl! Edit at your own risk.\n", - ctx->fp); + "# This file was generated by libcurl! Edit at your own risk.\n", + ctx->fp); r = curlx_base64_encode((const char *)shmac, shmac_len, &enc, &enc_len); if(r) From eaa7651374898cef89e5783b0219bdffcc0eb60e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 17 Nov 2025 23:49:15 +0100 Subject: [PATCH 010/140] lib: replace `_tcsncpy`/`wcsncpy`/`wcscpy` with `_s` counterparts (Windows) Replace: - curl_sspi: macro `_tcsncpy()` with `_tcsncpy_s()`. - curlx/fopen: `wcsncpy()` with `wcsncpy_s()`. - curlx/fopen: `wcscpy()` with `wcscpy_s()`. Use of the pre-existing functions were safe. This patch aims to use the recommended Windows CRT functions. Handle errors returned by them. Also to avoid the compiler warnings silenced via `_CRT_SECURE_NO_WARNINGS`: ``` lib/curl_sspi.c(152): warning C4996: 'wcsncpy': This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. lib/curlx/fopen.c(161): warning C4996: 'wcsncpy': This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. lib/curlx/fopen.c(162): warning C4996: 'wcscpy': This function or variable may be unsafe. Consider using wcscpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. lib/curlx/fopen.c(174): warning C4996: 'wcsncpy': This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. lib/curlx/fopen.c(175): warning C4996: 'wcscpy': This function or variable may be unsafe. Consider using wcscpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. ``` Refs: https://learn.microsoft.com/cpp/c-runtime-library/reference/strncpy-strncpy-l-wcsncpy-wcsncpy-l-mbsncpy-mbsncpy-l https://learn.microsoft.com/cpp/c-runtime-library/reference/strncpy-s-strncpy-s-l-wcsncpy-s-wcsncpy-s-l-mbsncpy-s-mbsncpy-s-l https://learn.microsoft.com/cpp/c-runtime-library/security-features-in-the-crt Cherry-picked from #19581 (in part) Closes #19589 --- lib/curl_setup.h | 2 +- lib/curl_sspi.c | 7 +++++-- lib/curlx/fopen.c | 20 ++++++++++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 0df96d5efd28..05e6149f6139 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -98,7 +98,7 @@ #define _CRT_SECURE_NO_WARNINGS /* for __sys_errlist, __sys_nerr, _open(), _wfopen(), _wopen(), fopen(), freopen(), getenv(), gmtime(), mbstowcs(), sprintf(), - strcpy(), wcscpy(), wcsncpy(), wcstombs(), + strcpy(), wcstombs(), in tests: localtime(), open(), sscanf() */ #endif #endif /* _MSC_VER */ diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index 32b4c894d6b5..369cf18967a3 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -149,8 +149,11 @@ CURLcode Curl_create_sspi_identity(const char *userp, const char *passwdp, curlx_unicodefree(useranddomain.tchar_ptr); return CURLE_OUT_OF_MEMORY; } - _tcsncpy(dup_domain.tchar_ptr, domain.tchar_ptr, domlen); - *(dup_domain.tchar_ptr + domlen) = TEXT('\0'); + if(_tcsncpy_s(dup_domain.tchar_ptr, domlen + 1, domain.tchar_ptr, domlen)) { + curlx_unicodefree(dup_domain.tchar_ptr); + curlx_unicodefree(useranddomain.tchar_ptr); + return CURLE_OUT_OF_MEMORY; + } identity->Domain = dup_domain.tbyte_ptr; identity->DomainLength = curlx_uztoul(domlen); dup_domain.tchar_ptr = NULL; diff --git a/lib/curlx/fopen.c b/lib/curlx/fopen.c index 333eff7de7e2..f33075316250 100644 --- a/lib/curlx/fopen.c +++ b/lib/curlx/fopen.c @@ -158,8 +158,14 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) if(!temp) goto cleanup; - wcsncpy(temp, L"\\\\?\\UNC\\", 8); - wcscpy(temp + 8, fbuf + 2); + if(wcsncpy_s(temp, needed, L"\\\\?\\UNC\\", 8)) { + (free)(temp); + goto cleanup; + } + if(wcscpy_s(temp + 8, needed, fbuf + 2)) { + (free)(temp); + goto cleanup; + } } else { /* "\\?\" + full path + null */ @@ -171,8 +177,14 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) if(!temp) goto cleanup; - wcsncpy(temp, L"\\\\?\\", 4); - wcscpy(temp + 4, fbuf); + if(wcsncpy_s(temp, needed, L"\\\\?\\", 4)) { + (free)(temp); + goto cleanup; + } + if(wcscpy_s(temp + 4, needed, fbuf)) { + (free)(temp); + goto cleanup; + } } (free)(fbuf); From 9e6f1c5efb7a70e1f33e467a738f3e3f652f3174 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 21 Nov 2025 12:43:54 +0100 Subject: [PATCH 011/140] build: add build-level `CURL_DISABLE_TYPECHECK` options Usage: - autotools: `--disable-typecheck` (or `--enable-typecheck` (default)) - cmake: `-DCURL_DISABLE_TYPECHECK=ON`. To disable `curl_easy_setopt()`/`curl_easy_getinfo()` type checking with supported (new) gcc and clang compilers. It is useful to improve build performance for the `tests/libtest` target. In particular the CodeQL analyzer may take above an hour to compile with type checking enabled, and disabling it brings it down to seconds. On local machines it may also cut build times in half when build testdeps, depending on platform and compiler. Other than these cases, we recommend leaving type checking enabled. Ref: fdacf34aaeac79ad14fa48dcafae24a6de68823d #19632 Also: - GHA/codeql: use it. - test1165: check in `include/curl`. - lib1912: delete stray todo comment. - spelling and comment nits. Closes #19637 --- .github/workflows/codeql.yml | 6 +-- CMakeLists.txt | 4 +- configure.ac | 82 +++++++++++++++++++++++------------- docs/CURL-DISABLE.md | 10 ++++- docs/INSTALL-CMAKE.md | 3 +- include/curl/typecheck-gcc.h | 4 +- lib/curl_config.h.cmake | 5 ++- tests/libtest/lib1912.c | 3 +- tests/test1165.pl | 3 +- 9 files changed, 76 insertions(+), 44 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index c42d71773567..9ee723cf73ec 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -108,8 +108,7 @@ jobs: # MultiSSL export PKG_CONFIG_PATH; PKG_CONFIG_PATH="$(brew --prefix c-ares)/lib/pkgconfig:$(brew --prefix mbedtls)/lib/pkgconfig:$(brew --prefix rustls-ffi)/lib/pkgconfig:$(brew --prefix gsasl)/lib/pkgconfig" - cmake -B _bld1 -G Ninja -DENABLE_DEBUG=ON \ - -DCMAKE_C_FLAGS=-DCURL_DISABLE_TYPECHECK \ + cmake -B _bld1 -G Ninja -DCURL_DISABLE_TYPECHECK=ON -DENABLE_DEBUG=ON \ -DCURL_USE_GNUTLS=ON -DCURL_USE_MBEDTLS=ON -DCURL_USE_RUSTLS=ON -DCURL_USE_WOLFSSL=ON \ -DUSE_LIBRTMP=ON -DCURL_USE_GSASL=ON -DCURL_USE_GSSAPI=ON -DUSE_SSLS_EXPORT=ON -DUSE_ECH=ON -DENABLE_ARES=ON \ -DCURL_DISABLE_VERBOSE_STRINGS=ON @@ -119,8 +118,7 @@ jobs: # HTTP/3 export PKG_CONFIG_PATH; PKG_CONFIG_PATH="$(brew --prefix libnghttp3)/lib/pkgconfig:$(brew --prefix libngtcp2)/lib/pkgconfig:$(brew --prefix gsasl)/lib/pkgconfig" - cmake -B _bld2 -G Ninja \ - -DCMAKE_C_FLAGS=-DCURL_DISABLE_TYPECHECK \ + cmake -B _bld2 -G Ninja -DCURL_DISABLE_TYPECHECK=ON \ -DCURL_USE_OPENSSL=ON -DOPENSSL_ROOT_DIR="$(brew --prefix openssl)" -DUSE_NGTCP2=ON \ -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=ON \ -DUSE_LIBRTMP=ON -DCURL_USE_GSASL=ON -DCURL_USE_GSSAPI=ON -DUSE_SSLS_EXPORT=ON diff --git a/CMakeLists.txt b/CMakeLists.txt index 7de2162c6cd3..20336e097c0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -462,7 +462,7 @@ option(CURL_DISABLE_SMB "Disable SMB" OFF) mark_as_advanced(CURL_DISABLE_SMB) option(CURL_DISABLE_SMTP "Disable SMTP" OFF) mark_as_advanced(CURL_DISABLE_SMTP) -option(CURL_DISABLE_SOCKETPAIR "Disable use of socketpair for curl_multi_poll" OFF) +option(CURL_DISABLE_SOCKETPAIR "Disable use of socketpair for curl_multi_poll()" OFF) mark_as_advanced(CURL_DISABLE_SOCKETPAIR) option(CURL_DISABLE_WEBSOCKETS "Disable WebSocket" OFF) mark_as_advanced(CURL_DISABLE_WEBSOCKETS) @@ -470,6 +470,8 @@ option(CURL_DISABLE_TELNET "Disable Telnet" OFF) mark_as_advanced(CURL_DISABLE_TELNET) option(CURL_DISABLE_TFTP "Disable TFTP" OFF) mark_as_advanced(CURL_DISABLE_TFTP) +option(CURL_DISABLE_TYPECHECK "Disable curl_easy_setopt()/curl_easy_getinfo() type checking" OFF) +mark_as_advanced(CURL_DISABLE_TYPECHECK) option(CURL_DISABLE_VERBOSE_STRINGS "Disable verbose strings" OFF) mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS) diff --git a/configure.ac b/configure.ac index 6c1b9c9ba666..d72b33d5287b 100644 --- a/configure.ac +++ b/configure.ac @@ -140,36 +140,37 @@ AC_SUBST(VERSIONNUM) dnl dnl initialize all the info variables - curl_ssl_msg="no (--with-{openssl,gnutls,mbedtls,wolfssl,schannel,amissl,rustls} )" - curl_ssh_msg="no (--with-{libssh,libssh2})" - curl_zlib_msg="no (--with-zlib)" - curl_brotli_msg="no (--with-brotli)" - curl_zstd_msg="no (--with-zstd)" - curl_gss_msg="no (--with-gssapi)" - curl_gsasl_msg="no (--with-gsasl)" -curl_tls_srp_msg="no (--enable-tls-srp)" - curl_res_msg="blocking (--enable-ares / --enable-threaded-resolver)" - curl_ipv6_msg="no (--enable-ipv6)" -curl_unix_sockets_msg="no (--enable-unix-sockets)" - curl_idn_msg="no (--with-{libidn2,winidn})" - curl_docs_msg="enabled (--disable-docs)" - curl_manual_msg="no (--enable-manual)" -curl_libcurl_msg="enabled (--disable-libcurl-option)" -curl_verbose_msg="enabled (--disable-verbose)" - curl_sspi_msg="no (--enable-sspi)" - curl_ldap_msg="no (--enable-ldap / --with-ldap-lib / --with-lber-lib)" - curl_ldaps_msg="no (--enable-ldaps)" - curl_ipfs_msg="no (--enable-ipfs)" - curl_rtsp_msg="no (--enable-rtsp)" - curl_rtmp_msg="no (--with-librtmp)" - curl_psl_msg="no (--with-libpsl)" - curl_altsvc_msg="enabled (--disable-alt-svc)" -curl_headers_msg="enabled (--disable-headers-api)" - curl_hsts_msg="enabled (--disable-hsts)" - ssl_backends= - curl_h1_msg="enabled (internal)" - curl_h2_msg="no (--with-nghttp2)" - curl_h3_msg="no (--with-ngtcp2 --with-nghttp3, --with-quiche, --with-openssl-quic)" + curl_ssl_msg="no (--with-{openssl,gnutls,mbedtls,wolfssl,schannel,amissl,rustls} )" + curl_ssh_msg="no (--with-{libssh,libssh2})" + curl_zlib_msg="no (--with-zlib)" + curl_brotli_msg="no (--with-brotli)" + curl_zstd_msg="no (--with-zstd)" + curl_gss_msg="no (--with-gssapi)" + curl_gsasl_msg="no (--with-gsasl)" + curl_tls_srp_msg="no (--enable-tls-srp)" + curl_res_msg="blocking (--enable-ares / --enable-threaded-resolver)" + curl_ipv6_msg="no (--enable-ipv6)" +curl_unix_sockets_msg="no (--enable-unix-sockets)" + curl_idn_msg="no (--with-{libidn2,winidn})" + curl_docs_msg="enabled (--disable-docs)" + curl_manual_msg="no (--enable-manual)" + curl_libcurl_msg="enabled (--disable-libcurl-option)" + curl_typecheck_msg="enabled (--disable-typecheck)" + curl_verbose_msg="enabled (--disable-verbose)" + curl_sspi_msg="no (--enable-sspi)" + curl_ldap_msg="no (--enable-ldap / --with-ldap-lib / --with-lber-lib)" + curl_ldaps_msg="no (--enable-ldaps)" + curl_ipfs_msg="no (--enable-ipfs)" + curl_rtsp_msg="no (--enable-rtsp)" + curl_rtmp_msg="no (--with-librtmp)" + curl_psl_msg="no (--with-libpsl)" + curl_altsvc_msg="enabled (--disable-alt-svc)" + curl_headers_msg="enabled (--disable-headers-api)" + curl_hsts_msg="enabled (--disable-hsts)" + ssl_backends= + curl_h1_msg="enabled (internal)" + curl_h2_msg="no (--with-nghttp2)" + curl_h3_msg="no (--with-ngtcp2 --with-nghttp3, --with-quiche, --with-openssl-quic)" enable_altsvc="yes" hsts="yes" @@ -4345,6 +4346,26 @@ AC_CHECK_HEADER(dirent.h, CURL_CONVERT_INCLUDE_TO_ISYSTEM +dnl ************************************************************ +dnl disable curl_easy_setopt()/curl_easy_getinfo() type checking +dnl +AC_MSG_CHECKING([whether to enable curl_easy_setopt()/curl_easy_getinfo() type checking]) +AC_ARG_ENABLE(typecheck, +AS_HELP_STRING([--enable-typecheck],[Enable type checking (default)]) +AS_HELP_STRING([--disable-typecheck],[Disable type checking]), +[ case "$enableval" in + no) + AC_MSG_RESULT(no) + AC_DEFINE(CURL_DISABLE_TYPECHECK, 1, [to disable type checking]) + curl_typecheck_msg="no" + ;; + *) + AC_MSG_RESULT(yes) + ;; + esac ], + AC_MSG_RESULT(yes) +) + dnl ************************************************************ dnl disable verbose text strings dnl @@ -5521,6 +5542,7 @@ AC_MSG_NOTICE([Configured to build curl/libcurl: Build libcurl: Shared=${enable_shared}, Static=${enable_static} Built-in manual: ${curl_manual_msg} --libcurl option: ${curl_libcurl_msg} + Type checking: ${curl_typecheck_msg} Verbose errors: ${curl_verbose_msg} Code coverage: ${curl_coverage_msg} SSPI: ${curl_sspi_msg} diff --git a/docs/CURL-DISABLE.md b/docs/CURL-DISABLE.md index 63de4026a6d2..c266f0c0adc9 100644 --- a/docs/CURL-DISABLE.md +++ b/docs/CURL-DISABLE.md @@ -68,8 +68,8 @@ Disable the FTP (and FTPS) protocol ## `CURL_DISABLE_GETOPTIONS` -Disable the `curl_easy_options` API calls that lets users get information -about existing options to `curl_easy_setopt`. +Disable the `curl_easy_options()` API calls that lets users get information +about existing options to `curl_easy_setopt()`. ## `CURL_DISABLE_GOPHER` @@ -182,6 +182,12 @@ Disable the TELNET protocol Disable the TFTP protocol +## `CURL_DISABLE_TYPECHECK` + +Disable `curl_easy_setopt()`/`curl_easy_getinfo()` type checking. + +Useful to improve build performance for the `tests/libtest` test tool. + ## `CURL_DISABLE_VERBOSE_STRINGS` Disable verbose strings and error messages. diff --git a/docs/INSTALL-CMAKE.md b/docs/INSTALL-CMAKE.md index 9921fbf12c4c..bd9555b61461 100644 --- a/docs/INSTALL-CMAKE.md +++ b/docs/INSTALL-CMAKE.md @@ -317,10 +317,11 @@ target_link_libraries(my_target PRIVATE CURL::libcurl) - `CURL_DISABLE_SHUFFLE_DNS`: Disable shuffle DNS feature. Default: `OFF` - `CURL_DISABLE_SMB`: Disable SMB. Default: `OFF` - `CURL_DISABLE_SMTP`: Disable SMTP. Default: `OFF` -- `CURL_DISABLE_SOCKETPAIR`: Disable use of socketpair for curl_multi_poll. Default: `OFF` +- `CURL_DISABLE_SOCKETPAIR`: Disable use of socketpair for curl_multi_poll(). Default: `OFF` - `CURL_DISABLE_SRP`: Disable TLS-SRP support. Default: `OFF` - `CURL_DISABLE_TELNET`: Disable Telnet. Default: `OFF` - `CURL_DISABLE_TFTP`: Disable TFTP. Default: `OFF` +- `CURL_DISABLE_TYPECHECK`: Disable curl_easy_setopt()/curl_easy_getinfo() type checking. Default: `OFF` - `CURL_DISABLE_VERBOSE_STRINGS`: Disable verbose strings. Default: `OFF` - `CURL_DISABLE_WEBSOCKETS`: Disable WebSocket. Default: `OFF` - `HTTP_ONLY`: Disable all protocols except HTTP (This overrides all `CURL_DISABLE_*` options). Default: `OFF` diff --git a/include/curl/typecheck-gcc.h b/include/curl/typecheck-gcc.h index 063cea57e6f2..bf03e0d9359b 100644 --- a/include/curl/typecheck-gcc.h +++ b/include/curl/typecheck-gcc.h @@ -24,7 +24,7 @@ * ***************************************************************************/ -/* wraps curl_easy_setopt() with typechecking */ +/* wraps curl_easy_setopt() with type checking */ /* To add a new kind of warning, add an * if(curlcheck_sometype_option(_curl_opt)) @@ -159,7 +159,7 @@ curl_easy_setopt(handle, option, value); \ }) -/* wraps curl_easy_getinfo() with typechecking */ +/* wraps curl_easy_getinfo() with type checking */ #define curl_easy_getinfo(handle, info, arg) \ __extension__({ \ if(__builtin_constant_p(info)) { \ diff --git a/lib/curl_config.h.cmake b/lib/curl_config.h.cmake index 88b991d7ef94..acbb428575cc 100644 --- a/lib/curl_config.h.cmake +++ b/lib/curl_config.h.cmake @@ -151,7 +151,7 @@ /* disabled WebSocket */ #cmakedefine CURL_DISABLE_WEBSOCKETS 1 -/* disables use of socketpair for curl_multi_poll */ +/* disables use of socketpair for curl_multi_poll() */ #cmakedefine CURL_DISABLE_SOCKETPAIR 1 /* disables TELNET */ @@ -160,6 +160,9 @@ /* disables TFTP */ #cmakedefine CURL_DISABLE_TFTP 1 +/* disables curl_easy_setopt()/curl_easy_getinfo() type checking */ +#cmakedefine CURL_DISABLE_TYPECHECK 1 + /* disables verbose strings */ #cmakedefine CURL_DISABLE_VERBOSE_STRINGS 1 diff --git a/tests/libtest/lib1912.c b/tests/libtest/lib1912.c index dd3e63881656..0dd246e4612b 100644 --- a/tests/libtest/lib1912.c +++ b/tests/libtest/lib1912.c @@ -31,7 +31,7 @@ static CURLcode test_lib1912(const char *URL) { -/* Only test if GCC typechecking is available */ +/* Only test if GCC/clang type checking is available */ int error = 0; #ifdef CURLINC_TYPECHECK_GCC_H const struct curl_easyoption *o; @@ -73,7 +73,6 @@ static CURLcode test_lib1912(const char *URL) print_err(o->name, "CURLOT_OBJECT"); error++; } - /* Todo: no gcc typecheck for CURLOPTTYPE_BLOB types? */ } #endif (void)URL; diff --git a/tests/test1165.pl b/tests/test1165.pl index 654a2ad64265..049b764647fd 100755 --- a/tests/test1165.pl +++ b/tests/test1165.pl @@ -86,7 +86,7 @@ sub scan_cmake_config_h { scanconf_cmake(\%disable_cmake_config_h, "$root/lib/curl_config.h.cmake"); } -my %whitelisted = ("CURL_DISABLE_TYPECHECK" => 1); +my %whitelisted = ('CURL_DISABLE_DEPRECATION' => 1); sub scan_file { my ($source)=@_; @@ -114,6 +114,7 @@ sub scan_dir { } sub scan_sources { + scan_dir("$root/include/curl"); scan_dir("$root/src"); scan_dir("$root/lib"); scan_dir("$root/lib/vtls"); From 6aa8fa3fdfdb1a0d4d022cc04e478f13e2b6b880 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Fri, 21 Nov 2025 13:06:00 +0100 Subject: [PATCH 012/140] apple-sectrust: always ask when `native_ca_store` is in use When OpenSSL fails to verify the peer certificate, we checked for one specific reason code and did not ask Apple SecTrust for any other failure. Always ask Apple SecTrust after OpenSSL fails when the `native_ca_store` is enabled. If the user configures a CAfile or CApath, the native store is disabled, so this does not affect use cases where users asks curl to use a specific set of trust anchors. Do the same for GnuTLS Fixes #19636 Reported-by: ffath-vo on github Closes #19638 --- lib/vtls/gtls.c | 3 +-- lib/vtls/openssl.c | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c index dbb442f36314..55a75fa72150 100644 --- a/lib/vtls/gtls.c +++ b/lib/vtls/gtls.c @@ -1687,8 +1687,7 @@ Curl_gtls_verifyserver(struct Curl_cfilter *cf, infof(data, " SSL certificate verified by GnuTLS"); #ifdef USE_APPLE_SECTRUST - if(!verified && ssl_config->native_ca_store && - (verify_status & GNUTLS_CERT_SIGNER_NOT_FOUND)) { + if(!verified && ssl_config->native_ca_store) { result = glts_apple_verify(cf, data, peer, &chain, &verified); if(result && (result != CURLE_PEER_FAILED_VERIFICATION)) goto out; /* unexpected error */ diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index 5d35ba1a1530..8991d965d9be 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -4829,9 +4829,7 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, infof(data, "SSL certificate verified via OpenSSL."); #ifdef USE_APPLE_SECTRUST - if(!verified && - conn_config->verifypeer && ssl_config->native_ca_store && - (ossl_verify == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY)) { + if(!verified && conn_config->verifypeer && ssl_config->native_ca_store) { /* we verify using Apple SecTrust *unless* OpenSSL already verified. * This may happen if the application intercepted the OpenSSL callback * and installed its own. */ From 047b36d7a698c952b7d76ea3ce303a3d58ae637a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 21 Nov 2025 14:34:31 +0100 Subject: [PATCH 013/140] smb: fix a size check to be overflow safe In smb_send_message, although it could never actually overflow it might as well be done correctly. Also do the check earlier. Closes #19640 --- lib/smb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/smb.c b/lib/smb.c index 2aa8e96644a9..4ef35c295d15 100644 --- a/lib/smb.c +++ b/lib/smb.c @@ -668,12 +668,12 @@ static CURLcode smb_send_message(struct Curl_easy *data, unsigned char cmd, const void *msg, size_t msg_len) { - smb_format_message(smbc, req, (struct smb_header *)smbc->send_buf, - cmd, msg_len); - if((sizeof(struct smb_header) + msg_len) > MAX_MESSAGE_SIZE) { + if((MAX_MESSAGE_SIZE - sizeof(struct smb_header)) < msg_len) { DEBUGASSERT(0); return CURLE_SEND_ERROR; } + smb_format_message(smbc, req, (struct smb_header *)smbc->send_buf, + cmd, msg_len); memcpy(smbc->send_buf + sizeof(struct smb_header), msg, msg_len); return smb_send(data, smbc, sizeof(struct smb_header) + msg_len, 0); From e2be5689744716b63477d2e250b53fcac1f8c3b4 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Thu, 20 Nov 2025 10:58:54 +0100 Subject: [PATCH 014/140] multi: make max_total_* members size_t Check size_t conversion on setting these members via CURLMIPT_*. Use members without casting. Closes #19618 --- lib/cshutdn.c | 3 +-- lib/curl_setup.h | 3 +++ lib/curlx/warnless.c | 12 ++++++++++++ lib/curlx/warnless.h | 4 ++++ lib/multi.c | 6 ++++-- lib/multihandle.h | 9 ++++----- lib/url.c | 2 +- 7 files changed, 29 insertions(+), 10 deletions(-) diff --git a/lib/cshutdn.c b/lib/cshutdn.c index f9f636640a03..e039d027625b 100644 --- a/lib/cshutdn.c +++ b/lib/cshutdn.c @@ -414,8 +414,7 @@ void Curl_cshutdn_add(struct cshutdn *cshutdn, size_t conns_in_pool) { struct Curl_easy *data = cshutdn->multi->admin; - size_t max_total = (cshutdn->multi->max_total_connections > 0) ? - (size_t)cshutdn->multi->max_total_connections : 0; + size_t max_total = cshutdn->multi->max_total_connections; /* Add the connection to our shutdown list for non-blocking shutdown * during multi processing. */ diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 05e6149f6139..d75de9416cbf 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -627,6 +627,9 @@ #endif #endif +#if SIZEOF_LONG > SIZEOF_SIZE_T +#error "unexpected: 'long' is larger than 'size_t'" +#endif /* * Arg 2 type for gethostname in case it has not been defined in config file. */ diff --git a/lib/curlx/warnless.c b/lib/curlx/warnless.c index 5ed27b3e4cbf..fafa83c98c97 100644 --- a/lib/curlx/warnless.c +++ b/lib/curlx/warnless.c @@ -333,6 +333,18 @@ bool curlx_sotouz_fits(curl_off_t sonum, size_t *puznum) return TRUE; } + +bool curlx_sltouz(long slnum, size_t *puznum) +{ + if(slnum < 0) { + *puznum = 0; + return FALSE; + } + /* We error in curl_setup.h if SIZEOF_LONG > SIZEOF_SIZE_T */ + *puznum = (size_t)slnum; + return TRUE; +} + curl_off_t curlx_uztoso(size_t uznum) { #if SIZEOF_SIZE_T >= SIZEOF_CURL_OFF_T diff --git a/lib/curlx/warnless.h b/lib/curlx/warnless.h index c8861d8488c3..52e7ec2a5c5d 100644 --- a/lib/curlx/warnless.h +++ b/lib/curlx/warnless.h @@ -73,6 +73,10 @@ bool curlx_sztouz(ssize_t sznum, size_t *puznum); * too large and set 0 */ bool curlx_sotouz_fits(curl_off_t sonum, size_t *puznum); +/* Convert a long to size_t, return FALSE if negative or too large + * and set 0 */ +bool curlx_sltouz(long sznum, size_t *puznum); + #ifdef _WIN32 #undef read #define read(fd, buf, count) (ssize_t)_read(fd, buf, curlx_uztoui(count)) diff --git a/lib/multi.c b/lib/multi.c index c52ee54c7723..3fc1c948f507 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -3271,10 +3271,12 @@ CURLMcode curl_multi_setopt(CURLM *m, multi->maxconnects = (unsigned int)uarg; break; case CURLMOPT_MAX_HOST_CONNECTIONS: - multi->max_host_connections = va_arg(param, long); + if(!curlx_sltouz(va_arg(param, long), &multi->max_host_connections)) + res = CURLM_BAD_FUNCTION_ARGUMENT; break; case CURLMOPT_MAX_TOTAL_CONNECTIONS: - multi->max_total_connections = va_arg(param, long); + if(!curlx_sltouz(va_arg(param, long), &multi->max_total_connections)) + res = CURLM_BAD_FUNCTION_ARGUMENT; break; /* options formerly used for pipelining */ case CURLMOPT_MAX_PIPELINE_LENGTH: diff --git a/lib/multihandle.h b/lib/multihandle.h index 69f977bb94ed..fbb8bdfeeb59 100644 --- a/lib/multihandle.h +++ b/lib/multihandle.h @@ -149,11 +149,10 @@ struct Curl_multi { struct cshutdn cshutdn; /* connection shutdown handling */ struct cpool cpool; /* connection pool (bundles) */ - long max_host_connections; /* if >0, a fixed limit of the maximum number - of connections per host */ - - long max_total_connections; /* if >0, a fixed limit of the maximum number - of connections in total */ + size_t max_host_connections; /* if >0, a fixed limit of the maximum number + of connections per host */ + size_t max_total_connections; /* if >0, a fixed limit of the maximum number + of connections in total */ /* timer callback and user data pointer for the *socket() API */ curl_multi_timer_callback timer_cb; diff --git a/lib/url.c b/lib/url.c index b4069e30f18b..7e4d455a8cd8 100644 --- a/lib/url.c +++ b/lib/url.c @@ -3690,7 +3690,7 @@ static CURLcode create_conn(struct Curl_easy *data, CURL_TRC_M(data, "Allowing sub-requests (like DoH) to override " "max connection limit"); else { - infof(data, "No connections available, total of %ld reached.", + infof(data, "No connections available, total of %zu reached.", data->multi->max_total_connections); connections_available = FALSE; } From a439fc0e372c3de7df3b8ae3ca7752bc3cbca826 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 20 Nov 2025 05:59:59 +0000 Subject: [PATCH 015/140] GHA: update gnutls/gnutls to 3.8.11 from 3.8.10 Closes #19613 --- .github/workflows/http3-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/http3-linux.yml b/.github/workflows/http3-linux.yml index 223c6afbf46d..10aac5e0c699 100644 --- a/.github/workflows/http3-linux.yml +++ b/.github/workflows/http3-linux.yml @@ -47,7 +47,7 @@ env: # renovate: datasource=github-tags depName=google/boringssl versioning=semver registryUrl=https://github.com BORINGSSL_VERSION: 0.20251110.0 # renovate: datasource=github-tags depName=gnutls/gnutls versioning=semver registryUrl=https://github.com - GNUTLS_VERSION: 3.8.10 + GNUTLS_VERSION: 3.8.11 # renovate: datasource=github-tags depName=wolfSSL/wolfssl versioning=semver extractVersion=^v?(?.+)-stable$ registryUrl=https://github.com WOLFSSL_VERSION: 5.8.4 # renovate: datasource=github-tags depName=ngtcp2/nghttp3 versioning=semver registryUrl=https://github.com From acfcc2b28806a1be7e027205673b1a33618ddfb5 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 21 Nov 2025 15:57:17 +0100 Subject: [PATCH 016/140] checksrc: ban `_tcsncpy`, `wcscpy`, `wcsncpy` Follow-up to eaa7651374898cef89e5783b0219bdffcc0eb60e #19589 Closes #19641 --- scripts/checksrc.pl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/checksrc.pl b/scripts/checksrc.pl index c9f008f1a1df..88db59f116d1 100755 --- a/scripts/checksrc.pl +++ b/scripts/checksrc.pl @@ -78,11 +78,14 @@ "_mbsncat" => 1, "_tcscat" => 1, "_tcsdup" => 1, + "_tcsncpy" => 1, "_tcsncat" => 1, "_wcscat" => 1, "_wcsncat" => 1, "_wcsdup" => 1, "wcsdup" => 1, + "wcscpy" => 1, + "wcsncpy" => 1, "LoadLibrary" => 1, "LoadLibraryA" => 1, "LoadLibraryW" => 1, From 18b94293133c1e035b5ac5b4fde854d1f17418a3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 18 Nov 2025 01:48:04 +0100 Subject: [PATCH 017/140] curlx: replace `mbstowcs`/`wcstombs` with `_s` counterparts (Windows) They are used in Windows-specific `fopen()`, `freopen`, `open()` and `curlx_get_winapi_error()` calls, and in `fix_excessive_path()` in Unicode builds. Refs: https://learn.microsoft.com/cpp/c-runtime-library/reference/mbstowcs-mbstowcs-l https://learn.microsoft.com/cpp/c-runtime-library/reference/mbstowcs-s-mbstowcs-s-l https://learn.microsoft.com/cpp/c-runtime-library/reference/wcstombs-wcstombs-l https://learn.microsoft.com/cpp/c-runtime-library/reference/wcstombs-s-wcstombs-s-l Also ban these functions via checksrc. Co-authored-by: Jay Satiro Closes #19581 --- lib/curl_setup.h | 3 +-- lib/curlx/fopen.c | 22 ++++++++++++---------- lib/curlx/winapi.c | 30 +++++++++++++----------------- scripts/checksrc.pl | 2 ++ 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/lib/curl_setup.h b/lib/curl_setup.h index d75de9416cbf..db438a8b0a47 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -97,8 +97,7 @@ #ifndef _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS /* for __sys_errlist, __sys_nerr, _open(), _wfopen(), _wopen(), fopen(), freopen(), - getenv(), gmtime(), mbstowcs(), sprintf(), - strcpy(), wcstombs(), + getenv(), gmtime(), sprintf(), strcpy(), in tests: localtime(), open(), sscanf() */ #endif #endif /* _MSC_VER */ diff --git a/lib/curlx/fopen.c b/lib/curlx/fopen.c index f33075316250..dc1c2bb4e67d 100644 --- a/lib/curlx/fopen.c +++ b/lib/curlx/fopen.c @@ -97,15 +97,16 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) #ifndef _UNICODE /* convert multibyte input to unicode */ - needed = mbstowcs(NULL, in, 0); - if(needed == (size_t)-1 || needed >= max_path_len) + if(mbstowcs_s(&needed, NULL, 0, in, 0)) + goto cleanup; + if(!needed || needed >= max_path_len) goto cleanup; - ++needed; /* for NUL */ ibuf = (malloc)(needed * sizeof(wchar_t)); if(!ibuf) goto cleanup; - count = mbstowcs(ibuf, in, needed); - if(count == (size_t)-1 || count >= needed) + if(mbstowcs_s(&count, ibuf, needed, in, needed - 1)) + goto cleanup; + if(count != needed) goto cleanup; in_w = ibuf; #else @@ -193,15 +194,16 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) #ifndef _UNICODE /* convert unicode full path to multibyte output */ - needed = wcstombs(NULL, fbuf, 0); - if(needed == (size_t)-1 || needed >= max_path_len) + if(wcstombs_s(&needed, NULL, 0, fbuf, 0)) + goto cleanup; + if(!needed || needed >= max_path_len) goto cleanup; - ++needed; /* for NUL */ obuf = (malloc)(needed); if(!obuf) goto cleanup; - count = wcstombs(obuf, fbuf, needed); - if(count == (size_t)-1 || count >= needed) + if(wcstombs_s(&count, obuf, needed, fbuf, needed - 1)) + goto cleanup; + if(count != needed) goto cleanup; *out = obuf; obuf = NULL; diff --git a/lib/curlx/winapi.c b/lib/curlx/winapi.c index 2dc277c1c1fa..7b3d6b60369c 100644 --- a/lib/curlx/winapi.c +++ b/lib/curlx/winapi.c @@ -52,6 +52,7 @@ const char *curlx_get_winapi_error(DWORD err, char *buf, size_t buflen) { char *p; wchar_t wbuf[256]; + DWORD wlen; if(!buflen) return NULL; @@ -62,23 +63,18 @@ const char *curlx_get_winapi_error(DWORD err, char *buf, size_t buflen) /* We return the local codepage version of the error string because if it is output to the user's terminal it will likely be with functions which expect the local codepage (eg fprintf, failf, infof). */ - if(FormatMessageW((FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS), NULL, err, - LANG_NEUTRAL, wbuf, CURL_ARRAYSIZE(wbuf), NULL)) { - size_t written = wcstombs(buf, wbuf, buflen - 1); - if(written != (size_t)-1) - buf[written] = '\0'; - else - *buf = '\0'; - } - - /* Truncate multiple lines */ - p = strchr(buf, '\n'); - if(p) { - if(p > buf && *(p-1) == '\r') - *(p-1) = '\0'; - else - *p = '\0'; + wlen = FormatMessageW((FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS), NULL, err, + LANG_NEUTRAL, wbuf, CURL_ARRAYSIZE(wbuf), NULL); + if(wlen && !wcstombs_s(NULL, buf, buflen, wbuf, wlen)) { + /* Truncate multiple lines */ + p = strchr(buf, '\n'); + if(p) { + if(p > buf && *(p-1) == '\r') + *(p-1) = '\0'; + else + *p = '\0'; + } } return *buf ? buf : NULL; diff --git a/scripts/checksrc.pl b/scripts/checksrc.pl index 88db59f116d1..a2f458b6c1ac 100755 --- a/scripts/checksrc.pl +++ b/scripts/checksrc.pl @@ -86,6 +86,8 @@ "wcsdup" => 1, "wcscpy" => 1, "wcsncpy" => 1, + "mbstowcs" => 1, + "wcstombs" => 1, "LoadLibrary" => 1, "LoadLibraryA" => 1, "LoadLibraryW" => 1, From 905b718de3fb9287c7c0037b2737aa395f01ad3c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 21 Nov 2025 16:53:51 +0100 Subject: [PATCH 018/140] Revert "GHA: update gnutls/gnutls to 3.8.11 from 3.8.10" This reverts commit a439fc0e372c3de7df3b8ae3ca7752bc3cbca826. It requires a version of libnettle that is not included in these Ubuntu versions: "Libnettle 3.10 was not found" Closes #19642 --- .github/workflows/http3-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/http3-linux.yml b/.github/workflows/http3-linux.yml index 10aac5e0c699..223c6afbf46d 100644 --- a/.github/workflows/http3-linux.yml +++ b/.github/workflows/http3-linux.yml @@ -47,7 +47,7 @@ env: # renovate: datasource=github-tags depName=google/boringssl versioning=semver registryUrl=https://github.com BORINGSSL_VERSION: 0.20251110.0 # renovate: datasource=github-tags depName=gnutls/gnutls versioning=semver registryUrl=https://github.com - GNUTLS_VERSION: 3.8.11 + GNUTLS_VERSION: 3.8.10 # renovate: datasource=github-tags depName=wolfSSL/wolfssl versioning=semver extractVersion=^v?(?.+)-stable$ registryUrl=https://github.com WOLFSSL_VERSION: 5.8.4 # renovate: datasource=github-tags depName=ngtcp2/nghttp3 versioning=semver registryUrl=https://github.com From 7d75c728a65be961c63169fcf9f307c3324e440b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 20 Nov 2025 23:57:04 +0100 Subject: [PATCH 019/140] KNOWN_RISKS: known risks when running and using curl and libcurl Closes #19631 --- docs/KNOWN_RISKS.md | 138 ++++++++++++++++++++++++++++++++++++++++++++ docs/Makefile.am | 1 + 2 files changed, 139 insertions(+) create mode 100644 docs/KNOWN_RISKS.md diff --git a/docs/KNOWN_RISKS.md b/docs/KNOWN_RISKS.md new file mode 100644 index 000000000000..3773b94f86bd --- /dev/null +++ b/docs/KNOWN_RISKS.md @@ -0,0 +1,138 @@ + + +# Known Risks + +This is an incomplete list of known risks when running and using curl and +libcurl. + +## Insecure transfers + +When using curl to perform transfers with protocols that are insecure or the +server identity is unverified, everything that is sent and received can be +intercepted by eavesdroppers and the servers can easily be spoofed by +impostors. + +## Untrusted input + +You should **never** run curl command lines or use curl config files provided +to you from untrusted sources. + +curl can do a lot of things, and you should only ask it do things you want and +deem correct. + +Even just accepting just the URL part without careful vetting might make curl +do things you do not like. Like accessing internal hosts, like connecting to +rogue servers that redirect to even weirder places, like using ports or +protocols that play tricks on you. + +## Command line misuse + +The command line tool and its options should be used and be expected to work +as documented. Relying on undocumented functions or side-effects is unreliable +as they may cause problems or get changed behavior between releases. + +For several command line options, you can confuse either curl or the involved +server endpoint by using characters or byte sequences for the option that are +not expected. For example, adding line feeds and/or carriage returns to inputs +can produce unexpected, invalid, or insecure results. + +## API misuse + +Applications using the libcurl API in a way that is not documented to work or +even documented to not work, is unsafe and might cause security problems. We +only guarantee secure and proper functionality when the APIs are used as +documented. + +## Local attackers already present + +When there is a local attacker present locally, curl cannot prevent such an +adversary to use curl's full potential. Possibly in malicious ways. + +## Remote attackers already present + +When there is a remote attacker already present in the server, curl cannot +protect its operations against mischief. For example, if an attacker manages +to insert a symlink in your remote upload directory the upload may cause +havoc. Maybe the attacker makes certain responses come back with unexpected +content. + +## Debug & Experiments + +We encourage users to test curl experiments and use debug code, but only in +controlled environments and setups - never in production. + +Using debug builds and experimental curl features in production is a security +risk. Do not do that. + +The same applies to scripts and software which are not installed by default +through the make install rule: they are not intended or made for production +use. + +## URL inconsistencies + +URL parser inconsistencies between browsers and curl are expected and are not +considered security vulnerabilities. The WHATWG URL Specification and RFC +3986+ (the plus meaning that it is an extended version) [are not completely +interoperable](https://github.com/bagder/docs/blob/master/URL-interop.md). + +You must never expect two independent URL parsers to treat every URL +identically. + +## Visible command line arguments + +The curl command blanks the contents of a number of command line arguments to +prevent them from appearing in process listings. It does not blank all +arguments, even though some that are not blanked might contain sensitive data. + + - not all systems allow the arguments to be blanked in the first place + - since curl blanks the argument itself they are readable for a short moment + no matter what + - virtually every argument can contain sensitive data, depending on use + - blanking all arguments would make it impractical for users to differentiate + curl command lines in process listings + +## HTTP headers in redirects + +It is powerful to provide a set of custom headers to curl. Beware that when +asking curl to follow HTTP redirects, it also sends those headers to the new +URL which might be a different server. That might do another redirect etc. + +curl makes some limited attempts to not leak credentials this way when set +using the standard curl options, but when you pass on custom headers curl +cannot know what headers or details in those headers are sensitive. + +## Verbose logs + +When asked to provide verbose output and trace logging, curl may output and +show details that are private and sensitive. Like for example raw credentials +or the password weakly disguised using base64 encoding. + +## Terminal output and escape sequences + +Content that is transferred from a server and gets displayed in a terminal by +curl may contain escape sequences or use other tricks to fool the user. Escape +sequences, moving cursor, changing color etc, is also frequently used for +good. To reduce the risk of getting fooled, save files and browse them after +download using a display method that minimizes risks. + +## Legacy dependencies + +Every curl build is made to use a range of third party libraries. Each third +party library also needs to be safe and secure for the entire operation to be +risk-free. + +Relying on legacy dependencies is a risk. + +## Weak algorithms + +curl supports several cryptographic algorithms that are considered weak, like +DES and MD5. These algorithms are still in use because some protocols and +transfer options require use of them. For example NTLM or legacy HTTP Digest +authentication. + +curl users should consider switching to servers and options that use modern +and secure algorithms. diff --git a/docs/Makefile.am b/docs/Makefile.am index 65ba28c0eb50..5349c63cc22d 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -108,6 +108,7 @@ EXTRA_DIST = \ INTERNALS.md \ IPFS.md \ KNOWN_BUGS \ + KNOWN_RISKS.md \ MAIL-ETIQUETTE.md \ MANUAL.md \ options-in-versions \ From 4ebef2f0d9e3d14c31bdc342235863ef30bdf7d1 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 22 Nov 2025 18:03:40 +0100 Subject: [PATCH 020/140] tool_operate: fix case of ignoring return code in single_transfer When glob_url() returns error, stop. Closes #19649 --- src/tool_operate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tool_operate.c b/src/tool_operate.c index b969375422c3..eea5ff37a260 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -1199,7 +1199,7 @@ static CURLcode single_transfer(struct OperationConfig *config, if(u->infile) { if(!config->globoff && !glob_inuse(&state->inglob)) result = glob_url(&state->inglob, u->infile, &state->upnum, err); - if(!state->uploadfile) { + if(!result && !state->uploadfile) { if(glob_inuse(&state->inglob)) result = glob_next_url(&state->uploadfile, &state->inglob); else if(!state->upidx) { From 36b9987acbc42734b1dab0e3f96d64aba1350839 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 22 Nov 2025 19:09:42 +0100 Subject: [PATCH 021/140] tool_operate: fix a case of ignoring return code in operate() If get_args() returns error, do not overwrite the variable in the next call. Also, avoid allocating memory for the default user-agent. Closes #19650 --- src/config2setopts.c | 4 +++- src/tool_operate.c | 24 +++++++++++++----------- src/tool_paramhlp.c | 17 ----------------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/config2setopts.c b/src/config2setopts.c index 154319231f11..d3bd39c8647c 100644 --- a/src/config2setopts.c +++ b/src/config2setopts.c @@ -37,6 +37,7 @@ #include "tool_cb_see.h" #include "tool_cb_dbg.h" #include "tool_helpers.h" +#include "tool_version.h" #define BUFFER_SIZE 102400L @@ -874,7 +875,8 @@ CURLcode config2setopts(struct OperationConfig *config, if(proto_http || proto_rtsp) { MY_SETOPT_STR(curl, CURLOPT_REFERER, config->referer); - MY_SETOPT_STR(curl, CURLOPT_USERAGENT, config->useragent); + MY_SETOPT_STR(curl, CURLOPT_USERAGENT, config->useragent ? + config->useragent : CURL_NAME "/" CURL_VERSION); } if(use_proto == proto_http || use_proto == proto_https) { diff --git a/src/tool_operate.c b/src/tool_operate.c index eea5ff37a260..69cfef96d786 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -2321,17 +2321,19 @@ CURLcode operate(int argc, argv_item_t argv[]) operation = operation->next; } while(!result && operation); - /* Set the current operation pointer */ - global->current = global->first; - - /* now run! */ - result = run_all_transfers(share, result); - - if(global->ssl_sessions && feature_ssls_export) { - CURLcode r2 = tool_ssls_save(global->first, share, - global->ssl_sessions); - if(r2 && !result) - result = r2; + if(!result) { + /* Set the current operation pointer */ + global->current = global->first; + + /* now run! */ + result = run_all_transfers(share, result); + + if(global->ssl_sessions && feature_ssls_export) { + CURLcode r2 = tool_ssls_save(global->first, share, + global->ssl_sessions); + if(r2 && !result) + result = r2; + } } } diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 2e7b98f26eb0..15293c0cc6ce 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -650,14 +650,6 @@ long delegation(const char *str) return CURLGSSAPI_DELEGATION_NONE; } -/* - * my_useragent: returns allocated string with default user agent - */ -static char *my_useragent(void) -{ - return strdup(CURL_NAME "/" CURL_VERSION); -} - #define isheadersep(x) ((((x)==':') || ((x)==';'))) /* @@ -705,15 +697,6 @@ CURLcode get_args(struct OperationConfig *config, const size_t i) if(!result && config->proxyuserpwd) result = checkpasswd("proxy", i, last, &config->proxyuserpwd); - /* Check if we have a user agent */ - if(!result && !config->useragent) { - config->useragent = my_useragent(); - if(!config->useragent) { - errorf("out of memory"); - result = CURLE_OUT_OF_MEMORY; - } - } - return result; } From f13f320dee7ea37bc01cc7b4282450b6165373c9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 22 Nov 2025 22:44:39 +0100 Subject: [PATCH 022/140] tool_msgs: make voutf() use stack instead of heap For printf()ing the message to show. Closes #19651 --- src/tool_msgs.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/tool_msgs.c b/src/tool_msgs.c index 896788745c7c..ae0b6b983586 100644 --- a/src/tool_msgs.c +++ b/src/tool_msgs.c @@ -42,18 +42,15 @@ static void voutf(const char *prefix, const char *fmt, va_list ap) { - size_t width = (get_terminal_columns() - strlen(prefix)); size_t len; char *ptr; - char *print_buffer; + char buffer[1024]; + size_t termw = get_terminal_columns(); + size_t prefw = strlen(prefix); + size_t width = termw > prefw ? termw - prefw : SIZE_MAX; DEBUGASSERT(!strchr(fmt, '\n')); - - print_buffer = curl_mvaprintf(fmt, ap); - if(!print_buffer) - return; - len = strlen(print_buffer); - - ptr = print_buffer; + len = curl_mvsnprintf(buffer, sizeof(buffer), fmt, ap); + ptr = buffer; while(len > 0) { fputs(prefix, tool_stderr); @@ -79,7 +76,6 @@ static void voutf(const char *prefix, len = 0; } } - curl_free(print_buffer); } /* From 74f7505974836f633c955dbce7514f12f78ddc5b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 23 Nov 2025 14:42:59 +0100 Subject: [PATCH 023/140] asyn-ares: remove hostname free on OOM The freeing of the already allocated hostname is done by Curl_async_shutdown(). This extra free in the RR code path made a double-free. Presumably not detected because the CI torture tests don't run HTTPS-RR enabled? Follow-up to 8d0bfe74fb Closes #19658 --- lib/asyn-ares.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index ad9147a01c34..e01f7ba3d24e 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -748,10 +748,8 @@ struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, #ifdef USE_HTTPSRR if(port != 443) { rrname = curl_maprintf("_%d_.https.%s", port, hostname); - if(!rrname) { - free(data->state.async.hostname); + if(!rrname) return NULL; - } } #endif From 29b3b1ae6d7ce561700cfe81aaba3b3ebc8a7a6a Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Sun, 23 Nov 2025 16:59:40 +0100 Subject: [PATCH 024/140] wolfssl: fix cipher list, skip 5.8.4 regression - adjust cipher list in infof() statement for min/max TLS version - skip test_17_07 for wolfSSL 5.8.4 when CHACHA20 is negotiated due to regression with homebrew build on ARM systems. Fixes #19644 Reported-by: Viktor Szakats Closes #19662 --- lib/vtls/wolfssl.c | 52 +++++++++++++++++++++-------------- tests/http/test_17_ssl_use.py | 4 +++ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c index a8090d1bf1ad..c8fc8c4add1a 100644 --- a/lib/vtls/wolfssl.c +++ b/lib/vtls/wolfssl.c @@ -1043,62 +1043,69 @@ static CURLcode client_certificate(struct Curl_easy *data, static CURLcode ssl_version(struct Curl_easy *data, struct ssl_primary_config *conn_config, - struct wssl_ctx *wctx) + struct wssl_ctx *wctx, + int *min_version, int *max_version) { int res; + *min_version = *max_version = 0; switch(conn_config->version) { case CURL_SSLVERSION_DEFAULT: case CURL_SSLVERSION_TLSv1: case CURL_SSLVERSION_TLSv1_0: - res = wolfSSL_CTX_set_min_proto_version(wctx->ssl_ctx, TLS1_VERSION); + *min_version = TLS1_VERSION; break; case CURL_SSLVERSION_TLSv1_1: - res = wolfSSL_CTX_set_min_proto_version(wctx->ssl_ctx, TLS1_1_VERSION); + *min_version = TLS1_1_VERSION; break; case CURL_SSLVERSION_TLSv1_2: - res = wolfSSL_CTX_set_min_proto_version(wctx->ssl_ctx, TLS1_2_VERSION); + *min_version = TLS1_2_VERSION; break; #ifdef WOLFSSL_TLS13 case CURL_SSLVERSION_TLSv1_3: - res = wolfSSL_CTX_set_min_proto_version(wctx->ssl_ctx, TLS1_3_VERSION); + *min_version = TLS1_3_VERSION; break; #endif default: failf(data, "wolfSSL: unsupported minimum TLS version value"); return CURLE_SSL_CONNECT_ERROR; } - if(res != WOLFSSL_SUCCESS) { - failf(data, "wolfSSL: failed set the minimum TLS version"); - return CURLE_SSL_CONNECT_ERROR; - } switch(conn_config->version_max) { #ifdef WOLFSSL_TLS13 case CURL_SSLVERSION_MAX_TLSv1_3: - res = wolfSSL_CTX_set_max_proto_version(wctx->ssl_ctx, TLS1_3_VERSION); + *max_version = TLS1_3_VERSION; break; #endif case CURL_SSLVERSION_MAX_TLSv1_2: - res = wolfSSL_CTX_set_max_proto_version(wctx->ssl_ctx, TLS1_2_VERSION); + *max_version = TLS1_2_VERSION; break; case CURL_SSLVERSION_MAX_TLSv1_1: - res = wolfSSL_CTX_set_max_proto_version(wctx->ssl_ctx, TLS1_1_VERSION); + *max_version = TLS1_1_VERSION; break; case CURL_SSLVERSION_MAX_TLSv1_0: - res = wolfSSL_CTX_set_max_proto_version(wctx->ssl_ctx, TLS1_VERSION); + *max_version = TLS1_VERSION; break; case CURL_SSLVERSION_MAX_DEFAULT: case CURL_SSLVERSION_MAX_NONE: - res = WOLFSSL_SUCCESS; break; default: failf(data, "wolfSSL: unsupported maximum TLS version value"); return CURLE_SSL_CONNECT_ERROR; } + + res = wolfSSL_CTX_set_min_proto_version(wctx->ssl_ctx, *min_version); if(res != WOLFSSL_SUCCESS) { - failf(data, "wolfSSL: failed set the maximum TLS version"); + failf(data, "wolfSSL: failed set the minimum TLS version"); return CURLE_SSL_CONNECT_ERROR; } + + if(*max_version) { + res = wolfSSL_CTX_set_max_proto_version(wctx->ssl_ctx, *max_version); + if(res != WOLFSSL_SUCCESS) { + failf(data, "wolfSSL: failed set the maximum TLS version"); + return CURLE_SSL_CONNECT_ERROR; + } + } return CURLE_OK; } @@ -1126,6 +1133,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, #endif CURLcode result = CURLE_FAILED_INIT; unsigned char transport; + int tls_min, tls_max; DEBUGASSERT(!wctx->ssl_ctx); DEBUGASSERT(!wctx->ssl); @@ -1159,7 +1167,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, goto out; } - result = ssl_version(data, conn_config, wctx); + result = ssl_version(data, conn_config, wctx, &tls_min, &tls_max); if(result) goto out; @@ -1183,12 +1191,14 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, struct dynbuf c; curlx_dyn_init(&c, MAX_CIPHER_LEN); - if(ciphers13) - result = curlx_dyn_add(&c, ciphers13); - else - result = wssl_add_default_ciphers(TRUE, &c); + if(!tls_max || (tls_max >= TLS1_3_VERSION)) { + if(ciphers13) + result = curlx_dyn_add(&c, ciphers13); + else + result = wssl_add_default_ciphers(TRUE, &c); + } - if(!result) { + if(!result && (tls_min < TLS1_3_VERSION)) { if(ciphers12) { if(curlx_dyn_len(&c)) result = curlx_dyn_addn(&c, ":", 1); diff --git a/tests/http/test_17_ssl_use.py b/tests/http/test_17_ssl_use.py index 58ad7fdf1576..85c43d568e2c 100644 --- a/tests/http/test_17_ssl_use.py +++ b/tests/http/test_17_ssl_use.py @@ -258,6 +258,10 @@ def test_17_07_ssl_ciphers(self, env: Env, httpd, configures_httpd, curl = CurlClient(env=env) url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo' # SSL backend specifics + # see wolfSSL/wolfssl#9462 + if env.curl_uses_lib('wolfssl') and env.curl_lib_version('wolfssl') == '5.8.4' \ + and ciphers13 and 'TLS_CHACHA20_POLY1305_SHA256' in ciphers13: + pytest.skip('wolfSSL 5.8.4 is borked on ARM with CHACHA20') if env.curl_uses_lib('gnutls'): pytest.skip('GnuTLS does not support setting ciphers') elif env.curl_uses_lib('boringssl'): From 74cf7725d7c47cb66818063bbb1773b4fc6e1247 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 23 Nov 2025 09:37:41 +0000 Subject: [PATCH 025/140] GHA: update ngtcp2/ngtcp2 to v1.18.0 from v1.17.0 Closes #19655 --- .github/workflows/http3-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/http3-linux.yml b/.github/workflows/http3-linux.yml index 223c6afbf46d..e7406c16eb58 100644 --- a/.github/workflows/http3-linux.yml +++ b/.github/workflows/http3-linux.yml @@ -53,7 +53,7 @@ env: # renovate: datasource=github-tags depName=ngtcp2/nghttp3 versioning=semver registryUrl=https://github.com NGHTTP3_VERSION: 1.12.0 # renovate: datasource=github-tags depName=ngtcp2/ngtcp2 versioning=semver registryUrl=https://github.com - NGTCP2_VERSION: 1.17.0 + NGTCP2_VERSION: 1.18.0 # renovate: datasource=github-tags depName=nghttp2/nghttp2 versioning=semver registryUrl=https://github.com NGHTTP2_VERSION: 1.68.0 # renovate: datasource=github-tags depName=cloudflare/quiche versioning=semver registryUrl=https://github.com From 4d04a0301629d1d37476e312202c0c62b5db309e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 23 Nov 2025 18:23:32 +0000 Subject: [PATCH 026/140] GHA: update ngtcp2/nghttp3 to v1.13.0 from v1.12.0 Closes #19654 --- .github/workflows/http3-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/http3-linux.yml b/.github/workflows/http3-linux.yml index e7406c16eb58..a6c5972cd948 100644 --- a/.github/workflows/http3-linux.yml +++ b/.github/workflows/http3-linux.yml @@ -51,7 +51,7 @@ env: # renovate: datasource=github-tags depName=wolfSSL/wolfssl versioning=semver extractVersion=^v?(?.+)-stable$ registryUrl=https://github.com WOLFSSL_VERSION: 5.8.4 # renovate: datasource=github-tags depName=ngtcp2/nghttp3 versioning=semver registryUrl=https://github.com - NGHTTP3_VERSION: 1.12.0 + NGHTTP3_VERSION: 1.13.0 # renovate: datasource=github-tags depName=ngtcp2/ngtcp2 versioning=semver registryUrl=https://github.com NGTCP2_VERSION: 1.18.0 # renovate: datasource=github-tags depName=nghttp2/nghttp2 versioning=semver registryUrl=https://github.com From b5265b24b059c1d37512d76b767ff832a68ab817 Mon Sep 17 00:00:00 2001 From: bttrfl on github <33011292+bttrfl@users.noreply.github.com> Date: Sun, 23 Nov 2025 06:55:16 +0300 Subject: [PATCH 027/140] speedcheck: do not trigger low speed cancel on transfers with CURL_READFUNC_PAUSE When a trasfer is paused from a read callback with a CURL_READFUNC_PAUSE code, it should be excluded from the speedcheck. Currently only transfers paused from write callbacks are excluded, because the code only checks for "recv direction" of the transfer. This commit adds a check for "send direction". Issue similar to https://github.com/curl/curl/issues/6358 Closes #19653 --- lib/speedcheck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/speedcheck.c b/lib/speedcheck.c index aede06001920..b074199c37d6 100644 --- a/lib/speedcheck.c +++ b/lib/speedcheck.c @@ -42,7 +42,7 @@ void Curl_speedinit(struct Curl_easy *data) CURLcode Curl_speedcheck(struct Curl_easy *data, struct curltime now) { - if(Curl_xfer_recv_is_paused(data)) + if(Curl_xfer_recv_is_paused(data) || Curl_xfer_send_is_paused(data)) /* A paused transfer is not qualified for speed checks */ return CURLE_OK; From c77bed81a2e1325ffdebc223c27e3d1355147529 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 18 Nov 2025 14:29:09 +0100 Subject: [PATCH 028/140] memdebug: produce stack trace dump with libbacktrace Enable with "configure --enable-backtrace", inserts a backtrace in the memdump log when a torture test limit is reached. Closes #19657 --- configure.ac | 16 ++++++++++++++++ lib/memdebug.c | 38 ++++++++++++++++++++++++++++++++++++++ tests/memanalyze.pl | 5 ++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index d72b33d5287b..1481a096b2bc 100644 --- a/configure.ac +++ b/configure.ac @@ -1108,6 +1108,22 @@ AS_HELP_STRING([--enable-libgcc],[use libgcc when linking]), AC_MSG_RESULT(no) ) +AC_MSG_CHECKING([whether to use libbacktrace]) +AC_ARG_WITH(backtrace, +AS_HELP_STRING([--enable-backtrace],[use libbacktrace when linking]), +[ case "$enableval" in + yes) + LIBS="-lbacktrace $LIBS" + AC_DEFINE(USE_BACKTRACE, 1, [if libbacktrace is in use]) + AC_MSG_RESULT(yes) + ;; + *) + AC_MSG_RESULT(no) + ;; + esac ], + AC_MSG_RESULT(no) +) + CURL_CHECK_LIB_XNET dnl gethostbyname without lib or in the nsl lib? diff --git a/lib/memdebug.c b/lib/memdebug.c index 758c7b6aa7e2..cbda4a2be144 100644 --- a/lib/memdebug.c +++ b/lib/memdebug.c @@ -31,6 +31,10 @@ #include "urldata.h" #include "curlx/fopen.h" /* for CURLX_FOPEN_LOW(), CURLX_FREOPEN_LOW() */ +#ifdef USE_BACKTRACE +#include "backtrace.h" +#endif + /* The last 2 #include files should be in this order */ #include "curl_memory.h" #include "memdebug.h" @@ -58,6 +62,9 @@ FILE *curl_dbg_logfile = NULL; static bool registered_cleanup = FALSE; /* atexit registered cleanup */ static bool memlimit = FALSE; /* enable memory limit */ static long memsize = 0; /* set number of mallocs allowed */ +#ifdef USE_BACKTRACE +struct backtrace_state *btstate; +#endif /* LeakSantizier (LSAN) calls _exit() instead of exit() when a leak is detected on exit so the logfile must be closed explicitly or data could be lost. @@ -73,6 +80,33 @@ static void curl_dbg_cleanup(void) } curl_dbg_logfile = NULL; } +#ifdef USE_BACKTRACE +static void error_callback(void *data, const char *message, int error_number) +{ + (void)data; + if(error_number == -1) + curl_dbg_log("compile with -g\n\n"); + else + curl_dbg_log("Backtrace error %d: %s\n", error_number, message); +} + +static int full_callback(void *data, uintptr_t pc, const char *pathname, + int line_number, const char *function) +{ + (void)data; + (void)pc; + if(pathname || function || line_number) + curl_dbg_log("BT %s:%d -- %s\n", pathname, line_number, function); + return 0; +} + +static void dump_bt(void) +{ + backtrace_full(btstate, 0, full_callback, error_callback, NULL); +} +#else +#define dump_bt() /* nothing to do */ +#endif /* this sets the log filename */ void curl_dbg_memdebug(const char *logname) @@ -88,6 +122,9 @@ void curl_dbg_memdebug(const char *logname) setbuf(curl_dbg_logfile, (char *)NULL); #endif } +#ifdef USE_BACKTRACE + btstate = backtrace_create_state(NULL, 0, error_callback, NULL); +#endif if(!registered_cleanup) registered_cleanup = !atexit(curl_dbg_cleanup); } @@ -115,6 +152,7 @@ static bool countcheck(const char *func, int line, const char *source) /* log to stderr also */ curl_mfprintf(stderr, "LIMIT %s:%d %s reached memlimit\n", source, line, func); + dump_bt(); fflush(curl_dbg_logfile); /* because it might crash now */ /* !checksrc! disable ERRNOVAR 1 */ errno = ENOMEM; diff --git a/tests/memanalyze.pl b/tests/memanalyze.pl index e35b2e7abadf..2b38e5e8a424 100755 --- a/tests/memanalyze.pl +++ b/tests/memanalyze.pl @@ -130,7 +130,10 @@ sub newtotal { chomp $_; my $line = $_; $lnum++; - if($line =~ /^LIMIT ([^ ]*):(\d*) (.*)/) { + if($line =~ /^BT/) { + # back-trace, ignore + } + elsif($line =~ /^LIMIT ([^ ]*):(\d*) (.*)/) { # new memory limit test prefix my $i = $3; my ($source, $linenum) = ($1, $2); From 039fb84cb4e05cc899bb00b2c8456677516529c1 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 24 Nov 2025 13:08:37 +0100 Subject: [PATCH 029/140] tool_writeout: bail out proper on OOM Closes #19667 --- src/tool_writeout.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tool_writeout.c b/src/tool_writeout.c index cdfa23a752d9..52b35345f4a9 100644 --- a/src/tool_writeout.c +++ b/src/tool_writeout.c @@ -763,6 +763,8 @@ void ourWriteOut(struct OperationConfig *config, struct per_transfer *per, variables, CURL_ARRAYSIZE(variables), sizeof(variables[0]), matchvar); } + else + break; if(wv) { switch(wv->id) { case VAR_ONERROR: From d03712169b7a02e3a9b3c3a5c060395ed37b626e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 24 Nov 2025 12:49:15 +0100 Subject: [PATCH 030/140] cmake: add support for libbacktrace, fix two build issues Also: - memdebug: fix symbol collision in unity builds. - memdebug: fix compiler warning by making a variable static. Follow-up to c77bed81a2e1325ffdebc223c27e3d1355147529 #19657 Closes #19666 --- .github/scripts/pyspelling.words | 1 + CMake/FindLibbacktrace.cmake | 52 ++++++++++++++++++++++++++++++++ CMakeLists.txt | 15 +++++++++ Makefile.am | 1 + docs/INSTALL-CMAKE.md | 3 ++ lib/curl_config.h.cmake | 3 ++ lib/memdebug.c | 9 +++--- 7 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 CMake/FindLibbacktrace.cmake diff --git a/.github/scripts/pyspelling.words b/.github/scripts/pyspelling.words index 5c96701cd09b..984424200b9e 100644 --- a/.github/scripts/pyspelling.words +++ b/.github/scripts/pyspelling.words @@ -434,6 +434,7 @@ LDAPS ldaps LF LGTM +libbacktrace libbrotlidec libc libcurl diff --git a/CMake/FindLibbacktrace.cmake b/CMake/FindLibbacktrace.cmake new file mode 100644 index 000000000000..444c5f90fdcf --- /dev/null +++ b/CMake/FindLibbacktrace.cmake @@ -0,0 +1,52 @@ +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) Daniel Stenberg, , et al. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at https://curl.se/docs/copyright.html. +# +# You may opt to use, copy, modify, merge, publish, distribute and/or sell +# copies of the Software, and permit persons to whom the Software is +# furnished to do so, under the terms of the COPYING file. +# +# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# KIND, either express or implied. +# +# SPDX-License-Identifier: curl +# +########################################################################### +# Find the libbacktrace library +# +# Input variables: +# +# - `LIBBACKTRACE_INCLUDE_DIR`: Absolute path to libbacktrace include directory. +# - `LIBBACKTRACE_LIBRARY`: Absolute path to `libbacktrace` library. +# +# Result variables: +# +# - `LIBBACKTRACE_FOUND`: System has libbacktrace. +# - `LIBBACKTRACE_INCLUDE_DIRS`: The libbacktrace include directories. +# - `LIBBACKTRACE_LIBRARIES`: The libbacktrace library names. + +find_path(LIBBACKTRACE_INCLUDE_DIR NAMES "backtrace.h") +find_library(LIBBACKTRACE_LIBRARY NAMES "backtrace" "libbacktrace") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Libbacktrace + REQUIRED_VARS + LIBBACKTRACE_INCLUDE_DIR + LIBBACKTRACE_LIBRARY +) + +if(LIBBACKTRACE_FOUND) + set(LIBBACKTRACE_INCLUDE_DIRS ${LIBBACKTRACE_INCLUDE_DIR}) + set(LIBBACKTRACE_LIBRARIES ${LIBBACKTRACE_LIBRARY}) +endif() + +mark_as_advanced(LIBBACKTRACE_INCLUDE_DIR LIBBACKTRACE_LIBRARY) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20336e097c0e..5d6e7ca3e667 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1421,6 +1421,21 @@ if(CURL_USE_GSSAPI) endif() endif() +# libbacktrace +option(CURL_USE_LIBBACKTRACE "Use libbacktrace. Requires build with TrackMemory and DWARF debug information." OFF) +if(CURL_USE_LIBBACKTRACE) + if(NOT ENABLE_CURLDEBUG) + message(FATAL_ERROR "libbacktrace requires TrackMemory enabled") + endif() + if(NOT CMAKE_BUILD_TYPE MATCHES "(Debug|RelWithDebInfo)") + message(FATAL_ERROR "libbacktrace requires debug information") + endif() + find_package(Libbacktrace REQUIRED) + list(APPEND CURL_LIBS ${LIBBACKTRACE_LIBRARIES}) + include_directories(SYSTEM ${LIBBACKTRACE_INCLUDE_DIRS}) + set(USE_BACKTRACE ON) +endif() + # libuv option(CURL_USE_LIBUV "Use libuv for event-based tests" OFF) if(CURL_USE_LIBUV) diff --git a/Makefile.am b/Makefile.am index 1ed54423e532..d289f33d5756 100644 --- a/Makefile.am +++ b/Makefile.am @@ -37,6 +37,7 @@ CMAKE_DIST = \ CMake/FindGnuTLS.cmake \ CMake/FindGSS.cmake \ CMake/FindLDAP.cmake \ + CMake/FindLibbacktrace.cmake \ CMake/FindLibgsasl.cmake \ CMake/FindLibidn2.cmake \ CMake/FindLibpsl.cmake \ diff --git a/docs/INSTALL-CMAKE.md b/docs/INSTALL-CMAKE.md index bd9555b61461..026db0762892 100644 --- a/docs/INSTALL-CMAKE.md +++ b/docs/INSTALL-CMAKE.md @@ -355,6 +355,7 @@ Details via CMake - `CURL_USE_GNUTLS`: Enable GnuTLS for SSL/TLS. Default: `OFF` - `CURL_USE_GSASL`: Use libgsasl. Default: `OFF` - `CURL_USE_GSSAPI`: Use GSSAPI implementation. Default: `OFF` +- `CURL_USE_LIBBACKTRACE`: Use [libbacktrace](https://github.com/ianlancetaylor/libbacktrace). Requires build with TrackMemory and DWARF debug information. Default: `OFF` - `CURL_USE_LIBPSL`: Use libpsl. Default: `ON` - `CURL_USE_LIBSSH2`: Use libssh2. Default: `ON` - `CURL_USE_LIBSSH`: Use libssh. Default: `OFF` @@ -411,6 +412,8 @@ Details via CMake - `LDAP_INCLUDE_DIR`: Absolute path to LDAP include directory. - `LDAP_LIBRARY`: Absolute path to `ldap` library. - `LDAP_LBER_LIBRARY`: Absolute path to `lber` library. +- `LIBBACKTRACE_INCLUDE_DIR`: Absolute path to libbacktrace include directory (https://github.com/ianlancetaylor/libbacktrace). +- `LIBBACKTRACE_LIBRARY`: Absolute path to `libbacktrace` library. - `LIBGSASL_INCLUDE_DIR`: Absolute path to libgsasl include directory. - `LIBGSASL_LIBRARY`: Absolute path to `libgsasl` library. - `LIBIDN2_INCLUDE_DIR`: Absolute path to libidn2 include directory. diff --git a/lib/curl_config.h.cmake b/lib/curl_config.h.cmake index acbb428575cc..37ec3d9a6551 100644 --- a/lib/curl_config.h.cmake +++ b/lib/curl_config.h.cmake @@ -730,6 +730,9 @@ ${SIZEOF_TIME_T_CODE} /* Define to 1 if you have the header file. */ #cmakedefine HAVE_UV_H 1 +/* if libbacktrace is in use */ +#cmakedefine USE_BACKTRACE 1 + /* Define to 1 if you do not want the OpenSSL configuration to be loaded automatically */ #cmakedefine CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG 1 diff --git a/lib/memdebug.c b/lib/memdebug.c index cbda4a2be144..6ec292654f80 100644 --- a/lib/memdebug.c +++ b/lib/memdebug.c @@ -63,7 +63,7 @@ static bool registered_cleanup = FALSE; /* atexit registered cleanup */ static bool memlimit = FALSE; /* enable memory limit */ static long memsize = 0; /* set number of mallocs allowed */ #ifdef USE_BACKTRACE -struct backtrace_state *btstate; +static struct backtrace_state *btstate; #endif /* LeakSantizier (LSAN) calls _exit() instead of exit() when a leak is detected @@ -81,7 +81,8 @@ static void curl_dbg_cleanup(void) curl_dbg_logfile = NULL; } #ifdef USE_BACKTRACE -static void error_callback(void *data, const char *message, int error_number) +static void error_bt_callback(void *data, const char *message, + int error_number) { (void)data; if(error_number == -1) @@ -102,7 +103,7 @@ static int full_callback(void *data, uintptr_t pc, const char *pathname, static void dump_bt(void) { - backtrace_full(btstate, 0, full_callback, error_callback, NULL); + backtrace_full(btstate, 0, full_callback, error_bt_callback, NULL); } #else #define dump_bt() /* nothing to do */ @@ -123,7 +124,7 @@ void curl_dbg_memdebug(const char *logname) #endif } #ifdef USE_BACKTRACE - btstate = backtrace_create_state(NULL, 0, error_callback, NULL); + btstate = backtrace_create_state(NULL, 0, error_bt_callback, NULL); #endif if(!registered_cleanup) registered_cleanup = !atexit(curl_dbg_cleanup); From 537987d8c66aac6ec96cde098ab45525e156b54e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Nov 2025 01:20:44 +0100 Subject: [PATCH 031/140] curl_fopen: do not pass invalid mode flags to `open()` on Windows The safe (`_s`) variants of the Windows `open()` reject these flags, while the classic ones silently accepted them. Also: - also drop the now unused `stat()` call on Windows. - replace magic number with their equivalent Windows and Unix-specific `S_*` macros. Refs: https://learn.microsoft.com/cpp/c-runtime-library/reference/open-wopen https://learn.microsoft.com/cpp/c-runtime-library/reference/fstat-fstat32-fstat64-fstati64-fstat32i64-fstat64i32 Cherry-picked from #19643 Closes #19645 --- lib/curl_fopen.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/curl_fopen.c b/lib/curl_fopen.c index fd0c7c65d201..f16b3d6cde0d 100644 --- a/lib/curl_fopen.c +++ b/lib/curl_fopen.c @@ -93,11 +93,14 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename, CURLcode result = CURLE_WRITE_ERROR; unsigned char randbuf[41]; char *tempstore = NULL; +#ifndef _WIN32 struct_stat sb; +#endif int fd = -1; char *dir = NULL; *tempname = NULL; +#ifndef _WIN32 *fh = curlx_fopen(filename, FOPEN_WRITETEXT); if(!*fh) goto fail; @@ -105,6 +108,7 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename, return CURLE_OK; } curlx_fclose(*fh); +#endif *fh = NULL; result = Curl_rand_alnum(data, randbuf, sizeof(randbuf)); @@ -125,13 +129,16 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename, } result = CURLE_WRITE_ERROR; -#if (defined(ANDROID) || defined(__ANDROID__)) && \ +#ifdef _WIN32 + fd = curlx_open(tempstore, O_WRONLY | O_CREAT | O_EXCL, + S_IREAD | S_IWRITE); +#elif (defined(ANDROID) || defined(__ANDROID__)) && \ (defined(__i386__) || defined(__arm__)) fd = curlx_open(tempstore, O_WRONLY | O_CREAT | O_EXCL, - (mode_t)(0600 | sb.st_mode)); + (mode_t)(S_IRUSR | S_IWUSR | sb.st_mode)); #else fd = curlx_open(tempstore, O_WRONLY | O_CREAT | O_EXCL, - 0600 | sb.st_mode); + S_IRUSR | S_IWUSR | sb.st_mode); #endif if(fd == -1) goto fail; From 82013066a6149aa906b1fda3f8f1f27bd272a6c2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Nov 2025 01:42:15 +0100 Subject: [PATCH 032/140] file: do not pass invalid mode flags to `open()` on upload (Windows) Ref: https://learn.microsoft.com/cpp/c-runtime-library/reference/open-wopen Ref: #19645 Cherry-picked from #19643 Closes #19647 --- lib/file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/file.c b/lib/file.c index 826bed6d802c..69370690746e 100644 --- a/lib/file.c +++ b/lib/file.c @@ -343,7 +343,10 @@ static CURLcode file_upload(struct Curl_easy *data, else mode |= O_TRUNC; -#if (defined(ANDROID) || defined(__ANDROID__)) && \ +#ifdef _WIN32 + fd = curlx_open(file->path, mode, + data->set.new_file_perms & (_S_IREAD | _S_IWRITE)); +#elif (defined(ANDROID) || defined(__ANDROID__)) && \ (defined(__i386__) || defined(__arm__)) fd = curlx_open(file->path, mode, (mode_t)data->set.new_file_perms); #else From 1eca08a5417740320501448b64e8584de349126c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 21 Nov 2025 15:55:33 +0100 Subject: [PATCH 033/140] curlx/strerr: use `strerror_s()` on Windows To replace deprecated, unsafe `sys_nerr`, `sys_errlist` global variables with the function suggested by the CRT warning silenced via `_CRT_SECURE_NO_WARNINGS`: ``` lib/curlx/strerr.c(291): warning C4996: '__sys_nerr': This function or variable may be unsafe. Consider using strerror instead. lib/curlx/strerr.c(292): warning C4996: '__sys_errlist': This function or variable may be unsafe. Consider using strerror instead. ``` (where `strerror` in turn suggests `strerror_s`...) Upside: returns an error and has a Unicode variant. Downaside: happy to return success when passing unrecognized error codes. Work it around by looking for the string "Unknown error" returned in such cases and falling back to other methods to retrieve a description. Refs: https://learn.microsoft.com/cpp/c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr https://learn.microsoft.com/cpp/c-runtime-library/reference/strerror-s-strerror-s-wcserror-s-wcserror-s Closes #19646 --- lib/curl_setup.h | 6 +++--- lib/curlx/strerr.c | 13 ++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/curl_setup.h b/lib/curl_setup.h index db438a8b0a47..886a8814936a 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -95,9 +95,9 @@ unlink(), etc. */ #endif #ifndef _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_WARNINGS /* for __sys_errlist, __sys_nerr, _open(), - _wfopen(), _wopen(), fopen(), freopen(), - getenv(), gmtime(), sprintf(), strcpy(), +#define _CRT_SECURE_NO_WARNINGS /* for _open(), _wfopen(), _wopen(), fopen(), + freopen(), getenv(), gmtime(), sprintf(), + strcpy(), in tests: localtime(), open(), sscanf() */ #endif #endif /* _MSC_VER */ diff --git a/lib/curlx/strerr.c b/lib/curlx/strerr.c index 047588ed183a..376f68b0b20d 100644 --- a/lib/curlx/strerr.c +++ b/lib/curlx/strerr.c @@ -287,17 +287,12 @@ const char *curlx_strerror(int err, char *buf, size_t buflen) *buf = '\0'; #ifdef _WIN32 - /* 'sys_nerr' is the maximum errno number, it is not widely portable */ - if(err >= 0 && err < sys_nerr) - SNPRINTF(buf, buflen, "%s", sys_errlist[err]); - else { - if( + if((!strerror_s(buf, buflen, err) || !strcmp(buf, "Unknown error")) && #ifdef USE_WINSOCK - !get_winsock_error(err, buf, buflen) && + !get_winsock_error(err, buf, buflen) && #endif - !curlx_get_winapi_error((DWORD)err, buf, buflen)) - SNPRINTF(buf, buflen, "Unknown error %d (%#x)", err, err); - } + !curlx_get_winapi_error((DWORD)err, buf, buflen)) + SNPRINTF(buf, buflen, "Unknown error %d (%#x)", err, err); #else /* !_WIN32 */ #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R) From 3696ac4e29836dd3e5e3b2101d53294846a6ec1b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 24 Nov 2025 10:43:14 +0000 Subject: [PATCH 034/140] GHA: update dependency ngtcp2/nghttp3 to v1.13.1 Closes #19664 --- .github/workflows/http3-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/http3-linux.yml b/.github/workflows/http3-linux.yml index a6c5972cd948..3f52c146563e 100644 --- a/.github/workflows/http3-linux.yml +++ b/.github/workflows/http3-linux.yml @@ -51,7 +51,7 @@ env: # renovate: datasource=github-tags depName=wolfSSL/wolfssl versioning=semver extractVersion=^v?(?.+)-stable$ registryUrl=https://github.com WOLFSSL_VERSION: 5.8.4 # renovate: datasource=github-tags depName=ngtcp2/nghttp3 versioning=semver registryUrl=https://github.com - NGHTTP3_VERSION: 1.13.0 + NGHTTP3_VERSION: 1.13.1 # renovate: datasource=github-tags depName=ngtcp2/ngtcp2 versioning=semver registryUrl=https://github.com NGTCP2_VERSION: 1.18.0 # renovate: datasource=github-tags depName=nghttp2/nghttp2 versioning=semver registryUrl=https://github.com From fa1270a0d1c8234929e1d399ff06ef8f31a2b0b9 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 24 Nov 2025 14:43:49 +0100 Subject: [PATCH 035/140] vquic: do not pass invalid mode flags to `open()` (Windows) Follow-up to 82013066a6149aa906b1fda3f8f1f27bd272a6c2 #19647 Closes #19670 --- lib/vquic/vquic.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/vquic/vquic.c b/lib/vquic/vquic.c index 539d9bfeae36..562a99e4fee0 100644 --- a/lib/vquic/vquic.c +++ b/lib/vquic/vquic.c @@ -665,7 +665,11 @@ CURLcode Curl_qlogdir(struct Curl_easy *data, if(!result) { int qlogfd = curlx_open(curlx_dyn_ptr(&fname), O_WRONLY | O_CREAT | CURL_O_BINARY, - data->set.new_file_perms); + data->set.new_file_perms +#ifdef _WIN32 + & (_S_IREAD | _S_IWRITE) +#endif + ); if(qlogfd != -1) *qlogfdp = qlogfd; } From 2b7515ae8e1d448fd6da2fddb74d36c4867cca80 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 24 Nov 2025 14:51:18 +0100 Subject: [PATCH 036/140] tftpd: fix/tidy up `open()` mode flags - replace 0777 with `S_I*` macros. - fix to not pass invalid flags on Windows. Follow-up to 537987d8c66aac6ec96cde098ab45525e156b54e #19645 Closes #19671 --- tests/server/tftpd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index dd7291c7ceb0..6631e2439b96 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -445,7 +445,15 @@ static ssize_t write_behind(struct testcase *test, int convert) if(!test->ofile) { char outfile[256]; snprintf(outfile, sizeof(outfile), "%s/upload.%ld", logdir, test->testno); - test->ofile = open(outfile, O_CREAT|O_RDWR|CURL_O_BINARY, 0777); + test->ofile = open(outfile, O_CREAT | O_RDWR | CURL_O_BINARY, +#ifdef _WIN32 + S_IREAD | S_IWRITE +#else + S_IRUSR | S_IWUSR | S_IXUSR | + S_IRGRP | S_IWGRP | S_IXGRP | + S_IROTH | S_IWOTH | S_IXOTH +#endif + ); if(test->ofile == -1) { logmsg("Could not create and/or open file %s for upload!", outfile); return -1; /* failure! */ From 2b57d415e5a0d0afceeb90c54b45a1644a4f8a40 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 24 Nov 2025 19:38:34 +0100 Subject: [PATCH 037/140] content_encoding: drop a guard for brotli 1.0.0+ macro Also add comment with version requirement for the other guard. Refs: https://github.com/google/brotli/commit/19d86fb9a60aa7034d4981b69a5b656f5b90017e https://github.com/google/brotli/commit/03739d2b113afe60638069c4e1604dc2ac27380d Ref: #19672 Follow-up to e639d4ca4d794c222dde4680d9ff35053f501042 Closes #19673 --- lib/content_encoding.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/content_encoding.c b/lib/content_encoding.c index b724b576b41d..f128f7565f77 100644 --- a/lib/content_encoding.c +++ b/lib/content_encoding.c @@ -384,12 +384,10 @@ static CURLcode brotli_map_error(BrotliDecoderErrorCode be) case BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: case BROTLI_DECODER_ERROR_FORMAT_PADDING_1: case BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -#ifdef BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY +#ifdef BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY /* brotli v1.1.0+ */ case BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY: #endif -#ifdef BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET case BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -#endif case BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: return CURLE_BAD_CONTENT_ENCODING; case BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: From be4462a415a96c203be5be9c59d956b24d43f5c2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 24 Nov 2025 18:45:53 +0100 Subject: [PATCH 038/140] INTERNALS.md: add brotli and zstd version info And alpha-sort the dependency list Closes #19672 --- docs/INTERNALS.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/INTERNALS.md b/docs/INTERNALS.md index e9bb82a33d8e..acc4506e6722 100644 --- a/docs/INTERNALS.md +++ b/docs/INTERNALS.md @@ -24,19 +24,21 @@ versions of libs and build tools. We aim to support these or later versions. - - OpenSSL 3.0.0 (2021-09-07) - - LibreSSL 2.9.1 (2019-04-22) - - GnuTLS 3.6.5 (2018-12-01) - - mbedTLS 3.2.0 (2022-07-11) - - zlib 1.2.5.2 (2011-12-11) - - libssh2 1.9.0 (2019-06-20) + - brotli 1.0.0 (2017-09-21) - c-ares 1.6.0 (2008-12-09) - - libssh 0.9.0 (2019-06-28) + - GnuTLS 3.6.5 (2018-12-01) - libidn2 2.0.0 (2017-03-29) - - wolfSSL 3.4.6 (2017-09-22) - - OpenLDAP 2.0 (2000-08-01) + - LibreSSL 2.9.1 (2019-04-22) + - libssh 0.9.0 (2019-06-28) + - libssh2 1.9.0 (2019-06-20) + - mbedTLS 3.2.0 (2022-07-11) - MIT Kerberos 1.3 (2003-07-31) - nghttp2 1.15.0 (2016-09-25) + - OpenLDAP 2.0 (2000-08-01) + - OpenSSL 3.0.0 (2021-09-07) + - wolfSSL 3.4.6 (2017-09-22) + - zlib 1.2.5.2 (2011-12-11) + - zstd 1.0 (2016-08-31) ## Build tools From bfde7811213d482789683094510f0680ee0291e4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 24 Nov 2025 23:32:59 +0100 Subject: [PATCH 039/140] RELEASE-NOTES: synced --- RELEASE-NOTES | 56 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3af5605c8dc6..217f8c750446 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -4,22 +4,27 @@ curl and libcurl 8.18.0 Command line options: 273 curl_easy_setopt() options: 308 Public functions in libcurl: 100 - Contributors: 3546 + Contributors: 3549 This release includes the following changes: o build: drop support for VS2008 (Windows) [62] o build: drop Windows CE / CeGCC support [69] + o gnutls: drop support for GnuTLS < 3.6.5 [167] + o gnutls: implement CURLOPT_CAINFO_BLOB [168] o openssl: bump minimum OpenSSL version to 3.0.0 [60] This release includes the following bugfixes: o _PROGRESS.md: add the E unit, mention kibibyte [24] o AmigaOS: increase minimum stack size for tool_main [137] + o apple-sectrust: always ask when `native_ca_store` is in use [162] + o asyn-ares: remove hostname free on OOM [122] o asyn-thrdd: release rrname if ares_init_options fails [41] o autotools: drop autoconf <2.59 compatibility code (zz60-xc-ovr) [70] o badwords: fix issues found in scripts and other files [142] o badwords: fix issues found in tests [156] + o build: add build-level `CURL_DISABLE_TYPECHECK` options [163] o build: exclude clang prereleases from compiler warning options [154] o build: tidy-up MSVC CRT warning suppression macros [140] o ccsidcurl: make curl_mime_data_ccsid() use the converted size [74] @@ -39,6 +44,7 @@ This release includes the following bugfixes: o cookie: return error on OOM [131] o cshutdn: acknowledge FD_SETSIZE for shutdown descriptors [25] o curl: fix progress meter in parallel mode [15] + o curl_fopen: do not pass invalid mode flags to `open()` on Windows [84] o curl_sasl: make Curl_sasl_decode_mech compare case insensitively [160] o curl_setup.h: document more funcs flagged by `_CRT_SECURE_NO_WARNINGS` [124] o curl_setup.h: drop stray `#undef stat` (Windows) [103] @@ -47,6 +53,8 @@ This release includes the following bugfixes: o CURLINFO_TLS_SSL_PTR.md: remove CURLINFO_TLS_SESSION text [49] o CURLOPT_READFUNCTION.md: clarify the size of the buffer [47] o CURLOPT_SSH_KEYFUNCTION.md: fix minor indent mistake in example + o curlx/strerr: use `strerror_s()` on Windows [75] + o curlx: replace `mbstowcs`/`wcstombs` with `_s` counterparts (Windows) [143] o digest_sspi: fix a memory leak on error path [149] o digest_sspi: properly free sspi identity [12] o DISTROS.md: add OpenBSD [126] @@ -56,6 +64,7 @@ This release includes the following bugfixes: o examples/multithread: fix race condition [101] o examples: make functions/data static where missing [139] o examples: tidy-up headers and includes [138] + o file: do not pass invalid mode flags to `open()` on upload (Windows) [83] o ftp: refactor a piece of code by merging the repeated part [40] o ftp: remove #ifdef for define that is always defined [76] o getinfo: improve perf in debug mode [99] @@ -76,6 +85,7 @@ This release includes the following bugfixes: o lib: error for OOM when extracting URL query [127] o lib: fix gssapi.h include on IBMi [55] o lib: refactor the type of funcs which have useless return and checks [1] + o lib: replace `_tcsncpy`/`wcsncpy`/`wcscpy` with `_s` counterparts (Windows) [164] o libssh2: add paths to error messages for quote commands [114] o libssh2: cleanup ssh_force_knownhost_key_type [64] o libssh2: replace atoi() in ssh_force_knownhost_key_type [63] @@ -87,10 +97,12 @@ This release includes the following bugfixes: o mk-ca-bundle.pl: default to SHA256 fingerprints with `-t` option [73] o mk-ca-bundle.pl: use `open()` with argument list to replace backticks [71] o mqtt: reject overly big messages [39] + o multi: make max_total_* members size_t [158] o noproxy: replace atoi with curlx_str_number [67] o openssl: exit properly on OOM when getting certchain [133] o openssl: fix a potential memory leak of bio_out [150] o openssl: fix a potential memory leak of params.cert [151] + o openssl: no verify failf message unless strict [166] o openssl: release ssl_session if sess_reuse_cb fails [43] o openssl: remove code handling default version [28] o OS400/ccsidcurl: fix curl_easy_setopt_ccsid for non-converted blobs [94] @@ -114,7 +126,9 @@ This release includes the following bugfixes: o setopt: disable CURLOPT_HAPROXY_CLIENT_IP on NULL [30] o setopt: when setting bad protocols, don't store them [9] o sftp: fix range downloads in both SSH backends [82] + o smb: fix a size check to be overflow safe [161] o socks_sspi: use free() not FreeContextBuffer() [93] + o speedcheck: do not trigger low speed cancel on transfers with CURL_READFUNC_PAUSE [113] o telnet: replace atoi for BINARY handling with curlx_str_number [66] o TEST-SUITE.md: correct the man page's path [136] o test07_22: fix flakiness [95] @@ -125,21 +139,27 @@ This release includes the following bugfixes: o tests/server: do not fall back to original data file in `test2fopen()` [32] o tests/server: replace `atoi()` and `atol()` with `curlx_str_number()` [110] o tftp: release filename if conn_get_remote_addr fails [42] + o tftpd: fix/tidy up `open()` mode flags [57] o tidy-up: move `CURL_UNCONST()` out from macro `curl_unicodefree()` [121] o tool: consider (some) curl_easy_setopt errors fatal [7] o tool_cfgable: free ssl-sessions at exit [123] o tool_getparam: verify that a file exists for some options [134] o tool_help: add checks to avoid unsigned wrap around [14] o tool_ipfs: check return codes better [20] + o tool_msgs: make voutf() use stack instead of heap [125] o tool_operate: exit on curl_share_setopt errors [108] + o tool_operate: fix a case of ignoring return code in operate() [128] + o tool_operate: fix case of ignoring return code in single_transfer [129] o tool_operate: remove redundant condition [19] o tool_operate: use curlx_str_number instead of atoi [68] o tool_paramhlp: refuse --proto remove all protocols [10] o tool_urlglob: clean up used memory on errors better [44] + o tool_writeout: bail out proper on OOM [104] o url: if OOM in parse_proxy() return error [132] o urlapi: fix mem-leaks in curl_url_get error paths [22] o verify-release: update to avoid shellcheck warning SC2034 [88] o vquic-tls/gnutls: call Curl_gtls_verifyserver unconditionally [96] + o vquic: do not pass invalid mode flags to `open()` (Windows) [58] o vtls: fix CURLOPT_CAPATH use [51] o vtls: handle possible malicious certs_num from peer [53] o vtls: pinned key check [98] @@ -147,6 +167,7 @@ This release includes the following bugfixes: o wolfSSL: able to differentiate between IP and DNS in alt names [13] o wolfssl: avoid NULL dereference in OOM situation [77] o wolfssl: fix a potential memory leak of session [6] + o wolfssl: fix cipher list, skip 5.8.4 regression [117] o wolfssl: simplify wssl_send_earlydata [111] This release includes the following known bugs: @@ -160,6 +181,7 @@ For all changes ever done in curl: Planned upcoming removals include: o OpenSSL-QUIC + o RTMP support o Support for c-ares versions before 1.16.0 o Support for Windows XP/2003 @@ -168,14 +190,15 @@ Planned upcoming removals include: This release would not have looked like this without help, code, reports and advice from friends like these: - Aleksandr Sergeev, Andrew Kirillov, boingball, Brad King, Christian Schmitz, - Dan Fandrich, Daniel McCarney, Daniel Stenberg, Fd929c2CE5fA on github, - Gisle Vanem, Jiyong Yang, Juliusz Sosinowicz, Leonardo Taccari, - letshack9707 on hackerone, Marcel Raad, nait-furry, Nick Korepanov, + Aleksandr Sergeev, Andrew Kirillov, boingball, Brad King, bttrfl on github, + Christian Schmitz, Dan Fandrich, Daniel McCarney, Daniel Stenberg, + Fd929c2CE5fA on github, ffath-vo on github, Gisle Vanem, Jiyong Yang, + Juliusz Sosinowicz, Leonardo Taccari, letshack9707 on hackerone, + Marc Aldorasi, Marcel Raad, nait-furry, ncaklovic on github, Nick Korepanov, Omdahake on github, Patrick Monnerat, pelioro on hackerone, Ray Satiro, renovate[bot], Samuel Henrique, Stanislav Fort, Stefan Eissing, Thomas Klausner, Viktor Szakats, Wesley Moore, Xiaoke Wang - (29 contributors) + (33 contributors) References to bug reports and discussions on issues: @@ -233,6 +256,8 @@ References to bug reports and discussions on issues: [54] = https://curl.se/bug/?i=19399 [55] = https://curl.se/bug/?i=19336 [56] = https://curl.se/bug/?i=19396 + [57] = https://curl.se/bug/?i=19671 + [58] = https://curl.se/bug/?i=19670 [59] = https://curl.se/bug/?i=19630 [60] = https://curl.se/bug/?i=18330 [61] = https://curl.se/bug/?i=19484 @@ -248,6 +273,7 @@ References to bug reports and discussions on issues: [71] = https://curl.se/bug/?i=19461 [73] = https://curl.se/bug/?i=19359 [74] = https://curl.se/bug/?i=19465 + [75] = https://curl.se/bug/?i=19646 [76] = https://curl.se/bug/?i=19463 [77] = https://curl.se/bug/?i=19459 [78] = https://curl.se/bug/?i=19431 @@ -255,6 +281,8 @@ References to bug reports and discussions on issues: [80] = https://curl.se/bug/?i=19452 [81] = https://curl.se/bug/?i=19425 [82] = https://curl.se/bug/?i=19460 + [83] = https://curl.se/bug/?i=19647 + [84] = https://curl.se/bug/?i=19645 [86] = https://curl.se/bug/?i=19451 [87] = https://curl.se/bug/?i=19450 [88] = https://curl.se/bug/?i=19449 @@ -273,6 +301,7 @@ References to bug reports and discussions on issues: [101] = https://curl.se/bug/?i=19524 [102] = https://curl.se/bug/?i=19518 [103] = https://curl.se/bug/?i=19519 + [104] = https://curl.se/bug/?i=19667 [105] = https://curl.se/bug/?i=19517 [106] = https://curl.se/bug/?i=19144 [107] = https://curl.se/bug/?i=19512 @@ -280,15 +309,21 @@ References to bug reports and discussions on issues: [110] = https://curl.se/bug/?i=19510 [111] = https://curl.se/bug/?i=19509 [112] = https://curl.se/bug/?i=19495 + [113] = https://curl.se/bug/?i=19653 [114] = https://curl.se/bug/?i=19605 + [117] = https://curl.se/bug/?i=19644 [118] = https://curl.se/bug/?i=19493 [119] = https://curl.se/bug/?i=19483 [120] = https://curl.se/bug/?i=19506 [121] = https://curl.se/bug/?i=19606 + [122] = https://curl.se/bug/?i=19658 [123] = https://curl.se/bug/?i=19602 [124] = https://curl.se/bug/?i=19597 + [125] = https://curl.se/bug/?i=19651 [126] = https://curl.se/bug/?i=19596 [127] = https://curl.se/bug/?i=19594 + [128] = https://curl.se/bug/?i=19650 + [129] = https://curl.se/bug/?i=19649 [130] = https://curl.se/bug/?i=19593 [131] = https://curl.se/bug/?i=19591 [132] = https://curl.se/bug/?i=19590 @@ -300,6 +335,7 @@ References to bug reports and discussions on issues: [139] = https://curl.se/bug/?i=19579 [140] = https://curl.se/bug/?i=19175 [142] = https://curl.se/bug/?i=19572 + [143] = https://curl.se/bug/?i=19581 [144] = https://curl.se/bug/?i=19571 [146] = https://curl.se/bug/?i=19543 [147] = https://curl.se/bug/?i=19568 @@ -312,5 +348,13 @@ References to bug reports and discussions on issues: [154] = https://curl.se/bug/?i=19566 [156] = https://curl.se/bug/?i=19541 [157] = https://curl.se/bug/?i=19520 + [158] = https://curl.se/bug/?i=19618 [159] = https://curl.se/bug/?i=19540 [160] = https://curl.se/bug/?i=19535 + [161] = https://curl.se/bug/?i=19640 + [162] = https://curl.se/bug/?i=19636 + [163] = https://curl.se/bug/?i=19637 + [164] = https://curl.se/bug/?i=19589 + [166] = https://curl.se/bug/?i=19615 + [167] = https://curl.se/bug/?i=19609 + [168] = https://curl.se/bug/?i=19612 From 24b36fdd1585ea22e5e1f00791f1c20423433cde Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Tue, 11 Nov 2025 14:26:48 +0100 Subject: [PATCH 040/140] ratelimit: redesign Description of how this works in `docs/internal/RATELIMITS.ms`. Notable implementation changes: - KEEP_SEND_PAUSE/KEEP_SEND_HOLD and KEEP_RECV_PAUSE/KEEP_RECV_HOLD no longer exist. Pausing is down via blocked the new rlimits. - KEEP_SEND_TIMED no longer exists. Pausing "100-continue" transfers is done in the new `Curl_http_perform_pollset()` method. - HTTP/2 rate limiting implemented via window updates. When transfer initiaiting connection has a ratelimit, adjust the initial window size - HTTP/3 ngtcp2 rate limitin implemnented via ack updates - HTTP/3 quiche does not seem to support this via its API - the default progress-meter has been improved for accuracy in "current speed" results. pytest speed tests have been improved. Closes #19384 --- docs/Makefile.am | 1 + docs/internals/RATELIMITS.md | 100 +++++++++++ lib/Makefile.inc | 4 +- lib/cf-h1-proxy.c | 13 +- lib/file.c | 19 +- lib/ftp.c | 9 +- lib/http.c | 36 ++-- lib/http.h | 6 +- lib/http2.c | 113 ++++++++---- lib/imap.c | 5 +- lib/ldap.c | 2 +- lib/multi.c | 278 +++++++++++++++-------------- lib/multi_ev.c | 2 +- lib/multiif.h | 3 +- lib/pingpong.c | 7 +- lib/pop3.c | 5 +- lib/progress.c | 317 +++++++++++++++++---------------- lib/progress.h | 24 ++- lib/ratelimit.c | 200 +++++++++++++++++++++ lib/ratelimit.h | 92 ++++++++++ lib/request.c | 13 +- lib/request.h | 1 + lib/rtsp.c | 5 +- lib/select.c | 15 +- lib/select.h | 14 +- lib/sendf.c | 23 +++ lib/setopt.c | 2 + lib/smtp.c | 5 +- lib/speedcheck.c | 80 --------- lib/speedcheck.h | 35 ---- lib/telnet.c | 7 +- lib/tftp.c | 11 +- lib/transfer.c | 87 ++++----- lib/transfer.h | 3 - lib/url.c | 6 +- lib/urldata.h | 43 ++--- lib/vquic/curl_ngtcp2.c | 53 ++++-- lib/vssh/libssh.c | 12 +- lib/vssh/libssh2.c | 11 +- lib/vtls/schannel.c | 5 +- lib/ws.c | 8 +- tests/data/Makefile.am | 2 +- tests/data/test3216 | 19 ++ tests/http/test_02_download.py | 14 +- tests/http/test_07_upload.py | 4 +- tests/unit/Makefile.inc | 2 +- tests/unit/unit1606.c | 6 +- tests/unit/unit3216.c | 103 +++++++++++ 48 files changed, 1148 insertions(+), 677 deletions(-) create mode 100644 docs/internals/RATELIMITS.md create mode 100644 lib/ratelimit.c create mode 100644 lib/ratelimit.h delete mode 100644 lib/speedcheck.c delete mode 100644 lib/speedcheck.h create mode 100644 tests/data/test3216 create mode 100644 tests/unit/unit3216.c diff --git a/docs/Makefile.am b/docs/Makefile.am index 5349c63cc22d..da5812a0eb76 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -63,6 +63,7 @@ INTERNALDOCS = \ internals/MULTI-EV.md \ internals/NEW-PROTOCOL.md \ internals/PORTING.md \ + internals/RATELIMITS.md \ internals/README.md \ internals/SCORECARD.md \ internals/SPLAY.md \ diff --git a/docs/internals/RATELIMITS.md b/docs/internals/RATELIMITS.md new file mode 100644 index 000000000000..af72211b7874 --- /dev/null +++ b/docs/internals/RATELIMITS.md @@ -0,0 +1,100 @@ + + +# Rate Limiting Transfers + +Rate limiting a transfer means that no more than "n bytes per second" +shall be sent or received. It can be set individually for both directions +via `CURLOPT_MAX_RECV_SPEED_LARGE` and `CURLOPT_MAX_SEND_SPEED_LARGE`. These +options may be adjusted for an ongoing transfer. + +### Implementation Base + +`ratelimit.[ch]` implements `struct Curl_rlimit` and functions to manage +such limits. It has the following properties: + +* `rate_per_sec`: how many "tokens" can be used per second, 0 for infinite. +* `tokens`: the currently available tokens to consume +* `burst_per_sec`: an upper limit on tokens available +* `ts`: the microsecond timestamp of the last tokens update +* `spare_us`: elapsed microseconds that have not counted yet for a token update +* `blocked`: if the limit is blocked + +Tokens can be *drained* from an `rlimit`. This reduces `tokens`, even to +negative values. To enforce the limits, tokens should not be drained +further when they reach 0, but such things may happen. + +An `rlimit`can be asked how long to wait until `tokens` are positive again. +This is given in milliseconds. When token are available, this wait +time is 0. + +Ideally a user of `rlimit` would consume the available tokens to 0, then +get a wait times of 1000ms, after which the set rate of tokens has +regenerated. Rinse and repeat. + +Should a user drain twice the amount of the rate, tokens are negative +and the wait time is 2 seconds. The `spare_us` account for the +time that has passed for the consumption. When a user takes 250ms to +consume the rate, the wait time is then 750ms. + +When a user drains nothing for two seconds, the available tokens would +grow to twice the rate, unless a burst rate is set. + +Finally, an `rlimit` may be set to `blocked` and later unblocked again. +A blocked `rlimit` has no tokens available. This works also when the rate +is unlimited (`rate_per_sec` set to 0). + +### Downloads + +`rlimit` is in `data->progress.dl.rlimit`. `setopt.c` initializes it whenever +the application sets `CURLOPT_MAX_RECV_SPEED_LARGE`. This may be done +in the middle of a transfer. + +`rlimit` tokens are drained in the "protocol" client writer. Checks for +capacity depend on the protocol: + +* HTTP and other plain protocols: `transfer.c:sendrecv_dl()` reads only +up to capacity. +* HTTP/2: capacity is used to adjust a stream's window size. Since all +streams start with `64kb`, `rlimit` takes a few seconds to take effect. +* HTTP/3: ngtcp2 acknowledges stream data according to capacity. It +keeps track of bytes not acknowledged yet. This has the same effect as HTTP/2 +window sizes. + +(The quiche API does not offer control of `ACK`s and `rlimits` for download +do not work in that backend.) + +### Uploads + +`rlimit` is in `data->progress.ul.rlimit`. `setopt.c` initializes it whenever +the application sets `CURLOPT_MAX_SEND_SPEED_LARGE`. This may be done +in the middle of a transfer. + +The upload capacity is checked in `Curl_client_read()` and readers are +only asked to read bytes up to the `rlimit` capacity. This limits upload +of data for all protocols in the same way. + +### Pause/Unpause + +Pausing of up-/downloads sets the corresponding `rlimit` to blocked. Unpausing +removes that block. + +### Suspending transfers + +While obeying the `rlimit` for up-/download leads to the desired transfer +rates, the other issue that needs care is CPU consumption. + +`rlimits` are inspected when computing the "pollset" of a transfer. When +a transfer wants to send, but not send tokens are available, the `POLLOUT` +is removed from the pollset. Same for receiving. + +For a transfer that is, due to `rlimit`, not able to progress, the pollset +is then empty. No socket events are monitored, no CPU activity +happens. For paused transfers, this is sufficient. + +Draining `rlimit` happens when a transfer is in `PERFORM` state and +exhausted limits cause the timer `TOOFAST` to be set. When the fires, +the transfer runs again and `rlimit`s are re-evaluated. diff --git a/lib/Makefile.inc b/lib/Makefile.inc index 4bdf293f8976..9c9d5c918691 100644 --- a/lib/Makefile.inc +++ b/lib/Makefile.inc @@ -234,6 +234,7 @@ LIB_CFILES = \ progress.c \ psl.c \ rand.c \ + ratelimit.c \ rename.c \ request.c \ rtsp.c \ @@ -249,7 +250,6 @@ LIB_CFILES = \ socks.c \ socks_gssapi.c \ socks_sspi.c \ - speedcheck.c \ splay.c \ strcase.c \ strdup.c \ @@ -366,6 +366,7 @@ LIB_HFILES = \ progress.h \ psl.h \ rand.h \ + ratelimit.h \ rename.h \ request.h \ rtsp.h \ @@ -383,7 +384,6 @@ LIB_HFILES = \ sockaddr.h \ socketpair.h \ socks.h \ - speedcheck.h \ splay.h \ strcase.h \ strdup.h \ diff --git a/lib/cf-h1-proxy.c b/lib/cf-h1-proxy.c index 91d690e31a9e..985500f23e06 100644 --- a/lib/cf-h1-proxy.c +++ b/lib/cf-h1-proxy.c @@ -384,8 +384,8 @@ static CURLcode recv_CONNECT_resp(struct Curl_cfilter *cf, /* socket buffer drained, return */ return CURLE_OK; - if(Curl_pgrsUpdate(data)) - return CURLE_ABORTED_BY_CALLBACK; + if(!result) + result = Curl_pgrsUpdate(data); if(result) { ts->keepon = KEEPON_DONE; @@ -565,10 +565,8 @@ static CURLcode H1_CONNECT(struct Curl_cfilter *cf, /* read what is there */ CURL_TRC_CF(data, cf, "CONNECT receive"); result = recv_CONNECT_resp(cf, data, ts, &done); - if(Curl_pgrsUpdate(data)) { - result = CURLE_ABORTED_BY_CALLBACK; - goto out; - } + if(!result) + result = Curl_pgrsUpdate(data); /* error or not complete yet. return for more multi-multi */ if(result || !done) goto out; @@ -671,8 +669,7 @@ static CURLcode cf_h1_proxy_connect(struct Curl_cfilter *cf, /* The real request will follow the CONNECT, reset request partially */ Curl_req_soft_reset(&data->req, data); Curl_client_reset(data); - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); + Curl_pgrsReset(data); tunnel_free(cf, data); } diff --git a/lib/file.c b/lib/file.c index 69370690746e..3de92408c490 100644 --- a/lib/file.c +++ b/lib/file.c @@ -60,7 +60,6 @@ #include "sendf.h" #include "escape.h" #include "file.h" -#include "speedcheck.h" #include "multiif.h" #include "transfer.h" #include "url.h" @@ -415,13 +414,10 @@ static CURLcode file_upload(struct Curl_easy *data, Curl_pgrsSetUploadCounter(data, bytecount); - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; - else - result = Curl_speedcheck(data, curlx_now()); + result = Curl_pgrsCheck(data); } - if(!result && Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; + if(!result) + result = Curl_pgrsUpdate(data); out: close(fd); @@ -620,10 +616,7 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) if(result) goto out; - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; - else - result = Curl_speedcheck(data, curlx_now()); + result = Curl_pgrsCheck(data); if(result) goto out; } @@ -657,8 +650,8 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) #endif } - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; + if(!result) + result = Curl_pgrsUpdate(data); out: Curl_multi_xfer_buf_release(data, xfer_buf); diff --git a/lib/ftp.c b/lib/ftp.c index ac4fdc25c96a..c289581fd5a4 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -65,7 +65,6 @@ #include "sockaddr.h" /* required for Curl_sockaddr_storage */ #include "multiif.h" #include "url.h" -#include "speedcheck.h" #include "curlx/warnless.h" #include "http_proxy.h" #include "socks.h" @@ -675,8 +674,7 @@ static CURLcode getftpresponse(struct Curl_easy *data, return CURLE_RECV_ERROR; } else if(ev == 0) { - if(Curl_pgrsUpdate(data)) - return CURLE_ABORTED_BY_CALLBACK; + result = Curl_pgrsUpdate(data); continue; /* just continue in our loop for the timeout duration */ } } @@ -4344,10 +4342,7 @@ CURLcode ftp_regular_transfer(struct Curl_easy *data, bool connected = FALSE; data->req.size = -1; /* make sure this is unknown at this point */ - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); - Curl_pgrsSetUploadSize(data, -1); - Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsReset(data); ftpc->ctl_valid = TRUE; /* starts good */ diff --git a/lib/http.c b/lib/http.c index 095a9127a4ee..a1e449d35441 100644 --- a/lib/http.c +++ b/lib/http.c @@ -129,9 +129,9 @@ const struct Curl_handler Curl_handler_http = { ZERO_NULL, /* connecting */ ZERO_NULL, /* doing */ ZERO_NULL, /* proto_pollset */ - Curl_http_do_pollset, /* doing_pollset */ + Curl_http_doing_pollset, /* doing_pollset */ ZERO_NULL, /* domore_pollset */ - ZERO_NULL, /* perform_pollset */ + Curl_http_perform_pollset, /* perform_pollset */ ZERO_NULL, /* disconnect */ Curl_http_write_resp, /* write_resp */ Curl_http_write_resp_hd, /* write_resp_hd */ @@ -159,9 +159,9 @@ const struct Curl_handler Curl_handler_https = { NULL, /* connecting */ ZERO_NULL, /* doing */ NULL, /* proto_pollset */ - Curl_http_do_pollset, /* doing_pollset */ + Curl_http_doing_pollset, /* doing_pollset */ ZERO_NULL, /* domore_pollset */ - ZERO_NULL, /* perform_pollset */ + Curl_http_perform_pollset, /* perform_pollset */ ZERO_NULL, /* disconnect */ Curl_http_write_resp, /* write_resp */ Curl_http_write_resp_hd, /* write_resp_hd */ @@ -1560,13 +1560,30 @@ CURLcode Curl_http_connect(struct Curl_easy *data, bool *done) /* this returns the socket to wait for in the DO and DOING state for the multi interface and then we are always _sending_ a request and thus we wait for the single socket to become writable only */ -CURLcode Curl_http_do_pollset(struct Curl_easy *data, - struct easy_pollset *ps) +CURLcode Curl_http_doing_pollset(struct Curl_easy *data, + struct easy_pollset *ps) { /* write mode */ return Curl_pollset_add_out(data, ps, data->conn->sock[FIRSTSOCKET]); } +CURLcode Curl_http_perform_pollset(struct Curl_easy *data, + struct easy_pollset *ps) +{ + struct connectdata *conn = data->conn; + CURLcode result = CURLE_OK; + + if(CURL_WANT_RECV(data)) { + result = Curl_pollset_add_in(data, ps, conn->sock[FIRSTSOCKET]); + } + + /* on a "Expect: 100-continue" timed wait, do not poll for outgoing */ + if(!result && Curl_req_want_send(data) && !http_exp100_is_waiting(data)) { + result = Curl_pollset_add_out(data, ps, conn->sock[FIRSTSOCKET]); + } + return result; +} + /* * Curl_http_done() gets called after a single HTTP request has been * performed. @@ -4872,8 +4889,6 @@ static void http_exp100_continue(struct Curl_easy *data, struct cr_exp100_ctx *ctx = reader->ctx; if(ctx->state > EXP100_SEND_DATA) { ctx->state = EXP100_SEND_DATA; - data->req.keepon |= KEEP_SEND; - data->req.keepon &= ~KEEP_SEND_TIMED; Curl_expire_done(data, EXPIRE_100_TIMEOUT); } } @@ -4903,8 +4918,6 @@ static CURLcode cr_exp100_read(struct Curl_easy *data, ctx->state = EXP100_AWAITING_CONTINUE; ctx->start = curlx_now(); Curl_expire(data, data->set.expect_100_timeout, EXPIRE_100_TIMEOUT); - data->req.keepon &= ~KEEP_SEND; - data->req.keepon |= KEEP_SEND_TIMED; *nread = 0; *eos = FALSE; return CURLE_OK; @@ -4917,8 +4930,6 @@ static CURLcode cr_exp100_read(struct Curl_easy *data, ms = curlx_timediff_ms(curlx_now(), ctx->start); if(ms < data->set.expect_100_timeout) { DEBUGF(infof(data, "cr_exp100_read, AWAITING_CONTINUE, not expired")); - data->req.keepon &= ~KEEP_SEND; - data->req.keepon |= KEEP_SEND_TIMED; *nread = 0; *eos = FALSE; return CURLE_OK; @@ -4938,7 +4949,6 @@ static void cr_exp100_done(struct Curl_easy *data, { struct cr_exp100_ctx *ctx = reader->ctx; ctx->state = premature ? EXP100_FAILED : EXP100_SEND_DATA; - data->req.keepon &= ~KEEP_SEND_TIMED; Curl_expire_done(data, EXPIRE_100_TIMEOUT); } diff --git a/lib/http.h b/lib/http.h index 67ef17f5b953..ef41d7bb2249 100644 --- a/lib/http.h +++ b/lib/http.h @@ -115,8 +115,10 @@ CURLcode Curl_http_setup_conn(struct Curl_easy *data, CURLcode Curl_http(struct Curl_easy *data, bool *done); CURLcode Curl_http_done(struct Curl_easy *data, CURLcode, bool premature); CURLcode Curl_http_connect(struct Curl_easy *data, bool *done); -CURLcode Curl_http_do_pollset(struct Curl_easy *data, - struct easy_pollset *ps); +CURLcode Curl_http_doing_pollset(struct Curl_easy *data, + struct easy_pollset *ps); +CURLcode Curl_http_perform_pollset(struct Curl_easy *data, + struct easy_pollset *ps); CURLcode Curl_http_write_resp(struct Curl_easy *data, const char *buf, size_t blen, bool is_eos); diff --git a/lib/http2.c b/lib/http2.c index a1caa2020f7c..5d1a502810fb 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -98,33 +98,6 @@ #define H2_SETTINGS_IV_LEN 3 #define H2_BINSETTINGS_LEN 80 -static size_t populate_settings(nghttp2_settings_entry *iv, - struct Curl_easy *data) -{ - iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; - iv[0].value = Curl_multi_max_concurrent_streams(data->multi); - - iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; - iv[1].value = H2_STREAM_WINDOW_SIZE_INITIAL; - - iv[2].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH; - iv[2].value = data->multi->push_cb != NULL; - - return 3; -} - -static ssize_t populate_binsettings(uint8_t *binsettings, - struct Curl_easy *data) -{ - nghttp2_settings_entry iv[H2_SETTINGS_IV_LEN]; - size_t ivlen; - - ivlen = populate_settings(iv, data); - /* this returns number of bytes it wrote or a negative number on error. */ - return nghttp2_pack_settings_payload(binsettings, H2_BINSETTINGS_LEN, - iv, ivlen); -} - struct cf_h2_ctx { nghttp2_session *h2; /* The easy handle used in the current filter call, cleared at return */ @@ -137,6 +110,7 @@ struct cf_h2_ctx { struct uint_hash streams; /* hash of `data->mid` to `h2_stream_ctx` */ size_t drain_total; /* sum of all stream's UrlState drain */ + uint32_t initial_win_size; /* current initial window size (settings) */ uint32_t max_concurrent_streams; uint32_t goaway_error; /* goaway error code from server */ int32_t remote_max_sid; /* max id processed by server */ @@ -204,6 +178,60 @@ static void cf_h2_ctx_close(struct cf_h2_ctx *ctx) } } +static uint32_t cf_h2_initial_win_size(struct Curl_easy *data) +{ +#if NGHTTP2_HAS_SET_LOCAL_WINDOW_SIZE + /* If the transfer has a rate-limit lower than the default initial + * stream window size, use that. It needs to be at least 8k or servers + * may be unhappy. */ + if(data->progress.dl.rlimit.rate_per_step && + (data->progress.dl.rlimit.rate_per_step < H2_STREAM_WINDOW_SIZE_INITIAL)) + return CURLMAX((uint32_t)data->progress.dl.rlimit.rate_per_step, 8192); +#endif + return H2_STREAM_WINDOW_SIZE_INITIAL; +} + +static size_t populate_settings(nghttp2_settings_entry *iv, + struct Curl_easy *data, + struct cf_h2_ctx *ctx) +{ + iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; + iv[0].value = Curl_multi_max_concurrent_streams(data->multi); + + iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; + iv[1].value = cf_h2_initial_win_size(data); + if(ctx) + ctx->initial_win_size = iv[1].value; + iv[2].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH; + iv[2].value = data->multi->push_cb != NULL; + + return 3; +} + +static ssize_t populate_binsettings(uint8_t *binsettings, + struct Curl_easy *data) +{ + nghttp2_settings_entry iv[H2_SETTINGS_IV_LEN]; + size_t ivlen; + + ivlen = populate_settings(iv, data, NULL); + /* this returns number of bytes it wrote or a negative number on error. */ + return nghttp2_pack_settings_payload(binsettings, H2_BINSETTINGS_LEN, + iv, ivlen); +} + +static CURLcode cf_h2_update_settings(struct cf_h2_ctx *ctx, + uint32_t initial_win_size) +{ + nghttp2_settings_entry entry; + entry.settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; + entry.value = initial_win_size; + if(nghttp2_submit_settings(ctx->h2, NGHTTP2_FLAG_NONE, &entry, 1)) + return CURLE_SEND_ERROR; + ctx->initial_win_size = initial_win_size; + return CURLE_OK; +} + static CURLcode nw_out_flush(struct Curl_cfilter *cf, struct Curl_easy *data); @@ -296,16 +324,18 @@ static void h2_stream_hash_free(unsigned int id, void *stream) static int32_t cf_h2_get_desired_local_win(struct Curl_cfilter *cf, struct Curl_easy *data) { + curl_off_t avail = Curl_rlimit_avail(&data->progress.dl.rlimit, + curlx_now()); + (void)cf; - if(data->set.max_recv_speed && data->set.max_recv_speed < INT32_MAX) { - /* The transfer should only receive `max_recv_speed` bytes per second. - * We restrict the stream's local window size, so that the server cannot - * send us "too much" at a time. - * This gets less precise the higher the latency. */ - return (int32_t)data->set.max_recv_speed; + if(avail < CURL_OFF_T_MAX) { /* limit in place */ + if(avail <= 0) + return 0; + else if(avail < INT32_MAX) + return (int32_t)avail; } #ifdef DEBUGBUILD - else { + { struct cf_h2_ctx *ctx = cf->ctx; CURL_TRC_CF(data, cf, "stream_win_max=%d", ctx->stream_win_max); return ctx->stream_win_max; @@ -580,7 +610,7 @@ static CURLcode cf_h2_ctx_open(struct Curl_cfilter *cf, nghttp2_settings_entry iv[H2_SETTINGS_IV_LEN]; size_t ivlen; - ivlen = populate_settings(iv, data); + ivlen = populate_settings(iv, data, ctx); rc = nghttp2_submit_settings(ctx->h2, NGHTTP2_FLAG_NONE, iv, ivlen); if(rc) { @@ -2007,6 +2037,9 @@ static CURLcode stream_recv(struct Curl_cfilter *cf, struct Curl_easy *data, (void)len; *pnread = 0; + if(!stream->xfer_result) + stream->xfer_result = cf_h2_update_local_win(cf, data, stream); + if(stream->xfer_result) { CURL_TRC_CF(data, cf, "[%d] xfer write failed", stream->id); result = stream->xfer_result; @@ -2239,6 +2272,7 @@ static CURLcode h2_submit(struct h2_stream_ctx **pstream, nghttp2_priority_spec pri_spec; size_t nwritten; CURLcode result = CURLE_OK; + uint32_t initial_win_size; *pnwritten = 0; Curl_dynhds_init(&h2_headers, 0, DYN_HTTP_REQUEST); @@ -2276,6 +2310,15 @@ static CURLcode h2_submit(struct h2_stream_ctx **pstream, if(!nghttp2_session_check_request_allowed(ctx->h2)) CURL_TRC_CF(data, cf, "send request NOT allowed (via nghttp2)"); + /* Check the initial windows size of the transfer (rate-limits?) and + * send an updated settings on changes from previous value. */ + initial_win_size = cf_h2_initial_win_size(data); + if(initial_win_size != ctx->initial_win_size) { + result = cf_h2_update_settings(ctx, initial_win_size); + if(result) + goto out; + } + switch(data->state.httpreq) { case HTTPREQ_POST: case HTTPREQ_POST_FORM: diff --git a/lib/imap.c b/lib/imap.c index faa595561dfa..181b0d7009d6 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -1938,10 +1938,7 @@ static CURLcode imap_regular_transfer(struct Curl_easy *data, data->req.size = -1; /* Set the progress data */ - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); - Curl_pgrsSetUploadSize(data, -1); - Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsReset(data); /* Carry out the perform */ result = imap_perform(data, &connected, dophase_done); diff --git a/lib/ldap.c b/lib/ldap.c index f0bc2f2a3790..fa1a4a4d25c5 100644 --- a/lib/ldap.c +++ b/lib/ldap.c @@ -509,7 +509,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) goto quit; } - Curl_pgrsSetDownloadCounter(data, 0); + Curl_pgrsReset(data); rc = ldap_search_s(server, ludp->lud_dn, (curl_ldap_num_t)ludp->lud_scope, ludp->lud_filter, ludp->lud_attrs, 0, &ldapmsg); diff --git a/lib/multi.c b/lib/multi.c index 3fc1c948f507..5ea93348e4e5 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -43,7 +43,6 @@ #include "select.h" #include "curlx/warnless.h" #include "curlx/wait.h" -#include "speedcheck.h" #include "conncache.h" #include "multihandle.h" #include "sigpipe.h" @@ -923,79 +922,145 @@ void Curl_attach_connection(struct Curl_easy *data, conn->handler->attach(data, conn); } +/* adjust pollset for rate limits/pauses */ +static CURLcode multi_adjust_pollset(struct Curl_easy *data, + struct easy_pollset *ps) +{ + CURLcode result = CURLE_OK; + + if(ps->n) { + struct curltime now = curlx_now(); + bool send_blocked, recv_blocked; + + recv_blocked = (Curl_rlimit_avail(&data->progress.dl.rlimit, now) <= 0); + send_blocked = (Curl_rlimit_avail(&data->progress.ul.rlimit, now) <= 0); + if(send_blocked || recv_blocked) { + int i; + for(i = 0; i <= SECONDARYSOCKET; ++i) { + curl_socket_t sock = data->conn->sock[i]; + if(sock == CURL_SOCKET_BAD) + continue; + if(recv_blocked && Curl_pollset_want_recv(data, ps, sock)) { + result = Curl_pollset_remove_in(data, ps, sock); + if(result) + break; + } + if(send_blocked && Curl_pollset_want_send(data, ps, sock)) { + result = Curl_pollset_remove_out(data, ps, sock); + if(result) + break; + } + } + } + + /* Not blocked and wanting to receive. If there is data pending + * in the connection filters, make transfer run again. */ + if(!recv_blocked && + ((Curl_pollset_want_recv(data, ps, data->conn->sock[FIRSTSOCKET]) && + Curl_conn_data_pending(data, FIRSTSOCKET)) || + (Curl_pollset_want_recv(data, ps, data->conn->sock[SECONDARYSOCKET]) && + Curl_conn_data_pending(data, SECONDARYSOCKET)))) { + CURL_TRC_M(data, "pollset[] has POLLIN, but there is still " + "buffered input -> mark as dirty"); + Curl_multi_mark_dirty(data); + } + } + return result; +} + static CURLcode mstate_connecting_pollset(struct Curl_easy *data, struct easy_pollset *ps) { - if(data->conn) { - curl_socket_t sockfd = Curl_conn_get_first_socket(data); - if(sockfd != CURL_SOCKET_BAD) { - /* Default is to wait to something from the server */ - return Curl_pollset_change(data, ps, sockfd, CURL_POLL_IN, 0); - } + struct connectdata *conn = data->conn; + curl_socket_t sockfd; + CURLcode result = CURLE_OK; + + if(Curl_xfer_recv_is_paused(data)) + return CURLE_OK; + /* If a socket is set, receiving is default. If the socket + * has not been determined yet (eyeballing), always ask the + * connection filters for what to monitor. */ + sockfd = Curl_conn_get_first_socket(data); + if(sockfd != CURL_SOCKET_BAD) { + result = Curl_pollset_change(data, ps, sockfd, CURL_POLL_IN, 0); + if(!result) + result = multi_adjust_pollset(data, ps); } - return CURLE_OK; + if(!result) + result = Curl_conn_adjust_pollset(data, conn, ps); + return result; } static CURLcode mstate_protocol_pollset(struct Curl_easy *data, struct easy_pollset *ps) { struct connectdata *conn = data->conn; - if(conn) { - curl_socket_t sockfd; - if(conn->handler->proto_pollset) - return conn->handler->proto_pollset(data, ps); - sockfd = conn->sock[FIRSTSOCKET]; + CURLcode result = CURLE_OK; + + if(conn->handler->proto_pollset) + result = conn->handler->proto_pollset(data, ps); + else { + curl_socket_t sockfd = conn->sock[FIRSTSOCKET]; if(sockfd != CURL_SOCKET_BAD) { /* Default is to wait to something from the server */ - return Curl_pollset_change(data, ps, sockfd, CURL_POLL_IN, 0); + result = Curl_pollset_change(data, ps, sockfd, CURL_POLL_IN, 0); } } - return CURLE_OK; + if(!result) + result = multi_adjust_pollset(data, ps); + if(!result) + result = Curl_conn_adjust_pollset(data, conn, ps); + return result; } static CURLcode mstate_do_pollset(struct Curl_easy *data, struct easy_pollset *ps) { struct connectdata *conn = data->conn; - if(conn) { - if(conn->handler->doing_pollset) - return conn->handler->doing_pollset(data, ps); - else if(CONN_SOCK_IDX_VALID(conn->send_idx)) { - /* Default is that we want to send something to the server */ - return Curl_pollset_add_out( - data, ps, conn->sock[conn->send_idx]); - } + CURLcode result = CURLE_OK; + + if(conn->handler->doing_pollset) + result = conn->handler->doing_pollset(data, ps); + else if(CONN_SOCK_IDX_VALID(conn->send_idx)) { + /* Default is that we want to send something to the server */ + result = Curl_pollset_add_out(data, ps, conn->sock[conn->send_idx]); } - return CURLE_OK; + if(!result) + result = multi_adjust_pollset(data, ps); + if(!result) + result = Curl_conn_adjust_pollset(data, conn, ps); + return result; } static CURLcode mstate_domore_pollset(struct Curl_easy *data, struct easy_pollset *ps) { struct connectdata *conn = data->conn; - if(conn) { - if(conn->handler->domore_pollset) - return conn->handler->domore_pollset(data, ps); - else if(CONN_SOCK_IDX_VALID(conn->send_idx)) { - /* Default is that we want to send something to the server */ - return Curl_pollset_add_out( - data, ps, conn->sock[conn->send_idx]); - } + CURLcode result = CURLE_OK; + + if(conn->handler->domore_pollset) + result = conn->handler->domore_pollset(data, ps); + else if(CONN_SOCK_IDX_VALID(conn->send_idx)) { + /* Default is that we want to send something to the server */ + result = Curl_pollset_add_out(data, ps, conn->sock[conn->send_idx]); } - return CURLE_OK; + if(!result) + result = multi_adjust_pollset(data, ps); + if(!result) + result = Curl_conn_adjust_pollset(data, conn, ps); + return result; } static CURLcode mstate_perform_pollset(struct Curl_easy *data, struct easy_pollset *ps) { struct connectdata *conn = data->conn; - if(!conn) - return CURLE_OK; - else if(conn->handler->perform_pollset) - return conn->handler->perform_pollset(data, ps); + CURLcode result = CURLE_OK; + + if(conn->handler->perform_pollset) + result = conn->handler->perform_pollset(data, ps); else { /* Default is to obey the data->req.keepon flags for send/recv */ - CURLcode result = CURLE_OK; if(CURL_WANT_RECV(data) && CONN_SOCK_IDX_VALID(conn->recv_idx)) { result = Curl_pollset_add_in( data, ps, conn->sock[conn->recv_idx]); @@ -1006,19 +1071,21 @@ static CURLcode mstate_perform_pollset(struct Curl_easy *data, result = Curl_pollset_add_out( data, ps, conn->sock[conn->send_idx]); } - return result; } + if(!result) + result = multi_adjust_pollset(data, ps); + if(!result) + result = Curl_conn_adjust_pollset(data, conn, ps); + return result; } /* Initializes `poll_set` with the current socket poll actions needed * for transfer `data`. */ CURLMcode Curl_multi_pollset(struct Curl_easy *data, - struct easy_pollset *ps, - const char *caller) + struct easy_pollset *ps) { CURLMcode mresult = CURLM_OK; CURLcode result = CURLE_OK; - bool expect_sockets = TRUE; /* If the transfer has no connection, this is fine. Happens when called via curl_multi_remove_handle() => Curl_multi_ev_assess() => @@ -1033,70 +1100,49 @@ CURLMcode Curl_multi_pollset(struct Curl_easy *data, case MSTATE_SETUP: case MSTATE_CONNECT: /* nothing to poll for yet */ - expect_sockets = FALSE; break; case MSTATE_RESOLVING: result = Curl_resolv_pollset(data, ps); - /* connection filters are not involved in this phase. It is OK if we get no - * sockets to wait for. Resolving can wake up from other sources. */ - expect_sockets = FALSE; break; case MSTATE_CONNECTING: case MSTATE_TUNNELING: - if(!Curl_xfer_recv_is_paused(data)) { - result = mstate_connecting_pollset(data, ps); - if(!result) - result = Curl_conn_adjust_pollset(data, data->conn, ps); - } - else - expect_sockets = FALSE; + result = mstate_connecting_pollset(data, ps); break; case MSTATE_PROTOCONNECT: case MSTATE_PROTOCONNECTING: result = mstate_protocol_pollset(data, ps); - if(!result) - result = Curl_conn_adjust_pollset(data, data->conn, ps); break; case MSTATE_DO: case MSTATE_DOING: result = mstate_do_pollset(data, ps); - if(!result) - result = Curl_conn_adjust_pollset(data, data->conn, ps); break; case MSTATE_DOING_MORE: result = mstate_domore_pollset(data, ps); - if(!result) - result = Curl_conn_adjust_pollset(data, data->conn, ps); break; case MSTATE_DID: /* same as PERFORMING in regard to polling */ case MSTATE_PERFORMING: result = mstate_perform_pollset(data, ps); - if(!result) - result = Curl_conn_adjust_pollset(data, data->conn, ps); break; case MSTATE_RATELIMITING: /* we need to let time pass, ignore socket(s) */ - expect_sockets = FALSE; break; case MSTATE_DONE: case MSTATE_COMPLETED: case MSTATE_MSGSENT: /* nothing more to poll for */ - expect_sockets = FALSE; break; default: failf(data, "multi_getsock: unexpected multi state %d", data->mstate); DEBUGASSERT(0); - expect_sockets = FALSE; break; } @@ -1110,39 +1156,27 @@ CURLMcode Curl_multi_pollset(struct Curl_easy *data, goto out; } - /* Unblocked and waiting to receive with buffered input. - * Make transfer run again at next opportunity. */ - if(!Curl_xfer_is_blocked(data) && !Curl_xfer_is_too_fast(data) && - ((Curl_pollset_want_read(data, ps, data->conn->sock[FIRSTSOCKET]) && - Curl_conn_data_pending(data, FIRSTSOCKET)) || - (Curl_pollset_want_read(data, ps, data->conn->sock[SECONDARYSOCKET]) && - Curl_conn_data_pending(data, SECONDARYSOCKET)))) { - CURL_TRC_M(data, "%s pollset[] has POLLIN, but there is still " - "buffered input to consume -> mark as dirty", caller); - Curl_multi_mark_dirty(data); - } - #ifndef CURL_DISABLE_VERBOSE_STRINGS if(CURL_TRC_M_is_verbose(data)) { size_t timeout_count = Curl_llist_count(&data->state.timeoutlist); switch(ps->n) { case 0: - CURL_TRC_M(data, "%s pollset[], timeouts=%zu, paused %d/%d (r/w)", - caller, timeout_count, + CURL_TRC_M(data, "pollset[], timeouts=%zu, paused %d/%d (r/w)", + timeout_count, Curl_xfer_send_is_paused(data), Curl_xfer_recv_is_paused(data)); break; case 1: - CURL_TRC_M(data, "%s pollset[fd=%" FMT_SOCKET_T " %s%s], timeouts=%zu", - caller, ps->sockets[0], + CURL_TRC_M(data, "pollset[fd=%" FMT_SOCKET_T " %s%s], timeouts=%zu", + ps->sockets[0], (ps->actions[0] & CURL_POLL_IN) ? "IN" : "", (ps->actions[0] & CURL_POLL_OUT) ? "OUT" : "", timeout_count); break; case 2: - CURL_TRC_M(data, "%s pollset[fd=%" FMT_SOCKET_T " %s%s, " + CURL_TRC_M(data, "pollset[fd=%" FMT_SOCKET_T " %s%s, " "fd=%" FMT_SOCKET_T " %s%s], timeouts=%zu", - caller, ps->sockets[0], + ps->sockets[0], (ps->actions[0] & CURL_POLL_IN) ? "IN" : "", (ps->actions[0] & CURL_POLL_OUT) ? "OUT" : "", ps->sockets[1], @@ -1151,27 +1185,14 @@ CURLMcode Curl_multi_pollset(struct Curl_easy *data, timeout_count); break; default: - CURL_TRC_M(data, "%s pollset[fds=%u], timeouts=%zu", - caller, ps->n, timeout_count); + CURL_TRC_M(data, "pollset[fds=%u], timeouts=%zu", + ps->n, timeout_count); break; } CURL_TRC_EASY_TIMERS(data); } #endif - if(expect_sockets && !ps->n && data->multi && - !Curl_uint_bset_contains(&data->multi->dirty, data->mid) && - !Curl_llist_count(&data->state.timeoutlist) && - !Curl_cwriter_is_paused(data) && !Curl_creader_is_paused(data) && - Curl_conn_is_ip_connected(data, FIRSTSOCKET)) { - /* We expected sockets for POLL monitoring, but none are set. - * We are not dirty (and run anyway). - * We are not waiting on any timer. - * None of the READ/WRITE directions are paused. - * We are connected to the server on IP level, at least. */ - infof(data, "WARNING: no socket in pollset or timer, transfer may stall!"); - DEBUGASSERT(0); - } out: return mresult; } @@ -1205,7 +1226,7 @@ CURLMcode curl_multi_fdset(CURLM *m, continue; } - Curl_multi_pollset(data, &ps, "curl_multi_fdset"); + Curl_multi_pollset(data, &ps); for(i = 0; i < ps.n; i++) { if(!FDSET_SOCK(ps.sockets[i])) /* pretend it does not exist */ @@ -1268,7 +1289,7 @@ CURLMcode curl_multi_waitfds(CURLM *m, Curl_uint_bset_remove(&multi->dirty, mid); continue; } - Curl_multi_pollset(data, &ps, "curl_multi_waitfds"); + Curl_multi_pollset(data, &ps); need += Curl_waitfds_add_ps(&cwfds, &ps); } while(Curl_uint_bset_next(&multi->process, mid, &mid)); @@ -1354,7 +1375,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi, Curl_uint_bset_remove(&multi->dirty, mid); continue; } - Curl_multi_pollset(data, &ps, "multi_wait"); + Curl_multi_pollset(data, &ps); if(Curl_pollfds_add_ps(&cpfds, &ps)) { result = CURLM_OUT_OF_MEMORY; goto out; @@ -1907,35 +1928,28 @@ static CURLcode multi_follow(struct Curl_easy *data, } static CURLcode mspeed_check(struct Curl_easy *data, - struct curltime *nowp) + struct curltime now) { timediff_t recv_wait_ms = 0; timediff_t send_wait_ms = 0; - /* check if over send speed */ - if(data->set.max_send_speed) - send_wait_ms = Curl_pgrsLimitWaitTime(&data->progress.ul, - data->set.max_send_speed, - *nowp); - - /* check if over recv speed */ - if(data->set.max_recv_speed) - recv_wait_ms = Curl_pgrsLimitWaitTime(&data->progress.dl, - data->set.max_recv_speed, - *nowp); + /* check if our send/recv limits require idle waits */ + send_wait_ms = Curl_rlimit_wait_ms(&data->progress.ul.rlimit, now); + recv_wait_ms = Curl_rlimit_wait_ms(&data->progress.dl.rlimit, now); if(send_wait_ms || recv_wait_ms) { if(data->mstate != MSTATE_RATELIMITING) { - Curl_ratelimit(data, *nowp); multistate(data, MSTATE_RATELIMITING); } Curl_expire(data, CURLMAX(send_wait_ms, recv_wait_ms), EXPIRE_TOOFAST); Curl_multi_clear_dirty(data); + CURL_TRC_M(data, "[RLIMIT] waiting %" FMT_TIMEDIFF_T "ms", + CURLMAX(send_wait_ms, recv_wait_ms)); return CURLE_AGAIN; } else if(data->mstate != MSTATE_PERFORMING) { + CURL_TRC_M(data, "[RLIMIT] wait over, continue"); multistate(data, MSTATE_PERFORMING); - Curl_ratelimit(data, *nowp); } return CURLE_OK; } @@ -1951,7 +1965,7 @@ static CURLMcode state_performing(struct Curl_easy *data, CURLcode result = *resultp = CURLE_OK; *stream_errorp = FALSE; - if(mspeed_check(data, nowp) == CURLE_AGAIN) + if(mspeed_check(data, *nowp) == CURLE_AGAIN) return CURLM_OK; /* read/write data if it is ready to do so */ @@ -2073,7 +2087,8 @@ static CURLMcode state_performing(struct Curl_easy *data, } } else { /* not errored, not done */ - mspeed_check(data, nowp); + *nowp = curlx_now(); + mspeed_check(data, *nowp); } free(newurl); *resultp = result; @@ -2228,10 +2243,7 @@ static CURLMcode state_ratelimiting(struct Curl_easy *data, CURLMcode rc = CURLM_OK; DEBUGASSERT(data->conn); /* if both rates are within spec, resume transfer */ - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; - else - result = Curl_speedcheck(data, *nowp); + result = Curl_pgrsCheck(data); if(result) { if(!(data->conn->handler->flags & PROTOPT_DUAL) && @@ -2242,7 +2254,7 @@ static CURLMcode state_ratelimiting(struct Curl_easy *data, multi_done(data, result, TRUE); } else { - if(!mspeed_check(data, nowp)) + if(!mspeed_check(data, *nowp)) rc = CURLM_CALL_MULTI_PERFORM; } *resultp = result; @@ -2387,6 +2399,8 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, (HTTP/2), or the full connection for older protocols */ bool stream_error = FALSE; rc = CURLM_OK; + /* update at start for continuous increase when looping */ + *nowp = curlx_now(); if(multi_ischanged(multi, TRUE)) { CURL_TRC_M(data, "multi changed, check CONNECT_PEND queue"); @@ -2704,16 +2718,18 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, rc = CURLM_CALL_MULTI_PERFORM; } /* if there is still a connection to use, call the progress function */ - else if(data->conn && Curl_pgrsUpdate(data)) { - /* aborted due to progress callback return code must close the - connection */ - result = CURLE_ABORTED_BY_CALLBACK; - streamclose(data->conn, "Aborted by callback"); - - /* if not yet in DONE state, go there, otherwise COMPLETED */ - multistate(data, (data->mstate < MSTATE_DONE) ? - MSTATE_DONE : MSTATE_COMPLETED); - rc = CURLM_CALL_MULTI_PERFORM; + else if(data->conn) { + result = Curl_pgrsUpdate(data); + if(result) { + /* aborted due to progress callback return code must close the + connection */ + streamclose(data->conn, "Aborted by callback"); + + /* if not yet in DONE state, go there, otherwise COMPLETED */ + multistate(data, (data->mstate < MSTATE_DONE) ? + MSTATE_DONE : MSTATE_COMPLETED); + rc = CURLM_CALL_MULTI_PERFORM; + } } } diff --git a/lib/multi_ev.c b/lib/multi_ev.c index f5000a456245..098f8da643af 100644 --- a/lib/multi_ev.c +++ b/lib/multi_ev.c @@ -508,7 +508,7 @@ static CURLMcode mev_assess(struct Curl_multi *multi, } } else - Curl_multi_pollset(data, &ps, "ev assess"); + Curl_multi_pollset(data, &ps); last_ps = mev_get_last_pollset(data, conn); if(!last_ps && ps.n) { diff --git a/lib/multiif.h b/lib/multiif.h index 1423d5a03d0c..81cf665bd3d8 100644 --- a/lib/multiif.h +++ b/lib/multiif.h @@ -73,8 +73,7 @@ CURLMcode Curl_multi_add_perform(struct Curl_multi *multi, unsigned int Curl_multi_max_concurrent_streams(struct Curl_multi *multi); CURLMcode Curl_multi_pollset(struct Curl_easy *data, - struct easy_pollset *ps, - const char *caller); + struct easy_pollset *ps); /** * Borrow the transfer buffer from the multi, suitable diff --git a/lib/pingpong.c b/lib/pingpong.c index 670d37c38e62..297389043f0e 100644 --- a/lib/pingpong.c +++ b/lib/pingpong.c @@ -33,7 +33,6 @@ #include "sendf.h" #include "select.h" #include "progress.h" -#include "speedcheck.h" #include "pingpong.h" #include "multiif.h" #include "vtls/vtls.h" @@ -122,11 +121,7 @@ CURLcode Curl_pp_statemach(struct Curl_easy *data, if(block) { /* if we did not wait, we do not have to spend time on this now */ - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; - else - result = Curl_speedcheck(data, curlx_now()); - + result = Curl_pgrsCheck(data); if(result) return result; } diff --git a/lib/pop3.c b/lib/pop3.c index d469dc07660d..05203c1a074e 100644 --- a/lib/pop3.c +++ b/lib/pop3.c @@ -1503,10 +1503,7 @@ static CURLcode pop3_regular_transfer(struct Curl_easy *data, data->req.size = -1; /* Set the progress data */ - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); - Curl_pgrsSetUploadSize(data, -1); - Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsReset(data); /* Carry out the perform */ result = pop3_perform(data, &connected, dophase_done); diff --git a/lib/progress.c b/lib/progress.c index 228f5dc19737..3985e1c1bfbd 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -28,6 +28,7 @@ #include "sendf.h" #include "multiif.h" #include "progress.h" +#include "transfer.h" #include "curlx/timeval.h" /* check rate limits within this many recent milliseconds, at minimum. */ @@ -92,6 +93,55 @@ static char *max6data(curl_off_t bytes, char *max6) } #endif +static void pgrs_speedinit(struct Curl_easy *data) +{ + memset(&data->state.keeps_speed, 0, sizeof(struct curltime)); +} + +/* + * @unittest: 1606 + */ +UNITTEST CURLcode pgrs_speedcheck(struct Curl_easy *data, + struct curltime *pnow) +{ + if(!data->set.low_speed_time || !data->set.low_speed_limit || + Curl_xfer_recv_is_paused(data) || Curl_xfer_send_is_paused(data)) + /* A paused transfer is not qualified for speed checks */ + return CURLE_OK; + + if((data->progress.current_speed >= 0) && data->set.low_speed_time) { + if(data->progress.current_speed < data->set.low_speed_limit) { + if(!data->state.keeps_speed.tv_sec) + /* under the limit at this moment */ + data->state.keeps_speed = *pnow; + else { + /* how long has it been under the limit */ + timediff_t howlong = curlx_timediff_ms(*pnow, data->state.keeps_speed); + + if(howlong >= data->set.low_speed_time * 1000) { + /* too long */ + failf(data, + "Operation too slow. " + "Less than %ld bytes/sec transferred the last %ld seconds", + data->set.low_speed_limit, + data->set.low_speed_time); + return CURLE_OPERATION_TIMEDOUT; + } + } + } + else + /* faster right now */ + data->state.keeps_speed.tv_sec = 0; + } + + if(data->set.low_speed_limit) + /* if low speed limit is enabled, set the expire timer to make this + connection's speed get checked again in a second */ + Curl_expire(data, 1000, EXPIRE_SPEEDCHECK); + + return CURLE_OK; +} + /* New proposed interface, 9th of February 2000: @@ -119,10 +169,19 @@ int Curl_pgrsDone(struct Curl_easy *data) * hidden */ curl_mfprintf(data->set.err, "\n"); - data->progress.speeder_c = 0; /* reset the progress meter display */ return 0; } +void Curl_pgrsReset(struct Curl_easy *data) +{ + Curl_pgrsSetUploadCounter(data, 0); + Curl_pgrsSetDownloadCounter(data, 0); + Curl_pgrsSetUploadSize(data, -1); + Curl_pgrsSetDownloadSize(data, -1); + data->progress.speeder_c = 0; /* reset speed records */ + pgrs_speedinit(data); +} + /* reset the known transfer sizes */ void Curl_pgrsResetTransferSizes(struct Curl_easy *data) { @@ -130,6 +189,14 @@ void Curl_pgrsResetTransferSizes(struct Curl_easy *data) Curl_pgrsSetUploadSize(data, -1); } +void Curl_pgrsRecvPause(struct Curl_easy *data, bool enable) +{ + if(!enable) { + data->progress.speeder_c = 0; /* reset speed records */ + pgrs_speedinit(data); /* reset low speed measurements */ + } +} + /* * * Curl_pgrsTimeWas(). Store the timestamp time at the given label. @@ -228,72 +295,11 @@ void Curl_pgrsStartNow(struct Curl_easy *data) p->speeder_c = 0; /* reset the progress meter display */ p->start = curlx_now(); p->is_t_startransfer_set = FALSE; - p->ul.limit.start = p->start; - p->dl.limit.start = p->start; - p->ul.limit.start_size = 0; - p->dl.limit.start_size = 0; p->dl.cur_size = 0; p->ul.cur_size = 0; /* the sizes are unknown at start */ p->dl_size_known = FALSE; p->ul_size_known = FALSE; - Curl_ratelimit(data, p->start); -} - -/* - * This is used to handle speed limits, calculating how many milliseconds to - * wait until we are back under the speed limit, if needed. - * - * The way it works is by having a "starting point" (time & amount of data - * transferred by then) used in the speed computation, to be used instead of - * the start of the transfer. This starting point is regularly moved as - * transfer goes on, to keep getting accurate values (instead of average over - * the entire transfer). - * - * This function takes the current amount of data transferred, the amount at - * the starting point, the limit (in bytes/s), the time of the starting point - * and the current time. - * - * Returns 0 if no waiting is needed or when no waiting is needed but the - * starting point should be reset (to current); or the number of milliseconds - * to wait to get back under the speed limit. - */ -timediff_t Curl_pgrsLimitWaitTime(struct pgrs_dir *d, - curl_off_t bytes_per_sec, - struct curltime now) -{ - curl_off_t bytes = d->cur_size - d->limit.start_size; - timediff_t should_ms; - timediff_t took_ms; - - /* no limit or we did not get to any bytes yet */ - if(!bytes_per_sec || !bytes) - return 0; - - /* The time it took us to have `bytes` */ - took_ms = curlx_timediff_ceil_ms(now, d->limit.start); - - /* The time it *should* have taken us to have `bytes` - * when obeying the bytes_per_sec speed_limit. */ - if(bytes < CURL_OFF_T_MAX/1000) { - /* (1000 * bytes / (bytes / sec)) = 1000 * sec = ms */ - should_ms = (timediff_t) (1000 * bytes / bytes_per_sec); - } - else { - /* large `bytes`, first calc the seconds it should have taken. - * if that is small enough, convert to milliseconds. */ - should_ms = (timediff_t) (bytes / bytes_per_sec); - if(should_ms < TIMEDIFF_T_MAX/1000) - should_ms *= 1000; - else - should_ms = TIMEDIFF_T_MAX; - } - - if(took_ms < should_ms) { - /* when gotten to `bytes` too fast, wait the difference */ - return should_ms - took_ms; - } - return 0; } /* @@ -304,28 +310,6 @@ void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size) data->progress.dl.cur_size = size; } -/* - * Update the timestamp and sizestamp to use for rate limit calculations. - */ -void Curl_ratelimit(struct Curl_easy *data, struct curltime now) -{ - /* do not set a new stamp unless the time since last update is long enough */ - if(data->set.max_recv_speed) { - if(curlx_timediff_ms(now, data->progress.dl.limit.start) >= - MIN_RATE_LIMIT_PERIOD) { - data->progress.dl.limit.start = now; - data->progress.dl.limit.start_size = data->progress.dl.cur_size; - } - } - if(data->set.max_send_speed) { - if(curlx_timediff_ms(now, data->progress.ul.limit.start) >= - MIN_RATE_LIMIT_PERIOD) { - data->progress.ul.limit.start = now; - data->progress.ul.limit.start_size = data->progress.ul.cur_size; - } - } -} - /* * Set the number of uploaded bytes so far. */ @@ -378,75 +362,82 @@ static curl_off_t trspeed(curl_off_t size, /* number of bytes */ } /* returns TRUE if it is time to show the progress meter */ -static bool progress_calc(struct Curl_easy *data, struct curltime now) +static bool progress_calc(struct Curl_easy *data, struct curltime *pnow) { - bool timetoshow = FALSE; struct Progress * const p = &data->progress; + int i_next, i_oldest, i_latest; + timediff_t duration_ms; + curl_off_t amount; /* The time spent so far (from the start) in microseconds */ - p->timespent = curlx_timediff_us(now, p->start); + p->timespent = curlx_timediff_us(*pnow, p->start); p->dl.speed = trspeed(p->dl.cur_size, p->timespent); p->ul.speed = trspeed(p->ul.cur_size, p->timespent); - /* Calculations done at most once a second, unless end is reached */ - if(p->lastshow != now.tv_sec) { - int countindex; /* amount of seconds stored in the speeder array */ - int nowindex = p->speeder_c% CURR_TIME; - p->lastshow = now.tv_sec; - timetoshow = TRUE; - - /* Let's do the "current speed" thing, with the dl + ul speeds - combined. Store the speed at entry 'nowindex'. */ - p->speeder[ nowindex ] = p->dl.cur_size + p->ul.cur_size; - - /* remember the exact time for this moment */ - p->speeder_time [ nowindex ] = now; - - /* advance our speeder_c counter, which is increased every time we get - here and we expect it to never wrap as 2^32 is a lot of seconds! */ + if(!p->speeder_c) { /* no previous record exists */ + p->speed_amount[0] = p->dl.cur_size + p->ul.cur_size; + p->speed_time[0] = *pnow; p->speeder_c++; - - /* figure out how many index entries of data we have stored in our speeder - array. With N_ENTRIES filled in, we have about N_ENTRIES-1 seconds of - transfer. Imagine, after one second we have filled in two entries, - after two seconds we have filled in three entries etc. */ - countindex = ((p->speeder_c >= CURR_TIME) ? CURR_TIME : p->speeder_c) - 1; - - /* first of all, we do not do this if there is no counted seconds yet */ - if(countindex) { - int checkindex; - timediff_t span_ms; - curl_off_t amount; - - /* Get the index position to compare with the 'nowindex' position. - Get the oldest entry possible. While we have less than CURR_TIME - entries, the first entry will remain the oldest. */ - checkindex = (p->speeder_c >= CURR_TIME) ? p->speeder_c%CURR_TIME : 0; - - /* Figure out the exact time for the time span */ - span_ms = curlx_timediff_ms(now, p->speeder_time[checkindex]); - if(span_ms == 0) - span_ms = 1; /* at least one millisecond MUST have passed */ - - /* Calculate the average speed the last 'span_ms' milliseconds */ - amount = p->speeder[nowindex]- p->speeder[checkindex]; - - if(amount > (0xffffffff/1000)) - /* the 'amount' value is bigger than would fit in 32 bits if - multiplied with 1000, so we use the double math for this */ - p->current_speed = (curl_off_t) - ((double)amount/((double)span_ms/1000.0)); - else - /* the 'amount' value is small enough to fit within 32 bits even - when multiplied with 1000 */ - p->current_speed = amount * 1000/span_ms; + /* use the overall average at the start */ + p->current_speed = p->ul.speed + p->dl.speed; + p->lastshow = pnow->tv_sec; + return TRUE; + } + /* We have at least one record now. Where to put the next and + * where is the latest one? */ + i_next = p->speeder_c % CURL_SPEED_RECORDS; + i_latest = (i_next > 0) ? (i_next - 1) : (CURL_SPEED_RECORDS - 1); + + /* Make a new record only when some time has passed. + * Too frequent calls otherwise ruin the history. */ + if(curlx_timediff_ms(*pnow, p->speed_time[i_latest]) >= 1000) { + p->speeder_c++; + i_latest = i_next; + p->speed_amount[i_latest] = p->dl.cur_size + p->ul.cur_size; + p->speed_time[i_latest] = *pnow; + } + else if(data->req.done) { + /* When a transfer is done, and we did not have a current speed + * already, update the last record. Otherwise, stay at the speed + * we have. The last chunk of data, when rate limiting, would increase + * reported speed since it no longer measures a full second. */ + if(!p->current_speed) { + p->speed_amount[i_latest] = p->dl.cur_size + p->ul.cur_size; + p->speed_time[i_latest] = *pnow; } - else - /* the first second we use the average */ - p->current_speed = p->ul.speed + p->dl.speed; + } + else { + /* transfer ongoing, wait for more time to pass. */ + return FALSE; + } - } /* Calculations end */ - return timetoshow; + i_oldest = (p->speeder_c < CURL_SPEED_RECORDS) ? 0 : + ((i_latest + 1) % CURL_SPEED_RECORDS); + + /* How much we transferred between oldest and current records */ + amount = p->speed_amount[i_latest]- p->speed_amount[i_oldest]; + /* How long this took */ + duration_ms = curlx_timediff_ms(p->speed_time[i_latest], + p->speed_time[i_oldest]); + if(duration_ms <= 0) + duration_ms = 1; + + if(amount > (CURL_OFF_T_MAX/1000)) { + /* the 'amount' value is bigger than would fit in 64 bits if + multiplied with 1000, so we use the double math for this */ + p->current_speed = (curl_off_t) + (((double)amount * 1000.0)/(double)duration_ms); + } + else { + /* the 'amount' value is small enough to fit within 32 bits even + when multiplied with 1000 */ + p->current_speed = amount * 1000 / duration_ms; + } + + if((p->lastshow == pnow->tv_sec) && !data->req.done) + return FALSE; + p->lastshow = pnow->tv_sec; + return TRUE; } #ifndef CURL_DISABLE_PROGRESS_METER @@ -568,7 +559,7 @@ static void progress_meter(struct Curl_easy *data) * Curl_pgrsUpdate() returns 0 for success or the value returned by the * progress callback! */ -static int pgrsupdate(struct Curl_easy *data, bool showprogress) +static CURLcode pgrsupdate(struct Curl_easy *data, bool showprogress) { if(!data->progress.hide) { if(data->set.fxferinfo) { @@ -582,9 +573,11 @@ static int pgrsupdate(struct Curl_easy *data, bool showprogress) data->progress.ul.cur_size); Curl_set_in_callback(data, FALSE); if(result != CURL_PROGRESSFUNC_CONTINUE) { - if(result) + if(result) { failf(data, "Callback aborted"); - return result; + return CURLE_ABORTED_BY_CALLBACK; + } + return CURLE_OK; } } else if(data->set.fprogress) { @@ -598,9 +591,11 @@ static int pgrsupdate(struct Curl_easy *data, bool showprogress) (double)data->progress.ul.cur_size); Curl_set_in_callback(data, FALSE); if(result != CURL_PROGRESSFUNC_CONTINUE) { - if(result) + if(result) { failf(data, "Callback aborted"); - return result; + return CURLE_ABORTED_BY_CALLBACK; + } + return CURLE_OK; } } @@ -608,21 +603,37 @@ static int pgrsupdate(struct Curl_easy *data, bool showprogress) progress_meter(data); } - return 0; + return CURLE_OK; } -int Curl_pgrsUpdate(struct Curl_easy *data) +static CURLcode pgrs_update(struct Curl_easy *data, struct curltime *pnow) { - struct curltime now = curlx_now(); /* what time is it */ - bool showprogress = progress_calc(data, now); + bool showprogress = progress_calc(data, pnow); return pgrsupdate(data, showprogress); } +CURLcode Curl_pgrsUpdate(struct Curl_easy *data) +{ + struct curltime now = curlx_now(); /* what time is it */ + return pgrs_update(data, &now); +} + +CURLcode Curl_pgrsCheck(struct Curl_easy *data) +{ + struct curltime now = curlx_now(); + CURLcode result; + + result = pgrs_update(data, &now); + if(!result && !data->req.done) + result = pgrs_speedcheck(data, &now); + return result; +} + /* * Update all progress, do not do progress meter/callbacks. */ void Curl_pgrsUpdate_nometer(struct Curl_easy *data) { struct curltime now = curlx_now(); /* what time is it */ - (void)progress_calc(data, now); + (void)progress_calc(data, &now); } diff --git a/lib/progress.h b/lib/progress.h index 7a176b7554ac..96a26fe1a4d9 100644 --- a/lib/progress.h +++ b/lib/progress.h @@ -26,6 +26,7 @@ #include "curlx/timeval.h" +struct Curl_easy; typedef enum { TIMER_NONE, @@ -50,15 +51,23 @@ void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size); void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size); void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size); -void Curl_ratelimit(struct Curl_easy *data, struct curltime now); -int Curl_pgrsUpdate(struct Curl_easy *data); + +/* perform progress update, invoking callbacks at intervals */ +CURLcode Curl_pgrsUpdate(struct Curl_easy *data); +/* perform progress update, no callbacks invoked */ void Curl_pgrsUpdate_nometer(struct Curl_easy *data); +/* perform progress update with callbacks and speed checks */ +CURLcode Curl_pgrsCheck(struct Curl_easy *data); + +/* Inform progress/speedcheck about receive pausing */ +void Curl_pgrsRecvPause(struct Curl_easy *data, bool enable); +/* Reset sizes and couners for up- and download. */ +void Curl_pgrsReset(struct Curl_easy *data); +/* Reset sizes for up- and download. */ void Curl_pgrsResetTransferSizes(struct Curl_easy *data); + struct curltime Curl_pgrsTime(struct Curl_easy *data, timerid timer); -timediff_t Curl_pgrsLimitWaitTime(struct pgrs_dir *d, - curl_off_t speed_limit, - struct curltime now); /** * Update progress timer with the elapsed time from its start to `timestamp`. * This allows updating timers later and is used by happy eyeballing, where @@ -69,4 +78,9 @@ void Curl_pgrsTimeWas(struct Curl_easy *data, timerid timer, void Curl_pgrsEarlyData(struct Curl_easy *data, curl_off_t sent); +#ifdef UNITTESTS +UNITTEST CURLcode pgrs_speedcheck(struct Curl_easy *data, + struct curltime *pnow); +#endif + #endif /* HEADER_CURL_PROGRESS_H */ diff --git a/lib/ratelimit.c b/lib/ratelimit.c new file mode 100644 index 000000000000..8b34d77e1313 --- /dev/null +++ b/lib/ratelimit.c @@ -0,0 +1,200 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ + +#include "curl_setup.h" + +#include "curlx/timeval.h" +#include "ratelimit.h" + + +#define CURL_US_PER_SEC 1000000 +#define CURL_RLIMIT_MIN_CHUNK (16 * 1024) +#define CURL_RLIMIT_MAX_STEPS 2 /* 500ms interval */ + +void Curl_rlimit_init(struct Curl_rlimit *r, + curl_off_t rate_per_s, + curl_off_t burst_per_s, + struct curltime ts) +{ + curl_off_t rate_steps; + + DEBUGASSERT(rate_per_s >= 0); + DEBUGASSERT(burst_per_s >= rate_per_s || !burst_per_s); + r->step_us = CURL_US_PER_SEC; + r->rate_per_step = rate_per_s; + r->burst_per_step = burst_per_s; + /* On rates that are multiples of CURL_RLIMIT_MIN_CHUNK, we reduce + * the interval `step_us` from 1 second to smaller steps with at + * most CURL_RLIMIT_MAX_STEPS. + * Smaller means more CPU, but also more precision. */ + rate_steps = rate_per_s / CURL_RLIMIT_MIN_CHUNK; + rate_steps = CURLMIN(rate_steps, CURL_RLIMIT_MAX_STEPS); + if(rate_steps >= 2) { + r->step_us /= rate_steps; + r->rate_per_step /= rate_steps; + r->burst_per_step /= rate_steps; + } + r->tokens = r->rate_per_step; + r->spare_us = 0; + r->ts = ts; + r->blocked = FALSE; +} + +void Curl_rlimit_start(struct Curl_rlimit *r, struct curltime ts) +{ + r->tokens = r->rate_per_step; + r->spare_us = 0; + r->ts = ts; +} + +bool Curl_rlimit_active(struct Curl_rlimit *r) +{ + return (r->rate_per_step > 0) || r->blocked; +} + +bool Curl_rlimit_is_blocked(struct Curl_rlimit *r) +{ + return r->blocked; +} + +static void ratelimit_update(struct Curl_rlimit *r, + struct curltime ts) +{ + timediff_t elapsed_us, elapsed_steps; + curl_off_t token_gain; + + DEBUGASSERT(r->rate_per_step); + if((r->ts.tv_sec == ts.tv_sec) && (r->ts.tv_usec == ts.tv_usec)) + return; + + elapsed_us = curlx_timediff_us(ts, r->ts); + if(elapsed_us < 0) { /* not going back in time */ + curl_mfprintf(stderr, "rlimit: neg elapsed time %" FMT_TIMEDIFF_T "us\n", + elapsed_us); + DEBUGASSERT(0); + return; + } + + elapsed_us += r->spare_us; + if(elapsed_us < r->step_us) + return; + + /* we do the update */ + r->ts = ts; + elapsed_steps = elapsed_us / r->step_us; + r->spare_us = elapsed_us % r->step_us; + + /* How many tokens did we gain since the last update? */ + if(r->rate_per_step > (CURL_OFF_T_MAX / elapsed_steps)) + token_gain = CURL_OFF_T_MAX; + else { + token_gain = r->rate_per_step * elapsed_steps; + } + + /* Limit the token again by the burst rate per second (if set), so we + * do not suddenly have a huge number of tokens after inactivity. */ + r->tokens += token_gain; + if(r->burst_per_step && (r->tokens > r->burst_per_step)) { + r->tokens = r->burst_per_step; + } +} + +curl_off_t Curl_rlimit_avail(struct Curl_rlimit *r, + struct curltime ts) +{ + if(r->blocked) + return 0; + else if(r->rate_per_step) { + ratelimit_update(r, ts); + return r->tokens; + } + else + return CURL_OFF_T_MAX; +} + +void Curl_rlimit_drain(struct Curl_rlimit *r, + size_t tokens, + struct curltime ts) +{ + if(r->blocked || !r->rate_per_step) + return; + + ratelimit_update(r, ts); +#if SIZEOF_CURL_OFF_T <= SIZEOF_SIZE_T + if(tokens > CURL_OFF_T_MAX) { + r->tokens = CURL_OFF_T_MIN; + return; + } + else +#endif + { + curl_off_t val = (curl_off_t)tokens; + if((CURL_OFF_T_MIN + val) < r->tokens) + r->tokens -= val; + else + r->tokens = CURL_OFF_T_MIN; + } +} + +timediff_t Curl_rlimit_wait_ms(struct Curl_rlimit *r, + struct curltime ts) +{ + timediff_t wait_us, elapsed_us; + + if(r->blocked || !r->rate_per_step) + return 0; + ratelimit_update(r, ts); + if(r->tokens > 0) + return 0; + + /* How much time will it take tokens to become positive again? + * Deduct `spare_us` and check against already elapsed time */ + wait_us = (1 + (-r->tokens / r->rate_per_step)) * r->step_us; + wait_us -= r->spare_us; + + elapsed_us = curlx_timediff_us(ts, r->ts); + if(elapsed_us >= wait_us) + return 0; + wait_us -= elapsed_us; + return (wait_us + 999) / 1000; /* in milliseconds */ +} + +void Curl_rlimit_block(struct Curl_rlimit *r, + bool activate, + struct curltime ts) +{ + if(!activate == !r->blocked) + return; + + r->ts = ts; + r->blocked = activate; + if(!r->blocked) { + /* Start rate limiting fresh. The amount of time this was blocked + * does not generate extra tokens. */ + Curl_rlimit_start(r, ts); + } + else { + r->tokens = 0; + } +} diff --git a/lib/ratelimit.h b/lib/ratelimit.h new file mode 100644 index 000000000000..53f803039145 --- /dev/null +++ b/lib/ratelimit.h @@ -0,0 +1,92 @@ +#ifndef HEADER_Curl_rlimit_H +#define HEADER_Curl_rlimit_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ + +#include "curlx/timeval.h" + +/* This is a rate limiter that provides "tokens" to be consumed + * per second with a "burst" rate limitation. Example: + * A rate limit of 1 megabyte per second with a burst rate of 1.5MB. + * - initially 1 million tokens are available. + * - these are drained in the first second. + * - checking available tokens before the 2nd second will return 0. + * - at/after the 2nd second, 1 million tokens are available again. + * - nothing happens for a second, the 1 million tokens would grow + * to 2 million, however the burst limit caps those at 1.5 million. + * Thus: + * - setting "burst" to CURL_OFF_T_MAX would average tokens over the + * complete lifetime. E.g. for a download, at the *end* of it, the + * average rate from start to finish would be the rate limit. + * - setting "burst" to the same value as "rate" would make a + * download always try to stay *at/below* the rate and slow times will + * not generate extra tokens. + * A rate limit can be blocked, causing the available tokens to become + * always 0 until unblocked. After unblocking, the rate limiting starts + * again with no history of the past. + * Finally, a rate limiter with rate 0 will always have CURL_OFF_T_MAX + * tokens available, unless blocked. + */ + +struct Curl_rlimit { + curl_off_t rate_per_step; /* rate tokens are generated per step us */ + curl_off_t burst_per_step; /* burst rate of tokens per step us */ + timediff_t step_us; /* microseconds between token increases */ + curl_off_t tokens; /* tokens available in the next second */ + timediff_t spare_us; /* microseconds unaffecting tokens */ + struct curltime ts; /* time of the last update */ + BIT(blocked); /* blocking sets available tokens to 0 */ +}; + +void Curl_rlimit_init(struct Curl_rlimit *r, + curl_off_t rate_per_s, + curl_off_t burst_per_s, + struct curltime ts); + +/* Start ratelimiting with the given timestamp. Resets available tokens. */ +void Curl_rlimit_start(struct Curl_rlimit *r, struct curltime ts); + +/* How many milliseconds to wait until token are available again. */ +timediff_t Curl_rlimit_wait_ms(struct Curl_rlimit *r, + struct curltime ts); + +/* Return if rate limiting of tokens is active */ +bool Curl_rlimit_active(struct Curl_rlimit *r); +bool Curl_rlimit_is_blocked(struct Curl_rlimit *r); + +/* Return how many tokens are available to spend, may be negative */ +curl_off_t Curl_rlimit_avail(struct Curl_rlimit *r, + struct curltime ts); + +/* Drain tokens from the ratelimit, return how many are now available. */ +void Curl_rlimit_drain(struct Curl_rlimit *r, + size_t tokens, + struct curltime ts); + +/* Block/unblock ratelimiting. A blocked ratelimit has 0 tokens available. */ +void Curl_rlimit_block(struct Curl_rlimit *r, + bool activate, + struct curltime ts); + +#endif /* HEADER_Curl_rlimit_H */ diff --git a/lib/request.c b/lib/request.c index 9778a0c95372..5bfcdfbfb8c7 100644 --- a/lib/request.c +++ b/lib/request.c @@ -258,7 +258,7 @@ static CURLcode req_set_upload_done(struct Curl_easy *data) { DEBUGASSERT(!data->req.upload_done); data->req.upload_done = TRUE; - data->req.keepon &= ~(KEEP_SEND|KEEP_SEND_TIMED); /* we are done sending */ + data->req.keepon &= ~KEEP_SEND; /* we are done sending */ Curl_pgrsTime(data, TIMER_POSTRANSFER); Curl_creader_done(data, data->req.upload_aborted); @@ -420,9 +420,9 @@ bool Curl_req_want_send(struct Curl_easy *data) * - or request has buffered data to send * - or transfer connection has pending data to send */ return !data->req.done && - (((data->req.keepon & KEEP_SENDBITS) == KEEP_SEND) || - !Curl_req_sendbuf_empty(data) || - Curl_xfer_needs_flush(data)); + ((data->req.keepon & KEEP_SEND) || + !Curl_req_sendbuf_empty(data) || + Curl_xfer_needs_flush(data)); } bool Curl_req_done_sending(struct Curl_easy *data) @@ -458,8 +458,7 @@ CURLcode Curl_req_abort_sending(struct Curl_easy *data) if(!data->req.upload_done) { Curl_bufq_reset(&data->req.sendbuf); data->req.upload_aborted = TRUE; - /* no longer KEEP_SEND and KEEP_SEND_PAUSE */ - data->req.keepon &= ~KEEP_SENDBITS; + data->req.keepon &= ~KEEP_SEND; return req_set_upload_done(data); } return CURLE_OK; @@ -470,6 +469,6 @@ CURLcode Curl_req_stop_send_recv(struct Curl_easy *data) /* stop receiving and ALL sending as well, including PAUSE and HOLD. * We might still be paused on receive client writes though, so * keep those bits around. */ - data->req.keepon &= ~(KEEP_RECV|KEEP_SENDBITS); + data->req.keepon &= ~(KEEP_RECV|KEEP_SEND); return Curl_req_abort_sending(data); } diff --git a/lib/request.h b/lib/request.h index e12d5efdcb23..0f9e0a6ff4fc 100644 --- a/lib/request.h +++ b/lib/request.h @@ -130,6 +130,7 @@ struct SingleRequest { BIT(sendbuf_init); /* sendbuf is initialized */ BIT(shutdown); /* request end will shutdown connection */ BIT(shutdown_err_ignore); /* errors in shutdown will not fail request */ + BIT(reader_started); /* client reads have started */ }; /** diff --git a/lib/rtsp.c b/lib/rtsp.c index 95215b8d4bfa..b4b3d6dd556d 100644 --- a/lib/rtsp.c +++ b/lib/rtsp.c @@ -142,7 +142,7 @@ const struct Curl_handler Curl_handler_rtsp = { ZERO_NULL, /* proto_pollset */ rtsp_do_pollset, /* doing_pollset */ ZERO_NULL, /* domore_pollset */ - ZERO_NULL, /* perform_pollset */ + Curl_http_perform_pollset, /* perform_pollset */ ZERO_NULL, /* disconnect */ rtsp_rtp_write_resp, /* write_resp */ rtsp_rtp_write_resp_hd, /* write_resp_hd */ @@ -668,8 +668,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) /* if a request-body has been sent off, we make sure this progress is noted properly */ Curl_pgrsSetUploadCounter(data, data->req.writebytecount); - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; + result = Curl_pgrsUpdate(data); } out: curlx_dyn_free(&req_buffer); diff --git a/lib/select.c b/lib/select.c index 7818082e7543..041733973e9e 100644 --- a/lib/select.c +++ b/lib/select.c @@ -711,7 +711,7 @@ void Curl_pollset_check(struct Curl_easy *data, *pwant_read = *pwant_write = FALSE; } -bool Curl_pollset_want_read(struct Curl_easy *data, +bool Curl_pollset_want_recv(struct Curl_easy *data, struct easy_pollset *ps, curl_socket_t sock) { @@ -723,3 +723,16 @@ bool Curl_pollset_want_read(struct Curl_easy *data, } return FALSE; } + +bool Curl_pollset_want_send(struct Curl_easy *data, + struct easy_pollset *ps, + curl_socket_t sock) +{ + unsigned int i; + (void)data; + for(i = 0; i < ps->n; ++i) { + if((ps->sockets[i] == sock) && (ps->actions[i] & CURL_POLL_OUT)) + return TRUE; + } + return FALSE; +} diff --git a/lib/select.h b/lib/select.h index c1f975e9d79c..fb54686af3e2 100644 --- a/lib/select.h +++ b/lib/select.h @@ -163,8 +163,12 @@ CURLcode Curl_pollset_set(struct Curl_easy *data, #define Curl_pollset_add_in(data, ps, sock) \ Curl_pollset_change((data), (ps), (sock), CURL_POLL_IN, 0) +#define Curl_pollset_remove_in(data, ps, sock) \ + Curl_pollset_change((data), (ps), (sock), 0, CURL_POLL_IN) #define Curl_pollset_add_out(data, ps, sock) \ Curl_pollset_change((data), (ps), (sock), CURL_POLL_OUT, 0) +#define Curl_pollset_remove_out(data, ps, sock) \ + Curl_pollset_change((data), (ps), (sock), 0, CURL_POLL_OUT) #define Curl_pollset_add_inout(data, ps, sock) \ Curl_pollset_change((data), (ps), (sock), \ CURL_POLL_IN|CURL_POLL_OUT, 0) @@ -188,10 +192,12 @@ void Curl_pollset_check(struct Curl_easy *data, struct easy_pollset *ps, curl_socket_t sock, bool *pwant_read, bool *pwant_write); -/** - * Return TRUE if the pollset contains socket with CURL_POLL_IN. - */ -bool Curl_pollset_want_read(struct Curl_easy *data, +/* TRUE if the pollset contains socket with CURL_POLL_IN. */ +bool Curl_pollset_want_recv(struct Curl_easy *data, + struct easy_pollset *ps, + curl_socket_t sock); +/* TRUE if the pollset contains socket with CURL_POLL_OUT. */ +bool Curl_pollset_want_send(struct Curl_easy *data, struct easy_pollset *ps, curl_socket_t sock); diff --git a/lib/sendf.c b/lib/sendf.c index 655444a29504..f70abb5797bc 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -108,6 +108,7 @@ static void cl_reset_writer(struct Curl_easy *data) static void cl_reset_reader(struct Curl_easy *data) { struct Curl_creader *reader = data->req.reader_stack; + data->req.reader_started = FALSE; while(reader) { data->req.reader_stack = reader->next; reader->crt->do_close(data, reader); @@ -231,6 +232,7 @@ static CURLcode cw_download_write(struct Curl_easy *data, if(!is_connect && !ctx->started_response) { Curl_pgrsTime(data, TIMER_STARTTRANSFER); + Curl_rlimit_start(&data->progress.dl.rlimit, curlx_now()); ctx->started_response = TRUE; } @@ -301,7 +303,9 @@ static CURLcode cw_download_write(struct Curl_easy *data, if(result) return result; } + /* Update stats, write and report progress */ + Curl_rlimit_drain(&data->progress.dl.rlimit, nwrite, curlx_now()); data->req.bytecount += nwrite; Curl_pgrsSetDownloadCounter(data, data->req.bytecount); @@ -1198,9 +1202,28 @@ CURLcode Curl_client_read(struct Curl_easy *data, char *buf, size_t blen, return result; DEBUGASSERT(data->req.reader_stack); } + if(!data->req.reader_started) { + Curl_rlimit_start(&data->progress.ul.rlimit, curlx_now()); + data->req.reader_started = TRUE; + } + if(Curl_rlimit_active(&data->progress.ul.rlimit)) { + curl_off_t ul_avail = + Curl_rlimit_avail(&data->progress.ul.rlimit, curlx_now()); + if(ul_avail <= 0) { + result = CURLE_OK; + *eos = FALSE; + goto out; + } + if(ul_avail < (curl_off_t)blen) + blen = (size_t)ul_avail; + } result = Curl_creader_read(data, data->req.reader_stack, buf, blen, nread, eos); + if(!result) + Curl_rlimit_drain(&data->progress.ul.rlimit, *nread, curlx_now()); + +out: CURL_TRC_READ(data, "client_read(len=%zu) -> %d, nread=%zu, eos=%d", blen, result, *nread, *eos); return result; diff --git a/lib/setopt.c b/lib/setopt.c index 338e94d1bbf4..1147deb1162f 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -2842,6 +2842,7 @@ static CURLcode setopt_offt(struct Curl_easy *data, CURLoption option, if(offt < 0) return CURLE_BAD_FUNCTION_ARGUMENT; s->max_send_speed = offt; + Curl_rlimit_init(&data->progress.ul.rlimit, offt, offt, curlx_now()); break; case CURLOPT_MAX_RECV_SPEED_LARGE: /* @@ -2851,6 +2852,7 @@ static CURLcode setopt_offt(struct Curl_easy *data, CURLoption option, if(offt < 0) return CURLE_BAD_FUNCTION_ARGUMENT; s->max_recv_speed = offt; + Curl_rlimit_init(&data->progress.dl.rlimit, offt, offt, curlx_now()); break; case CURLOPT_RESUME_FROM_LARGE: /* diff --git a/lib/smtp.c b/lib/smtp.c index f36459634ebb..af4676dc182d 100644 --- a/lib/smtp.c +++ b/lib/smtp.c @@ -1697,10 +1697,7 @@ static CURLcode smtp_regular_transfer(struct Curl_easy *data, data->req.size = -1; /* Set the progress data */ - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); - Curl_pgrsSetUploadSize(data, -1); - Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsReset(data); /* Carry out the perform */ result = smtp_perform(data, smtpc, smtp, &connected, dophase_done); diff --git a/lib/speedcheck.c b/lib/speedcheck.c deleted file mode 100644 index b074199c37d6..000000000000 --- a/lib/speedcheck.c +++ /dev/null @@ -1,80 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ - -#include "curl_setup.h" - -#include -#include "urldata.h" -#include "sendf.h" -#include "transfer.h" -#include "multiif.h" -#include "speedcheck.h" - -void Curl_speedinit(struct Curl_easy *data) -{ - memset(&data->state.keeps_speed, 0, sizeof(struct curltime)); -} - -/* - * @unittest: 1606 - */ -CURLcode Curl_speedcheck(struct Curl_easy *data, - struct curltime now) -{ - if(Curl_xfer_recv_is_paused(data) || Curl_xfer_send_is_paused(data)) - /* A paused transfer is not qualified for speed checks */ - return CURLE_OK; - - if((data->progress.current_speed >= 0) && data->set.low_speed_time) { - if(data->progress.current_speed < data->set.low_speed_limit) { - if(!data->state.keeps_speed.tv_sec) - /* under the limit at this moment */ - data->state.keeps_speed = now; - else { - /* how long has it been under the limit */ - timediff_t howlong = curlx_timediff_ms(now, data->state.keeps_speed); - - if(howlong >= data->set.low_speed_time * 1000) { - /* too long */ - failf(data, - "Operation too slow. " - "Less than %ld bytes/sec transferred the last %ld seconds", - data->set.low_speed_limit, - data->set.low_speed_time); - return CURLE_OPERATION_TIMEDOUT; - } - } - } - else - /* faster right now */ - data->state.keeps_speed.tv_sec = 0; - } - - if(data->set.low_speed_limit) - /* if low speed limit is enabled, set the expire timer to make this - connection's speed get checked again in a second */ - Curl_expire(data, 1000, EXPIRE_SPEEDCHECK); - - return CURLE_OK; -} diff --git a/lib/speedcheck.h b/lib/speedcheck.h deleted file mode 100644 index f54365cadfac..000000000000 --- a/lib/speedcheck.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef HEADER_CURL_SPEEDCHECK_H -#define HEADER_CURL_SPEEDCHECK_H -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ - -#include "curl_setup.h" - -#include "curlx/timeval.h" -struct Curl_easy; -void Curl_speedinit(struct Curl_easy *data); -CURLcode Curl_speedcheck(struct Curl_easy *data, - struct curltime now); - -#endif /* HEADER_CURL_SPEEDCHECK_H */ diff --git a/lib/telnet.c b/lib/telnet.c index 45a70808ea6b..d0ca5a66ce11 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -1659,9 +1659,10 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) } } - if(Curl_pgrsUpdate(data)) { - result = CURLE_ABORTED_BY_CALLBACK; - break; + if(!result) { + result = Curl_pgrsUpdate(data); + if(result) + keepon = FALSE; } } #endif diff --git a/lib/tftp.c b/lib/tftp.c index c730f8499ec4..ce9d200f05e3 100644 --- a/lib/tftp.c +++ b/lib/tftp.c @@ -59,7 +59,6 @@ #include "multiif.h" #include "url.h" #include "strcase.h" -#include "speedcheck.h" #include "select.h" #include "escape.h" #include "curlx/strerr.h" @@ -1175,9 +1174,10 @@ static CURLcode tftp_receive_packet(struct Curl_easy *data, } /* Update the progress meter */ - if(Curl_pgrsUpdate(data)) { + result = Curl_pgrsUpdate(data); + if(result) { tftp_state_machine(state, TFTP_EVENT_ERROR); - return CURLE_ABORTED_BY_CALLBACK; + return result; } } return result; @@ -1297,10 +1297,7 @@ static CURLcode tftp_doing(struct Curl_easy *data, bool *dophase_done) /* The multi code does not have this logic for the DOING state so we provide it for TFTP since it may do the entire transfer in this state. */ - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; - else - result = Curl_speedcheck(data, curlx_now()); + result = Curl_pgrsCheck(data); } return result; } diff --git a/lib/transfer.c b/lib/transfer.c index b576e6b88dbe..fbacdf429061 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -65,7 +65,6 @@ #include "cw-out.h" #include "transfer.h" #include "sendf.h" -#include "speedcheck.h" #include "progress.h" #include "http.h" #include "url.h" @@ -241,10 +240,9 @@ static CURLcode sendrecv_dl(struct Curl_easy *data, char *buf, *xfer_buf; size_t blen, xfer_blen; int maxloops = 10; - curl_off_t total_received = 0; bool is_multiplex = FALSE; bool rcvd_eagain = FALSE; - bool is_eos = FALSE; + bool is_eos = FALSE, rate_limited = FALSE; result = Curl_multi_xfer_buf_borrow(data, &xfer_buf, &xfer_blen); if(result) @@ -265,15 +263,21 @@ static CURLcode sendrecv_dl(struct Curl_easy *data, buf = xfer_buf; bytestoread = xfer_blen; - if(bytestoread && data->set.max_recv_speed > 0) { - /* In case of speed limit on receiving: if this loop already got - * a quarter of the quota, break out. We want to stutter a bit - * to keep in the limit, but too small receives will just cost - * cpu unnecessarily. */ - if(total_received && (total_received >= (data->set.max_recv_speed / 4))) + if(bytestoread && Curl_rlimit_active(&data->progress.dl.rlimit)) { + curl_off_t dl_avail = Curl_rlimit_avail(&data->progress.dl.rlimit, + curlx_now()); + /* DEBUGF(infof(data, "dl_rlimit, available=%" FMT_OFF_T, dl_avail)); + */ + /* In case of rate limited downloads: if this loop already got + * data and less than 16k is left in the limit, break out. + * We want to stutter a bit to keep in the limit, but too small + * receives will just cost cpu unnecessarily. */ + if(dl_avail <= 0) { + rate_limited = TRUE; break; - if(data->set.max_recv_speed < (curl_off_t)bytestoread) - bytestoread = (size_t)data->set.max_recv_speed; + } + if(dl_avail < (curl_off_t)bytestoread) + bytestoread = (size_t)dl_avail; } rcvd_eagain = FALSE; @@ -315,7 +319,6 @@ static CURLcode sendrecv_dl(struct Curl_easy *data, if(k->eos_written) /* already did write this to client, leave */ break; } - total_received += blen; result = Curl_xfer_write_resp(data, buf, blen, is_eos); if(result || data->req.done) @@ -327,13 +330,13 @@ static CURLcode sendrecv_dl(struct Curl_easy *data, if((!is_multiplex && data->req.download_done) || is_eos) { data->req.keepon &= ~KEEP_RECV; } - /* if we are PAUSEd or stopped receiving, leave the loop */ - if((k->keepon & KEEP_RECV_PAUSE) || !(k->keepon & KEEP_RECV)) + /* if we stopped receiving, leave the loop */ + if(!(k->keepon & KEEP_RECV)) break; } while(maxloops--); - if(!is_eos && !Curl_xfer_is_blocked(data) && + if(!is_eos && !rate_limited && CURL_WANT_RECV(data) && (!rcvd_eagain || data_pending(data, rcvd_eagain))) { /* Did not read until EAGAIN/EOS or there is still data pending * in buffers. Mark as read-again via simulated SELECT results. */ @@ -396,16 +399,13 @@ CURLcode Curl_sendrecv(struct Curl_easy *data, struct curltime *nowp) } /* If we still have writing to do, we check if we have a writable socket. */ - if(Curl_req_want_send(data) || (data->req.keepon & KEEP_SEND_TIMED)) { + if(Curl_req_want_send(data)) { result = sendrecv_ul(data); if(result) goto out; } - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; - else - result = Curl_speedcheck(data, *nowp); + result = Curl_pgrsCheck(data); if(result) goto out; @@ -440,16 +440,14 @@ CURLcode Curl_sendrecv(struct Curl_easy *data, struct curltime *nowp) result = CURLE_PARTIAL_FILE; goto out; } - if(Curl_pgrsUpdate(data)) { - result = CURLE_ABORTED_BY_CALLBACK; - goto out; - } } /* If there is nothing more to send/recv, the request is done */ - if((k->keepon & (KEEP_RECVBITS|KEEP_SENDBITS)) == 0) + if((k->keepon & (KEEP_RECV|KEEP_SEND)) == 0) data->req.done = TRUE; + result = Curl_pgrsUpdate(data); + out: if(result) DEBUGF(infof(data, "Curl_sendrecv() -> %d", result)); @@ -913,51 +911,30 @@ bool Curl_xfer_is_blocked(struct Curl_easy *data) bool Curl_xfer_send_is_paused(struct Curl_easy *data) { - return (data->req.keepon & KEEP_SEND_PAUSE); + return Curl_rlimit_is_blocked(&data->progress.ul.rlimit); } bool Curl_xfer_recv_is_paused(struct Curl_easy *data) { - return (data->req.keepon & KEEP_RECV_PAUSE); + return Curl_rlimit_is_blocked(&data->progress.dl.rlimit); } CURLcode Curl_xfer_pause_send(struct Curl_easy *data, bool enable) { CURLcode result = CURLE_OK; - if(enable) { - data->req.keepon |= KEEP_SEND_PAUSE; - } - else { - data->req.keepon &= ~KEEP_SEND_PAUSE; - if(Curl_creader_is_paused(data)) - result = Curl_creader_unpause(data); - } + Curl_rlimit_block(&data->progress.ul.rlimit, enable, curlx_now()); + if(!enable && Curl_creader_is_paused(data)) + result = Curl_creader_unpause(data); return result; } CURLcode Curl_xfer_pause_recv(struct Curl_easy *data, bool enable) { CURLcode result = CURLE_OK; - if(enable) { - data->req.keepon |= KEEP_RECV_PAUSE; - } - else { - data->req.keepon &= ~KEEP_RECV_PAUSE; - if(Curl_cwriter_is_paused(data)) - result = Curl_cwriter_unpause(data); - } + Curl_rlimit_block(&data->progress.dl.rlimit, enable, curlx_now()); + if(!enable && Curl_cwriter_is_paused(data)) + result = Curl_cwriter_unpause(data); Curl_conn_ev_data_pause(data, enable); + Curl_pgrsRecvPause(data, enable); return result; } - -bool Curl_xfer_is_too_fast(struct Curl_easy *data) -{ - struct Curl_llist_node *e = Curl_llist_head(&data->state.timeoutlist); - while(e) { - struct time_node *n = Curl_node_elem(e); - e = Curl_node_next(e); - if(n->eid == EXPIRE_TOOFAST) - return TRUE; - } - return FALSE; -} diff --git a/lib/transfer.h b/lib/transfer.h index 6145efb4a5fd..b96629d97968 100644 --- a/lib/transfer.h +++ b/lib/transfer.h @@ -143,7 +143,4 @@ bool Curl_xfer_recv_is_paused(struct Curl_easy *data); CURLcode Curl_xfer_pause_send(struct Curl_easy *data, bool enable); CURLcode Curl_xfer_pause_recv(struct Curl_easy *data, bool enable); -/* Query if transfer has expire timeout TOOFAST set. */ -bool Curl_xfer_is_too_fast(struct Curl_easy *data); - #endif /* HEADER_CURL_TRANSFER_H */ diff --git a/lib/url.c b/lib/url.c index 7e4d455a8cd8..f9b1ed0808e7 100644 --- a/lib/url.c +++ b/lib/url.c @@ -88,7 +88,6 @@ #include "select.h" #include "multiif.h" #include "easyif.h" -#include "speedcheck.h" #include "curlx/warnless.h" #include "getinfo.h" #include "pop3.h" @@ -3884,7 +3883,6 @@ CURLcode Curl_connect(struct Curl_easy *data, CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn) { - /* if this is a pushed stream, we need this: */ CURLcode result; if(conn) { @@ -3904,9 +3902,7 @@ CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn) result = Curl_req_start(&data->req, data); if(!result) { - Curl_speedinit(data); - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); + Curl_pgrsReset(data); } return result; } diff --git a/lib/urldata.h b/lib/urldata.h index 4b112e7072dd..e4fc49753fd4 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -156,6 +156,7 @@ typedef unsigned int curl_prot_t; #include "curlx/dynbuf.h" #include "dynhds.h" #include "request.h" +#include "ratelimit.h" #include "netrc.h" /* On error return, the value of `pnwritten` has no meaning */ @@ -426,30 +427,11 @@ struct hostname { #define KEEP_NONE 0 #define KEEP_RECV (1<<0) /* there is or may be data to read */ #define KEEP_SEND (1<<1) /* there is or may be data to write */ -#define KEEP_RECV_HOLD (1<<2) /* when set, no reading should be done but there - might still be data to read */ -#define KEEP_SEND_HOLD (1<<3) /* when set, no writing should be done but there - might still be data to write */ -#define KEEP_RECV_PAUSE (1<<4) /* reading is paused */ -#define KEEP_SEND_PAUSE (1<<5) /* writing is paused */ - -/* KEEP_SEND_TIMED is set when the transfer should attempt sending - * at timer (or other) events. A transfer waiting on a timer will - * remove KEEP_SEND to suppress POLLOUTs of the connection. - * Adding KEEP_SEND_TIMED will then attempt to send whenever the transfer - * enters the "readwrite" loop, e.g. when a timer fires. - * This is used in HTTP for 'Expect: 100-continue' waiting. */ -#define KEEP_SEND_TIMED (1<<6) - -#define KEEP_RECVBITS (KEEP_RECV | KEEP_RECV_HOLD | KEEP_RECV_PAUSE) -#define KEEP_SENDBITS (KEEP_SEND | KEEP_SEND_HOLD | KEEP_SEND_PAUSE) - -/* transfer wants to send is not PAUSE or HOLD */ -#define CURL_WANT_SEND(data) \ - (((data)->req.keepon & KEEP_SENDBITS) == KEEP_SEND) -/* transfer receive is not on PAUSE or HOLD */ -#define CURL_WANT_RECV(data) \ - (((data)->req.keepon & KEEP_RECVBITS) == KEEP_RECV) + +/* transfer wants to send */ +#define CURL_WANT_SEND(data) ((data)->req.keepon & KEEP_SEND) +/* transfer wants to receive */ +#define CURL_WANT_RECV(data) ((data)->req.keepon & KEEP_RECV) #define FIRSTSOCKET 0 #define SECONDARYSOCKET 1 @@ -805,16 +787,11 @@ struct PureInfo { BIT(used_proxy); /* the transfer used a proxy */ }; -struct pgrs_measure { - struct curltime start; /* when measure started */ - curl_off_t start_size; /* the 'cur_size' the measure started at */ -}; - struct pgrs_dir { curl_off_t total_size; /* total expected bytes */ curl_off_t cur_size; /* transferred bytes so far */ curl_off_t speed; /* bytes per second transferred */ - struct pgrs_measure limit; + struct Curl_rlimit rlimit; /* speed limiting / pausing */ }; struct Progress { @@ -843,10 +820,10 @@ struct Progress { struct curltime t_startqueue; struct curltime t_acceptdata; -#define CURR_TIME (5 + 1) /* 6 entries for 5 seconds */ +#define CURL_SPEED_RECORDS (5 + 1) /* 6 entries for 5 seconds */ - curl_off_t speeder[ CURR_TIME ]; - struct curltime speeder_time[ CURR_TIME ]; + curl_off_t speed_amount[ CURL_SPEED_RECORDS ]; + struct curltime speed_time[ CURL_SPEED_RECORDS ]; unsigned char speeder_c; BIT(hide); BIT(ul_size_known); diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index ecfa895a2eaf..f63162b34417 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -80,10 +80,9 @@ #define QUIC_HANDSHAKE_TIMEOUT (10*NGTCP2_SECONDS) /* A stream window is the maximum amount we need to buffer for - * each active transfer. We use HTTP/3 flow control and only ACK - * when we take things out of the buffer. + * each active transfer. * Chunk size is large enough to take a full DATA frame */ -#define H3_STREAM_WINDOW_SIZE (128 * 1024) +#define H3_STREAM_WINDOW_SIZE (64 * 1024) #define H3_STREAM_CHUNK_SIZE (16 * 1024) #if H3_STREAM_CHUNK_SIZE < NGTCP2_MAX_UDP_PAYLOAD_SIZE #error H3_STREAM_CHUNK_SIZE smaller than NGTCP2_MAX_UDP_PAYLOAD_SIZE @@ -242,6 +241,7 @@ struct h3_stream_ctx { size_t sendbuf_len_in_flight; /* sendbuf amount "in flight" */ curl_uint64_t error3; /* HTTP/3 stream error code */ curl_off_t upload_left; /* number of request bytes left to upload */ + uint64_t download_unacked; /* bytes not acknowledged yet */ int status_code; /* HTTP status code */ CURLcode xfer_result; /* result from xfer_resp_write(_hd) */ BIT(resp_hds_complete); /* we have a complete, final response */ @@ -472,7 +472,7 @@ static void quic_settings(struct cf_ngtcp2_ctx *ctx, s->handshake_timeout = (data->set.connecttimeout > 0) ? data->set.connecttimeout * NGTCP2_MILLISECONDS : QUIC_HANDSHAKE_TIMEOUT; s->max_window = 100 * ctx->max_stream_window; - s->max_stream_window = 10 * ctx->max_stream_window; + s->max_stream_window = ctx->max_stream_window; s->no_pmtud = FALSE; #ifdef NGTCP2_SETTINGS_V3 /* try ten times the ngtcp2 defaults here for problems with Caddy */ @@ -1057,6 +1057,35 @@ static void h3_xfer_write_resp(struct Curl_cfilter *cf, } } +static void cf_ngtcp2_ack_stream(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct h3_stream_ctx *stream) +{ + struct cf_ngtcp2_ctx *ctx = cf->ctx; + struct curltime now = curlx_now(); + curl_off_t avail; + uint64_t ack_len = 0; + + /* How many byte to ack on the stream? */ + + /* how much does rate limiting allow us to acknowledge? */ + avail = Curl_rlimit_avail(&data->progress.dl.rlimit, now); + if(avail == CURL_OFF_T_MAX) { /* no rate limit, ack all */ + ack_len = stream->download_unacked; + } + else if(avail > 0) { + ack_len = CURLMIN(stream->download_unacked, (uint64_t)avail); + } + + if(ack_len) { + CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] ACK %" PRIu64 + "/%" PRIu64 " bytes of DATA", stream->id, + ack_len, stream->download_unacked); + ngtcp2_conn_extend_max_stream_offset(ctx->qconn, stream->id, ack_len); + stream->download_unacked -= ack_len; + } +} + static int cb_h3_recv_data(nghttp3_conn *conn, int64_t stream3_id, const uint8_t *buf, size_t blen, void *user_data, void *stream_user_data) @@ -1073,13 +1102,15 @@ static int cb_h3_recv_data(nghttp3_conn *conn, int64_t stream3_id, return NGHTTP3_ERR_CALLBACK_FAILURE; h3_xfer_write_resp(cf, data, stream, (const char *)buf, blen, FALSE); - if(blen) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] ACK %zu bytes of DATA", - stream->id, blen); - ngtcp2_conn_extend_max_stream_offset(ctx->qconn, stream->id, blen); - ngtcp2_conn_extend_max_offset(ctx->qconn, blen); - } CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] DATA len=%zu", stream->id, blen); + + ngtcp2_conn_extend_max_offset(ctx->qconn, blen); + if(UINT64_MAX - blen < stream->download_unacked) + stream->download_unacked = UINT64_MAX; /* unlikely */ + else + stream->download_unacked += blen; + + cf_ngtcp2_ack_stream(cf, data, stream); return 0; } @@ -1374,6 +1405,8 @@ static CURLcode cf_ngtcp2_recv(struct Curl_cfilter *cf, struct Curl_easy *data, goto out; } + cf_ngtcp2_ack_stream(cf, data, stream); + if(cf_progress_ingress(cf, data, &pktx)) { result = CURLE_RECV_ERROR; goto out; diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index 9428a20a5f39..77a915884aaf 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -54,7 +54,6 @@ #include "../http.h" /* for HTTP proxy tunnel stuff */ #include "ssh.h" #include "../url.h" -#include "../speedcheck.h" #include "../vtls/vtls.h" #include "../cfilters.h" #include "../connect.h" @@ -2481,17 +2480,13 @@ static CURLcode myssh_block_statemach(struct Curl_easy *data, while((sshc->state != SSH_STOP) && !result) { bool block; timediff_t left_ms = 1000; - struct curltime now = curlx_now(); result = myssh_statemach_act(data, sshc, sshp, &block); if(result) break; if(!disconnect) { - if(Curl_pgrsUpdate(data)) - return CURLE_ABORTED_BY_CALLBACK; - - result = Curl_speedcheck(data, now); + result = Curl_pgrsCheck(data); if(result) break; @@ -2746,10 +2741,7 @@ static CURLcode myssh_do_it(struct Curl_easy *data, bool *done) sshc->secondCreateDirs = 0; /* reset the create directory attempt state variable */ - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); - Curl_pgrsSetUploadSize(data, -1); - Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsReset(data); if(conn->handler->protocol & CURLPROTO_SCP) result = scp_perform(data, &connected, done); diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index 3a7e14053fb9..714e3953730a 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -53,7 +53,6 @@ #include "../http.h" /* for HTTP proxy tunnel stuff */ #include "ssh.h" #include "../url.h" -#include "../speedcheck.h" #include "../vtls/vtls.h" #include "../cfilters.h" #include "../connect.h" @@ -3135,10 +3134,7 @@ static CURLcode ssh_block_statemach(struct Curl_easy *data, break; if(!disconnect) { - if(Curl_pgrsUpdate(data)) - return CURLE_ABORTED_BY_CALLBACK; - - result = Curl_speedcheck(data, now); + result = Curl_pgrsCheck(data); if(result) break; @@ -3534,10 +3530,7 @@ static CURLcode ssh_do(struct Curl_easy *data, bool *done) sshc->secondCreateDirs = 0; /* reset the create directory attempt state variable */ - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); - Curl_pgrsSetUploadSize(data, -1); - Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsReset(data); if(conn->handler->protocol & CURLPROTO_SCP) result = scp_perform(data, &connected, done); diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c index a40c440234ae..f7e831f002e5 100644 --- a/lib/vtls/schannel.c +++ b/lib/vtls/schannel.c @@ -1811,10 +1811,9 @@ schannel_recv_renegotiate(struct Curl_cfilter *cf, struct Curl_easy *data, int what; timediff_t timeout_ms, remaining; - if(Curl_pgrsUpdate(data)) { - result = CURLE_ABORTED_BY_CALLBACK; + result = Curl_pgrsUpdate(data); + if(result) break; - } elapsed = curlx_timediff_ms(curlx_now(), rs->start_time); if(elapsed >= MAX_RENEG_BLOCK_TIME) { diff --git a/lib/ws.c b/lib/ws.c index 140bdece47d8..b5c02bda9555 100644 --- a/lib/ws.c +++ b/lib/ws.c @@ -1927,9 +1927,9 @@ const struct Curl_handler Curl_handler_ws = { ZERO_NULL, /* connecting */ ZERO_NULL, /* doing */ ZERO_NULL, /* proto_pollset */ - Curl_http_do_pollset, /* doing_pollset */ + Curl_http_doing_pollset, /* doing_pollset */ ZERO_NULL, /* domore_pollset */ - ZERO_NULL, /* perform_pollset */ + Curl_http_perform_pollset, /* perform_pollset */ ZERO_NULL, /* disconnect */ Curl_http_write_resp, /* write_resp */ Curl_http_write_resp_hd, /* write_resp_hd */ @@ -1954,9 +1954,9 @@ const struct Curl_handler Curl_handler_wss = { NULL, /* connecting */ ZERO_NULL, /* doing */ NULL, /* proto_pollset */ - Curl_http_do_pollset, /* doing_pollset */ + Curl_http_doing_pollset, /* doing_pollset */ ZERO_NULL, /* domore_pollset */ - ZERO_NULL, /* perform_pollset */ + Curl_http_perform_pollset, /* perform_pollset */ ZERO_NULL, /* disconnect */ Curl_http_write_resp, /* write_resp */ Curl_http_write_resp_hd, /* write_resp_hd */ diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index fc10723814e1..bc3abbc7d80c 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -280,7 +280,7 @@ test3032 test3033 test3034 test3035 \ test3100 test3101 test3102 test3103 test3104 test3105 \ \ test3200 test3201 test3202 test3203 test3204 test3205 test3206 test3207 test3208 \ -test3209 test3210 test3211 test3212 test3213 test3214 test3215 \ +test3209 test3210 test3211 test3212 test3213 test3214 test3215 test3216 \ test4000 test4001 EXTRA_DIST = $(TESTCASES) DISABLED data-xml1 diff --git a/tests/data/test3216 b/tests/data/test3216 new file mode 100644 index 000000000000..923090c70ac1 --- /dev/null +++ b/tests/data/test3216 @@ -0,0 +1,19 @@ + + + +unittest +ratelimit + + + +# +# Client-side + + +unittest + + +ratelimit unit tests + + + diff --git a/tests/http/test_02_download.py b/tests/http/test_02_download.py index 9abe497539d2..8cfd68b20463 100644 --- a/tests/http/test_02_download.py +++ b/tests/http/test_02_download.py @@ -27,11 +27,9 @@ import difflib import filecmp import logging -import math import os import re import sys -from datetime import timedelta import pytest from testenv import Env, CurlClient, LocalClient @@ -424,15 +422,17 @@ def test_02_24_speed_limit(self, env: Env, httpd, nghttpx, proto): count = 1 url = f'https://{env.authority_for(env.domain1, proto)}/data-1m' curl = CurlClient(env=env) - speed_limit = 384 * 1024 - min_duration = math.floor((1024 * 1024)/speed_limit) + speed_limit = 256 * 1024 r = curl.http_download(urls=[url], alpn_proto=proto, extra_args=[ '--limit-rate', f'{speed_limit}' ]) r.check_response(count=count, http_status=200) - assert r.duration > timedelta(seconds=min_duration), \ - f'rate limited transfer should take more than {min_duration}s, '\ - f'not {r.duration}' + dl_speed = r.stats[0]['speed_download'] + # speed limit is only exact on long durations. Ideally this transfer + # would take 4 seconds, but it may end just after 3 because then + # we have downloaded the rest and will not wait for the rate + # limit to increase again. + assert dl_speed <= ((1024*1024)/3), f'{r.stats[0]}' # make extreme parallel h2 upgrades, check invalid conn reuse # before protocol switch has happened diff --git a/tests/http/test_07_upload.py b/tests/http/test_07_upload.py index 8d6901884146..9e49ad7f4737 100644 --- a/tests/http/test_07_upload.py +++ b/tests/http/test_07_upload.py @@ -557,7 +557,7 @@ def test_07_50_put_speed_limit(self, env: Env, httpd, nghttpx, proto): r.check_response(count=count, http_status=200) assert r.responses[0]['header']['received-length'] == f'{up_len}', f'{r.responses[0]}' up_speed = r.stats[0]['speed_upload'] - assert (speed_limit * 0.5) <= up_speed <= (speed_limit * 1.5), f'{r.stats[0]}' + assert up_speed <= (speed_limit * 1.1), f'{r.stats[0]}' # speed limited on echo handler @pytest.mark.parametrize("proto", Env.http_protos()) @@ -573,7 +573,7 @@ def test_07_51_echo_speed_limit(self, env: Env, httpd, nghttpx, proto): ]) r.check_response(count=count, http_status=200) up_speed = r.stats[0]['speed_upload'] - assert (speed_limit * 0.5) <= up_speed <= (speed_limit * 1.5), f'{r.stats[0]}' + assert up_speed <= (speed_limit * 1.1), f'{r.stats[0]}' # upload larger data, triggering "Expect: 100-continue" code paths @pytest.mark.parametrize("proto", ['http/1.1']) diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc index 7027973d2f93..af5e2ebc7594 100644 --- a/tests/unit/Makefile.inc +++ b/tests/unit/Makefile.inc @@ -42,4 +42,4 @@ TESTS_C = \ unit1979.c unit1980.c \ unit2600.c unit2601.c unit2602.c unit2603.c unit2604.c unit2605.c \ unit3200.c unit3205.c \ - unit3211.c unit3212.c unit3213.c unit3214.c + unit3211.c unit3212.c unit3213.c unit3214.c unit3216.c diff --git a/tests/unit/unit1606.c b/tests/unit/unit1606.c index d323b5ce020b..4e290db72a76 100644 --- a/tests/unit/unit1606.c +++ b/tests/unit/unit1606.c @@ -23,7 +23,7 @@ ***************************************************************************/ #include "unitcheck.h" -#include "speedcheck.h" +#include "progress.h" #include "urldata.h" static CURLcode t1606_setup(struct Curl_easy **easy) @@ -58,12 +58,12 @@ static int runawhile(struct Curl_easy *easy, curl_easy_setopt(easy, CURLOPT_LOW_SPEED_LIMIT, speed_limit); curl_easy_setopt(easy, CURLOPT_LOW_SPEED_TIME, time_limit); - Curl_speedinit(easy); + Curl_pgrsReset(easy); do { /* fake the current transfer speed */ easy->progress.current_speed = speed; - res = Curl_speedcheck(easy, now); + res = pgrs_speedcheck(easy, &now); if(res) break; /* step the time */ diff --git a/tests/unit/unit3216.c b/tests/unit/unit3216.c new file mode 100644 index 000000000000..cbe9a5f0bf51 --- /dev/null +++ b/tests/unit/unit3216.c @@ -0,0 +1,103 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ +#include "unitcheck.h" + +#include "ratelimit.h" + +static CURLcode test_unit3216(const char *arg) +{ + UNITTEST_BEGIN_SIMPLE + struct Curl_rlimit r; + struct curltime ts; + + /* A ratelimit that is unlimited */ + ts = curlx_now(); + Curl_rlimit_init(&r, 0, 0, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == CURL_OFF_T_MAX, "inf"); + Curl_rlimit_drain(&r, 1000000, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == CURL_OFF_T_MAX, "drain keep inf"); + fail_unless(Curl_rlimit_wait_ms(&r, ts) == 0, "inf never waits"); + + Curl_rlimit_block(&r, TRUE, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == 0, "inf blocked to 0"); + Curl_rlimit_drain(&r, 1000000, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == 0, "blocked inf"); + Curl_rlimit_block(&r, FALSE, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == CURL_OFF_T_MAX, + "unblocked unlimited"); + + /* A ratelimit that give 10 tokens per second */ + ts = curlx_now(); + Curl_rlimit_init(&r, 10, 0, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == 10, "initial 10"); + Curl_rlimit_drain(&r, 5, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == 5, "drain to 5"); + Curl_rlimit_drain(&r, 3, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == 2, "drain to 2"); + ts.tv_usec += 1000; /* 1ms */ + Curl_rlimit_drain(&r, 3, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == -1, "drain to -1"); + fail_unless(Curl_rlimit_wait_ms(&r, ts) == 999, "wait 999ms"); + ts.tv_usec += 1000; /* 1ms */ + fail_unless(Curl_rlimit_wait_ms(&r, ts) == 998, "wait 998ms"); + ts.tv_sec += 1; + fail_unless(Curl_rlimit_avail(&r, ts) == 9, "10 inc per sec"); + ts.tv_sec += 1; + fail_unless(Curl_rlimit_avail(&r, ts) == 19, "10 inc per sec(2)"); + + Curl_rlimit_block(&r, TRUE, curlx_now()); + fail_unless(Curl_rlimit_avail(&r, curlx_now()) == 0, "10 blocked to 0"); + Curl_rlimit_block(&r, FALSE, curlx_now()); + fail_unless(Curl_rlimit_avail(&r, curlx_now()) == 10, "unblocked 10"); + + /* A ratelimit that give 10 tokens per second, max burst 15/s */ + ts = curlx_now(); + Curl_rlimit_init(&r, 10, 15, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == 10, "initial 10"); + Curl_rlimit_drain(&r, 5, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == 5, "drain to 5"); + Curl_rlimit_drain(&r, 3, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == 2, "drain to 2"); + Curl_rlimit_drain(&r, 3, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == -1, "drain to -1"); + ts.tv_sec += 1; + fail_unless(Curl_rlimit_avail(&r, ts) == 9, "10 inc per sec"); + ts.tv_sec += 1; + fail_unless(Curl_rlimit_avail(&r, ts) == 15, "10/15 burst limit"); + ts.tv_sec += 1; + fail_unless(Curl_rlimit_avail(&r, ts) == 15, "10/15 burst limit(2)"); + Curl_rlimit_drain(&r, 15, ts); + fail_unless(Curl_rlimit_avail(&r, ts) == 0, "drain to 0"); + fail_unless(Curl_rlimit_wait_ms(&r, ts) == 1000, "wait 1 sec"); + ts.tv_usec += 500000; /* half a sec, cheating on second carry */ + fail_unless(Curl_rlimit_avail(&r, ts) == 0, "0 after 0.5 sec"); + fail_unless(Curl_rlimit_wait_ms(&r, ts) == 500, "wait 0.5 sec"); + ts.tv_sec += 1; + fail_unless(Curl_rlimit_avail(&r, ts) == 10, "10 after 1.5 sec"); + fail_unless(Curl_rlimit_wait_ms(&r, ts) == 0, "wait 0"); + ts.tv_usec += 500000; /* half a sec, cheating on second carry */ + fail_unless(Curl_rlimit_avail(&r, ts) == 15, "10 after 2 sec"); + + UNITTEST_END_SIMPLE +} From 56f2479c1433bd4f886295fcdce2459d1333eecf Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 24 Nov 2025 12:46:01 +0100 Subject: [PATCH 041/140] manage: expand the 'libcurl support required' message Example of old text: --dns-ipv4-addr requires that libcurl is built to support c-ares. New version: For --dns-ipv4-addr to work, it requires that the underlying libcurl is built to support c-ares. Closes #19665 --- scripts/managen | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/managen b/scripts/managen index 61dae8cc1f0f..d8ff9bae5124 100755 --- a/scripts/managen +++ b/scripts/managen @@ -854,7 +854,7 @@ sub single { if($requires) { my $l = manpageify($long, $manpage); - push @foot, "$l requires that libcurl". + push @foot, "For $l to work, it requires that the underlying libcurl". " is built to support $requires.\n"; } if($mutexed) { From 3887069c661b40e76b053a4867eb565d4761ab3e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 21 Nov 2025 20:36:26 +0100 Subject: [PATCH 042/140] lib: rename internal header `share.h` to `curl_share.h` to avoid collision Windows CRTs have a `share.h`. Before this patch when trying to `#include ` it, the compiler picked up curl's internal `lib/share.h` instead. Rename it to avoid this issue. CRT `share.h` has constants necessary for using safe open CRT functions. Also rename `lib/share.c` to keep matching the header. Ref: https://learn.microsoft.com/cpp/c-runtime-library/sharing-constants Ref: 625f2c1644da58b9617479775badea21f125ce6d #16949 #16991 Cherry-picked from #19643 Closes #19676 --- lib/Makefile.inc | 4 ++-- lib/asyn-ares.c | 2 +- lib/asyn-base.c | 2 +- lib/asyn-thrdd.c | 2 +- lib/cf-socket.c | 2 +- lib/conncache.c | 2 +- lib/connect.c | 2 +- lib/cookie.c | 2 +- lib/{share.c => curl_share.c} | 2 +- lib/{share.h => curl_share.h} | 0 lib/doh.c | 2 +- lib/easy.c | 2 +- lib/hostip.c | 2 +- lib/hostip4.c | 2 +- lib/hostip6.c | 2 +- lib/hsts.c | 2 +- lib/http.c | 2 +- lib/multi.c | 2 +- lib/psl.c | 2 +- lib/setopt.c | 2 +- lib/url.c | 2 +- lib/vtls/vtls.c | 2 +- lib/vtls/vtls_scache.c | 2 +- tests/unit/unit1607.c | 2 +- tests/unit/unit1609.c | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) rename lib/{share.c => curl_share.c} (99%) rename lib/{share.h => curl_share.h} (100%) diff --git a/lib/Makefile.inc b/lib/Makefile.inc index 9c9d5c918691..cad02c823786 100644 --- a/lib/Makefile.inc +++ b/lib/Makefile.inc @@ -172,6 +172,7 @@ LIB_CFILES = \ curl_rtmp.c \ curl_sasl.c \ curl_sha512_256.c \ + curl_share.c \ curl_sspi.c \ curl_threads.c \ curl_trc.c \ @@ -242,7 +243,6 @@ LIB_CFILES = \ sendf.c \ setopt.c \ sha256.c \ - share.c \ slist.c \ smb.c \ smtp.c \ @@ -311,6 +311,7 @@ LIB_HFILES = \ curl_setup_once.h \ curl_sha256.h \ curl_sha512_256.h \ + curl_share.h \ curl_sspi.h \ curl_threads.h \ curl_trc.h \ @@ -376,7 +377,6 @@ LIB_HFILES = \ setup-os400.h \ setup-vms.h \ setup-win32.h \ - share.h \ sigpipe.h \ slist.h \ smb.h \ diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index e01f7ba3d24e..ab57d5e00b41 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -52,7 +52,7 @@ #include "sendf.h" #include "hostip.h" #include "hash.h" -#include "share.h" +#include "curl_share.h" #include "url.h" #include "multiif.h" #include "curlx/inet_pton.h" diff --git a/lib/asyn-base.c b/lib/asyn-base.c index a49e1752a57a..d7e8e7d15b86 100644 --- a/lib/asyn-base.c +++ b/lib/asyn-base.c @@ -51,7 +51,7 @@ #include "hash.h" #include "multiif.h" #include "select.h" -#include "share.h" +#include "curl_share.h" #include "url.h" #include "curl_memory.h" /* The last #include file should be: */ diff --git a/lib/asyn-thrdd.c b/lib/asyn-thrdd.c index 07b666304910..f4f57b547a01 100644 --- a/lib/asyn-thrdd.c +++ b/lib/asyn-thrdd.c @@ -59,7 +59,7 @@ #include "sendf.h" #include "hostip.h" #include "hash.h" -#include "share.h" +#include "curl_share.h" #include "url.h" #include "multiif.h" #include "curl_threads.h" diff --git a/lib/cf-socket.c b/lib/cf-socket.c index 0055f2d48c92..2930f95fe24c 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -75,7 +75,7 @@ #include "conncache.h" #include "multihandle.h" #include "rand.h" -#include "share.h" +#include "curl_share.h" #include "strdup.h" #include "system_win32.h" #include "curlx/version_win32.h" diff --git a/lib/conncache.c b/lib/conncache.c index 86dcce7138e6..275e490f23e8 100644 --- a/lib/conncache.c +++ b/lib/conncache.c @@ -38,7 +38,7 @@ #include "conncache.h" #include "http_negotiate.h" #include "http_ntlm.h" -#include "share.h" +#include "curl_share.h" #include "sigpipe.h" #include "connect.h" #include "select.h" diff --git a/lib/connect.c b/lib/connect.c index 4f9453907b0c..fbb5dcabff26 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -72,7 +72,7 @@ #include "curlx/warnless.h" #include "conncache.h" #include "multihandle.h" -#include "share.h" +#include "curl_share.h" #include "http_proxy.h" #include "socks.h" diff --git a/lib/cookie.c b/lib/cookie.c index 85356d563bb1..6099c6ea560d 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -31,7 +31,7 @@ #include "psl.h" #include "sendf.h" #include "slist.h" -#include "share.h" +#include "curl_share.h" #include "strcase.h" #include "curl_fopen.h" #include "curl_get_line.h" diff --git a/lib/share.c b/lib/curl_share.c similarity index 99% rename from lib/share.c rename to lib/curl_share.c index fdb80f5f64ab..b65d16c6281f 100644 --- a/lib/share.c +++ b/lib/curl_share.c @@ -27,7 +27,7 @@ #include #include "urldata.h" #include "connect.h" -#include "share.h" +#include "curl_share.h" #include "psl.h" #include "vtls/vtls.h" #include "vtls/vtls_scache.h" diff --git a/lib/share.h b/lib/curl_share.h similarity index 100% rename from lib/share.h rename to lib/curl_share.h diff --git a/lib/doh.c b/lib/doh.c index 636f0f41cf24..45524edf4c0b 100644 --- a/lib/doh.c +++ b/lib/doh.c @@ -33,7 +33,7 @@ #include "sendf.h" #include "multiif.h" #include "url.h" -#include "share.h" +#include "curl_share.h" #include "curlx/base64.h" #include "connect.h" #include "strdup.h" diff --git a/lib/easy.c b/lib/easy.c index 54896a8d55b4..8c7b9c23da68 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -53,7 +53,7 @@ #include "url.h" #include "getinfo.h" #include "hostip.h" -#include "share.h" +#include "curl_share.h" #include "strdup.h" #include "progress.h" #include "easyif.h" diff --git a/lib/hostip.c b/lib/hostip.c index 48889dcb43bc..d5f753f4b4a7 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -50,7 +50,7 @@ #include "hostip.h" #include "hash.h" #include "rand.h" -#include "share.h" +#include "curl_share.h" #include "url.h" #include "curlx/inet_ntop.h" #include "curlx/inet_pton.h" diff --git a/lib/hostip4.c b/lib/hostip4.c index e1ed007aafa3..d543c1e14b19 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -47,7 +47,7 @@ #include "sendf.h" #include "hostip.h" #include "hash.h" -#include "share.h" +#include "curl_share.h" #include "url.h" /* The last 2 #include files should be in this order */ diff --git a/lib/hostip6.c b/lib/hostip6.c index 9419b9e4d5fe..0f628b3fb5ca 100644 --- a/lib/hostip6.c +++ b/lib/hostip6.c @@ -48,7 +48,7 @@ #include "sendf.h" #include "hostip.h" #include "hash.h" -#include "share.h" +#include "curl_share.h" #include "url.h" #include "curlx/inet_pton.h" #include "connect.h" diff --git a/lib/hsts.c b/lib/hsts.c index ec332392c429..836481cd4c36 100644 --- a/lib/hsts.c +++ b/lib/hsts.c @@ -37,7 +37,7 @@ #include "sendf.h" #include "parsedate.h" #include "rename.h" -#include "share.h" +#include "curl_share.h" #include "strdup.h" #include "curlx/strparse.h" diff --git a/lib/http.c b/lib/http.c index a1e449d35441..ae932cd7c93a 100644 --- a/lib/http.c +++ b/lib/http.c @@ -65,7 +65,7 @@ #include "http_aws_sigv4.h" #include "url.h" #include "urlapi-int.h" -#include "share.h" +#include "curl_share.h" #include "hostip.h" #include "dynhds.h" #include "http.h" diff --git a/lib/multi.c b/lib/multi.c index 5ea93348e4e5..00af3ca2bddf 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -33,7 +33,7 @@ #include "connect.h" #include "progress.h" #include "easyif.h" -#include "share.h" +#include "curl_share.h" #include "psl.h" #include "multiif.h" #include "multi_ev.h" diff --git a/lib/psl.c b/lib/psl.c index 832d6d21b94a..f645763d063b 100644 --- a/lib/psl.c +++ b/lib/psl.c @@ -29,7 +29,7 @@ #ifdef USE_LIBPSL #include "psl.h" -#include "share.h" +#include "curl_share.h" /* The last 2 #include files should be in this order */ #include "curl_memory.h" diff --git a/lib/setopt.c b/lib/setopt.c index 1147deb1162f..fc95389312ad 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -41,7 +41,7 @@ #include "progress.h" #include "content_encoding.h" #include "strcase.h" -#include "share.h" +#include "curl_share.h" #include "vtls/vtls.h" #include "curlx/warnless.h" #include "sendf.h" diff --git a/lib/url.c b/lib/url.c index f9b1ed0808e7..1d4c6b1fc419 100644 --- a/lib/url.c +++ b/lib/url.c @@ -81,7 +81,7 @@ #include "cookie.h" #include "strcase.h" #include "escape.h" -#include "share.h" +#include "curl_share.h" #include "content_encoding.h" #include "http_digest.h" #include "http_negotiate.h" diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c index ed0af3d53b91..d116ec91edb3 100644 --- a/lib/vtls/vtls.c +++ b/lib/vtls/vtls.c @@ -63,7 +63,7 @@ #include "../strcase.h" #include "../url.h" #include "../progress.h" -#include "../share.h" +#include "../curl_share.h" #include "../multiif.h" #include "../curlx/fopen.h" #include "../curlx/timeval.h" diff --git a/lib/vtls/vtls_scache.c b/lib/vtls/vtls_scache.c index 328b12403e9b..3524a25a4417 100644 --- a/lib/vtls/vtls_scache.c +++ b/lib/vtls/vtls_scache.c @@ -41,7 +41,7 @@ #include "../strcase.h" #include "../url.h" #include "../llist.h" -#include "../share.h" +#include "../curl_share.h" #include "../curl_trc.h" #include "../curl_sha256.h" #include "../rand.h" diff --git a/tests/unit/unit1607.c b/tests/unit/unit1607.c index 089caa1c45b8..3e4d53d0be5e 100644 --- a/tests/unit/unit1607.c +++ b/tests/unit/unit1607.c @@ -25,7 +25,7 @@ #include "urldata.h" #include "connect.h" -#include "share.h" +#include "curl_share.h" #include "memdebug.h" /* LAST include file */ diff --git a/tests/unit/unit1609.c b/tests/unit/unit1609.c index 00164617f522..f3f318f2cf97 100644 --- a/tests/unit/unit1609.c +++ b/tests/unit/unit1609.c @@ -25,7 +25,7 @@ #include "urldata.h" #include "connect.h" -#include "share.h" +#include "curl_share.h" #include "memdebug.h" /* LAST include file */ From 56bfde6554716f302998a29a192c82bf681a62ee Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 24 Nov 2025 23:55:57 +0100 Subject: [PATCH 043/140] INTERNALS.md: add release dates to build dependencies Also: - delete `roffit`, that's not used anymore. Follow-up to ea0b575dab86a3c44dd1d547dc500276266aa382 #12753 Follow-up to 92d9dbe4c008646dd467d23dea963fa32e16cf85 #19611 Closes #19677 --- docs/INTERNALS.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/INTERNALS.md b/docs/INTERNALS.md index acc4506e6722..75393a5d1c72 100644 --- a/docs/INTERNALS.md +++ b/docs/INTERNALS.md @@ -46,13 +46,12 @@ versions of libs and build tools. we use a few "build tools" and we make sure that we remain functional with these versions: - - GNU Libtool 1.4.2 - - GNU Autoconf 2.59 - - GNU Automake 1.7 - - GNU M4 1.4 - - perl 5.8 (5.22 on Windows) - - roffit 0.5 - - cmake 3.7 + - GNU libtool 1.4.2 (2001-09-11) + - GNU autoconf 2.59 (2003-11-06) + - GNU automake 1.7 (2002-09-25) + - GNU m4 1.4 (2007-09-21) + - perl 5.8 (2002-07-19), on Windows: 5.22 (2015-06-01) + - cmake 3.7 (2016-11-11) Library Symbols =============== From ee97c2a96a07bad19504973df1384b18419a8eac Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 24 Nov 2025 15:55:17 +0100 Subject: [PATCH 044/140] tests/server: use curlx file open/close functions Replace: - `open()` with `curlx_open()` (1 call). - `fopen()` with `curlx_fopen()`. - `fclose()` with `curlx_fclose()`. To centralize interacting with the CRT in preparation for using "safe" alternatives on Windows. This also adds long-filename and Unicode support for these operations on Windows. Keep using `open()` in the signal handler to avoid any issues with calling code not allowed in signal handlers. Cherry-picked from #19643 Closes #19679 --- tests/server/.checksrc | 2 -- tests/server/dnsd.c | 10 +++++----- tests/server/mqttd.c | 10 +++++----- tests/server/rtspd.c | 14 +++++++------- tests/server/socksd.c | 8 ++++---- tests/server/sws.c | 18 +++++++++--------- tests/server/tftpd.c | 20 ++++++++++---------- tests/server/util.c | 18 +++++++++--------- 8 files changed, 49 insertions(+), 51 deletions(-) diff --git a/tests/server/.checksrc b/tests/server/.checksrc index a4e094e1c913..0386c677e6c3 100644 --- a/tests/server/.checksrc +++ b/tests/server/.checksrc @@ -3,8 +3,6 @@ # SPDX-License-Identifier: curl allowfunc accept -allowfunc fclose -allowfunc fopen allowfunc fprintf allowfunc freeaddrinfo allowfunc getaddrinfo diff --git a/tests/server/dnsd.c b/tests/server/dnsd.c index c541b05295b2..9b3a42e1590c 100644 --- a/tests/server/dnsd.c +++ b/tests/server/dnsd.c @@ -102,7 +102,7 @@ static int store_incoming(const unsigned char *data, size_t size, snprintf(dumpfile, sizeof(dumpfile), "%s/dnsd.input", logdir); /* Open request dump file. */ - server = fopen(dumpfile, "ab"); + server = curlx_fopen(dumpfile, "ab"); if(!server) { char errbuf[STRERROR_LEN]; int error = errno; @@ -162,7 +162,7 @@ static int store_incoming(const unsigned char *data, size_t size, if(*qlen > qbuflen) { logmsg("dnsd: query too large: %lu > %lu", (unsigned long)*qlen, (unsigned long)qbuflen); - fclose(server); + curlx_fclose(server); return -1; } memcpy(qbuf, qptr, *qlen); @@ -176,7 +176,7 @@ static int store_incoming(const unsigned char *data, size_t size, fprintf(server, "\n"); #endif - fclose(server); + curlx_fclose(server); return 0; } @@ -325,7 +325,7 @@ static void read_instructions(void) char file[256]; FILE *f; snprintf(file, sizeof(file), "%s/" INSTRUCTIONS, logdir); - f = fopen(file, FOPEN_READTEXT); + f = curlx_fopen(file, FOPEN_READTEXT); if(f) { char buf[256]; ancount_aaaa = ancount_a = 0; @@ -375,7 +375,7 @@ static void read_instructions(void) } } } - fclose(f); + curlx_fclose(f); } else logmsg("Error opening file '%s'", file); diff --git a/tests/server/mqttd.c b/tests/server/mqttd.c index 2701d61260e0..59c7540dcfc3 100644 --- a/tests/server/mqttd.c +++ b/tests/server/mqttd.c @@ -73,7 +73,7 @@ static void mqttd_resetdefaults(void) static void mqttd_getconfig(void) { - FILE *fp = fopen(configfile, FOPEN_READTEXT); + FILE *fp = curlx_fopen(configfile, FOPEN_READTEXT); mqttd_resetdefaults(); if(fp) { char buffer[512]; @@ -119,7 +119,7 @@ static void mqttd_getconfig(void) } } } - fclose(fp); + curlx_fclose(fp); } else { logmsg("No config file '%s' to read", configfile); @@ -430,7 +430,7 @@ static curl_socket_t mqttit(curl_socket_t fd) 0x04 /* protocol level */ }; snprintf(dumpfile, sizeof(dumpfile), "%s/%s", logdir, REQUEST_DUMP); - dump = fopen(dumpfile, "ab"); + dump = curlx_fopen(dumpfile, "ab"); if(!dump) goto end; @@ -636,9 +636,9 @@ static curl_socket_t mqttit(curl_socket_t fd) if(buffer) free(buffer); if(dump) - fclose(dump); + curlx_fclose(dump); if(stream) - fclose(stream); + curlx_fclose(stream); return CURL_SOCKET_BAD; } diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index 5ffd0f28e5ee..335bbaaa69de 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -255,7 +255,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) /* get the custom server control "commands" */ int error = getpart(&cmd, &cmdsize, "reply", "servercmd", stream); - fclose(stream); + curlx_fclose(stream); if(error) { logmsg("getpart() failed with error (%d)", error); req->open = FALSE; /* closes connection */ @@ -557,7 +557,7 @@ static void rtspd_storerequest(char *reqbuf, size_t totalsize) return; do { - dump = fopen(dumpfile, "ab"); + dump = curlx_fopen(dumpfile, "ab"); /* !checksrc! disable ERRNOVAR 1 */ } while(!dump && ((error = errno) == EINTR)); if(!dump) { @@ -589,7 +589,7 @@ static void rtspd_storerequest(char *reqbuf, size_t totalsize) storerequest_cleanup: - res = fclose(dump); + res = curlx_fclose(dump); if(res) logmsg("Error closing file %s error (%d) %s", dumpfile, errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); @@ -815,7 +815,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) } else { error = getpart(&ptr, &count, "reply", partbuf, stream); - fclose(stream); + curlx_fclose(stream); if(error) { logmsg("getpart() failed with error (%d)", error); return 0; @@ -841,7 +841,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) else { /* get the custom server control "commands" */ error = getpart(&cmd, &cmdsize, "reply", "postcmd", stream); - fclose(stream); + curlx_fclose(stream); if(error) { logmsg("getpart() failed with error (%d)", error); free(ptr); @@ -870,7 +870,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) else rtspd_prevbounce = FALSE; - dump = fopen(responsedump, "ab"); + dump = curlx_fopen(responsedump, "ab"); if(!dump) { error = errno; logmsg("fopen() failed with error (%d) %s", @@ -928,7 +928,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) req->rtp_buffersize = 0; } - res = fclose(dump); + res = curlx_fclose(dump); if(res) logmsg("Error closing file %s error (%d) %s", responsedump, errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); diff --git a/tests/server/socksd.c b/tests/server/socksd.c index 1a1d40113bf8..4205d26880bd 100644 --- a/tests/server/socksd.c +++ b/tests/server/socksd.c @@ -108,7 +108,7 @@ static void socksd_resetdefaults(void) static void socksd_getconfig(void) { - FILE *fp = fopen(configfile, FOPEN_READTEXT); + FILE *fp = curlx_fopen(configfile, FOPEN_READTEXT); socksd_resetdefaults(); if(fp) { char buffer[512]; @@ -180,7 +180,7 @@ static void socksd_getconfig(void) } } } - fclose(fp); + curlx_fclose(fp); } } @@ -470,7 +470,7 @@ static curl_socket_t sockit(curl_socket_t fd) { FILE *dump; - dump = fopen(reqlogfile, "ab"); + dump = curlx_fopen(reqlogfile, "ab"); if(dump) { int i; fprintf(dump, "atyp %u =>", type); @@ -493,7 +493,7 @@ static curl_socket_t sockit(curl_socket_t fd) fprintf(dump, "\n"); break; } - fclose(dump); + curlx_fclose(dump); } } diff --git a/tests/server/sws.c b/tests/server/sws.c index d590cd6fef69..b070614f525e 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -178,7 +178,7 @@ static bool socket_domain_is_ip(void) /* parse the file on disk that might have a test number for us */ static int parse_cmdfile(struct sws_httprequest *req) { - FILE *f = fopen(cmdfile, FOPEN_READTEXT); + FILE *f = curlx_fopen(cmdfile, FOPEN_READTEXT); if(f) { int testnum = DOCNUMBER_NOTHING; char buf[256]; @@ -188,7 +188,7 @@ static int parse_cmdfile(struct sws_httprequest *req) req->testno = testnum; } } - fclose(f); + curlx_fclose(f); } return 0; } @@ -220,7 +220,7 @@ static int sws_parse_servercmd(struct sws_httprequest *req) /* get the custom server control "commands" */ error = getpart(&orgcmd, &cmdsize, "reply", "servercmd", stream); - fclose(stream); + curlx_fclose(stream); if(error) { logmsg("getpart() failed with error (%d)", error); req->open = FALSE; /* closes connection */ @@ -734,7 +734,7 @@ static void sws_storerequest(const char *reqbuf, size_t totalsize) return; do { - dump = fopen(dumpfile, "ab"); + dump = curlx_fopen(dumpfile, "ab"); /* !checksrc! disable ERRNOVAR 1 */ } while(!dump && ((error = errno) == EINTR)); if(!dump) { @@ -766,7 +766,7 @@ static void sws_storerequest(const char *reqbuf, size_t totalsize) storerequest_cleanup: - res = fclose(dump); + res = curlx_fclose(dump); if(res) logmsg("Error closing file %s error (%d) %s", dumpfile, errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); @@ -1050,7 +1050,7 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req) } else { error = getpart(&ptr, &count, "reply", partbuf, stream); - fclose(stream); + curlx_fclose(stream); if(error) { logmsg("getpart() failed with error (%d)", error); return 0; @@ -1075,7 +1075,7 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req) else { /* get the custom server control "commands" */ error = getpart(&cmd, &cmdsize, "reply", "postcmd", stream); - fclose(stream); + curlx_fclose(stream); if(error) { logmsg("getpart() failed with error (%d)", error); free(ptr); @@ -1104,7 +1104,7 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req) else sws_prevbounce = FALSE; - dump = fopen(responsedump, "ab"); + dump = curlx_fopen(responsedump, "ab"); if(!dump) { error = errno; logmsg("fopen() failed with error (%d) %s", @@ -1158,7 +1158,7 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req) } } while((count > 0) && !got_exit_signal); - res = fclose(dump); + res = curlx_fclose(dump); if(res) logmsg("Error closing file %s error (%d) %s", responsedump, errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index 6631e2439b96..2eb31ff5ece8 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -445,13 +445,13 @@ static ssize_t write_behind(struct testcase *test, int convert) if(!test->ofile) { char outfile[256]; snprintf(outfile, sizeof(outfile), "%s/upload.%ld", logdir, test->testno); - test->ofile = open(outfile, O_CREAT | O_RDWR | CURL_O_BINARY, + test->ofile = curlx_open(outfile, O_CREAT | O_RDWR | CURL_O_BINARY, #ifdef _WIN32 - S_IREAD | S_IWRITE + S_IREAD | S_IWRITE #else - S_IRUSR | S_IWUSR | S_IXUSR | - S_IRGRP | S_IWGRP | S_IXGRP | - S_IROTH | S_IWOTH | S_IXOTH + S_IRUSR | S_IWUSR | S_IXUSR | + S_IRGRP | S_IWGRP | S_IXGRP | + S_IROTH | S_IWOTH | S_IXOTH #endif ); if(test->ofile == -1) { @@ -910,7 +910,7 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size) snprintf(dumpfile, sizeof(dumpfile), "%s/%s", logdir, REQUEST_DUMP); /* Open request dump file. */ - server = fopen(dumpfile, "ab"); + server = curlx_fopen(dumpfile, "ab"); if(!server) { char errbuf[STRERROR_LEN]; int error = errno; @@ -963,7 +963,7 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size) if(*cp || !mode) { nak(TFTP_EBADOP); - fclose(server); + curlx_fclose(server); return 3; } @@ -975,7 +975,7 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size) *cp = (char)tolower((int)*cp); /* store input protocol */ - fclose(server); + curlx_fclose(server); for(pf = formata; pf->f_mode; pf++) if(strcmp(pf->f_mode, mode) == 0) @@ -1036,7 +1036,7 @@ static int tftpd_parse_servercmd(struct testcase *req) /* get the custom server control "commands" */ error = getpart(&orgcmd, &cmdsize, "reply", "servercmd", stream); - fclose(stream); + curlx_fclose(stream); if(error) { logmsg("getpart() failed with error (%d)", error); return 1; /* done */ @@ -1155,7 +1155,7 @@ static int validate_access(struct testcase *test, else { size_t count; int error = getpart(&test->buffer, &count, "reply", partbuf, stream); - fclose(stream); + curlx_fclose(stream); if(error) { logmsg("getpart() failed with error (%d)", error); return TFTP_EACCESS; diff --git a/tests/server/util.c b/tests/server/util.c index 6551e4742635..8d8bf12c99dd 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -115,12 +115,12 @@ void logmsg(const char *msg, ...) va_end(ap); do { - logfp = fopen(serverlogfile, "ab"); + logfp = curlx_fopen(serverlogfile, "ab"); /* !checksrc! disable ERRNOVAR 1 */ } while(!logfp && (errno == EINTR)); if(logfp) { fprintf(logfp, "%s %s\n", timebuf, buffer); - fclose(logfp); + curlx_fclose(logfp); } else { char errbuf[STRERROR_LEN]; @@ -193,7 +193,7 @@ FILE *test2fopen(long testno, const char *logdir2) char filename[256]; /* first try the alternative, preprocessed, file */ snprintf(filename, sizeof(filename), "%s/test%ld", logdir2, testno); - stream = fopen(filename, "rb"); + stream = curlx_fopen(filename, "rb"); return stream; } @@ -224,7 +224,7 @@ int write_pidfile(const char *filename) curl_off_t pid; pid = our_getpid(); - pidfile = fopen(filename, "wb"); + pidfile = curlx_fopen(filename, "wb"); if(!pidfile) { char errbuf[STRERROR_LEN]; logmsg("Could not write pid file: %s (%d) %s", filename, @@ -232,7 +232,7 @@ int write_pidfile(const char *filename) return 0; /* fail */ } fprintf(pidfile, "%ld\n", (long)pid); - fclose(pidfile); + curlx_fclose(pidfile); logmsg("Wrote pid %ld to %s", (long)pid, filename); return 1; /* success */ } @@ -240,7 +240,7 @@ int write_pidfile(const char *filename) /* store the used port number in a file */ int write_portfile(const char *filename, int port) { - FILE *portfile = fopen(filename, "wb"); + FILE *portfile = curlx_fopen(filename, "wb"); if(!portfile) { char errbuf[STRERROR_LEN]; logmsg("Could not write port file: %s (%d) %s", filename, @@ -248,7 +248,7 @@ int write_portfile(const char *filename, int port) return 0; /* fail */ } fprintf(portfile, "%d\n", port); - fclose(portfile); + curlx_fclose(portfile); logmsg("Wrote port %d to %s", port, filename); return 1; /* success */ } @@ -261,7 +261,7 @@ void set_advisor_read_lock(const char *filename) int res; do { - lockfile = fopen(filename, "wb"); + lockfile = curlx_fopen(filename, "wb"); /* !checksrc! disable ERRNOVAR 1 */ } while(!lockfile && ((error = errno) == EINTR)); if(!lockfile) { @@ -270,7 +270,7 @@ void set_advisor_read_lock(const char *filename) return; } - res = fclose(lockfile); + res = curlx_fclose(lockfile); if(res) logmsg("Error closing lock file %s error (%d) %s", filename, errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); From 1e7d0bafc6d25d98ec72ff419df65fda3cf147a7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 18 Nov 2025 01:32:43 +0100 Subject: [PATCH 045/140] curlx/fopen: replace open CRT functions their with `_s` counterparts (Windows) - `_wopen` -> `_wsopen_s` - `_open`, `open` -> `_sopen_s` - `_wfopen` -> `_wfopen_s` - `fopen` -> `fopen_s` - `_wfreopen` -> `_wfreopen_s` - `freopen` -> `freopen_s` For better error handling and for using the CRT functions recommended via warnings suppressed by `_CRT_SECURE_NO_WARNINGS`. Also: - add missing `freopen_s()` prototype when building with mingw-w64 <5. https://sourceforge.net/p/mingw-w64/mingw-w64/ci/a5d824654cdc57f6eac1bb581b078986f3eb6856/ - tests/server: replace `open()` in the signal handler with `_sopen_s()` on Windows. - tests/server: reduce scope of a checksrc exception to a single line. - checksrc: ban replaced functions. Refs: https://learn.microsoft.com/cpp/c-runtime-library/reference/open-wopen https://learn.microsoft.com/cpp/c-runtime-library/reference/sopen-s-wsopen-s https://learn.microsoft.com/cpp/c-runtime-library/reference/freopen-wfreopen https://learn.microsoft.com/cpp/c-runtime-library/reference/fopen-wfopen https://learn.microsoft.com/cpp/c-runtime-library/reference/fopen-s-wfopen-s https://learn.microsoft.com/cpp/c-runtime-library/reference/freopen-s-wfreopen-s Closes #19643 --- lib/curl_setup.h | 5 ++--- lib/curlx/fopen.c | 21 +++++++++++++-------- scripts/checksrc.pl | 4 ++++ tests/server/.checksrc | 1 - tests/server/util.c | 16 ++++++++++++---- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 886a8814936a..0e5ebb60c9ef 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -95,10 +95,9 @@ unlink(), etc. */ #endif #ifndef _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_WARNINGS /* for _open(), _wfopen(), _wopen(), fopen(), - freopen(), getenv(), gmtime(), sprintf(), +#define _CRT_SECURE_NO_WARNINGS /* for getenv(), gmtime(), sprintf(), strcpy(), - in tests: localtime(), open(), sscanf() */ + in tests: localtime(), sscanf() */ #endif #endif /* _MSC_VER */ diff --git a/lib/curlx/fopen.c b/lib/curlx/fopen.c index dc1c2bb4e67d..0dc9699206cd 100644 --- a/lib/curlx/fopen.c +++ b/lib/curlx/fopen.c @@ -51,6 +51,8 @@ int curlx_fseek(void *stream, curl_off_t offset, int whence) #include "multibyte.h" +#include /* for _SH_DENYNO */ + /* declare GetFullPathNameW for mingw-w64 UWP builds targeting old windows */ #if defined(CURL_WINDOWS_UWP) && defined(__MINGW32__) && \ (_WIN32_WINNT < _WIN32_WINNT_WIN10) @@ -244,7 +246,7 @@ int curlx_win32_open(const char *filename, int oflag, ...) target = fixed; else target = filename_w; - result = _wopen(target, oflag, pmode); + errno = _wsopen_s(&result, target, oflag, _SH_DENYNO, pmode); curlx_unicodefree(filename_w); } else @@ -255,7 +257,7 @@ int curlx_win32_open(const char *filename, int oflag, ...) target = fixed; else target = filename; - result = _open(target, oflag, pmode); + errno = _sopen_s(&result, target, oflag, _SH_DENYNO, pmode); #endif (free)(fixed); @@ -276,7 +278,7 @@ FILE *curlx_win32_fopen(const char *filename, const char *mode) target = fixed; else target = filename_w; - result = _wfopen(target, mode_w); + errno = _wfopen_s(&result, target, mode_w); } else /* !checksrc! disable ERRNOVAR 1 */ @@ -288,14 +290,18 @@ FILE *curlx_win32_fopen(const char *filename, const char *mode) target = fixed; else target = filename; - /* !checksrc! disable BANNEDFUNC 1 */ - result = fopen(target, mode); + errno = fopen_s(&result, target, mode); #endif (free)(fixed); return result; } +#if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR < 5) +_CRTIMP errno_t __cdecl freopen_s(FILE **file, const char *filename, + const char *mode, FILE *stream); +#endif + FILE *curlx_win32_freopen(const char *filename, const char *mode, FILE *fp) { FILE *result = NULL; @@ -310,7 +316,7 @@ FILE *curlx_win32_freopen(const char *filename, const char *mode, FILE *fp) target = fixed; else target = filename_w; - result = _wfreopen(target, mode_w, fp); + errno = _wfreopen_s(&result, target, mode_w, fp); } else /* !checksrc! disable ERRNOVAR 1 */ @@ -322,8 +328,7 @@ FILE *curlx_win32_freopen(const char *filename, const char *mode, FILE *fp) target = fixed; else target = filename; - /* !checksrc! disable BANNEDFUNC 1 */ - result = freopen(target, mode, fp); + errno = freopen_s(&result, target, mode, fp); #endif (free)(fixed); diff --git a/scripts/checksrc.pl b/scripts/checksrc.pl index a2f458b6c1ac..d38ffecdb9b1 100755 --- a/scripts/checksrc.pl +++ b/scripts/checksrc.pl @@ -113,6 +113,10 @@ "fopen" => 1, "freopen" => 1, "open" => 1, + "_open" => 1, + "_wfopen" => 1, + "_wfreopen" => 1, + "_wopen" => 1, "stat" => 1, ); diff --git a/tests/server/.checksrc b/tests/server/.checksrc index 0386c677e6c3..163a217ee4be 100644 --- a/tests/server/.checksrc +++ b/tests/server/.checksrc @@ -6,7 +6,6 @@ allowfunc accept allowfunc fprintf allowfunc freeaddrinfo allowfunc getaddrinfo -allowfunc open allowfunc printf allowfunc recv allowfunc send diff --git a/tests/server/util.c b/tests/server/util.c index 8d8bf12c99dd..ae21ff8b1af8 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -27,6 +27,10 @@ #include #endif +#ifdef _WIN32 +#include +#endif + /* This function returns a pointer to STATIC memory. It converts the given * binary lump to a hex formatted string usable for output in logs or * whatever. @@ -359,13 +363,17 @@ static void exit_signal_handler(int signum) (void)!write(STDERR_FILENO, msg, sizeof(msg) - 1); } else { + int fd = -1; #ifdef _WIN32 -#define OPENMODE S_IREAD | S_IWRITE + if(!_sopen_s(&fd, serverlogfile, O_WRONLY | O_CREAT | O_APPEND, + _SH_DENYNO, S_IREAD | S_IWRITE) && + fd != -1) { #else -#define OPENMODE S_IRUSR | S_IWUSR -#endif - int fd = open(serverlogfile, O_WRONLY | O_CREAT | O_APPEND, OPENMODE); + /* !checksrc! disable BANNEDFUNC 1 */ + fd = open(serverlogfile, + O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR); if(fd != -1) { +#endif static const char msg[] = "exit_signal_handler: called\n"; (void)!write(fd, msg, sizeof(msg) - 1); close(fd); From a075d1c0d8684c0151cebf50b5cb64be6505c59d Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 25 Nov 2025 08:29:32 +0100 Subject: [PATCH 046/140] examples: fix minor typo Closes #19683 --- docs/examples/https.c | 2 +- docs/examples/imap-ssl.c | 2 +- docs/examples/pop3-ssl.c | 2 +- docs/examples/smtp-ssl.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/examples/https.c b/docs/examples/https.c index 905cdb07f23b..02fd8b87bd16 100644 --- a/docs/examples/https.c +++ b/docs/examples/https.c @@ -57,7 +57,7 @@ int main(void) #ifdef SKIP_HOSTNAME_VERIFICATION /* - * If the site you are connecting to uses a different hostname that what + * If the site you are connecting to uses a different hostname than what * they have mentioned in their server certificate's commonName (or * subjectAltName) fields, libcurl refuses to connect. You can skip this * check, but it makes the connection insecure. diff --git a/docs/examples/imap-ssl.c b/docs/examples/imap-ssl.c index d56d89331ac4..259eddc26f6a 100644 --- a/docs/examples/imap-ssl.c +++ b/docs/examples/imap-ssl.c @@ -67,7 +67,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); #endif - /* If the site you are connecting to uses a different hostname that what + /* If the site you are connecting to uses a different hostname than what * they have mentioned in their server certificate's commonName (or * subjectAltName) fields, libcurl refuses to connect. You can skip this * check, but it makes the connection insecure. */ diff --git a/docs/examples/pop3-ssl.c b/docs/examples/pop3-ssl.c index 0f5ac3692d83..4dd808c3f114 100644 --- a/docs/examples/pop3-ssl.c +++ b/docs/examples/pop3-ssl.c @@ -66,7 +66,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); #endif - /* If the site you are connecting to uses a different hostname that what + /* If the site you are connecting to uses a different hostname than what * they have mentioned in their server certificate's commonName (or * subjectAltName) fields, libcurl refuses to connect. You can skip this * check, but it makes the connection insecure. */ diff --git a/docs/examples/smtp-ssl.c b/docs/examples/smtp-ssl.c index a87a033fc4aa..4ebc58f1b5dd 100644 --- a/docs/examples/smtp-ssl.c +++ b/docs/examples/smtp-ssl.c @@ -115,7 +115,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); #endif - /* If the site you are connecting to uses a different hostname that what + /* If the site you are connecting to uses a different hostname than what * they have mentioned in their server certificate's commonName (or * subjectAltName) fields, libcurl refuses to connect. You can skip this * check, but it makes the connection insecure. */ From ce06fe7771052549ff430c86173b2eaca91f8a9c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 24 Nov 2025 14:00:09 +0100 Subject: [PATCH 047/140] hostip: make more functions return CURLcode - Curl_async_getaddrinfo() always returned NULL so it was pointless. Return proper curlcode instead to distinguish between errors. Same for Curl_doh(). - simplify the IP address handling - make Curl_str2addr() function return CURLcode Closes #19669 --- lib/asyn-ares.c | 22 +++---- lib/asyn-thrdd.c | 17 ++---- lib/asyn.h | 7 +-- lib/curl_addrinfo.c | 41 +++++++++---- lib/curl_addrinfo.h | 6 +- lib/doh.c | 22 ++++--- lib/doh.h | 11 ++-- lib/hostip.c | 132 +++++++++++++++++------------------------ tests/libtest/lib655.c | 4 +- 9 files changed, 117 insertions(+), 145 deletions(-) diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index ab57d5e00b41..d459fd4a75cd 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -718,25 +718,18 @@ static void async_ares_rr_done(void *user_data, ares_status_t status, /* * Curl_async_getaddrinfo() - when using ares * - * Returns name information about the given hostname and port number. If - * successful, the 'hostent' is returned and the fourth argument will point to - * memory we need to free after use. That memory *MUST* be freed with - * Curl_freeaddrinfo(), nothing else. + * Starts a name resolve for the given hostname and port number. */ -struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, - const char *hostname, - int port, - int ip_version, - int *waitp) +CURLcode Curl_async_getaddrinfo(struct Curl_easy *data, const char *hostname, + int port, int ip_version) { struct async_ares_ctx *ares = &data->state.async.ares; #ifdef USE_HTTPSRR char *rrname = NULL; #endif - *waitp = 0; /* default to synchronous response */ if(async_ares_init_lazy(data)) - return NULL; + return CURLE_FAILED_INIT; data->state.async.done = FALSE; /* not done */ data->state.async.dns = NULL; /* clear */ @@ -744,12 +737,12 @@ struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, data->state.async.ip_version = ip_version; data->state.async.hostname = strdup(hostname); if(!data->state.async.hostname) - return NULL; + return CURLE_OUT_OF_MEMORY; #ifdef USE_HTTPSRR if(port != 443) { rrname = curl_maprintf("_%d_.https.%s", port, hostname); if(!rrname) - return NULL; + return CURLE_OUT_OF_MEMORY; } #endif @@ -836,9 +829,8 @@ struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, async_ares_rr_done, data, NULL); } #endif - *waitp = 1; /* expect asynchronous response */ - return NULL; /* no struct yet */ + return CURLE_OK; } /* Set what DNS server are is to use. This is called in 2 situations: diff --git a/lib/asyn-thrdd.c b/lib/asyn-thrdd.c index f4f57b547a01..71e31e6d0d16 100644 --- a/lib/asyn-thrdd.c +++ b/lib/asyn-thrdd.c @@ -755,15 +755,11 @@ struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, /* * Curl_async_getaddrinfo() - for getaddrinfo */ -struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, - const char *hostname, - int port, - int ip_version, - int *waitp) +CURLcode Curl_async_getaddrinfo(struct Curl_easy *data, const char *hostname, + int port, int ip_version) { struct addrinfo hints; int pf = PF_INET; - *waitp = 0; /* default to synchronous response */ CURL_TRC_DNS(data, "init threaded resolve of %s:%d", hostname, port); #ifdef CURLRES_IPV6 @@ -785,14 +781,11 @@ struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, SOCK_STREAM : SOCK_DGRAM; /* fire up a new resolver thread! */ - if(async_thrdd_init(data, hostname, port, ip_version, &hints)) { - *waitp = 1; /* expect asynchronous response */ - return NULL; - } + if(async_thrdd_init(data, hostname, port, ip_version, &hints)) + return CURLE_OK; failf(data, "getaddrinfo() thread failed to start"); - return NULL; - + return CURLE_FAILED_INIT; } #endif /* !HAVE_GETADDRINFO */ diff --git a/lib/asyn.h b/lib/asyn.h index 7863042bbe37..8da7dd9720cc 100644 --- a/lib/asyn.h +++ b/lib/asyn.h @@ -118,11 +118,8 @@ CURLcode Curl_async_await(struct Curl_easy *data, * Each resolver backend must of course make sure to return data in the * correct format to comply with this. */ -struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, - const char *hostname, - int port, - int ip_version, - int *waitp); +CURLcode Curl_async_getaddrinfo(struct Curl_easy *data, const char *hostname, + int port, int ip_version); #ifdef USE_ARES /* common functions for c-ares and threaded resolver with HTTPSRR */ diff --git a/lib/curl_addrinfo.c b/lib/curl_addrinfo.c index fc26bef8333d..cd9b52febaa7 100644 --- a/lib/curl_addrinfo.c +++ b/lib/curl_addrinfo.c @@ -347,7 +347,7 @@ Curl_he2ai(const struct hostent *he, int port) #endif /* - * Curl_ip2addr() + * ip2addr() * * This function takes an Internet address, in binary form, as input parameter * along with its address family and the string version of the address, and it @@ -355,8 +355,9 @@ Curl_he2ai(const struct hostent *he, int port) * given address/host */ -struct Curl_addrinfo * -Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port) +static CURLcode +ip2addr(struct Curl_addrinfo **addrp, + int af, const void *inaddr, const char *hostname, int port) { struct Curl_addrinfo *ai; size_t addrsize; @@ -369,6 +370,7 @@ Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port) DEBUGASSERT(inaddr && hostname); namelen = strlen(hostname) + 1; + *addrp = NULL; if(af == AF_INET) addrsize = sizeof(struct sockaddr_in); @@ -377,12 +379,12 @@ Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port) addrsize = sizeof(struct sockaddr_in6); #endif else - return NULL; + return CURLE_BAD_FUNCTION_ARGUMENT; /* allocate memory to hold the struct, the address and the name */ ai = calloc(1, sizeof(struct Curl_addrinfo) + addrsize + namelen); if(!ai) - return NULL; + return CURLE_OUT_OF_MEMORY; /* put the address after the struct */ ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo)); /* then put the name after the address */ @@ -412,29 +414,46 @@ Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port) break; #endif } - - return ai; + *addrp = ai; + return CURLE_OK; } /* * Given an IPv4 or IPv6 dotted string address, this converts it to a proper * allocated Curl_addrinfo struct and returns it. */ -struct Curl_addrinfo *Curl_str2addr(char *address, int port) +CURLcode Curl_str2addr(const char *address, int port, + struct Curl_addrinfo **addrp) { struct in_addr in; if(curlx_inet_pton(AF_INET, address, &in) > 0) /* This is a dotted IP address 123.123.123.123-style */ - return Curl_ip2addr(AF_INET, &in, address, port); + return ip2addr(addrp, AF_INET, &in, address, port); +#ifdef USE_IPV6 + { + struct in6_addr in6; + if(curlx_inet_pton(AF_INET6, address, &in6) > 0) + /* This is a dotted IPv6 address ::1-style */ + return ip2addr(addrp, AF_INET6, &in6, address, port); + } +#endif + return CURLE_BAD_FUNCTION_ARGUMENT; /* bad input format */ +} + +bool Curl_is_ipaddr(const char *address) +{ + struct in_addr in; + if(curlx_inet_pton(AF_INET, address, &in) > 0) + return TRUE; #ifdef USE_IPV6 { struct in6_addr in6; if(curlx_inet_pton(AF_INET6, address, &in6) > 0) /* This is a dotted IPv6 address ::1-style */ - return Curl_ip2addr(AF_INET6, &in6, address, port); + return TRUE; } #endif - return NULL; /* bad input format */ + return FALSE; } #ifdef USE_UNIX_SOCKETS diff --git a/lib/curl_addrinfo.h b/lib/curl_addrinfo.h index 2303e95e314e..9a26c6784912 100644 --- a/lib/curl_addrinfo.h +++ b/lib/curl_addrinfo.h @@ -76,10 +76,8 @@ struct Curl_addrinfo * Curl_he2ai(const struct hostent *he, int port); #endif -struct Curl_addrinfo * -Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port); - -struct Curl_addrinfo *Curl_str2addr(char *dotted, int port); +bool Curl_is_ipaddr(const char *address); +CURLcode Curl_str2addr(const char *dotted, int port, struct Curl_addrinfo **); #ifdef USE_UNIX_SOCKETS struct Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, diff --git a/lib/doh.c b/lib/doh.c index 45524edf4c0b..83a83f534672 100644 --- a/lib/doh.c +++ b/lib/doh.c @@ -441,15 +441,12 @@ static CURLcode doh_probe_run(struct Curl_easy *data, } /* - * Curl_doh() resolves a name using DoH. It resolves a name and returns a - * 'Curl_addrinfo *' with the address information. + * Curl_doh() starts a name resolve using DoH. It resolves a name and returns + * a 'Curl_addrinfo *' with the address information. */ -struct Curl_addrinfo *Curl_doh(struct Curl_easy *data, - const char *hostname, - int port, - int ip_version, - int *waitp) +CURLcode Curl_doh(struct Curl_easy *data, const char *hostname, + int port, int ip_version) { CURLcode result = CURLE_OK; struct doh_probes *dohp = NULL; @@ -467,12 +464,12 @@ struct Curl_addrinfo *Curl_doh(struct Curl_easy *data, data->state.async.ip_version = ip_version; data->state.async.hostname = strdup(hostname); if(!data->state.async.hostname) - return NULL; + return CURLE_OUT_OF_MEMORY; /* start clean, consider allocating this struct on demand */ data->state.async.doh = dohp = calloc(1, sizeof(struct doh_probes)); if(!dohp) - return NULL; + return CURLE_OUT_OF_MEMORY; for(i = 0; i < DOH_SLOT_COUNT; ++i) { dohp->probe_resp[i].probe_mid = UINT_MAX; @@ -527,12 +524,11 @@ struct Curl_addrinfo *Curl_doh(struct Curl_easy *data, dohp->pending++; } #endif - *waitp = TRUE; /* this never returns synchronously */ - return NULL; + return CURLE_OK; error: Curl_doh_cleanup(data); - return NULL; + return result; } static DOHcode doh_skipqname(const unsigned char *doh, size_t dohlen, @@ -1300,6 +1296,8 @@ CURLcode Curl_doh_is_resolved(struct Curl_easy *data, result = Curl_dnscache_add(data, dns); *dnsp = data->state.async.dns; } + else + Curl_freeaddrinfo(ai); } /* address processing done */ /* All done */ diff --git a/lib/doh.h b/lib/doh.h index 3fd7de2c1c57..726fb9f73557 100644 --- a/lib/doh.h +++ b/lib/doh.h @@ -112,15 +112,12 @@ struct doh_probes { }; /* - * Curl_doh() resolve a name using DoH (DNS-over-HTTPS). It resolves a name - * and returns a 'Curl_addrinfo *' with the address information. + * Curl_doh() starts a name resolve using DoH (DNS-over-HTTPS). It resolves a + * name and returns a 'Curl_addrinfo *' with the address information. */ -struct Curl_addrinfo *Curl_doh(struct Curl_easy *data, - const char *hostname, - int port, - int ip_version, - int *waitp); +CURLcode Curl_doh(struct Curl_easy *data, const char *hostname, + int port, int ip_version); CURLcode Curl_doh_is_resolved(struct Curl_easy *data, struct Curl_dns_entry **dns); diff --git a/lib/hostip.c b/lib/hostip.c index d5f753f4b4a7..4c1bb9236776 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -509,10 +509,8 @@ Curl_dnscache_mk_entry(struct Curl_easy *data, /* shuffle addresses if requested */ if(data->set.dns_shuffle_addresses) { CURLcode result = Curl_shuffle_addr(data, &addr); - if(result) { - Curl_freeaddrinfo(addr); + if(result) return NULL; - } } #else (void)data; @@ -522,10 +520,8 @@ Curl_dnscache_mk_entry(struct Curl_easy *data, /* Create a new cache entry */ dns = calloc(1, sizeof(struct Curl_dns_entry) + hostlen); - if(!dns) { - Curl_freeaddrinfo(addr); + if(!dns) return NULL; - } dns->refcount = 1; /* the cache has the first reference */ dns->addr = addr; /* this is the address(es) */ @@ -569,6 +565,7 @@ dnscache_add_addr(struct Curl_easy *data, dns2 = Curl_hash_add(&dnscache->entries, entry_id, entry_len + 1, (void *)dns); if(!dns2) { + dns->addr = NULL; dnscache_entry_free(dns); return NULL; } @@ -744,40 +741,6 @@ static bool tailmatch(const char *full, size_t flen, return curl_strnequal(part, &full[flen - plen], plen); } -static struct Curl_addrinfo * -convert_ipaddr_direct(const char *hostname, int port, bool *is_ipaddr) -{ - struct in_addr in; - *is_ipaddr = FALSE; - /* First check if this is an IPv4 address string */ - if(curlx_inet_pton(AF_INET, hostname, &in) > 0) { - /* This is a dotted IP address 123.123.123.123-style */ - *is_ipaddr = TRUE; -#ifdef USE_RESOLVE_ON_IPS - (void)port; - return NULL; -#else - return Curl_ip2addr(AF_INET, &in, hostname, port); -#endif - } -#ifdef USE_IPV6 - else { - struct in6_addr in6; - /* check if this is an IPv6 address string */ - if(curlx_inet_pton(AF_INET6, hostname, &in6) > 0) { - /* This is an IPv6 address literal */ - *is_ipaddr = TRUE; -#ifdef USE_RESOLVE_ON_IPS - return NULL; -#else - return Curl_ip2addr(AF_INET6, &in6, hostname, port); -#endif - } - } -#endif /* USE_IPV6 */ - return NULL; -} - static bool can_resolve_ip_version(struct Curl_easy *data, int ip_version) { #ifdef CURLRES_IPV6 @@ -841,10 +804,10 @@ CURLcode Curl_resolv(struct Curl_easy *data, struct Curl_dnscache *dnscache = dnscache_get(data); struct Curl_dns_entry *dns = NULL; struct Curl_addrinfo *addr = NULL; - int respwait = 0; - bool is_ipaddr; + bool respwait = FALSE; size_t hostname_len; bool keep_negative = TRUE; /* cache a negative result */ + CURLcode result = CURLE_COULDNT_RESOLVE_HOST; *entry = NULL; @@ -853,8 +816,11 @@ CURLcode Curl_resolv(struct Curl_easy *data, #else (void)allowDOH; #endif - if(!dnscache) + DEBUGASSERT(dnscache); + if(!dnscache) { + result = CURLE_BAD_FUNCTION_ARGUMENT; goto error; + } /* We should intentionally error and not resolve .onion TLDs */ hostname_len = strlen(hostname); @@ -874,6 +840,7 @@ CURLcode Curl_resolv(struct Curl_easy *data, dnscache_unlock(data, dnscache); if(dns) { infof(data, "Hostname %s was found in DNS cache", hostname); + result = CURLE_OK; goto out; } @@ -882,7 +849,8 @@ CURLcode Curl_resolv(struct Curl_easy *data, void *resolver = NULL; int st; #ifdef CURLRES_ASYNCH - if(Curl_async_get_impl(data, &resolver)) + result = Curl_async_get_impl(data, &resolver); + if(result) goto error; #endif Curl_set_in_callback(data, TRUE); @@ -891,57 +859,58 @@ CURLcode Curl_resolv(struct Curl_easy *data, Curl_set_in_callback(data, FALSE); if(st) { keep_negative = FALSE; + result = CURLE_ABORTED_BY_CALLBACK; goto error; } } - /* shortcut literal IP addresses, if we are not told to resolve them. */ - addr = convert_ipaddr_direct(hostname, port, &is_ipaddr); - if(addr) - goto out; - + if(Curl_is_ipaddr(hostname)) { #ifndef USE_RESOLVE_ON_IPS - /* allowed to convert, hostname is IP address, then NULL means error */ - if(is_ipaddr) { - keep_negative = FALSE; - goto error; - } + /* shortcut literal IP addresses, if we are not told to resolve them. */ + result = Curl_str2addr(hostname, port, &addr); + if(result) + goto error; + goto out; #endif + } - /* Really need a resolver for hostname. */ - if(ip_version == CURL_IPRESOLVE_V6 && !Curl_ipv6works(data)) - goto error; - - if(!is_ipaddr && - (curl_strequal(hostname, "localhost") || - curl_strequal(hostname, "localhost.") || - tailmatch(hostname, hostname_len, STRCONST(".localhost")) || - tailmatch(hostname, hostname_len, STRCONST(".localhost.")))) { + if(curl_strequal(hostname, "localhost") || + curl_strequal(hostname, "localhost.") || + tailmatch(hostname, hostname_len, STRCONST(".localhost")) || + tailmatch(hostname, hostname_len, STRCONST(".localhost."))) { addr = get_localhost(port, hostname); + result = addr ? CURLE_OK : CURLE_OUT_OF_MEMORY; } #ifndef CURL_DISABLE_DOH - else if(!is_ipaddr && allowDOH && data->set.doh) { - addr = Curl_doh(data, hostname, port, ip_version, &respwait); + else if(!Curl_is_ipaddr(hostname) && allowDOH && data->set.doh) { + result = Curl_doh(data, hostname, port, ip_version); + respwait = TRUE; } #endif else { /* Can we provide the requested IP specifics in resolving? */ - if(!can_resolve_ip_version(data, ip_version)) + if(!can_resolve_ip_version(data, ip_version)) { + result = CURLE_COULDNT_RESOLVE_HOST; goto error; + } #ifdef CURLRES_ASYNCH - addr = Curl_async_getaddrinfo(data, hostname, port, ip_version, &respwait); + result = Curl_async_getaddrinfo(data, hostname, port, ip_version); + respwait = TRUE; #else - respwait = 0; /* no async waiting here */ + respwait = FALSE; /* no async waiting here */ addr = Curl_sync_getaddrinfo(data, hostname, port, ip_version); + if(addr) + result = CURLE_OK; #endif } out: - /* We either have found a `dns` or looked up the `addr` - * or `respwait` is set for an async operation. - * Everything else is a failure to resolve. */ - if(dns) { + /* We either have found a `dns` or looked up the `addr` or `respwait` is set + * for an async operation. Everything else is a failure to resolve. */ + if(result) + ; + else if(dns) { if(!dns->addr) { infof(data, "Negative DNS entry"); dns->refcount--; @@ -955,7 +924,12 @@ CURLcode Curl_resolv(struct Curl_easy *data, dns = Curl_dnscache_mk_entry(data, addr, hostname, 0, port, FALSE); if(!dns || Curl_dnscache_add(data, dns)) { /* this is OOM or similar, do not store such negative resolves */ + Curl_freeaddrinfo(addr); + if(dns) + /* avoid a dangling pointer to addr in the dying dns entry */ + dns->addr = NULL; keep_negative = FALSE; + result = CURLE_OUT_OF_MEMORY; goto error; } show_resolve_info(data, dns); @@ -967,6 +941,7 @@ CURLcode Curl_resolv(struct Curl_easy *data, *entry = dns; return dns ? CURLE_OK : CURLE_AGAIN; } + result = CURLE_COULDNT_RESOLVE_HOST; } error: if(dns) @@ -974,7 +949,8 @@ CURLcode Curl_resolv(struct Curl_easy *data, Curl_async_shutdown(data); if(keep_negative) store_negative_resolve(data, hostname, port); - return CURLE_COULDNT_RESOLVE_HOST; + DEBUGASSERT(result); + return result; } CURLcode Curl_resolv_blocking(struct Curl_easy *data, @@ -1338,6 +1314,7 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) while(*host) { struct Curl_str target; struct Curl_addrinfo *ai; + CURLcode result; if(!curlx_str_single(&host, '[')) { if(curlx_str_until(&host, &target, MAX_IPADR_LEN, ']') || @@ -1368,8 +1345,8 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) memcpy(address, curlx_str(&target), curlx_strlen(&target)); address[curlx_strlen(&target)] = '\0'; - ai = Curl_str2addr(address, (int)port); - if(!ai) { + result = Curl_str2addr(address, (int)port, &ai); + if(result) { infof(data, "Resolve address '%s' found illegal", address); goto err; } @@ -1428,11 +1405,12 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) /* put this new host in the cache */ dns = dnscache_add_addr(data, dnscache, head, curlx_str(&source), curlx_strlen(&source), (int)port, permanent); - if(dns) { + if(dns) /* release the returned reference; the cache itself will keep the * entry alive: */ dns->refcount--; - } + else + Curl_freeaddrinfo(head); dnscache_unlock(data, dnscache); diff --git a/tests/libtest/lib655.c b/tests/libtest/lib655.c index 07392cbd86b7..a213a1c493b3 100644 --- a/tests/libtest/lib655.c +++ b/tests/libtest/lib655.c @@ -82,9 +82,9 @@ static CURLcode test_lib655(const char *URL) /* this should fail */ res = curl_easy_perform(curl); - if(res != CURLE_COULDNT_RESOLVE_HOST) { + if(res != CURLE_ABORTED_BY_CALLBACK) { curl_mfprintf(stderr, "curl_easy_perform should have returned " - "CURLE_COULDNT_RESOLVE_HOST but instead returned error %d\n", + "CURLE_ABORTED_BY_CALLBACK but instead returned error %d\n", res); if(res == CURLE_OK) res = TEST_ERR_FAILURE; From 729f36e90fa8927ce85c4f1f7b67724988c35f00 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 25 Nov 2025 08:53:59 +0100 Subject: [PATCH 048/140] sendf: fix uninitialized variable in trace output Initialize *nread early on. Pointed out by CodeSonar Closes #19684 --- lib/sendf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/sendf.c b/lib/sendf.c index f70abb5797bc..4eabc14402da 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -1195,6 +1195,7 @@ CURLcode Curl_client_read(struct Curl_easy *data, char *buf, size_t blen, DEBUGASSERT(blen); DEBUGASSERT(nread); DEBUGASSERT(eos); + *nread = 0; if(!data->req.reader_stack) { result = Curl_creader_set_fread(data, data->state.infilesize); From d0ad652552564cbcf5c2f14869db0add4ff4ac50 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 25 Nov 2025 09:09:50 +0100 Subject: [PATCH 049/140] progress: remove two redundant variable checks The entry condition in the function already exits early if either low_speed_time or low_speed_limit is not set. Pointed out by CodeSonar Closes #19686 --- lib/progress.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/progress.c b/lib/progress.c index 3985e1c1bfbd..59c5b9a00f28 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -109,7 +109,7 @@ UNITTEST CURLcode pgrs_speedcheck(struct Curl_easy *data, /* A paused transfer is not qualified for speed checks */ return CURLE_OK; - if((data->progress.current_speed >= 0) && data->set.low_speed_time) { + if(data->progress.current_speed >= 0) { if(data->progress.current_speed < data->set.low_speed_limit) { if(!data->state.keeps_speed.tv_sec) /* under the limit at this moment */ @@ -134,10 +134,9 @@ UNITTEST CURLcode pgrs_speedcheck(struct Curl_easy *data, data->state.keeps_speed.tv_sec = 0; } - if(data->set.low_speed_limit) - /* if low speed limit is enabled, set the expire timer to make this - connection's speed get checked again in a second */ - Curl_expire(data, 1000, EXPIRE_SPEEDCHECK); + /* since low speed limit is enabled, set the expire timer to make this + connection's speed get checked again in a second */ + Curl_expire(data, 1000, EXPIRE_SPEEDCHECK); return CURLE_OK; } From b8f83738c3ab01c214a314981626c86c9ffaca72 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 25 Nov 2025 10:07:30 +0100 Subject: [PATCH 050/140] asyn-ares: handle Curl_dnscache_mk_entry() OOM error To avoid leaking memory. Follow-up to ce06fe7771052549ff430 Closes #19688 --- lib/asyn-ares.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index d459fd4a75cd..1bc0f3247b78 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -343,7 +343,8 @@ CURLcode Curl_async_is_resolved(struct Curl_easy *data, Curl_dnscache_mk_entry(data, ares->temp_ai, data->state.async.hostname, 0, data->state.async.port, FALSE); - ares->temp_ai = NULL; /* temp_ai now owned by entry */ + if(data->state.async.dns) + ares->temp_ai = NULL; /* temp_ai now owned by entry */ #ifdef HTTPSRR_WORKS if(data->state.async.dns) { struct Curl_https_rrinfo *lhrr = Curl_httpsrr_dup_move(&ares->hinfo); From 6069c340b42a2a4d05f5dc76c49cd3e20e09ccb7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 25 Nov 2025 10:14:28 +0100 Subject: [PATCH 051/140] tool_doswin: clear pointer when thread takes ownership Attempt to address #19675 Closes #19689 --- src/tool_doswin.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/tool_doswin.c b/src/tool_doswin.c index 6204296a8b51..cd0ec3b9c1b1 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -801,10 +801,7 @@ static DWORD WINAPI win_stdin_thread_func(void *thread_data) if(socket_w != CURL_SOCKET_BAD) sclose(socket_w); - if(tdata) { - free(tdata); - } - + free(tdata); return 0; } @@ -884,6 +881,7 @@ curl_socket_t win32_stdin_read_thread(void) errorf("CreateThread error: 0x%08lx", GetLastError()); break; } + tdata = NULL; /* win_stdin_thread_func owns it now */ /* Connect to the thread and rearrange our own STDIN handles */ socket_r = CURL_SOCKET(AF_INET, SOCK_STREAM, IPPROTO_TCP); From ba65073037152555aae279a5ef8eae808e3e675e Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Tue, 25 Nov 2025 09:30:34 +0100 Subject: [PATCH 052/140] speedlimit: also reset on send unpausing The low speedlimit currently counts both up- and download speed accumulated. So, when unpausing upload, also reset the counter. Closes #19687 --- lib/progress.c | 8 ++++++++ lib/progress.h | 3 ++- lib/transfer.c | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/progress.c b/lib/progress.c index 59c5b9a00f28..7124a307d1f5 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -196,6 +196,14 @@ void Curl_pgrsRecvPause(struct Curl_easy *data, bool enable) } } +void Curl_pgrsSendPause(struct Curl_easy *data, bool enable) +{ + if(!enable) { + data->progress.speeder_c = 0; /* reset speed records */ + pgrs_speedinit(data); /* reset low speed measurements */ + } +} + /* * * Curl_pgrsTimeWas(). Store the timestamp time at the given label. diff --git a/lib/progress.h b/lib/progress.h index 96a26fe1a4d9..5535c69cbff5 100644 --- a/lib/progress.h +++ b/lib/progress.h @@ -59,8 +59,9 @@ void Curl_pgrsUpdate_nometer(struct Curl_easy *data); /* perform progress update with callbacks and speed checks */ CURLcode Curl_pgrsCheck(struct Curl_easy *data); -/* Inform progress/speedcheck about receive pausing */ +/* Inform progress/speedcheck about receive/send pausing */ void Curl_pgrsRecvPause(struct Curl_easy *data, bool enable); +void Curl_pgrsSendPause(struct Curl_easy *data, bool enable); /* Reset sizes and couners for up- and download. */ void Curl_pgrsReset(struct Curl_easy *data); diff --git a/lib/transfer.c b/lib/transfer.c index fbacdf429061..04a013361ebd 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -925,6 +925,7 @@ CURLcode Curl_xfer_pause_send(struct Curl_easy *data, bool enable) Curl_rlimit_block(&data->progress.ul.rlimit, enable, curlx_now()); if(!enable && Curl_creader_is_paused(data)) result = Curl_creader_unpause(data); + Curl_pgrsSendPause(data, enable); return result; } From 92e6782d1f0dbf0f011fe01ecc4c17b4109561b2 Mon Sep 17 00:00:00 2001 From: Patrick Monnerat Date: Mon, 24 Nov 2025 19:50:26 +0100 Subject: [PATCH 053/140] doc: some returned in-memory data may not be altered Some public prototypes do not declare return values or out parameters as const where they should be. Avoid changing the public interface, but document those values as read-only. Closes #19692 --- docs/libcurl/curl_easy_escape.md | 3 ++- docs/libcurl/curl_easy_unescape.md | 3 ++- docs/libcurl/curl_escape.md | 3 ++- docs/libcurl/curl_getenv.md | 3 ++- docs/libcurl/curl_mprintf.md | 2 +- docs/libcurl/curl_multi_get_handles.md | 3 ++- docs/libcurl/curl_pushheader_byname.md | 3 ++- docs/libcurl/curl_pushheader_bynum.md | 3 ++- docs/libcurl/curl_slist_append.md | 4 ++-- docs/libcurl/curl_unescape.md | 3 ++- docs/libcurl/curl_url.md | 3 +++ docs/libcurl/curl_url_get.md | 1 + 12 files changed, 23 insertions(+), 11 deletions(-) diff --git a/docs/libcurl/curl_easy_escape.md b/docs/libcurl/curl_easy_escape.md index b10500ac2619..1480a75c591a 100644 --- a/docs/libcurl/curl_easy_escape.md +++ b/docs/libcurl/curl_easy_escape.md @@ -30,7 +30,8 @@ char *curl_easy_escape(CURL *curl, const char *string, int length); This function converts the given input *string* to a URL encoded string and returns that as a new allocated string. All input characters that are not a-z, A-Z, 0-9, '-', '.', '_' or '~' are converted to their "URL escaped" version -(**%NN** where **NN** is a two-digit hexadecimal number). +(**%NN** where **NN** is a two-digit hexadecimal number). Although not +constrained by its type, the returned string may not be altered. If *length* is set to 0 (zero), curl_easy_escape(3) uses strlen() on the input *string* to find out the size. This function does not accept input strings diff --git a/docs/libcurl/curl_easy_unescape.md b/docs/libcurl/curl_easy_unescape.md index 2e78ad5d9f07..49e4c6bf269a 100644 --- a/docs/libcurl/curl_easy_unescape.md +++ b/docs/libcurl/curl_easy_unescape.md @@ -30,7 +30,8 @@ char *curl_easy_unescape(CURL *curl, const char *input, This function converts the URL encoded string **input** to a "plain string" and returns that in an allocated memory area. All input characters that are URL encoded (%XX where XX is a two-digit hexadecimal number) are converted to their -binary versions. +binary versions. Although not constrained by its type, the returned data may +not be altered. If the **length** argument is set to 0 (zero), curl_easy_unescape(3) uses strlen() on **input** to find out the size. diff --git a/docs/libcurl/curl_escape.md b/docs/libcurl/curl_escape.md index c24d1890d493..967d375a9758 100644 --- a/docs/libcurl/curl_escape.md +++ b/docs/libcurl/curl_escape.md @@ -31,7 +31,8 @@ Obsolete function. Use curl_easy_escape(3) instead. This function converts the given input **string** to a URL encoded string and return that as a new allocated string. All input characters that are not a-z, A-Z or 0-9 are converted to their "URL escaped" version (**%NN** where -**NN** is a two-digit hexadecimal number). +**NN** is a two-digit hexadecimal number). Although not constrained by its +type, the returned string may not be altered. If the **length** argument is set to 0, curl_escape(3) uses strlen() on **string** to find out the size. diff --git a/docs/libcurl/curl_getenv.md b/docs/libcurl/curl_getenv.md index 2cfb58148ce7..047c913f2530 100644 --- a/docs/libcurl/curl_getenv.md +++ b/docs/libcurl/curl_getenv.md @@ -29,7 +29,8 @@ curl_getenv() is a portable wrapper for the getenv() function, meant to emulate its behavior and provide an identical interface for all operating systems libcurl builds on (including Windows). -You must curl_free(3) the returned string when you are done with it. +You must curl_free(3) the returned string when you are done with it and, +although not constrained by its type, it may not be altered. # %PROTOCOLS% diff --git a/docs/libcurl/curl_mprintf.md b/docs/libcurl/curl_mprintf.md index 4f5c090579ba..a592cfb3e661 100644 --- a/docs/libcurl/curl_mprintf.md +++ b/docs/libcurl/curl_mprintf.md @@ -67,7 +67,7 @@ the value of *ap* is undefined after the call. The functions **curl_maprintf()** and **curl_mvaprintf()** return the output string as pointer to a newly allocated memory area. The returned string -must be curl_free(3)ed by the receiver. +may not be overwritten and must be curl_free(3)ed by the receiver. All of these functions write the output under the control of a format string that specifies how subsequent arguments are converted for output. diff --git a/docs/libcurl/curl_multi_get_handles.md b/docs/libcurl/curl_multi_get_handles.md index f94436a889ba..56da272b8abf 100644 --- a/docs/libcurl/curl_multi_get_handles.md +++ b/docs/libcurl/curl_multi_get_handles.md @@ -41,7 +41,8 @@ are out of sync. The order of the easy handles within the array is not guaranteed. -The returned array must be freed with a call to curl_free(3) after use. +The returned array may not be overwritten and must be freed with a call to +curl_free(3) after use. # %PROTOCOLS% diff --git a/docs/libcurl/curl_pushheader_byname.md b/docs/libcurl/curl_pushheader_byname.md index d066ea7b85b5..e2968fcd4621 100644 --- a/docs/libcurl/curl_pushheader_byname.md +++ b/docs/libcurl/curl_pushheader_byname.md @@ -33,7 +33,8 @@ elsewhere and it has no function then. It returns the value for the given header field name (or NULL) for the incoming server push request. This is a shortcut so that the application does not have to loop through all headers to find the one it is interested in. The -data this function points to is freed when this callback returns. If more than +data this function points to is freed when this callback returns and, +although not constrained by its type, may not be altered. If more than one header field use the same name, this returns only the first one. # %PROTOCOLS% diff --git a/docs/libcurl/curl_pushheader_bynum.md b/docs/libcurl/curl_pushheader_bynum.md index 12555c57f0c1..2431ff446bb1 100644 --- a/docs/libcurl/curl_pushheader_bynum.md +++ b/docs/libcurl/curl_pushheader_bynum.md @@ -33,7 +33,8 @@ elsewhere and it has no function then. It returns the value for the header field at the given index **num**, for the incoming server push request or NULL. The data pointed to is freed by libcurl when this callback returns. The returned pointer points to a -"name:value" string that gets freed when this callback returns. +"name:value" string that gets freed when this callback returns; although +not constrained by its type, this string may not be altered. # %PROTOCOLS% diff --git a/docs/libcurl/curl_slist_append.md b/docs/libcurl/curl_slist_append.md index b2766f728db0..3ebc19e35418 100644 --- a/docs/libcurl/curl_slist_append.md +++ b/docs/libcurl/curl_slist_append.md @@ -33,8 +33,8 @@ new list. The specified **string** has been appended when this function returns. curl_slist_append(3) copies the string. The **string** argument must be a valid string pointer and cannot be NULL. -The list should be freed again (after usage) with -curl_slist_free_all(3). +The list should be freed (after usage) with curl_slist_free_all(3). +Its nodes and pointed content may not be altered outside this function. # %PROTOCOLS% diff --git a/docs/libcurl/curl_unescape.md b/docs/libcurl/curl_unescape.md index 2600f1436110..453fd53145b9 100644 --- a/docs/libcurl/curl_unescape.md +++ b/docs/libcurl/curl_unescape.md @@ -33,7 +33,8 @@ Deprecated. Use curl_easy_unescape(3) instead. This function converts the URL encoded string **input** to a "plain string" and return that as a new allocated string. All input characters that are URL encoded (%XX where XX is a two-digit hexadecimal number) are converted to -their plain text versions. +their plain text versions. Although not constrained by its type, the returned +data may not be altered. If the **length** argument is set to 0, curl_unescape(3) calls strlen() on **input** to find out the size. diff --git a/docs/libcurl/curl_url.md b/docs/libcurl/curl_url.md index 5872134e139a..8053e630b8af 100644 --- a/docs/libcurl/curl_url.md +++ b/docs/libcurl/curl_url.md @@ -38,6 +38,9 @@ single URL. When the object is first created, there is of course no components stored. They are then set in the object with the curl_url_set(3) function. +The object must be destroyed with a call to curl_url_cleanup(3) when no +longer needed. + # %PROTOCOLS% # EXAMPLE diff --git a/docs/libcurl/curl_url_get.md b/docs/libcurl/curl_url_get.md index a9bb0bdc23fb..bed1c02f1747 100644 --- a/docs/libcurl/curl_url_get.md +++ b/docs/libcurl/curl_url_get.md @@ -43,6 +43,7 @@ allocated string with the contents. The *flags* argument is a bitmask with individual features. The returned content pointer must be freed with curl_free(3) after use. +Although not constrained by its type, the pointed string may not be altered. # FLAGS From 74bd3e2f98b26b283dbdb5af543e0c43e61a6155 Mon Sep 17 00:00:00 2001 From: Patrick Monnerat Date: Mon, 24 Nov 2025 14:57:38 +0100 Subject: [PATCH 054/140] slist: constify Curl_slist_append_nodup() string argument Although finally stored as a non-const pointer, the string is intended to be left unchanged. This change allows using the function without the need of a cast for const pointers. Closes #19692 --- lib/slist.c | 5 +++-- lib/slist.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/slist.c b/lib/slist.c index 366b24760959..88fdd8a2bae2 100644 --- a/lib/slist.c +++ b/lib/slist.c @@ -58,7 +58,8 @@ static struct curl_slist *slist_get_last(struct curl_slist *list) * If an error occurs, NULL is returned and the string argument is NOT * released. */ -struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list, char *data) +struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list, + const char *data) { struct curl_slist *last; struct curl_slist *new_item; @@ -70,7 +71,7 @@ struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list, char *data) return NULL; new_item->next = NULL; - new_item->data = data; + new_item->data = CURL_UNCONST(data); /* if this is the first item, then new_item *is* the list */ if(!list) diff --git a/lib/slist.h b/lib/slist.h index 9561fd022686..47a30824db01 100644 --- a/lib/slist.h +++ b/lib/slist.h @@ -36,6 +36,6 @@ struct curl_slist *Curl_slist_duplicate(struct curl_slist *inlist); * it to the list. */ struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list, - char *data); + const char *data); #endif /* HEADER_CURL_SLIST_H */ From 62683ad3f49aeb60ab311cf52aacc5630116418a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 25 Nov 2025 03:35:40 +0100 Subject: [PATCH 055/140] curlx: replace `sprintf` with `snprintf` To avoid using a deprecated function on Windows. Also: de-dupe `SNPRINTF` definition in curlx. Closes #19681 --- lib/Makefile.inc | 1 + lib/curl_setup.h | 3 +-- lib/curlx/inet_ntop.c | 14 +++++++------- lib/curlx/snprintf.h | 36 ++++++++++++++++++++++++++++++++++++ lib/curlx/strerr.c | 15 +-------------- lib/curlx/winapi.c | 15 +-------------- src/Makefile.inc | 1 + 7 files changed, 48 insertions(+), 37 deletions(-) create mode 100644 lib/curlx/snprintf.h diff --git a/lib/Makefile.inc b/lib/Makefile.inc index cad02c823786..85faa875e072 100644 --- a/lib/Makefile.inc +++ b/lib/Makefile.inc @@ -50,6 +50,7 @@ LIB_CURLX_HFILES = \ curlx/inet_pton.h \ curlx/multibyte.h \ curlx/nonblock.h \ + curlx/snprintf.h \ curlx/strerr.h \ curlx/strparse.h \ curlx/timediff.h \ diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 0e5ebb60c9ef..664aa1432532 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -95,8 +95,7 @@ unlink(), etc. */ #endif #ifndef _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_WARNINGS /* for getenv(), gmtime(), sprintf(), - strcpy(), +#define _CRT_SECURE_NO_WARNINGS /* for getenv(), gmtime(), strcpy(), in tests: localtime(), sscanf() */ #endif #endif /* _MSC_VER */ diff --git a/lib/curlx/inet_ntop.c b/lib/curlx/inet_ntop.c index d4053f1a60f2..771af81474e7 100644 --- a/lib/curlx/inet_ntop.c +++ b/lib/curlx/inet_ntop.c @@ -32,6 +32,7 @@ #endif #include "inet_ntop.h" +#include "snprintf.h" #define IN6ADDRSZ 16 /* #define INADDRSZ 4 */ @@ -61,13 +62,12 @@ static char *inet_ntop4(const unsigned char *src, char *dst, size_t size) DEBUGASSERT(size >= 16); - /* this sprintf() does not overflow the buffer. Avoids snprintf to work more - widely. Avoids the msnprintf family to work as a curlx function. */ - (void)(sprintf)(tmp, "%d.%d.%d.%d", - ((int)((unsigned char)src[0])) & 0xff, - ((int)((unsigned char)src[1])) & 0xff, - ((int)((unsigned char)src[2])) & 0xff, - ((int)((unsigned char)src[3])) & 0xff); + /* this snprintf() does not overflow the buffer. */ + SNPRINTF(tmp, sizeof(tmp), "%d.%d.%d.%d", + ((int)((unsigned char)src[0])) & 0xff, + ((int)((unsigned char)src[1])) & 0xff, + ((int)((unsigned char)src[2])) & 0xff, + ((int)((unsigned char)src[3])) & 0xff); len = strlen(tmp); if(len == 0 || len >= size) { diff --git a/lib/curlx/snprintf.h b/lib/curlx/snprintf.h new file mode 100644 index 000000000000..266ea137fae6 --- /dev/null +++ b/lib/curlx/snprintf.h @@ -0,0 +1,36 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ + +/* Raw snprintf() for curlx */ + +#ifdef WITHOUT_LIBCURL /* when built for the test servers */ +#if defined(_MSC_VER) && (_MSC_VER < 1900) /* adjust for old MSVC */ +#define SNPRINTF _snprintf +#else +#define SNPRINTF snprintf +#endif +#else /* !WITHOUT_LIBCURL */ +#include +#define SNPRINTF curl_msnprintf +#endif /* WITHOUT_LIBCURL */ diff --git a/lib/curlx/strerr.c b/lib/curlx/strerr.c index 376f68b0b20d..c33d10701125 100644 --- a/lib/curlx/strerr.c +++ b/lib/curlx/strerr.c @@ -34,21 +34,8 @@ #include -#ifndef WITHOUT_LIBCURL -#include -#define SNPRINTF curl_msnprintf -#else -/* when built for the test servers */ - -/* adjust for old MSVC */ -#if defined(_MSC_VER) && (_MSC_VER < 1900) -#define SNPRINTF _snprintf -#else -#define SNPRINTF snprintf -#endif -#endif /* !WITHOUT_LIBCURL */ - #include "winapi.h" +#include "snprintf.h" #include "strerr.h" /* The last 2 #include files should be in this order */ #include "../curl_memory.h" diff --git a/lib/curlx/winapi.c b/lib/curlx/winapi.c index 7b3d6b60369c..4cacbcb618ea 100644 --- a/lib/curlx/winapi.c +++ b/lib/curlx/winapi.c @@ -29,20 +29,7 @@ */ #ifdef _WIN32 #include "winapi.h" - -#ifndef WITHOUT_LIBCURL -#include -#define SNPRINTF curl_msnprintf -#else -/* when built for the test servers */ - -/* adjust for old MSVC */ -#if defined(_MSC_VER) && (_MSC_VER < 1900) -#define SNPRINTF _snprintf -#else -#define SNPRINTF snprintf -#endif -#endif /* !WITHOUT_LIBCURL */ +#include "snprintf.h" /* This is a helper function for curlx_strerror that converts Windows API error * codes (GetLastError) to error messages. diff --git a/src/Makefile.inc b/src/Makefile.inc index fa5583755203..6e5e31f806e9 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -54,6 +54,7 @@ CURLX_HFILES = \ ../lib/curlx/fopen.h \ ../lib/curlx/multibyte.h \ ../lib/curlx/nonblock.h \ + ../lib/curlx/snprintf.h \ ../lib/curlx/strerr.h \ ../lib/curlx/strparse.h \ ../lib/curlx/timediff.h \ From 4f807db155815800fde49c3ef8291a3f7c345429 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 25 Nov 2025 10:42:07 +0100 Subject: [PATCH 056/140] INTERNALS.md: add more dependency versions and dates Closes #19691 --- docs/INTERNALS.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/INTERNALS.md b/docs/INTERNALS.md index 75393a5d1c72..222d9ab5ed69 100644 --- a/docs/INTERNALS.md +++ b/docs/INTERNALS.md @@ -36,6 +36,7 @@ versions of libs and build tools. - nghttp2 1.15.0 (2016-09-25) - OpenLDAP 2.0 (2000-08-01) - OpenSSL 3.0.0 (2021-09-07) + - Windows XP 5.1 (2001-08-24 - 2009-04-14) - wolfSSL 3.4.6 (2017-09-22) - zlib 1.2.5.2 (2011-12-11) - zstd 1.0 (2016-08-31) @@ -46,12 +47,14 @@ versions of libs and build tools. we use a few "build tools" and we make sure that we remain functional with these versions: - - GNU libtool 1.4.2 (2001-09-11) - - GNU autoconf 2.59 (2003-11-06) - - GNU automake 1.7 (2002-09-25) - - GNU m4 1.4 (2007-09-21) - - perl 5.8 (2002-07-19), on Windows: 5.22 (2015-06-01) - - cmake 3.7 (2016-11-11) + - cmake 3.7 (2016-11-11) + - GNU autoconf 2.59 (2003-11-06) + - GNU automake 1.7 (2002-09-25) + - GNU libtool 1.4.2 (2001-09-11) + - GNU m4 1.4 (2007-09-21) + - mingw-w64 3.0 (2013-09-20) + - perl 5.8 (2002-07-19), on Windows: 5.22 (2015-06-01) + - Visual Studio 2010 10.0 (2010-04-12 - 2020-07-14) Library Symbols =============== From 2b0ca15c49e2f437741603d6de29aaa7a7928d18 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Tue, 25 Nov 2025 11:39:04 +0100 Subject: [PATCH 057/140] ratelimit: remove a debug mprintf Follow-up to 24b36fdd1585ea22e5e Closes #19694 --- lib/ratelimit.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/ratelimit.c b/lib/ratelimit.c index 8b34d77e1313..c3593d593756 100644 --- a/lib/ratelimit.c +++ b/lib/ratelimit.c @@ -90,8 +90,6 @@ static void ratelimit_update(struct Curl_rlimit *r, elapsed_us = curlx_timediff_us(ts, r->ts); if(elapsed_us < 0) { /* not going back in time */ - curl_mfprintf(stderr, "rlimit: neg elapsed time %" FMT_TIMEDIFF_T "us\n", - elapsed_us); DEBUGASSERT(0); return; } From fc09a2da4ad0595292ecabda6f50f5d415b70527 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Sun, 23 Nov 2025 21:29:46 +0200 Subject: [PATCH 058/140] tool: log when loading .curlrc in verbose mode Inspired by @vszakats in https://github.com/curl/curl/pull/19631#issuecomment-3560803674 Closes #19663 --- src/tool_getparam.c | 2 +- src/tool_operate.c | 10 +++++++++- src/tool_parsecfg.c | 8 +++++++- src/tool_parsecfg.h | 3 ++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 0bb1329b5495..76113e45bd0d 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -2225,7 +2225,7 @@ static ParameterError opt_file(struct OperationConfig *config, err = PARAM_BAD_USE; } else { - err = parseconfig(nextarg, max_recursive); + err = parseconfig(nextarg, max_recursive, NULL); } break; case C_CRLFILE: /* --crlfile */ diff --git a/src/tool_operate.c b/src/tool_operate.c index 69cfef96d786..eb591935db4f 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -2227,6 +2227,8 @@ CURLcode operate(int argc, argv_item_t argv[]) { CURLcode result = CURLE_OK; const char *first_arg; + char *curlrc_path = NULL; + bool found_curlrc = FALSE; first_arg = argc > 1 ? convert_tchar_to_UTF8(argv[1]) : NULL; @@ -2240,7 +2242,8 @@ CURLcode operate(int argc, argv_item_t argv[]) if((argc == 1) || (first_arg && strncmp(first_arg, "-q", 2) && strcmp(first_arg, "--disable"))) { - parseconfig(NULL, CONFIG_MAX_LEVELS); /* ignore possible failure */ + if(!parseconfig(NULL, CONFIG_MAX_LEVELS, &curlrc_path)) + found_curlrc = TRUE; /* If we had no arguments then make sure a URL was specified in .curlrc */ if((argc < 2) && (!global->first->url_list)) { @@ -2254,6 +2257,11 @@ CURLcode operate(int argc, argv_item_t argv[]) if(!result) { /* Parse the command line arguments */ ParameterError res = parse_args(argc, argv); + if(found_curlrc) { + /* After parse_args so notef knows the verbosity */ + notef("Read config file from '%s'", curlrc_path); + free(curlrc_path); + } if(res) { result = CURLE_OK; diff --git a/src/tool_parsecfg.c b/src/tool_parsecfg.c index 53b63746b5ac..e7a00cf70883 100644 --- a/src/tool_parsecfg.c +++ b/src/tool_parsecfg.c @@ -81,7 +81,8 @@ static int unslashquote(const char *line, struct dynbuf *param) #define MAX_CONFIG_LINE_LENGTH (10*1024*1024) /* return 0 on everything-is-fine, and non-zero otherwise */ -ParameterError parseconfig(const char *filename, int max_recursive) +ParameterError parseconfig(const char *filename, int max_recursive, + char **resolved) { FILE *file = NULL; bool usedarg = FALSE; @@ -264,6 +265,11 @@ ParameterError parseconfig(const char *filename, int max_recursive) if((err == PARAM_READ_ERROR) && filename) errorf("cannot read config from '%s'", filename); + if(!err && resolved) { + *resolved = strdup(filename); + if(!*resolved) + err = PARAM_NO_MEM; + } free(pathalloc); return err; } diff --git a/src/tool_parsecfg.h b/src/tool_parsecfg.h index 3aad9bdd9cbd..860b9df38eda 100644 --- a/src/tool_parsecfg.h +++ b/src/tool_parsecfg.h @@ -27,7 +27,8 @@ /* only allow this many levels of recursive --config use */ #define CONFIG_MAX_LEVELS 5 -ParameterError parseconfig(const char *filename, int max_recursive); +ParameterError parseconfig(const char *filename, int max_recursive, + char **resolved); bool my_get_line(FILE *fp, struct dynbuf *db, bool *error); #endif /* HEADER_CURL_TOOL_PARSECFG_H */ From 208a6aebf223200293a5f0c1bdc3cced36d5af1f Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Tue, 25 Nov 2025 10:00:23 +0100 Subject: [PATCH 059/140] lib: timer stats improvements * move the TIMER_POSTQUEUE to the time a connection is chosen, so that TIMER_NAMELOOKUP always happens afterwards * client writer: do not trigger TIMER_STARTTRANSFER on CLIENTWRITE_INFO as ftp and other pingpong protocols write that before starting anything that is the tranfer itself * Elimnating debug trancing of "closed stream/connection - bailing" as confusing, as connection is not really closed on most cases. * Setting 'data->req.upload_done` correctly, so that no "abort upload" is happening at the end of a perfectly fine download. * Adding test cases with up-/download of 0-length files. * pytest: add a "timeline" of timer value checks to Resulst in curl.py, so that this can be used in several test cases, replacing the local stuff in test_16 * add timeline checks to ftp test cases Closes #19269 --- lib/cfilters.c | 13 +++--- lib/multi.c | 2 +- lib/request.c | 10 ++++- lib/sendf.c | 3 +- lib/transfer.c | 13 +----- lib/url.c | 1 + lib/vquic/curl_osslq.c | 8 ++++ tests/http/test_02_download.py | 6 ++- tests/http/test_16_info.py | 56 ++--------------------- tests/http/test_30_vsftpd.py | 21 ++++++--- tests/http/test_31_vsftpds.py | 5 +++ tests/http/test_32_ftps_vsftpd.py | 6 +++ tests/http/testenv/curl.py | 74 +++++++++++++++++++++++++++++++ tests/libtest/lib500.c | 5 ++- 14 files changed, 141 insertions(+), 82 deletions(-) diff --git a/lib/cfilters.c b/lib/cfilters.c index 507512f8aa46..f0da4778a685 100644 --- a/lib/cfilters.c +++ b/lib/cfilters.c @@ -63,8 +63,8 @@ CURLcode Curl_cf_def_shutdown(struct Curl_cfilter *cf, return CURLE_OK; } -static void conn_report_connect_stats(struct Curl_easy *data, - struct connectdata *conn); +static void conn_report_connect_stats(struct Curl_cfilter *cf, + struct Curl_easy *data); CURLcode Curl_cf_def_adjust_pollset(struct Curl_cfilter *cf, struct Curl_easy *data, @@ -508,7 +508,7 @@ CURLcode Curl_conn_connect(struct Curl_easy *data, * persist information at the connection. E.g. cf-socket sets the * socket and ip related information. */ cf_cntrl_update_info(data, data->conn); - conn_report_connect_stats(data, data->conn); + conn_report_connect_stats(cf, data); data->conn->keepalive = curlx_now(); #ifndef CURL_DISABLE_VERBOSE_STRINGS result = cf_verboseconnect(data, cf); @@ -518,7 +518,7 @@ CURLcode Curl_conn_connect(struct Curl_easy *data, else if(result) { CURL_TRC_CF(data, cf, "Curl_conn_connect(), filter returned %d", result); - conn_report_connect_stats(data, data->conn); + conn_report_connect_stats(cf, data); goto out; } @@ -1008,10 +1008,9 @@ static void cf_cntrl_update_info(struct Curl_easy *data, /** * Update connection statistics */ -static void conn_report_connect_stats(struct Curl_easy *data, - struct connectdata *conn) +static void conn_report_connect_stats(struct Curl_cfilter *cf, + struct Curl_easy *data) { - struct Curl_cfilter *cf = conn->cfilter[FIRSTSOCKET]; if(cf) { struct curltime connected; struct curltime appconnected; diff --git a/lib/multi.c b/lib/multi.c index 00af3ca2bddf..db04d64c231b 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -2337,7 +2337,7 @@ static CURLMcode state_connect(struct Curl_multi *multi, process_pending_handles(data->multi); if(!result) { - *nowp = Curl_pgrsTime(data, TIMER_POSTQUEUE); + *nowp = curlx_now(); if(async) /* We are now waiting for an asynchronous name lookup */ multistate(data, MSTATE_RESOLVING); diff --git a/lib/request.c b/lib/request.c index 5bfcdfbfb8c7..324c4c48f96d 100644 --- a/lib/request.c +++ b/lib/request.c @@ -393,6 +393,11 @@ CURLcode Curl_req_send(struct Curl_easy *data, struct dynbuf *req, return result; buf += nwritten; blen -= nwritten; + if(!blen) { + result = req_set_upload_done(data); + if(result) + return result; + } } if(blen) { @@ -469,6 +474,9 @@ CURLcode Curl_req_stop_send_recv(struct Curl_easy *data) /* stop receiving and ALL sending as well, including PAUSE and HOLD. * We might still be paused on receive client writes though, so * keep those bits around. */ + CURLcode result = CURLE_OK; + if(data->req.keepon & KEEP_SEND) + result = Curl_req_abort_sending(data); data->req.keepon &= ~(KEEP_RECV|KEEP_SEND); - return Curl_req_abort_sending(data); + return result; } diff --git a/lib/sendf.c b/lib/sendf.c index 4eabc14402da..6731cd874b6b 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -230,7 +230,8 @@ static CURLcode cw_download_write(struct Curl_easy *data, size_t nwrite, excess_len = 0; bool is_connect = !!(type & CLIENTWRITE_CONNECT); - if(!is_connect && !ctx->started_response) { + if(!ctx->started_response && + !(type & (CLIENTWRITE_INFO|CLIENTWRITE_CONNECT))) { Curl_pgrsTime(data, TIMER_STARTTRANSFER); Curl_rlimit_start(&data->progress.dl.rlimit, curlx_now()); ctx->started_response = TRUE; diff --git a/lib/transfer.c b/lib/transfer.c index 04a013361ebd..f2df2cef8cba 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -301,18 +301,7 @@ static CURLcode sendrecv_dl(struct Curl_easy *data, /* We only get a 0-length receive at the end of the response */ is_eos = (blen == 0); - if(!blen && (conn->recv[FIRSTSOCKET] == Curl_cf_recv)) { - /* if we receive 0 or less here and the protocol handler did not - replace the connection's `recv` callback, either the data transfer - is done or the server closed the connection and - we bail out from this! - With a `recv` replacement, we assume the protocol handler knows - what it is doing and a 0-length receive is fine. For example, - SFTP downloads of an empty file would show this. See #19165. */ - if(is_multiplex) - DEBUGF(infof(data, "nread == 0, stream closed, bailing")); - else - DEBUGF(infof(data, "nread <= 0, server closed connection, bailing")); + if(!blen) { result = Curl_req_stop_send_recv(data); if(result) goto out; diff --git a/lib/url.c b/lib/url.c index 1d4c6b1fc419..d953734dce9b 100644 --- a/lib/url.c +++ b/lib/url.c @@ -3834,6 +3834,7 @@ CURLcode Curl_connect(struct Curl_easy *data, if(!result) { DEBUGASSERT(conn); + Curl_pgrsTime(data, TIMER_POSTQUEUE); if(reused) { if(CONN_ATTACHED(conn) > 1) /* multiplexed */ diff --git a/lib/vquic/curl_osslq.c b/lib/vquic/curl_osslq.c index f447e8dddf0f..b890a8d9516d 100644 --- a/lib/vquic/curl_osslq.c +++ b/lib/vquic/curl_osslq.c @@ -1803,6 +1803,14 @@ static CURLcode cf_osslq_connect(struct Curl_cfilter *cf, if(err == 1) { /* connected */ + if(!ctx->got_first_byte) { + /* if not recorded yet, take the timestamp before we called + * SSL_do_handshake() as the time we received the first packet. */ + ctx->got_first_byte = TRUE; + ctx->first_byte_at = now; + } + /* Record the handshake complete with a new time stamp. */ + now = curlx_now(); ctx->handshake_at = now; ctx->q.last_io = now; CURL_TRC_CF(data, cf, "handshake complete after %" FMT_TIMEDIFF_T "ms", diff --git a/tests/http/test_02_download.py b/tests/http/test_02_download.py index 8cfd68b20463..dcfe9690bcb4 100644 --- a/tests/http/test_02_download.py +++ b/tests/http/test_02_download.py @@ -43,6 +43,7 @@ class TestDownload: @pytest.fixture(autouse=True, scope='class') def _class_scope(self, env, httpd): indir = httpd.docs_dir + env.make_data_file(indir=indir, fname="data-0k", fsize=0) env.make_data_file(indir=indir, fname="data-10k", fsize=10*1024) env.make_data_file(indir=indir, fname="data-100k", fsize=100*1024) env.make_data_file(indir=indir, fname="data-1m", fsize=1024*1024) @@ -52,9 +53,10 @@ def _class_scope(self, env, httpd): # download 1 file @pytest.mark.parametrize("proto", Env.http_protos()) - def test_02_01_download_1(self, env: Env, httpd, nghttpx, proto): + @pytest.mark.parametrize("docname", ['data.json', 'data-0k', 'data-10k', 'data-100k']) + def test_02_01_download_1(self, env: Env, httpd, nghttpx, proto, docname): curl = CurlClient(env=env) - url = f'https://{env.authority_for(env.domain1, proto)}/data.json' + url = f'https://{env.authority_for(env.domain1, proto)}/{docname}' r = curl.http_download(urls=[url], alpn_proto=proto) r.check_response(http_status=200) diff --git a/tests/http/test_16_info.py b/tests/http/test_16_info.py index 4e0d1ed5b1a9..80984a284ee1 100644 --- a/tests/http/test_16_info.py +++ b/tests/http/test_16_info.py @@ -56,6 +56,7 @@ def test_16_01_info_download(self, env: Env, httpd, nghttpx, proto): remote_ip='127.0.0.1') for idx, s in enumerate(r.stats): self.check_stat(idx, s, r, dl_size=30, ul_size=0) + r.check_stats_timeline(idx) # download plain file with a 302 redirect @pytest.mark.parametrize("proto", Env.http_protos()) @@ -71,6 +72,7 @@ def test_16_02_info_302_download(self, env: Env, httpd, nghttpx, proto): remote_ip='127.0.0.1') for idx, s in enumerate(r.stats): self.check_stat(idx, s, r, dl_size=30, ul_size=0) + r.check_stats_timeline(idx) @pytest.mark.parametrize("proto", Env.http_protos()) def test_16_03_info_upload(self, env: Env, httpd, nghttpx, proto): @@ -89,6 +91,7 @@ def test_16_03_info_upload(self, env: Env, httpd, nghttpx, proto): remote_ip='127.0.0.1') for idx, s in enumerate(r.stats): self.check_stat(idx, s, r, dl_size=fsize, ul_size=fsize) + r.check_stats_timeline(idx) # download plain file via http: ('time_appconnect' is 0) @pytest.mark.parametrize("proto", ['http/1.1']) @@ -101,9 +104,9 @@ def test_16_04_info_http_download(self, env: Env, httpd, nghttpx, proto): remote_port=env.http_port, remote_ip='127.0.0.1') for idx, s in enumerate(r.stats): self.check_stat(idx, s, r, dl_size=30, ul_size=0) + r.check_stats_timeline(idx) def check_stat(self, idx, s, r, dl_size=None, ul_size=None): - self.check_stat_times(s, idx) # we always send something self.check_stat_positive(s, idx, 'size_request') # we always receive response headers @@ -118,54 +121,3 @@ def check_stat(self, idx, s, r, dl_size=None, ul_size=None): def check_stat_positive(self, s, idx, key): assert key in s, f'stat #{idx} "{key}" missing: {s}' assert s[key] > 0, f'stat #{idx} "{key}" not positive: {s}' - - def check_stat_positive_or_0(self, s, idx, key): - assert key in s, f'stat #{idx} "{key}" missing: {s}' - assert s[key] >= 0, f'stat #{idx} "{key}" not positive: {s}' - - def check_stat_zero(self, s, key): - assert key in s, f'stat "{key}" missing: {s}' - assert s[key] == 0, f'stat "{key}" not zero: {s}' - - def check_stat_times(self, s, idx): - # check timings reported on a transfer for consistency - url = s['url_effective'] - # connect time is sometimes reported as 0 by openssl-quic (sigh) - self.check_stat_positive_or_0(s, idx, 'time_connect') - # all stat keys which reporting timings - all_keys = { - 'time_appconnect', 'time_redirect', - 'time_pretransfer', 'time_starttransfer', 'time_total' - } - # stat keys where we expect a positive value - pos_keys = {'time_pretransfer', 'time_starttransfer', 'time_total', 'time_queue'} - if s['num_connects'] > 0: - if url.startswith('https:'): - pos_keys.add('time_appconnect') - if s['num_redirects'] > 0: - pos_keys.add('time_redirect') - zero_keys = all_keys - pos_keys - # assert all zeros are zeros and the others are positive - for key in zero_keys: - self.check_stat_zero(s, key) - for key in pos_keys: - self.check_stat_positive(s, idx, key) - # assert that all timers before "time_pretransfer" are less or equal - for key in ['time_appconnect', 'time_connect', 'time_namelookup']: - assert s[key] < s['time_pretransfer'], f'time "{key}" larger than' \ - f'"time_pretransfer": {s}' - # assert transfer total is after pretransfer. - # (in MOST situations, pretransfer is before starttransfer, BUT - # in protocols like HTTP we might get a server response already before - # we transition to multi state DID.) - assert s['time_pretransfer'] <= s['time_total'], f'"time_pretransfer" '\ - f'greater than "time_total", {s}' - # assert that transfer start is before total - assert s['time_starttransfer'] <= s['time_total'], f'"time_starttransfer" '\ - f'greater than "time_total", {s}' - if s['num_redirects'] > 0: - assert s['time_queue'] < s['time_starttransfer'], f'"time_queue" '\ - f'greater/equal than "time_starttransfer", {s}' - else: - assert s['time_queue'] <= s['time_starttransfer'], f'"time_queue" '\ - f'greater than "time_starttransfer", {s}' diff --git a/tests/http/test_30_vsftpd.py b/tests/http/test_30_vsftpd.py index bffeae35cf7b..7d113d5363fe 100644 --- a/tests/http/test_30_vsftpd.py +++ b/tests/http/test_30_vsftpd.py @@ -63,10 +63,12 @@ def _class_scope(self, env, vsftpd): shutil.rmtree(vsftpd.docs_dir) if not os.path.exists(vsftpd.docs_dir): os.makedirs(vsftpd.docs_dir) + self._make_docs_file(docs_dir=vsftpd.docs_dir, fname='data-0k', fsize=0) self._make_docs_file(docs_dir=vsftpd.docs_dir, fname='data-1k', fsize=1024) self._make_docs_file(docs_dir=vsftpd.docs_dir, fname='data-10k', fsize=10*1024) self._make_docs_file(docs_dir=vsftpd.docs_dir, fname='data-1m', fsize=1024*1024) self._make_docs_file(docs_dir=vsftpd.docs_dir, fname='data-10m', fsize=10*1024*1024) + env.make_data_file(indir=env.gen_dir, fname="upload-0k", fsize=0) env.make_data_file(indir=env.gen_dir, fname="upload-1k", fsize=1024) env.make_data_file(indir=env.gen_dir, fname="upload-100k", fsize=100*1024) env.make_data_file(indir=env.gen_dir, fname="upload-1m", fsize=1024*1024) @@ -77,11 +79,12 @@ def test_30_01_list_dir(self, env: Env, vsftpd: VsFTPD): r = curl.ftp_get(urls=[url], with_stats=True) r.check_stats(count=1, http_status=226) lines = open(os.path.join(curl.run_dir, 'download_#1.data')).readlines() - assert len(lines) == 4, f'list: {lines}' + assert len(lines) == 5, f'list: {lines}' + r.check_stats_timelines() # download 1 file, no SSL @pytest.mark.parametrize("docname", [ - 'data-1k', 'data-1m', 'data-10m' + 'data-0k', 'data-1k', 'data-1m', 'data-10m' ]) def test_30_02_download_1(self, env: Env, vsftpd: VsFTPD, docname): curl = CurlClient(env=env) @@ -91,9 +94,10 @@ def test_30_02_download_1(self, env: Env, vsftpd: VsFTPD, docname): r = curl.ftp_get(urls=[url], with_stats=True) r.check_stats(count=count, http_status=226) self.check_downloads(curl, srcfile, count) + r.check_stats_timelines() @pytest.mark.parametrize("docname", [ - 'data-1k', 'data-1m', 'data-10m' + 'data-0k', 'data-1k', 'data-1m', 'data-10m' ]) def test_30_03_download_10_serial(self, env: Env, vsftpd: VsFTPD, docname): curl = CurlClient(env=env) @@ -104,9 +108,10 @@ def test_30_03_download_10_serial(self, env: Env, vsftpd: VsFTPD, docname): r.check_stats(count=count, http_status=226) self.check_downloads(curl, srcfile, count) assert r.total_connects == count + 1, 'should reuse the control conn' + r.check_stats_timelines() @pytest.mark.parametrize("docname", [ - 'data-1k', 'data-1m', 'data-10m' + 'data-0k', 'data-1k', 'data-1m', 'data-10m' ]) def test_30_04_download_10_parallel(self, env: Env, vsftpd: VsFTPD, docname): curl = CurlClient(env=env) @@ -119,9 +124,10 @@ def test_30_04_download_10_parallel(self, env: Env, vsftpd: VsFTPD, docname): r.check_stats(count=count, http_status=226) self.check_downloads(curl, srcfile, count) assert r.total_connects > count + 1, 'should have used several control conns' + r.check_stats_timelines() @pytest.mark.parametrize("docname", [ - 'upload-1k', 'upload-100k', 'upload-1m' + 'upload-0k', 'upload-1k', 'upload-100k', 'upload-1m' ]) def test_30_05_upload_1(self, env: Env, vsftpd: VsFTPD, docname): curl = CurlClient(env=env) @@ -133,6 +139,7 @@ def test_30_05_upload_1(self, env: Env, vsftpd: VsFTPD, docname): r = curl.ftp_upload(urls=[url], fupload=f'{srcfile}', with_stats=True) r.check_stats(count=count, http_status=226) self.check_upload(env, vsftpd, docname=docname) + r.check_stats_timelines() def _rmf(self, path): if os.path.exists(path): @@ -188,6 +195,7 @@ def test_30_08_active_download(self, env: Env, vsftpd: VsFTPD): ]) r.check_stats(count=count, http_status=226) self.check_downloads(curl, srcfile, count) + r.check_stats_timelines() def test_30_09_active_up_file(self, env: Env, vsftpd: VsFTPD): docname = 'upload-1k' @@ -202,6 +210,7 @@ def test_30_09_active_up_file(self, env: Env, vsftpd: VsFTPD): ]) r.check_stats(count=count, http_status=226) self.check_upload(env, vsftpd, docname=docname) + r.check_stats_timelines() def test_30_10_active_up_ascii(self, env: Env, vsftpd: VsFTPD): docname = 'upload-1k' @@ -216,6 +225,7 @@ def test_30_10_active_up_ascii(self, env: Env, vsftpd: VsFTPD): ]) r.check_stats(count=count, http_status=226) self.check_upload(env, vsftpd, docname=docname, binary=False) + r.check_stats_timelines() def test_30_11_download_non_existing(self, env: Env, vsftpd: VsFTPD): curl = CurlClient(env=env) @@ -223,6 +233,7 @@ def test_30_11_download_non_existing(self, env: Env, vsftpd: VsFTPD): r = curl.ftp_get(urls=[url], with_stats=True) r.check_exit_code(78) r.check_stats(count=1, exitcode=78) + r.check_stats_timelines() def check_downloads(self, client, srcfile: str, count: int, complete: bool = True): diff --git a/tests/http/test_31_vsftpds.py b/tests/http/test_31_vsftpds.py index f7e32cb77b77..93fef708ccdd 100644 --- a/tests/http/test_31_vsftpds.py +++ b/tests/http/test_31_vsftpds.py @@ -85,6 +85,7 @@ def test_31_01_list_dir(self, env: Env, vsftpds: VsFTPD): r.check_stats(count=1, http_status=226) lines = open(os.path.join(curl.run_dir, 'download_#1.data')).readlines() assert len(lines) == 4, f'list: {lines}' + r.check_stats_timelines() # download 1 file, no SSL @pytest.mark.parametrize("docname", [ @@ -98,6 +99,7 @@ def test_31_02_download_1(self, env: Env, vsftpds: VsFTPD, docname): r = curl.ftp_ssl_get(urls=[url], with_stats=True) r.check_stats(count=count, http_status=226) self.check_downloads(curl, srcfile, count) + r.check_stats_timelines() @pytest.mark.parametrize("docname", [ 'data-1k', 'data-1m', 'data-10m' @@ -111,6 +113,7 @@ def test_31_03_download_10_serial(self, env: Env, vsftpds: VsFTPD, docname): r.check_stats(count=count, http_status=226) self.check_downloads(curl, srcfile, count) assert r.total_connects == count + 1, 'should reuse the control conn' + r.check_stats_timelines() @pytest.mark.parametrize("docname", [ 'data-1k', 'data-1m', 'data-10m' @@ -126,6 +129,7 @@ def test_31_04_download_10_parallel(self, env: Env, vsftpds: VsFTPD, docname): r.check_stats(count=count, http_status=226) self.check_downloads(curl, srcfile, count) assert r.total_connects > count + 1, 'should have used several control conns' + r.check_stats_timelines() @pytest.mark.parametrize("docname", [ 'upload-1k', 'upload-100k', 'upload-1m' @@ -140,6 +144,7 @@ def test_31_05_upload_1(self, env: Env, vsftpds: VsFTPD, docname): r = curl.ftp_ssl_upload(urls=[url], fupload=f'{srcfile}', with_stats=True) r.check_stats(count=count, http_status=226) self.check_upload(env, vsftpds, docname=docname) + r.check_stats_timelines() def _rmf(self, path): if os.path.exists(path): diff --git a/tests/http/test_32_ftps_vsftpd.py b/tests/http/test_32_ftps_vsftpd.py index 46690a84355e..7a849d374044 100644 --- a/tests/http/test_32_ftps_vsftpd.py +++ b/tests/http/test_32_ftps_vsftpd.py @@ -85,6 +85,7 @@ def test_32_01_list_dir(self, env: Env, vsftpds: VsFTPD): r.check_stats(count=1, http_status=226) lines = open(os.path.join(curl.run_dir, 'download_#1.data')).readlines() assert len(lines) == 4, f'list: {lines}' + r.check_stats_timelines() # download 1 file, no SSL @pytest.mark.parametrize("docname", [ @@ -98,6 +99,7 @@ def test_32_02_download_1(self, env: Env, vsftpds: VsFTPD, docname): r = curl.ftp_get(urls=[url], with_stats=True) r.check_stats(count=count, http_status=226) self.check_downloads(curl, srcfile, count) + r.check_stats_timelines() @pytest.mark.parametrize("docname", [ 'data-1k', 'data-1m', 'data-10m' @@ -111,6 +113,7 @@ def test_32_03_download_10_serial(self, env: Env, vsftpds: VsFTPD, docname): r.check_stats(count=count, http_status=226) self.check_downloads(curl, srcfile, count) assert r.total_connects == count + 1, 'should reuse the control conn' + r.check_stats_timelines() # 2 serial transfers, first with 'ftps://' and second with 'ftp://' # we want connection reuse in this case @@ -123,6 +126,7 @@ def test_32_03b_ftp_compat_ftps(self, env: Env, vsftpds: VsFTPD): r = curl.ftp_get(urls=[url1, url2], with_stats=True) r.check_stats(count=count, http_status=226) assert r.total_connects == count + 1, 'should reuse the control conn' + r.check_stats_timelines() @pytest.mark.parametrize("docname", [ 'data-1k', 'data-1m', 'data-10m' @@ -138,6 +142,7 @@ def test_32_04_download_10_parallel(self, env: Env, vsftpds: VsFTPD, docname): r.check_stats(count=count, http_status=226) self.check_downloads(curl, srcfile, count) assert r.total_connects > count + 1, 'should have used several control conns' + r.check_stats_timelines() @pytest.mark.parametrize("docname", [ 'upload-1k', 'upload-100k', 'upload-1m' @@ -152,6 +157,7 @@ def test_32_05_upload_1(self, env: Env, vsftpds: VsFTPD, docname): r = curl.ftp_upload(urls=[url], fupload=f'{srcfile}', with_stats=True) r.check_stats(count=count, http_status=226) self.check_upload(env, vsftpds, docname=docname) + r.check_stats_timelines() def _rmf(self, path): if os.path.exists(path): diff --git a/tests/http/testenv/curl.py b/tests/http/testenv/curl.py index a92e4f681f34..e486715fa79b 100644 --- a/tests/http/testenv/curl.py +++ b/tests/http/testenv/curl.py @@ -493,6 +493,80 @@ def check_stats(self, count: int, http_status: Optional[int] = None, f'status #{idx} remote_ip: expected {remote_ip}, '\ f'got {x["remote_ip"]}\n{self.dump_stat(x)}' + def check_stat_positive(self, s, idx, key): + assert key in s, f'stat #{idx} "{key}" missing: {s}' + assert s[key] > 0, f'stat #{idx} "{key}" not positive: {s}' + + def check_stat_positive_or_0(self, s, idx, key): + assert key in s, f'stat #{idx} "{key}" missing: {s}' + assert s[key] >= 0, f'stat #{idx} "{key}" not positive: {s}' + + def check_stat_zero(self, s, key): + assert key in s, f'stat "{key}" missing: {s}' + assert s[key] == 0, f'stat "{key}" not zero: {s}' + + def check_stats_timelines(self): + for i in range(len(self._stats)): + self.check_stats_timeline(i) + + def check_stats_timeline(self, idx): + # check timings reported on a transfer for consistency + s = self._stats[idx] + + url = s['url_effective'] + # connect time is sometimes reported as 0 by openssl-quic (sigh) + self.check_stat_positive_or_0(s, idx, 'time_connect') + # all stat keys which reporting timings + all_keys = { + 'time_queue', 'time_namelookup', + 'time_connect', 'time_appconnect', + 'time_pretransfer', 'time_posttransfer', + 'time_starttransfer', 'time_total', + } + # stat keys where we expect a positive value + ref_tl = [] + exact_match = True + # redirects mess up the queue time, only count without + if s['time_redirect'] == 0: + ref_tl += ['time_queue'] + else: + exact_match = False + # connect events? + if url.startswith('ftp'): + # ftp is messy with connect events for its DATA connection + exact_match = False + elif s['num_connects'] > 0: + ref_tl += ['time_namelookup', 'time_connect'] + if url.startswith('https:'): + ref_tl += ['time_appconnect'] + # what kind of transfer was it? + if s['size_upload'] == 0 and s['size_download'] > 0: + # this is a download + dl_tl = ['time_pretransfer', 'time_starttransfer'] + if s['size_request'] > 0: + dl_tl = ['time_posttransfer'] + dl_tl + ref_tl += dl_tl + elif s['size_upload'] > 0 and s['size_download'] == 0: + # this is an upload + ul_tl = ['time_pretransfer', 'time_posttransfer'] + ref_tl += ul_tl + else: + # could be a 0-length upload or 0-length download, not sure + exact_match = False + # always there at the end + ref_tl += ['time_total'] + + # assert all events in reference timeline are > 0 + for key in ref_tl: + self.check_stat_positive(s, idx, key) + if exact_match: + # assert all events not in reference timeline are 0 + for key in [key for key in all_keys if key not in ref_tl]: + self.check_stat_zero(s, key) + # calculate the timeline that did happen + seen_tl = sorted(ref_tl, key=lambda ts: s[ts]) + assert seen_tl == ref_tl, f'{[f"{ts}: {s[ts]}" for ts in seen_tl]}' + def dump_logs(self): lines = ['>>--stdout ----------------------------------------------\n'] lines.extend(self._stdout) diff --git a/tests/libtest/lib500.c b/tests/libtest/lib500.c index ffb974f4f0cb..ff886a05ca60 100644 --- a/tests/libtest/lib500.c +++ b/tests/libtest/lib500.c @@ -128,7 +128,10 @@ static CURLcode test_lib500(const char *URL) (time_pretransfer / 1000000), (long)(time_pretransfer % 1000000)); } - if(time_pretransfer > time_posttransfer) { + if(time_posttransfer > time_pretransfer) { + /* counter-intuitive: on a GET request, all bytes are sent *before* + * PRETRANSFER happens. Thus POSTTRANSFER has to be smaller. + * The reverse would be true for a POST/PUT. */ curl_mfprintf(moo, "pretransfer vs posttransfer: %" CURL_FORMAT_CURL_OFF_T ".%06ld %" CURL_FORMAT_CURL_OFF_T ".%06ld\n", From 16b44f6a3ad13386a25dfc005794696a69f949b0 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Wed, 19 Nov 2025 11:54:36 +0100 Subject: [PATCH 060/140] multi: simplify admin handle processing Fold the special connection pool shutdown handling in multi the things the admin handle cares about. Add the admin handle to the 'process' bitset, deduce it from the 'running' count. The admin handle is the processed like any other transfer, but has a special case in `multi_runsingle()`. Simplifies all other multi processing parts. Closes #19604 --- lib/multi.c | 82 ++++++++++++++++++++++---------------------------- lib/multi_ev.c | 5 ++- lib/multi_ev.h | 3 +- 3 files changed, 39 insertions(+), 51 deletions(-) diff --git a/lib/multi.c b/lib/multi.c index db04d64c231b..5789861026af 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -101,9 +101,9 @@ static void move_pending_to_connect(struct Curl_multi *multi, static CURLMcode add_next_timeout(struct curltime now, struct Curl_multi *multi, struct Curl_easy *d); -static CURLMcode multi_timeout(struct Curl_multi *multi, - struct curltime *expire_time, - long *timeout_ms); +static void multi_timeout(struct Curl_multi *multi, + struct curltime *expire_time, + long *timeout_ms); static void process_pending_handles(struct Curl_multi *multi); static void multi_xfer_bufs_free(struct Curl_multi *multi); #ifdef DEBUGBUILD @@ -273,11 +273,13 @@ struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, multi->admin->multi = multi; multi->admin->state.internal = TRUE; Curl_llist_init(&multi->admin->state.timeoutlist, NULL); + #ifdef DEBUGBUILD if(getenv("CURL_DEBUG")) multi->admin->set.verbose = TRUE; #endif Curl_uint_tbl_add(&multi->xfers, multi->admin, &multi->admin->mid); + Curl_uint_bset_add(&multi->process, multi->admin->mid); if(Curl_cshutdn_init(&multi->cshutdn, multi)) goto error; @@ -413,7 +415,6 @@ static CURLMcode multi_xfers_add(struct Curl_multi *multi, return CURLM_OK; } - CURLMcode curl_multi_add_handle(CURLM *m, CURL *d) { CURLMcode rc; @@ -500,6 +501,7 @@ CURLMcode curl_multi_add_handle(CURLM *m, CURL *d) /* Make sure the new handle will run */ Curl_multi_mark_dirty(data); + /* Necessary in event based processing, where dirty handles trigger * a timeout callback invocation. */ rc = Curl_update_timer(multi); @@ -1441,7 +1443,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi, * poll. Collecting the sockets may install new timers by protocols * and connection filters. * Use the shorter one of the internal and the caller requested timeout. */ - (void)multi_timeout(multi, &expire_time, &timeout_internal); + multi_timeout(multi, &expire_time, &timeout_internal); if((timeout_internal >= 0) && (timeout_internal < (long)timeout_ms)) timeout_ms = (int)timeout_internal; @@ -1562,7 +1564,8 @@ static CURLMcode multi_wait(struct Curl_multi *multi, long sleep_ms = 0; /* Avoid busy-looping when there is nothing particular to wait for */ - if(!curl_multi_timeout(multi, &sleep_ms) && sleep_ms) { + multi_timeout(multi, &expire_time, &sleep_ms); + if(sleep_ms) { if(sleep_ms > timeout_ms) sleep_ms = timeout_ms; /* when there are no easy handles in the multi, this holds a -1 @@ -2394,6 +2397,11 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, * again during processing, triggering a re-run later. */ Curl_uint_bset_remove(&multi->dirty, data->mid); + if(data == multi->admin) { + Curl_cshutdn_perform(&multi->cshutdn, multi->admin, CURL_SOCKET_TIMEOUT); + return CURLM_OK; + } + do { /* A "stream" here is a logical stream if the protocol can handle that (HTTP/2), or the full connection for older protocols */ @@ -2810,19 +2818,13 @@ CURLMcode curl_multi_perform(CURLM *m, int *running_handles) Curl_uint_bset_remove(&multi->dirty, mid); continue; } - if(data != multi->admin) { - /* admin handle is processed below */ - sigpipe_apply(data, &pipe_st); - result = multi_runsingle(multi, &now, data); - if(result) - returncode = result; - } + sigpipe_apply(data, &pipe_st); + result = multi_runsingle(multi, &now, data); + if(result) + returncode = result; } while(Curl_uint_bset_next(&multi->process, mid, &mid)); } - - sigpipe_apply(multi->admin, &pipe_st); - Curl_cshutdn_perform(&multi->cshutdn, multi->admin, CURL_SOCKET_TIMEOUT); sigpipe_restore(&pipe_st); if(multi_ischanged(m, TRUE)) @@ -3077,7 +3079,6 @@ struct multi_run_ctx { struct curltime now; size_t run_xfers; SIGPIPE_MEMBER(pipe_st); - bool run_cpool; }; static void multi_mark_expired_as_dirty(struct multi_run_ctx *mrc) @@ -3127,12 +3128,7 @@ static CURLMcode multi_run_dirty(struct multi_run_ctx *mrc) if(data) { CURL_TRC_M(data, "multi_run_dirty"); - if(data == multi->admin) { - Curl_uint_bset_remove(&multi->dirty, mid); - mrc->run_cpool = TRUE; - continue; - } - else if(!Curl_uint_bset_contains(&multi->process, mid)) { + if(!Curl_uint_bset_contains(&multi->process, mid)) { /* We are no longer processing this transfer */ Curl_uint_bset_remove(&multi->dirty, mid); continue; @@ -3185,13 +3181,12 @@ static CURLMcode multi_socket(struct Curl_multi *multi, /* Reassess event status of all active transfers */ result = Curl_multi_ev_assess_xfer_bset(multi, &multi->process); } - mrc.run_cpool = TRUE; goto out; } if(s != CURL_SOCKET_TIMEOUT) { /* Mark all transfers of that socket as dirty */ - Curl_multi_ev_dirty_xfers(multi, s, &mrc.run_cpool); + Curl_multi_ev_dirty_xfers(multi, s); } else { /* Asked to run due to time-out. Clear the 'last_expire_ts' variable to @@ -3200,7 +3195,6 @@ static CURLMcode multi_socket(struct Curl_multi *multi, handles the case when the application asks libcurl to run the timeout prematurely. */ memset(&multi->last_expire_ts, 0, sizeof(multi->last_expire_ts)); - mrc.run_cpool = TRUE; } multi_mark_expired_as_dirty(&mrc); @@ -3220,10 +3214,6 @@ static CURLMcode multi_socket(struct Curl_multi *multi, } out: - if(mrc.run_cpool) { - sigpipe_apply(multi->admin, &mrc.pipe_st); - Curl_cshutdn_perform(&multi->cshutdn, multi->admin, s); - } sigpipe_restore(&mrc.pipe_st); if(multi_ischanged(multi, TRUE)) @@ -3394,9 +3384,9 @@ static bool multi_has_dirties(struct Curl_multi *multi) return FALSE; } -static CURLMcode multi_timeout(struct Curl_multi *multi, - struct curltime *expire_time, - long *timeout_ms) +static void multi_timeout(struct Curl_multi *multi, + struct curltime *expire_time, + long *timeout_ms) { static const struct curltime tv_zero = {0, 0}; #ifndef CURL_DISABLE_VERBOSE_STRINGS @@ -3405,13 +3395,13 @@ static CURLMcode multi_timeout(struct Curl_multi *multi, if(multi->dead) { *timeout_ms = 0; - return CURLM_OK; + return; } if(multi_has_dirties(multi)) { *expire_time = curlx_now(); *timeout_ms = 0; - return CURLM_OK; + return; } else if(multi->timetree) { /* we have a tree of expire times */ @@ -3462,8 +3452,6 @@ static CURLMcode multi_timeout(struct Curl_multi *multi, } } #endif - - return CURLM_OK; } CURLMcode curl_multi_timeout(CURLM *m, @@ -3479,7 +3467,8 @@ CURLMcode curl_multi_timeout(CURLM *m, if(multi->in_callback) return CURLM_RECURSIVE_API_CALL; - return multi_timeout(multi, &expire_time, timeout_ms); + multi_timeout(multi, &expire_time, timeout_ms); + return CURLM_OK; } /* @@ -3495,9 +3484,7 @@ CURLMcode Curl_update_timer(struct Curl_multi *multi) if(!multi->timer_cb || multi->dead) return CURLM_OK; - if(multi_timeout(multi, &expire_ts, &timeout_ms)) { - return CURLM_OK; - } + multi_timeout(multi, &expire_ts, &timeout_ms); if(timeout_ms < 0 && multi->last_timeout_ms < 0) { /* nothing to do */ @@ -3836,6 +3823,7 @@ CURLMcode curl_multi_get_offt(CURLM *m, curl_off_t *pvalue) { struct Curl_multi *multi = m; + unsigned int n; if(!GOOD_MULTI_HANDLE(multi)) return CURLM_BAD_HANDLE; @@ -3843,15 +3831,17 @@ CURLMcode curl_multi_get_offt(CURLM *m, return CURLM_BAD_FUNCTION_ARGUMENT; switch(info) { - case CURLMINFO_XFERS_CURRENT: { - unsigned int n = Curl_uint_tbl_count(&multi->xfers); + case CURLMINFO_XFERS_CURRENT: + n = Curl_uint_tbl_count(&multi->xfers); if(n && multi->admin) --n; *pvalue = (curl_off_t)n; return CURLM_OK; - } case CURLMINFO_XFERS_RUNNING: - *pvalue = (curl_off_t)Curl_uint_bset_count(&multi->process); + n = Curl_uint_bset_count(&multi->process); + if(n && Curl_uint_bset_contains(&multi->process, multi->admin->mid)) + --n; + *pvalue = (curl_off_t)n; return CURLM_OK; case CURLMINFO_XFERS_PENDING: *pvalue = (curl_off_t)Curl_uint_bset_count(&multi->pending); @@ -4037,7 +4027,7 @@ static void multi_xfer_bufs_free(struct Curl_multi *multi) struct Curl_easy *Curl_multi_get_easy(struct Curl_multi *multi, unsigned int mid) { - struct Curl_easy *data = mid ? Curl_uint_tbl_get(&multi->xfers, mid) : NULL; + struct Curl_easy *data = Curl_uint_tbl_get(&multi->xfers, mid); if(data && GOOD_EASY_HANDLE(data)) return data; CURL_TRC_M(multi->admin, "invalid easy handle in xfer table for mid=%u", diff --git a/lib/multi_ev.c b/lib/multi_ev.c index 098f8da643af..086b037527a4 100644 --- a/lib/multi_ev.c +++ b/lib/multi_ev.c @@ -574,8 +574,7 @@ CURLMcode Curl_multi_ev_assign(struct Curl_multi *multi, } void Curl_multi_ev_dirty_xfers(struct Curl_multi *multi, - curl_socket_t s, - bool *run_cpool) + curl_socket_t s) { struct mev_sh_entry *entry; @@ -606,7 +605,7 @@ void Curl_multi_ev_dirty_xfers(struct Curl_multi *multi, } if(entry->conn) - *run_cpool = TRUE; + Curl_multi_mark_dirty(multi->admin); } } diff --git a/lib/multi_ev.h b/lib/multi_ev.h index 20c1aeac81a6..34548c323232 100644 --- a/lib/multi_ev.h +++ b/lib/multi_ev.h @@ -63,8 +63,7 @@ CURLMcode Curl_multi_ev_assess_conn(struct Curl_multi *multi, /* Mark all transfers tied to the given socket as dirty */ void Curl_multi_ev_dirty_xfers(struct Curl_multi *multi, - curl_socket_t s, - bool *run_cpool); + curl_socket_t s); /* Socket will be closed, forget anything we know about it. */ void Curl_multi_ev_socket_done(struct Curl_multi *multi, From 7e5f379d71b60f35f2a6b24e4bd5cf1935400c13 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Tue, 25 Nov 2025 10:24:14 +0100 Subject: [PATCH 061/140] bufq: use uint8_t instead of unsigned char Closes #19690 --- lib/bufq.c | 30 +++++++++++++++--------------- lib/bufq.h | 16 ++++++++-------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/bufq.c b/lib/bufq.c index e429ccf8e375..d38b78c6d5b2 100644 --- a/lib/bufq.c +++ b/lib/bufq.c @@ -51,9 +51,9 @@ static void chunk_reset(struct buf_chunk *chunk) } static size_t chunk_append(struct buf_chunk *chunk, - const unsigned char *buf, size_t len) + const uint8_t *buf, size_t len) { - unsigned char *p = &chunk->x.data[chunk->w_offset]; + uint8_t *p = &chunk->x.data[chunk->w_offset]; size_t n = chunk->dlen - chunk->w_offset; DEBUGASSERT(chunk->dlen >= chunk->w_offset); if(n) { @@ -65,9 +65,9 @@ static size_t chunk_append(struct buf_chunk *chunk, } static size_t chunk_read(struct buf_chunk *chunk, - unsigned char *buf, size_t len) + uint8_t *buf, size_t len) { - unsigned char *p = &chunk->x.data[chunk->r_offset]; + uint8_t *p = &chunk->x.data[chunk->r_offset]; size_t n = chunk->w_offset - chunk->r_offset; DEBUGASSERT(chunk->w_offset >= chunk->r_offset); if(!n) { @@ -89,7 +89,7 @@ static CURLcode chunk_slurpn(struct buf_chunk *chunk, size_t max_len, Curl_bufq_reader *reader, void *reader_ctx, size_t *pnread) { - unsigned char *p = &chunk->x.data[chunk->w_offset]; + uint8_t *p = &chunk->x.data[chunk->w_offset]; size_t n = chunk->dlen - chunk->w_offset; /* free amount */ CURLcode result; @@ -108,7 +108,7 @@ static CURLcode chunk_slurpn(struct buf_chunk *chunk, size_t max_len, } static void chunk_peek(const struct buf_chunk *chunk, - const unsigned char **pbuf, size_t *plen) + const uint8_t **pbuf, size_t *plen) { DEBUGASSERT(chunk->w_offset >= chunk->r_offset); *pbuf = &chunk->x.data[chunk->r_offset]; @@ -116,7 +116,7 @@ static void chunk_peek(const struct buf_chunk *chunk, } static void chunk_peek_at(const struct buf_chunk *chunk, size_t offset, - const unsigned char **pbuf, size_t *plen) + const uint8_t **pbuf, size_t *plen) { offset += chunk->r_offset; DEBUGASSERT(chunk->w_offset >= offset); @@ -370,7 +370,7 @@ static struct buf_chunk *get_non_full_tail(struct bufq *q) } CURLcode Curl_bufq_write(struct bufq *q, - const unsigned char *buf, size_t len, + const uint8_t *buf, size_t len, size_t *pnwritten) { struct buf_chunk *tail; @@ -400,10 +400,10 @@ CURLcode Curl_bufq_cwrite(struct bufq *q, const char *buf, size_t len, size_t *pnwritten) { - return Curl_bufq_write(q, (const unsigned char *)buf, len, pnwritten); + return Curl_bufq_write(q, (const uint8_t *)buf, len, pnwritten); } -CURLcode Curl_bufq_read(struct bufq *q, unsigned char *buf, size_t len, +CURLcode Curl_bufq_read(struct bufq *q, uint8_t *buf, size_t len, size_t *pnread) { *pnread = 0; @@ -422,11 +422,11 @@ CURLcode Curl_bufq_read(struct bufq *q, unsigned char *buf, size_t len, CURLcode Curl_bufq_cread(struct bufq *q, char *buf, size_t len, size_t *pnread) { - return Curl_bufq_read(q, (unsigned char *)buf, len, pnread); + return Curl_bufq_read(q, (uint8_t *)buf, len, pnread); } bool Curl_bufq_peek(struct bufq *q, - const unsigned char **pbuf, size_t *plen) + const uint8_t **pbuf, size_t *plen) { if(q->head && chunk_is_empty(q->head)) { prune_head(q); @@ -441,7 +441,7 @@ bool Curl_bufq_peek(struct bufq *q, } bool Curl_bufq_peek_at(struct bufq *q, size_t offset, - const unsigned char **pbuf, size_t *plen) + const uint8_t **pbuf, size_t *plen) { struct buf_chunk *c = q->head; size_t clen; @@ -477,7 +477,7 @@ void Curl_bufq_skip(struct bufq *q, size_t amount) CURLcode Curl_bufq_pass(struct bufq *q, Curl_bufq_writer *writer, void *writer_ctx, size_t *pwritten) { - const unsigned char *buf; + const uint8_t *buf; size_t blen; CURLcode result = CURLE_OK; @@ -507,7 +507,7 @@ CURLcode Curl_bufq_pass(struct bufq *q, Curl_bufq_writer *writer, } CURLcode Curl_bufq_write_pass(struct bufq *q, - const unsigned char *buf, size_t len, + const uint8_t *buf, size_t len, Curl_bufq_writer *writer, void *writer_ctx, size_t *pwritten) { diff --git a/lib/bufq.h b/lib/bufq.h index ad8e6435fae1..9557e5d33bba 100644 --- a/lib/bufq.h +++ b/lib/bufq.h @@ -38,7 +38,7 @@ struct buf_chunk { size_t r_offset; /* first unread bytes */ size_t w_offset; /* one after last written byte */ union { - unsigned char data[1]; /* the buffer for `dlen` bytes */ + uint8_t data[1]; /* the buffer for `dlen` bytes */ void *dummy; /* alignment */ } x; }; @@ -166,7 +166,7 @@ bool Curl_bufq_is_full(const struct bufq *q); * CURLE_AGAIN is returned if the buffer queue is full. */ CURLcode Curl_bufq_write(struct bufq *q, - const unsigned char *buf, size_t len, + const uint8_t *buf, size_t len, size_t *pnwritten); CURLcode Curl_bufq_cwrite(struct bufq *q, @@ -177,7 +177,7 @@ CURLcode Curl_bufq_cwrite(struct bufq *q, * Read buf from the start of the buffer queue. The buf is copied * and the amount of copied bytes is returned. */ -CURLcode Curl_bufq_read(struct bufq *q, unsigned char *buf, size_t len, +CURLcode Curl_bufq_read(struct bufq *q, uint8_t *buf, size_t len, size_t *pnread); CURLcode Curl_bufq_cread(struct bufq *q, char *buf, size_t len, @@ -193,10 +193,10 @@ CURLcode Curl_bufq_cread(struct bufq *q, char *buf, size_t len, * is modified, see `Curl_bufq_skip()`` */ bool Curl_bufq_peek(struct bufq *q, - const unsigned char **pbuf, size_t *plen); + const uint8_t **pbuf, size_t *plen); bool Curl_bufq_peek_at(struct bufq *q, size_t offset, - const unsigned char **pbuf, size_t *plen); + const uint8_t **pbuf, size_t *plen); /** * Tell the buffer queue to discard `amount` buf bytes at the head @@ -206,7 +206,7 @@ bool Curl_bufq_peek_at(struct bufq *q, size_t offset, void Curl_bufq_skip(struct bufq *q, size_t amount); typedef CURLcode Curl_bufq_writer(void *writer_ctx, - const unsigned char *buf, size_t len, + const uint8_t *buf, size_t len, size_t *pwritten); /** * Passes the chunks in the buffer queue to the writer and returns @@ -221,7 +221,7 @@ CURLcode Curl_bufq_pass(struct bufq *q, Curl_bufq_writer *writer, void *writer_ctx, size_t *pwritten); typedef CURLcode Curl_bufq_reader(void *reader_ctx, - unsigned char *buf, size_t len, + uint8_t *buf, size_t len, size_t *pnread); /** @@ -253,7 +253,7 @@ CURLcode Curl_bufq_sipn(struct bufq *q, size_t max_len, * amount buffered, chunk size, etc. */ CURLcode Curl_bufq_write_pass(struct bufq *q, - const unsigned char *buf, size_t len, + const uint8_t *buf, size_t len, Curl_bufq_writer *writer, void *writer_ctx, size_t *pwritten); From 0f6ad5ab7d040bf1b9dcc16d12430209079378a6 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Tue, 25 Nov 2025 13:03:04 +0100 Subject: [PATCH 062/140] ngtcp2: use stdint types Use int64_t and uint64_t directly without needing to cast to curl_int64_t and curl_uint64_t. Closes #19696 --- lib/vquic/curl_ngtcp2.c | 138 ++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 75 deletions(-) diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index f63162b34417..d6439287846e 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -215,10 +215,10 @@ static void cf_ngtcp2_setup_keep_alive(struct Curl_cfilter *cf, ngtcp2_duration keep_ns; keep_ns = (rp->max_idle_timeout > 1) ? (rp->max_idle_timeout / 2) : 1; ngtcp2_conn_set_keep_alive_timeout(ctx->qconn, keep_ns); - CURL_TRC_CF(data, cf, "peer idle timeout is %" FMT_PRIu64 "ms, " - "set keep-alive to %" FMT_PRIu64 " ms.", - (curl_uint64_t)(rp->max_idle_timeout / NGTCP2_MILLISECONDS), - (curl_uint64_t)(keep_ns / NGTCP2_MILLISECONDS)); + CURL_TRC_CF(data, cf, "peer idle timeout is %" PRIu64 "ms, " + "set keep-alive to %" PRIu64 " ms.", + (rp->max_idle_timeout / NGTCP2_MILLISECONDS), + (keep_ns / NGTCP2_MILLISECONDS)); } } @@ -235,11 +235,11 @@ static CURLcode cf_progress_egress(struct Curl_cfilter *cf, * All about the H3 internals of a stream */ struct h3_stream_ctx { - curl_int64_t id; /* HTTP/3 protocol identifier */ + int64_t id; /* HTTP/3 protocol identifier */ struct bufq sendbuf; /* h3 request body */ struct h1_req_parser h1; /* h1 request parsing */ size_t sendbuf_len_in_flight; /* sendbuf amount "in flight" */ - curl_uint64_t error3; /* HTTP/3 stream error code */ + uint64_t error3; /* HTTP/3 stream error code */ curl_off_t upload_left; /* number of request bytes left to upload */ uint64_t download_unacked; /* bytes not acknowledged yet */ int status_code; /* HTTP status code */ @@ -301,7 +301,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, #if NGTCP2_VERSION_NUM < 0x011100 struct cf_ngtcp2_sfind_ctx { - curl_int64_t stream_id; + int64_t stream_id; struct h3_stream_ctx *stream; unsigned int mid; }; @@ -320,7 +320,7 @@ static bool cf_ngtcp2_sfind(unsigned int mid, void *value, void *user_data) } static struct h3_stream_ctx * -cf_ngtcp2_get_stream(struct cf_ngtcp2_ctx *ctx, curl_int64_t stream_id) +cf_ngtcp2_get_stream(struct cf_ngtcp2_ctx *ctx, int64_t stream_id) { struct cf_ngtcp2_sfind_ctx fctx; fctx.stream_id = stream_id; @@ -330,7 +330,7 @@ cf_ngtcp2_get_stream(struct cf_ngtcp2_ctx *ctx, curl_int64_t stream_id) } #else static struct h3_stream_ctx *cf_ngtcp2_get_stream(struct cf_ngtcp2_ctx *ctx, - curl_int64_t stream_id) + int64_t stream_id) { struct Curl_easy *data = ngtcp2_conn_get_stream_user_data(ctx->qconn, stream_id); @@ -360,7 +360,7 @@ static void cf_ngtcp2_stream_close(struct Curl_cfilter *cf, NGHTTP3_H3_REQUEST_CANCELLED); result = cf_progress_egress(cf, data, NULL); if(result) - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cancel stream -> %d", + CURL_TRC_CF(data, cf, "[%" PRId64 "] cancel stream -> %d", stream->id, result); } } @@ -371,7 +371,7 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); (void)cf; if(stream) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] easy handle is done", + CURL_TRC_CF(data, cf, "[%" PRId64 "] easy handle is done", stream->id); cf_ngtcp2_stream_close(cf, data, stream); Curl_uint_hash_remove(&ctx->streams, data->mid); @@ -518,12 +518,11 @@ static int cf_ngtcp2_handshake_completed(ngtcp2_conn *tconn, void *user_data) const ngtcp2_transport_params *rp; rp = ngtcp2_conn_get_remote_transport_params(ctx->qconn); CURL_TRC_CF(data, cf, "handshake complete after %" FMT_TIMEDIFF_T - "ms, remote transport[max_udp_payload=%" FMT_PRIu64 - ", initial_max_data=%" FMT_PRIu64 + "ms, remote transport[max_udp_payload=%" PRIu64 + ", initial_max_data=%" PRIu64 "]", curlx_timediff_ms(ctx->handshake_at, ctx->started_at), - (curl_uint64_t)rp->max_udp_payload_size, - (curl_uint64_t)rp->initial_max_data); + rp->max_udp_payload_size, rp->initial_max_data); } #endif @@ -607,13 +606,12 @@ static void cf_ngtcp2_h3_err_set(struct Curl_cfilter *cf, } static int cb_recv_stream_data(ngtcp2_conn *tconn, uint32_t flags, - int64_t sid, uint64_t offset, + int64_t stream_id, uint64_t offset, const uint8_t *buf, size_t buflen, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; - curl_int64_t stream_id = (curl_int64_t)sid; nghttp3_ssize nconsumed; int fin = (flags & NGTCP2_STREAM_DATA_FLAG_FIN) ? 1 : 0; struct Curl_easy *data = stream_user_data; @@ -625,12 +623,12 @@ static int cb_recv_stream_data(ngtcp2_conn *tconn, uint32_t flags, if(!data) data = CF_DATA_CURRENT(cf); if(data) - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read_stream(len=%zu) -> %zd", + CURL_TRC_CF(data, cf, "[%" PRId64 "] read_stream(len=%zu) -> %zd", stream_id, buflen, nconsumed); if(nconsumed < 0) { struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); if(data && stream) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] error on known stream, " + CURL_TRC_CF(data, cf, "[%" PRId64 "] error on known stream, " "reset=%d, closed=%d", stream_id, stream->reset, stream->closed); } @@ -669,13 +667,12 @@ cb_acked_stream_data_offset(ngtcp2_conn *tconn, int64_t stream_id, } static int cb_stream_close(ngtcp2_conn *tconn, uint32_t flags, - int64_t sid, uint64_t app_error_code, + int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; struct Curl_easy *data = stream_user_data; - curl_int64_t stream_id = (curl_int64_t)sid; int rv; (void)tconn; @@ -690,9 +687,8 @@ static int cb_stream_close(ngtcp2_conn *tconn, uint32_t flags, } rv = nghttp3_conn_close_stream(ctx->h3conn, stream_id, app_error_code); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] quic close(app_error=%" - FMT_PRIu64 ") -> %d", stream_id, (curl_uint64_t)app_error_code, - rv); + CURL_TRC_CF(data, cf, "[%" PRId64 "] quic close(app_error=%" + PRIu64 ") -> %d", stream_id, app_error_code, rv); if(rv && rv != NGHTTP3_ERR_STREAM_NOT_FOUND) { cf_ngtcp2_h3_err_set(cf, data, rv); return NGTCP2_ERR_CALLBACK_FAILURE; @@ -701,13 +697,12 @@ static int cb_stream_close(ngtcp2_conn *tconn, uint32_t flags, return 0; } -static int cb_stream_reset(ngtcp2_conn *tconn, int64_t sid, +static int cb_stream_reset(ngtcp2_conn *tconn, int64_t stream_id, uint64_t final_size, uint64_t app_error_code, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; - curl_int64_t stream_id = (curl_int64_t)sid; struct Curl_easy *data = stream_user_data; int rv; (void)tconn; @@ -716,7 +711,7 @@ static int cb_stream_reset(ngtcp2_conn *tconn, int64_t sid, (void)data; rv = nghttp3_conn_shutdown_stream_read(ctx->h3conn, stream_id); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] reset -> %d", stream_id, rv); + CURL_TRC_CF(data, cf, "[%" PRId64 "] reset -> %d", stream_id, rv); if(rv && rv != NGHTTP3_ERR_STREAM_NOT_FOUND) { return NGTCP2_ERR_CALLBACK_FAILURE; } @@ -754,9 +749,8 @@ static int cb_extend_max_local_streams_bidi(ngtcp2_conn *tconn, (void)tconn; ctx->max_bidi_streams = max_streams; if(data) - CURL_TRC_CF(data, cf, "max bidi streams now %" FMT_PRIu64 - ", used %" FMT_PRIu64, (curl_uint64_t)ctx->max_bidi_streams, - (curl_uint64_t)ctx->used_bidi_streams); + CURL_TRC_CF(data, cf, "max bidi streams now %" PRIu64 ", used %" PRIu64, + ctx->max_bidi_streams, ctx->used_bidi_streams); return 0; } @@ -778,8 +772,7 @@ static int cb_extend_max_stream_data(ngtcp2_conn *tconn, int64_t stream_id, } stream = H3_STREAM_CTX(ctx, s_data); if(stream && stream->quic_flow_blocked) { - CURL_TRC_CF(s_data, cf, "[%" FMT_PRId64 "] unblock quic flow", - (curl_int64_t)stream_id); + CURL_TRC_CF(s_data, cf, "[%" PRId64 "] unblock quic flow", stream_id); stream->quic_flow_blocked = FALSE; Curl_multi_mark_dirty(s_data); } @@ -986,14 +979,13 @@ static CURLcode cf_ngtcp2_adjust_pollset(struct Curl_cfilter *cf, return result; } -static int cb_h3_stream_close(nghttp3_conn *conn, int64_t sid, +static int cb_h3_stream_close(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; struct Curl_easy *data = stream_user_data; - curl_int64_t stream_id = (curl_int64_t)sid; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); (void)conn; (void)stream_id; @@ -1003,15 +995,15 @@ static int cb_h3_stream_close(nghttp3_conn *conn, int64_t sid, return 0; stream->closed = TRUE; - stream->error3 = (curl_uint64_t)app_error_code; + stream->error3 = app_error_code; if(stream->error3 != NGHTTP3_H3_NO_ERROR) { stream->reset = TRUE; stream->send_closed = TRUE; - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] RESET: error %" FMT_PRIu64, + CURL_TRC_CF(data, cf, "[%" PRId64 "] RESET: error %" PRIu64, stream->id, stream->error3); } else { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] CLOSED", stream->id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] CLOSED", stream->id); } Curl_multi_mark_dirty(data); return 0; @@ -1031,7 +1023,7 @@ static void h3_xfer_write_resp_hd(struct Curl_cfilter *cf, if(!stream->xfer_result) { stream->xfer_result = Curl_xfer_write_resp_hd(data, buf, blen, eos); if(stream->xfer_result) - CURL_TRC_CF(data, cf, "[%"FMT_PRId64"] error %d writing %zu " + CURL_TRC_CF(data, cf, "[%" PRId64 "] error %d writing %zu " "bytes of headers", stream->id, stream->xfer_result, blen); } } @@ -1051,8 +1043,8 @@ static void h3_xfer_write_resp(struct Curl_cfilter *cf, stream->xfer_result = Curl_xfer_write_resp(data, buf, blen, eos); /* If the transfer write is errored, we do not want any more data */ if(stream->xfer_result) { - CURL_TRC_CF(data, cf, "[%"FMT_PRId64"] error %d writing %zu bytes " - "of data", stream->id, stream->xfer_result, blen); + CURL_TRC_CF(data, cf, "[%" PRId64 "] error %d writing %zu bytes of data", + stream->id, stream->xfer_result, blen); } } } @@ -1078,7 +1070,7 @@ static void cf_ngtcp2_ack_stream(struct Curl_cfilter *cf, } if(ack_len) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] ACK %" PRIu64 + CURL_TRC_CF(data, cf, "[%" PRId64 "] ACK %" PRIu64 "/%" PRIu64 " bytes of DATA", stream->id, ack_len, stream->download_unacked); ngtcp2_conn_extend_max_stream_offset(ctx->qconn, stream->id, ack_len); @@ -1102,7 +1094,7 @@ static int cb_h3_recv_data(nghttp3_conn *conn, int64_t stream3_id, return NGHTTP3_ERR_CALLBACK_FAILURE; h3_xfer_write_resp(cf, data, stream, (const char *)buf, blen, FALSE); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] DATA len=%zu", stream->id, blen); + CURL_TRC_CF(data, cf, "[%" PRId64 "] DATA len=%zu", stream->id, blen); ngtcp2_conn_extend_max_offset(ctx->qconn, blen); if(UINT64_MAX - blen < stream->download_unacked) @@ -1130,13 +1122,12 @@ static int cb_h3_deferred_consume(nghttp3_conn *conn, int64_t stream3_id, return 0; } -static int cb_h3_end_headers(nghttp3_conn *conn, int64_t sid, +static int cb_h3_end_headers(nghttp3_conn *conn, int64_t stream_id, int fin, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; struct Curl_easy *data = stream_user_data; - curl_int64_t stream_id = (curl_int64_t)sid; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); (void)conn; (void)stream_id; @@ -1148,7 +1139,7 @@ static int cb_h3_end_headers(nghttp3_conn *conn, int64_t sid, /* add a CRLF only if we have received some headers */ h3_xfer_write_resp_hd(cf, data, stream, STRCONST("\r\n"), stream->closed); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] end_headers, status=%d", + CURL_TRC_CF(data, cf, "[%" PRId64 "] end_headers, status=%d", stream_id, stream->status_code); if(stream->status_code / 100 != 1) { stream->resp_hds_complete = TRUE; @@ -1157,14 +1148,13 @@ static int cb_h3_end_headers(nghttp3_conn *conn, int64_t sid, return 0; } -static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, +static int cb_h3_recv_header(nghttp3_conn *conn, int64_t stream_id, int32_t token, nghttp3_rcbuf *name, nghttp3_rcbuf *value, uint8_t flags, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; - curl_int64_t stream_id = (curl_int64_t)sid; nghttp3_vec h3name = nghttp3_rcbuf_get_buf(name); nghttp3_vec h3val = nghttp3_rcbuf_get_buf(value); struct Curl_easy *data = stream_user_data; @@ -1196,7 +1186,7 @@ static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, if(!result) h3_xfer_write_resp_hd(cf, data, stream, curlx_dyn_ptr(&ctx->scratch), curlx_dyn_len(&ctx->scratch), FALSE); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] status: %s", + CURL_TRC_CF(data, cf, "[%" PRId64 "] status: %s", stream_id, curlx_dyn_ptr(&ctx->scratch)); if(result) { return NGHTTP3_ERR_CALLBACK_FAILURE; @@ -1204,7 +1194,7 @@ static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, } else { /* store as an HTTP1-style header */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] header: %.*s: %.*s", + CURL_TRC_CF(data, cf, "[%" PRId64 "] header: %.*s: %.*s", stream_id, (int)h3name.len, h3name.base, (int)h3val.len, h3val.base); curlx_dyn_reset(&ctx->scratch); @@ -1243,13 +1233,12 @@ static int cb_h3_stop_sending(nghttp3_conn *conn, int64_t stream_id, return 0; } -static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t sid, +static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; - curl_int64_t stream_id = (curl_int64_t)sid; struct Curl_easy *data = stream_user_data; int rv; (void)conn; @@ -1257,7 +1246,7 @@ static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t sid, rv = ngtcp2_conn_shutdown_stream_write(ctx->qconn, 0, stream_id, app_error_code); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] reset -> %d", stream_id, rv); + CURL_TRC_CF(data, cf, "[%" PRId64 "] reset -> %d", stream_id, rv); if(rv && rv != NGTCP2_ERR_STREAM_NOT_FOUND) { return NGHTTP3_ERR_CALLBACK_FAILURE; } @@ -1359,12 +1348,12 @@ static CURLcode recv_closed_stream(struct Curl_cfilter *cf, (void)cf; *pnread = 0; if(stream->reset) { - failf(data, "HTTP/3 stream %" FMT_PRId64 " reset by server", stream->id); + failf(data, "HTTP/3 stream %" PRId64 " reset by server", stream->id); return data->req.bytecount ? CURLE_PARTIAL_FILE : CURLE_HTTP3; } else if(!stream->resp_hds_complete) { failf(data, - "HTTP/3 stream %" FMT_PRId64 " was closed cleanly, but before " + "HTTP/3 stream %" PRId64 " was closed cleanly, but before " "getting all response header fields, treated as error", stream->id); return CURLE_HTTP3; @@ -1413,7 +1402,7 @@ static CURLcode cf_ngtcp2_recv(struct Curl_cfilter *cf, struct Curl_easy *data, } if(stream->xfer_result) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] xfer write failed", stream->id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] xfer write failed", stream->id); cf_ngtcp2_stream_close(cf, data, stream); result = stream->xfer_result; goto out; @@ -1428,7 +1417,7 @@ static CURLcode cf_ngtcp2_recv(struct Curl_cfilter *cf, struct Curl_easy *data, result = Curl_1st_err(result, cf_progress_egress(cf, data, &pktx)); result = Curl_1st_err(result, check_and_set_expiry(cf, data, &pktx)); denied: - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_recv(blen=%zu) -> %d, %zu", + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_recv(blen=%zu) -> %d, %zu", stream ? stream->id : -1, blen, result, *pnread); CF_DATA_RESTORE(cf, save); return result; @@ -1519,12 +1508,12 @@ cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, } else if(!nwritten) { /* Not EOF, and nothing to give, we signal WOULDBLOCK. */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read req body -> AGAIN", + CURL_TRC_CF(data, cf, "[%" PRId64 "] read req body -> AGAIN", stream->id); return NGHTTP3_ERR_WOULDBLOCK; } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read req body -> " + CURL_TRC_CF(data, cf, "[%" PRId64 "] read req body -> " "%d vecs%s with %zu (buffered=%zu, left=%" FMT_OFF_T ")", stream->id, (int)nvecs, *pflags == NGHTTP3_DATA_FLAG_EOF ? " EOF" : "", @@ -1605,7 +1594,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, result = CURLE_SEND_ERROR; goto out; } - stream->id = (curl_int64_t)sid; + stream->id = sid; ++ctx->used_bidi_streams; switch(data->state.httpreq) { @@ -1637,11 +1626,11 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, if(rc) { switch(rc) { case NGHTTP3_ERR_CONN_CLOSING: - CURL_TRC_CF(data, cf, "h3sid[%" FMT_PRId64 "] failed to send, " + CURL_TRC_CF(data, cf, "h3sid[%" PRId64 "] failed to send, " "connection is closing", stream->id); break; default: - CURL_TRC_CF(data, cf, "h3sid[%" FMT_PRId64 "] failed to send -> " + CURL_TRC_CF(data, cf, "h3sid[%" PRId64 "] failed to send -> " "%d (%s)", stream->id, rc, nghttp3_strerror(rc)); break; } @@ -1651,10 +1640,10 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, } if(Curl_trc_is_verbose(data)) { - infof(data, "[HTTP/3] [%" FMT_PRId64 "] OPENED stream for %s", + infof(data, "[HTTP/3] [%" PRId64 "] OPENED stream for %s", stream->id, data->state.url); for(i = 0; i < nheader; ++i) { - infof(data, "[HTTP/3] [%" FMT_PRId64 "] [%.*s: %.*s]", stream->id, + infof(data, "[HTTP/3] [%" PRId64 "] [%.*s: %.*s]", stream->id, (int)nva[i].namelen, nva[i].name, (int)nva[i].valuelen, nva[i].value); } @@ -1708,7 +1697,7 @@ static CURLcode cf_ngtcp2_send(struct Curl_cfilter *cf, struct Curl_easy *data, stream = H3_STREAM_CTX(ctx, data); } else if(stream->xfer_result) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] xfer write failed", stream->id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] xfer write failed", stream->id); cf_ngtcp2_stream_close(cf, data, stream); result = stream->xfer_result; goto out; @@ -1720,13 +1709,13 @@ static CURLcode cf_ngtcp2_send(struct Curl_cfilter *cf, struct Curl_easy *data, * body. This happens on 30x or 40x responses. * We silently discard the data sent, since this is not a transport * error situation. */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] discarding data" + CURL_TRC_CF(data, cf, "[%" PRId64 "] discarding data" "on closed stream with response", stream->id); result = CURLE_OK; *pnwritten = len; goto out; } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] send_body(len=%zu) " + CURL_TRC_CF(data, cf, "[%" PRId64 "] send_body(len=%zu) " "-> stream closed", stream->id, len); result = CURLE_HTTP3; goto out; @@ -1738,7 +1727,7 @@ static CURLcode cf_ngtcp2_send(struct Curl_cfilter *cf, struct Curl_easy *data, } else { result = Curl_bufq_write(&stream->sendbuf, buf, len, pnwritten); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_send, add to " + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_send, add to " "sendbuf(len=%zu) -> %d, %zu", stream->id, len, result, *pnwritten); if(result) @@ -1755,7 +1744,7 @@ static CURLcode cf_ngtcp2_send(struct Curl_cfilter *cf, struct Curl_easy *data, out: result = Curl_1st_err(result, check_and_set_expiry(cf, data, &pktx)); denied: - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_send(len=%zu) -> %d, %zu", + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_send(len=%zu) -> %d, %zu", stream ? stream->id : -1, len, result, *pnwritten); CF_DATA_RESTORE(cf, save); return result; @@ -1886,8 +1875,8 @@ static CURLcode read_pkt_to_send(void *userp, struct h3_stream_ctx *stream; DEBUGASSERT(ndatalen == -1); nghttp3_conn_block_stream(ctx->h3conn, stream_id); - CURL_TRC_CF(x->data, x->cf, "[%" FMT_PRId64 "] block quic flow", - (curl_int64_t)stream_id); + CURL_TRC_CF(x->data, x->cf, "[%" PRId64 "] block quic flow", + stream_id); stream = cf_ngtcp2_get_stream(ctx, stream_id); if(stream) /* it might be not one of our h3 streams? */ stream->quic_flow_blocked = TRUE; @@ -2171,8 +2160,8 @@ static CURLcode cf_ngtcp2_shutdown(struct Curl_cfilter *cf, (uint8_t *)buffer, sizeof(buffer), &ctx->last_error, pktx.ts); CURL_TRC_CF(data, cf, "start shutdown(err_type=%d, err_code=%" - FMT_PRIu64 ") -> %d", ctx->last_error.type, - (curl_uint64_t)ctx->last_error.error_code, (int)nwritten); + PRIu64 ") -> %d", ctx->last_error.type, + ctx->last_error.error_code, (int)nwritten); /* there are cases listed in ngtcp2 documentation where this call * may fail. Since we are doing a connection shutdown as graceful * as we can, such an error is ignored here. */ @@ -2670,9 +2659,8 @@ static CURLcode cf_ngtcp2_connect(struct Curl_cfilter *cf, result = CURLE_COULDNT_CONNECT; if(cerr) { - CURL_TRC_CF(data, cf, "connect error, type=%d, code=%" - FMT_PRIu64, - cerr->type, (curl_uint64_t)cerr->error_code); + CURL_TRC_CF(data, cf, "connect error, type=%d, code=%" PRIu64, + cerr->type, cerr->error_code); switch(cerr->type) { case NGTCP2_CCERR_TYPE_VERSION_NEGOTIATION: CURL_TRC_CF(data, cf, "error in version negotiation"); From ef4f791337cd13da7dd39e1867e7b038ee98f3a5 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Tue, 25 Nov 2025 13:21:25 +0100 Subject: [PATCH 063/140] quiche: use stdint types Use int64_t and uint64_t directly without needing to cast to curl_int64_t and curl_uint64_t. Closes #19697 --- lib/vquic/curl_quiche.c | 120 +++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 62 deletions(-) diff --git a/lib/vquic/curl_quiche.c b/lib/vquic/curl_quiche.c index 4fc25acad038..51cadd2e6ead 100644 --- a/lib/vquic/curl_quiche.c +++ b/lib/vquic/curl_quiche.c @@ -171,10 +171,10 @@ static CURLcode cf_flush_egress(struct Curl_cfilter *cf, * All about the H3 internals of a stream */ struct h3_stream_ctx { - curl_uint64_t id; /* HTTP/3 protocol stream identifier */ + uint64_t id; /* HTTP/3 protocol stream identifier */ struct bufq recvbuf; /* h3 response */ struct h1_req_parser h1; /* h1 request parsing */ - curl_uint64_t error3; /* HTTP/3 stream error code */ + uint64_t error3; /* HTTP/3 stream error code */ BIT(opened); /* TRUE after stream has been opened */ BIT(closed); /* TRUE on stream close */ BIT(reset); /* TRUE on stream reset */ @@ -243,7 +243,7 @@ static bool cf_quiche_do_resume(struct Curl_cfilter *cf, if(stream->quic_flow_blocked) { stream->quic_flow_blocked = FALSE; Curl_multi_mark_dirty(sdata); - CURL_TRC_CF(sdata, cf, "[%"FMT_PRIu64"] unblock", stream->id); + CURL_TRC_CF(sdata, cf, "[%" PRIu64 "] unblock", stream->id); } return TRUE; } @@ -294,7 +294,7 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) (void)cf; if(stream) { - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] easy handle is done", stream->id); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] easy handle is done", stream->id); if(ctx->qconn && !stream->closed) { quiche_conn_stream_shutdown(ctx->qconn, stream->id, QUICHE_SHUTDOWN_READ, CURL_H3_NO_ERROR); @@ -368,7 +368,7 @@ static int cb_each_header(uint8_t *name, size_t name_len, return CURLE_OK; if((name_len == 7) && !strncmp(HTTP_PSEUDO_STATUS, (char *)name, 7)) { - CURL_TRC_CF(x->data, x->cf, "[%" FMT_PRIu64 "] status: %.*s", + CURL_TRC_CF(x->data, x->cf, "[%" PRIu64 "] status: %.*s", stream->id, (int)value_len, value); result = write_resp_raw(x->cf, x->data, "HTTP/3 ", sizeof("HTTP/3 ") - 1); if(!result) @@ -377,7 +377,7 @@ static int cb_each_header(uint8_t *name, size_t name_len, result = write_resp_raw(x->cf, x->data, " \r\n", 3); } else { - CURL_TRC_CF(x->data, x->cf, "[%" FMT_PRIu64 "] header: %.*s: %.*s", + CURL_TRC_CF(x->data, x->cf, "[%" PRIu64 "] header: %.*s: %.*s", stream->id, (int)name_len, name, (int)value_len, value); result = write_resp_raw(x->cf, x->data, name, name_len); @@ -389,7 +389,7 @@ static int cb_each_header(uint8_t *name, size_t name_len, result = write_resp_raw(x->cf, x->data, "\r\n", 2); } if(result) { - CURL_TRC_CF(x->data, x->cf, "[%"FMT_PRIu64"] on header error %d", + CURL_TRC_CF(x->data, x->cf, "[%" PRIu64 "] on header error %d", stream->id, result); } return result; @@ -439,9 +439,9 @@ static CURLcode cf_recv_body(struct Curl_cfilter *cf, stream_resp_read, &cb_ctx, &nread); if(result && result != CURLE_AGAIN) { - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] recv_body error %zu", + CURL_TRC_CF(data, cf, "[%" PRIu64 "] recv_body error %zu", stream->id, nread); - failf(data, "Error %d in HTTP/3 response body for stream[%"FMT_PRIu64"]", + failf(data, "Error %d in HTTP/3 response body for stream[%" PRIu64 "]", result, stream->id); stream->closed = TRUE; stream->reset = TRUE; @@ -492,11 +492,11 @@ static CURLcode h3_process_event(struct Curl_cfilter *cf, cb_ctx.data = data; rc = quiche_h3_event_for_each_header(ev, cb_each_header, &cb_ctx); if(rc) { - failf(data, "Error %d in HTTP/3 response header for stream[%" - FMT_PRIu64"]", rc, stream->id); + failf(data, "Error %d in HTTP/3 response header for stream[%" PRIu64 "]", + rc, stream->id); return CURLE_RECV_ERROR; } - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] <- [HEADERS]", stream->id); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] <- [HEADERS]", stream->id); break; case QUICHE_H3_EVENT_DATA: @@ -506,7 +506,7 @@ static CURLcode h3_process_event(struct Curl_cfilter *cf, break; case QUICHE_H3_EVENT_RESET: - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] RESET", stream->id); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] RESET", stream->id); stream->closed = TRUE; stream->reset = TRUE; stream->send_closed = TRUE; @@ -514,7 +514,7 @@ static CURLcode h3_process_event(struct Curl_cfilter *cf, break; case QUICHE_H3_EVENT_FINISHED: - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] CLOSED", stream->id); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] CLOSED", stream->id); if(!stream->resp_hds_complete) { result = write_resp_raw(cf, data, "\r\n", 2); if(result) @@ -526,11 +526,11 @@ static CURLcode h3_process_event(struct Curl_cfilter *cf, break; case QUICHE_H3_EVENT_GOAWAY: - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] <- [GOAWAY]", stream->id); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] <- [GOAWAY]", stream->id); break; default: - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] recv, unhandled event %d", + CURL_TRC_CF(data, cf, "[%" PRIu64 "] recv, unhandled event %d", stream->id, quiche_h3_event_type(ev)); break; } @@ -545,14 +545,13 @@ static CURLcode cf_quiche_ev_process(struct Curl_cfilter *cf, CURLcode result = h3_process_event(cf, data, stream, ev); Curl_multi_mark_dirty(data); if(result) - CURL_TRC_CF(data, cf, "error processing event %s " - "for [%"FMT_PRIu64"] -> %d", cf_ev_name(ev), - stream->id, result); + CURL_TRC_CF(data, cf, "error processing event %s for [%" PRIu64 "] -> %d", + cf_ev_name(ev), stream->id, result); return result; } struct cf_quich_disp_ctx { - curl_uint64_t stream_id; + uint64_t stream_id; struct Curl_cfilter *cf; struct Curl_multi *multi; quiche_h3_event *ev; @@ -582,17 +581,17 @@ static CURLcode cf_poll_events(struct Curl_cfilter *cf, /* Take in the events and distribute them to the transfers. */ while(ctx->h3c) { - curl_int64_t stream3_id = quiche_h3_conn_poll(ctx->h3c, ctx->qconn, &ev); - if(stream3_id == QUICHE_H3_ERR_DONE) { + int64_t rv = quiche_h3_conn_poll(ctx->h3c, ctx->qconn, &ev); + if(rv == QUICHE_H3_ERR_DONE) { break; } - else if(stream3_id < 0) { - CURL_TRC_CF(data, cf, "error poll: %"FMT_PRId64, stream3_id); + else if(rv < 0) { + CURL_TRC_CF(data, cf, "error poll: %" PRId64, rv); return CURLE_HTTP3; } else { struct cf_quich_disp_ctx dctx; - dctx.stream_id = (curl_uint64_t)stream3_id; + dctx.stream_id = (uint64_t)rv; dctx.cf = cf; dctx.multi = data->multi; dctx.ev = ev; @@ -750,8 +749,8 @@ static CURLcode cf_flush_egress(struct Curl_cfilter *cf, struct cf_quiche_ctx *ctx = cf->ctx; size_t nread; CURLcode result; - curl_int64_t expiry_ns; - curl_int64_t timeout_ns; + int64_t expiry_ns; + int64_t timeout_ns; struct read_ctx readx; size_t pkt_count, gsolen; @@ -837,15 +836,13 @@ static CURLcode recv_closed_stream(struct Curl_cfilter *cf, DEBUGASSERT(stream); *pnread = 0; if(stream->reset) { - failf(data, - "HTTP/3 stream %" FMT_PRIu64 " reset by server", stream->id); + failf(data, "HTTP/3 stream %" PRIu64 " reset by server", stream->id); result = data->req.bytecount ? CURLE_PARTIAL_FILE : CURLE_HTTP3; - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] cf_recv, was reset -> %d", + CURL_TRC_CF(data, cf, "[%" PRIu64 "] cf_recv, was reset -> %d", stream->id, result); } else if(!stream->resp_got_header) { - failf(data, - "HTTP/3 stream %" FMT_PRIu64 " was closed cleanly, but before " + failf(data, "HTTP/3 stream %" PRIu64 " was closed cleanly, but before " "getting all response header fields, treated as error", stream->id); result = CURLE_HTTP3; @@ -868,7 +865,7 @@ static CURLcode cf_quiche_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(!Curl_bufq_is_empty(&stream->recvbuf)) { result = Curl_bufq_cread(&stream->recvbuf, buf, len, pnread); - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] read recvbuf(len=%zu) " + CURL_TRC_CF(data, cf, "[%" PRIu64 "] read recvbuf(len=%zu) " "-> %d, %zu", stream->id, len, result, *pnread); if(result) goto out; @@ -883,7 +880,7 @@ static CURLcode cf_quiche_recv(struct Curl_cfilter *cf, struct Curl_easy *data, /* recvbuf had nothing before, maybe after progressing ingress? */ if(!*pnread && !Curl_bufq_is_empty(&stream->recvbuf)) { result = Curl_bufq_cread(&stream->recvbuf, buf, len, pnread); - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] read recvbuf(len=%zu) " + CURL_TRC_CF(data, cf, "[%" PRIu64 "] read recvbuf(len=%zu) " "-> %d, %zu", stream->id, len, result, *pnread); if(result) goto out; @@ -908,7 +905,7 @@ static CURLcode cf_quiche_recv(struct Curl_cfilter *cf, struct Curl_easy *data, result = Curl_1st_err(result, cf_flush_egress(cf, data)); if(*pnread > 0) ctx->data_recvd += *pnread; - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] cf_recv(total=%" + CURL_TRC_CF(data, cf, "[%" PRIu64 "] cf_recv(total=%" FMT_OFF_T ") -> %d, %zu", stream->id, ctx->data_recvd, result, *pnread); return result; @@ -930,32 +927,31 @@ static CURLcode cf_quiche_send_body(struct Curl_cfilter *cf, /* Blocked on flow control and should HOLD sending. But when do we open * again? */ if(!quiche_conn_stream_writable(ctx->qconn, stream->id, len)) { - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] send_body(len=%zu) " + CURL_TRC_CF(data, cf, "[%" PRIu64 "] send_body(len=%zu) " "-> window exhausted", stream->id, len); stream->quic_flow_blocked = TRUE; } return CURLE_AGAIN; } else if(rv == QUICHE_H3_TRANSPORT_ERR_INVALID_STREAM_STATE) { - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] send_body(len=%zu) " + CURL_TRC_CF(data, cf, "[%" PRIu64 "] send_body(len=%zu) " "-> invalid stream state", stream->id, len); return CURLE_HTTP3; } else if(rv == QUICHE_H3_TRANSPORT_ERR_FINAL_SIZE) { - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] send_body(len=%zu) " - "-> exceeds size", stream->id, len); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] send_body(len=%zu) -> exceeds size", + stream->id, len); return CURLE_SEND_ERROR; } else if(!curlx_sztouz(rv, pnwritten)) { - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] send_body(len=%zu) " - "-> quiche err %zd", stream->id, len, rv); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] send_body(len=%zu) -> quiche err %zd", + stream->id, len, rv); return CURLE_SEND_ERROR; } else { if(eos && (len == *pnwritten)) stream->send_closed = TRUE; - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] send body(len=%zu, " - "eos=%d) -> %zu", + CURL_TRC_CF(data, cf, "[%" PRIu64 "] send body(len=%zu, eos=%d) -> %zu", stream->id, len, stream->send_closed, *pnwritten); return CURLE_OK; } @@ -969,7 +965,7 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, struct cf_quiche_ctx *ctx = cf->ctx; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); size_t nheader, i; - curl_int64_t stream3_id; + int64_t rv; struct dynhds h2_headers; quiche_h3_header *nva = NULL; CURLcode result = CURLE_OK; @@ -1027,37 +1023,37 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, if(eos && !blen) stream->send_closed = TRUE; - stream3_id = quiche_h3_send_request(ctx->h3c, ctx->qconn, nva, nheader, - stream->send_closed); - CURL_TRC_CF(data, cf, "quiche_send_request() -> %" FMT_PRIu64, stream3_id); - if(stream3_id < 0) { - if(QUICHE_H3_ERR_STREAM_BLOCKED == stream3_id) { + rv = quiche_h3_send_request(ctx->h3c, ctx->qconn, nva, nheader, + stream->send_closed); + CURL_TRC_CF(data, cf, "quiche_send_request() -> %" PRId64, rv); + if(rv < 0) { + if(QUICHE_H3_ERR_STREAM_BLOCKED == rv) { /* quiche seems to report this error if the connection window is * exhausted. Which happens frequently and intermittent. */ - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] blocked", stream->id); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] blocked", stream->id); stream->quic_flow_blocked = TRUE; result = CURLE_AGAIN; goto out; } else { - CURL_TRC_CF(data, cf, "send_request(%s) -> %" FMT_PRIu64, - data->state.url, stream3_id); + CURL_TRC_CF(data, cf, "send_request(%s) -> %" PRId64, + data->state.url, rv); } result = CURLE_SEND_ERROR; goto out; } DEBUGASSERT(!stream->opened); - stream->id = stream3_id; + stream->id = (uint64_t)rv; stream->opened = TRUE; stream->closed = FALSE; stream->reset = FALSE; if(Curl_trc_is_verbose(data)) { - infof(data, "[HTTP/3] [%" FMT_PRIu64 "] OPENED stream for %s", + infof(data, "[HTTP/3] [%" PRIu64 "] OPENED stream for %s", stream->id, data->state.url); for(i = 0; i < nheader; ++i) { - infof(data, "[HTTP/3] [%" FMT_PRIu64 "] [%.*s: %.*s]", stream->id, + infof(data, "[HTTP/3] [%" PRIu64 "] [%.*s: %.*s]", stream->id, (int)nva[i].name_len, nva[i].name, (int)nva[i].value_len, nva[i].value); } @@ -1113,13 +1109,13 @@ static CURLcode cf_quiche_send(struct Curl_cfilter *cf, struct Curl_easy *data, * sending the 30x response. * This is sort of a race: had the transfer loop called recv first, * it would see the response and stop/discard sending on its own- */ - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] discarding data" + CURL_TRC_CF(data, cf, "[%" PRIu64 "] discarding data" "on closed stream with response", stream->id); result = CURLE_OK; *pnwritten = len; goto out; } - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] send_body(len=%zu) " + CURL_TRC_CF(data, cf, "[%" PRIu64 "] send_body(len=%zu) " "-> stream closed", stream->id, len); result = CURLE_HTTP3; goto out; @@ -1131,8 +1127,8 @@ static CURLcode cf_quiche_send(struct Curl_cfilter *cf, struct Curl_easy *data, out: result = Curl_1st_err(result, cf_flush_egress(cf, data)); - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] cf_send(len=%zu) -> %d, %zu", - stream ? stream->id : (curl_uint64_t)~0, len, + CURL_TRC_CF(data, cf, "[%" PRIu64 "] cf_send(len=%zu) -> %d, %zu", + stream ? stream->id : (uint64_t)~0, len, result, *pnwritten); return result; } @@ -1144,7 +1140,7 @@ static bool stream_is_writeable(struct Curl_cfilter *cf, struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); return stream && (quiche_conn_stream_writable( - ctx->qconn, (curl_uint64_t)stream->id, 1) > 0); + ctx->qconn, stream->id, 1) > 0); } static CURLcode cf_quiche_adjust_pollset(struct Curl_cfilter *cf, @@ -1229,7 +1225,7 @@ static CURLcode cf_quiche_cntrl(struct Curl_cfilter *cf, stream->send_closed = TRUE; body[0] = 'X'; result = cf_quiche_send(cf, data, body, 0, TRUE, &sent); - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] DONE_SEND -> %d, %zu", + CURL_TRC_CF(data, cf, "[%" PRIu64 "] DONE_SEND -> %d, %zu", stream->id, result, sent); } break; @@ -1520,7 +1516,7 @@ static CURLcode cf_quiche_query(struct Curl_cfilter *cf, switch(query) { case CF_QUERY_MAX_CONCURRENT: { - curl_uint64_t max_streams = CONN_ATTACHED(cf->conn); + uint64_t max_streams = CONN_ATTACHED(cf->conn); if(!ctx->goaway && ctx->qconn) { max_streams += quiche_conn_peer_streams_left_bidi(ctx->qconn); } From bb63518ba71c3d7bb58e6eb605bb0a5962d7835e Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Tue, 25 Nov 2025 13:39:35 +0100 Subject: [PATCH 064/140] openssl-quic: use stdint types Use int64_t and uint64_t directly without needing to cast to curl_int64_t and curl_uint64_t. Closes #19698 --- lib/vquic/curl_osslq.c | 106 ++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 55 deletions(-) diff --git a/lib/vquic/curl_osslq.c b/lib/vquic/curl_osslq.c index b890a8d9516d..9d0193d55440 100644 --- a/lib/vquic/curl_osslq.c +++ b/lib/vquic/curl_osslq.c @@ -207,7 +207,7 @@ static CURLcode make_bio_addr(BIO_ADDR **pbio_addr, /* QUIC stream (not necessarily H3) */ struct cf_osslq_stream { - curl_int64_t id; + int64_t id; SSL *ssl; struct bufq recvbuf; /* QUIC war data recv buffer */ BIT(recvd_eos); @@ -228,7 +228,7 @@ static CURLcode cf_osslq_stream_open(struct cf_osslq_stream *s, if(!s->ssl) { return CURLE_FAILED_INIT; } - s->id = (curl_int64_t)SSL_get_stream_id(s->ssl); + s->id = SSL_get_stream_id(s->ssl); SSL_set_app_data(s->ssl, user_data); return CURLE_OK; } @@ -450,7 +450,7 @@ static CURLcode cf_osslq_h3conn_add_stream(struct cf_osslq_h3conn *h3, struct Curl_easy *data) { struct cf_osslq_ctx *ctx = cf->ctx; - curl_int64_t stream_id = (curl_int64_t)SSL_get_stream_id(stream_ssl); + int64_t stream_id = (int64_t)SSL_get_stream_id(stream_ssl); int stype = SSL_get_stream_type(stream_ssl); /* This could be a GREASE stream, e.g. HTTP/3 rfc9114 ch 6.2.3 * reserved stream type that is supposed to be discarded silently. @@ -461,7 +461,7 @@ static CURLcode cf_osslq_h3conn_add_stream(struct cf_osslq_h3conn *h3, struct cf_osslq_stream *nstream; if(h3->remote_ctrl_n >= CURL_ARRAYSIZE(h3->remote_ctrl)) { /* rejected, we are full */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] reject remote uni stream", + CURL_TRC_CF(data, cf, "[%" PRId64 "] reject remote uni stream", stream_id); SSL_free(stream_ssl); return CURLE_OK; @@ -470,12 +470,12 @@ static CURLcode cf_osslq_h3conn_add_stream(struct cf_osslq_h3conn *h3, nstream->id = stream_id; nstream->ssl = stream_ssl; Curl_bufq_initp(&nstream->recvbuf, &ctx->stream_bufcp, 1, BUFQ_OPT_NONE); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] accepted remote uni stream", + CURL_TRC_CF(data, cf, "[%" PRId64 "] accepted remote uni stream", stream_id); return CURLE_OK; } default: - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] reject remote %s" + CURL_TRC_CF(data, cf, "[%" PRId64 "] reject remote %s" " stream, type=%x", stream_id, (stype == SSL_STREAM_TYPE_BIDI) ? "bidi" : "write", stype); SSL_free(stream_ssl); @@ -579,7 +579,7 @@ struct h3_stream_ctx { struct h1_req_parser h1; /* h1 request parsing */ size_t sendbuf_len_in_flight; /* sendbuf amount "in flight" */ size_t recv_buf_nonflow; /* buffered bytes, not counting for flow control */ - curl_uint64_t error3; /* HTTP/3 stream error code */ + uint64_t error3; /* HTTP/3 stream error code */ curl_off_t upload_left; /* number of request bytes left to upload */ curl_off_t download_recvd; /* number of response DATA bytes received */ int status_code; /* HTTP status code */ @@ -649,7 +649,7 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) (void)cf; if(stream) { - CURL_TRC_CF(data, cf, "[%"FMT_PRId64"] easy handle is done", + CURL_TRC_CF(data, cf, "[%" PRIu64 "] easy handle is done", stream->s.id); if(ctx->h3.conn && (stream->s.id >= 0) && !stream->closed) { nghttp3_conn_shutdown_stream_read(ctx->h3.conn, stream->s.id); @@ -664,7 +664,7 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) } struct cf_ossq_find_ctx { - curl_int64_t stream_id; + int64_t stream_id; struct h3_stream_ctx *stream; }; @@ -743,11 +743,11 @@ static int cb_h3_stream_close(nghttp3_conn *conn, int64_t stream_id, if(stream->error3 != NGHTTP3_H3_NO_ERROR) { stream->reset = TRUE; stream->send_closed = TRUE; - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] RESET: error %" FMT_PRIu64, + CURL_TRC_CF(data, cf, "[%" PRId64 "] RESET: error %" PRIu64, stream->s.id, stream->error3); } else { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] CLOSED", stream->s.id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] CLOSED", stream->s.id); } Curl_multi_mark_dirty(data); return 0; @@ -806,12 +806,12 @@ static int cb_h3_recv_data(nghttp3_conn *conn, int64_t stream3_id, result = write_resp_raw(cf, data, buf, buflen, TRUE); if(result) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] DATA len=%zu, ERROR %d", + CURL_TRC_CF(data, cf, "[%" PRId64 "] DATA len=%zu, ERROR %d", stream->s.id, buflen, result); return NGHTTP3_ERR_CALLBACK_FAILURE; } stream->download_recvd += (curl_off_t)buflen; - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] DATA len=%zu, total=%" FMT_OFF_T, + CURL_TRC_CF(data, cf, "[%" PRId64 "] DATA len=%zu, total=%" FMT_OFF_T, stream->s.id, buflen, stream->download_recvd); Curl_multi_mark_dirty(data); return 0; @@ -829,18 +829,17 @@ static int cb_h3_deferred_consume(nghttp3_conn *conn, int64_t stream_id, (void)conn; (void)stream_id; if(stream) - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] deferred consume %zu bytes", + CURL_TRC_CF(data, cf, "[%" PRId64 "] deferred consume %zu bytes", stream->s.id, consumed); return 0; } -static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, +static int cb_h3_recv_header(nghttp3_conn *conn, int64_t stream_id, int32_t token, nghttp3_rcbuf *name, nghttp3_rcbuf *value, uint8_t flags, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; - curl_int64_t stream_id = sid; struct cf_osslq_ctx *ctx = cf->ctx; nghttp3_vec h3name = nghttp3_rcbuf_get_buf(name); nghttp3_vec h3val = nghttp3_rcbuf_get_buf(value); @@ -867,7 +866,7 @@ static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, return -1; ncopy = curl_msnprintf(line, sizeof(line), "HTTP/3 %03d \r\n", stream->status_code); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] status: %s", stream_id, line); + CURL_TRC_CF(data, cf, "[%" PRId64 "] status: %s", stream_id, line); result = write_resp_raw(cf, data, line, ncopy, FALSE); if(result) { return -1; @@ -875,7 +874,7 @@ static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, } else { /* store as an HTTP1-style header */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] header: %.*s: %.*s", + CURL_TRC_CF(data, cf, "[%" PRId64 "] header: %.*s: %.*s", stream_id, (int)h3name.len, h3name.base, (int)h3val.len, h3val.base); result = write_resp_raw(cf, data, h3name.base, h3name.len, FALSE); @@ -898,13 +897,12 @@ static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, return 0; } -static int cb_h3_end_headers(nghttp3_conn *conn, int64_t sid, +static int cb_h3_end_headers(nghttp3_conn *conn, int64_t stream_id, int fin, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_osslq_ctx *ctx = cf->ctx; struct Curl_easy *data = stream_user_data; - curl_int64_t stream_id = sid; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); CURLcode result = CURLE_OK; (void)conn; @@ -920,7 +918,7 @@ static int cb_h3_end_headers(nghttp3_conn *conn, int64_t sid, return -1; } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] end_headers, status=%d", + CURL_TRC_CF(data, cf, "[%" PRId64 "] end_headers, status=%d", stream_id, stream->status_code); if(stream->status_code / 100 != 1) { stream->resp_hds_complete = TRUE; @@ -929,14 +927,13 @@ static int cb_h3_end_headers(nghttp3_conn *conn, int64_t sid, return 0; } -static int cb_h3_stop_sending(nghttp3_conn *conn, int64_t sid, +static int cb_h3_stop_sending(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_osslq_ctx *ctx = cf->ctx; struct Curl_easy *data = stream_user_data; - curl_int64_t stream_id = sid; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); (void)conn; (void)app_error_code; @@ -944,19 +941,18 @@ static int cb_h3_stop_sending(nghttp3_conn *conn, int64_t sid, if(!stream || !stream->s.ssl) return 0; - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] stop_sending", stream_id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] stop_sending", stream_id); cf_osslq_stream_close(&stream->s); return 0; } -static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t sid, +static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_osslq_ctx *ctx = cf->ctx; struct Curl_easy *data = stream_user_data; - curl_int64_t stream_id = sid; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); int rv; (void)conn; @@ -965,7 +961,7 @@ static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t sid, SSL_STREAM_RESET_ARGS args = {0}; args.quic_error_code = app_error_code; rv = !SSL_stream_reset(stream->s.ssl, &args, sizeof(args)); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] reset -> %d", stream_id, rv); + CURL_TRC_CF(data, cf, "[%" PRId64 "] reset -> %d", stream_id, rv); if(!rv) { return NGHTTP3_ERR_CALLBACK_FAILURE; } @@ -1025,12 +1021,12 @@ cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, } else if(!nwritten) { /* Not EOF, and nothing to give, we signal WOULDBLOCK. */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read req body -> AGAIN", + CURL_TRC_CF(data, cf, "[%" PRId64 "] read req body -> AGAIN", stream->s.id); return NGHTTP3_ERR_WOULDBLOCK; } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read req body -> " + CURL_TRC_CF(data, cf, "[%" PRId64 "] read req body -> " "%d vecs%s with %zu (buffered=%zu, left=%" FMT_OFF_T ")", stream->s.id, (int)nvecs, *pflags == NGHTTP3_DATA_FLAG_EOF ? " EOF" : "", @@ -1262,7 +1258,7 @@ static CURLcode h3_quic_recv(void *reader_ctx, return CURLE_AGAIN; } else if(detail == SSL_ERROR_ZERO_RETURN) { - CURL_TRC_CF(x->data, x->cf, "[%" FMT_PRId64 "] h3_quic_recv -> EOS", + CURL_TRC_CF(x->data, x->cf, "[%" PRId64 "] h3_quic_recv -> EOS", x->s->id); x->s->recvd_eos = TRUE; return CURLE_OK; @@ -1275,7 +1271,7 @@ static CURLcode h3_quic_recv(void *reader_ctx, return CURLE_RECV_ERROR; } else { - CURL_TRC_CF(x->data, x->cf, "[%" FMT_PRId64 "] h3_quic_recv -> RESET, " + CURL_TRC_CF(x->data, x->cf, "[%" PRId64 "] h3_quic_recv -> RESET, " "rv=%d, app_err=%" FMT_PRIu64, x->s->id, rv, (curl_uint64_t)app_error_code); if(app_error_code != NGHTTP3_H3_NO_ERROR) @@ -1332,7 +1328,7 @@ static CURLcode cf_osslq_stream_recv(struct cf_osslq_stream *s, while(Curl_bufq_peek(&s->recvbuf, &buf, &blen)) { nread = nghttp3_conn_read_stream(ctx->h3.conn, s->id, buf, blen, 0); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] forward %zu bytes " + CURL_TRC_CF(data, cf, "[%" PRId64 "] forward %zu bytes " "to nghttp3 -> %zd", s->id, blen, nread); if(nread < 0) { failf(data, "nghttp3_conn_read_stream(len=%zu) error: %s", @@ -1372,7 +1368,7 @@ static CURLcode cf_osslq_stream_recv(struct cf_osslq_stream *s, rv = nghttp3_conn_close_stream(ctx->h3.conn, s->id, NGHTTP3_H3_NO_ERROR); s->closed = TRUE; - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] close nghttp3 stream -> %d", + CURL_TRC_CF(data, cf, "[%" PRId64 "] close nghttp3 stream -> %d", s->id, rv); if(rv < 0 && rv != NGHTTP3_ERR_STREAM_NOT_FOUND) { failf(data, "nghttp3_conn_close_stream returned error: %s", @@ -1385,7 +1381,7 @@ static CURLcode cf_osslq_stream_recv(struct cf_osslq_stream *s, } out: if(result) - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_osslq_stream_recv -> %d", + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_osslq_stream_recv -> %d", s->id, result); return result; } @@ -1609,7 +1605,7 @@ static CURLcode h3_send_streams(struct Curl_cfilter *cf, s = cf_osslq_get_qstream(cf, data, stream_id); if(!s) { failf(data, "nghttp3_conn_writev_stream gave unknown stream %" - FMT_PRId64, (curl_int64_t)stream_id); + PRId64, stream_id); result = CURLE_SEND_ERROR; goto out; } @@ -1630,7 +1626,7 @@ static CURLcode h3_send_streams(struct Curl_cfilter *cf, if(ok) { /* As OpenSSL buffers the data, we count this as acknowledged * from nghttp3's point of view */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] send %zu bytes to QUIC ok", + CURL_TRC_CF(data, cf, "[%" PRId64 "] send %zu bytes to QUIC ok", s->id, vec[i].len); acked_len += vec[i].len; } @@ -1640,14 +1636,14 @@ static CURLcode h3_send_streams(struct Curl_cfilter *cf, case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_READ: /* QUIC blocked us from writing more */ - CURL_TRC_CF(data, cf, "[%"FMT_PRId64 "] send %zu bytes to " + CURL_TRC_CF(data, cf, "[%" PRId64 "] send %zu bytes to " "QUIC blocked", s->id, vec[i].len); written = 0; nghttp3_conn_block_stream(ctx->h3.conn, s->id); s->send_blocked = blocked = TRUE; break; default: - failf(data, "[%"FMT_PRId64 "] send %zu bytes to QUIC, SSL error %d", + failf(data, "[%" PRId64 "] send %zu bytes to QUIC, SSL error %d", s->id, vec[i].len, detail); result = cf_osslq_ssl_err(cf, data, detail, CURLE_HTTP3); goto out; @@ -1673,13 +1669,13 @@ static CURLcode h3_send_streams(struct Curl_cfilter *cf, result = CURLE_SEND_ERROR; goto out; } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] forwarded %zu/%zu h3 bytes " + CURL_TRC_CF(data, cf, "[%" PRId64 "] forwarded %zu/%zu h3 bytes " "to QUIC, eos=%d", s->id, acked_len, total_len, eos); } if(eos && !s->send_blocked && !eos_written) { /* wrote everything and H3 indicates end of stream */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] closing QUIC stream", s->id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] closing QUIC stream", s->id); SSL_stream_conclude(s->ssl, 0); } } @@ -1980,11 +1976,11 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, if(rc) { switch(rc) { case NGHTTP3_ERR_CONN_CLOSING: - CURL_TRC_CF(data, cf, "h3sid[%"FMT_PRId64"] failed to send, " + CURL_TRC_CF(data, cf, "h3sid[%" PRId64 "] failed to send, " "connection is closing", stream->s.id); break; default: - CURL_TRC_CF(data, cf, "h3sid[%"FMT_PRId64 "] failed to send -> %d (%s)", + CURL_TRC_CF(data, cf, "h3sid[%" PRId64 "] failed to send -> %d (%s)", stream->s.id, rc, nghttp3_strerror(rc)); break; } @@ -1993,10 +1989,10 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, } if(Curl_trc_is_verbose(data)) { - infof(data, "[HTTP/3] [%" FMT_PRId64 "] OPENED stream for %s", + infof(data, "[HTTP/3] [%" PRId64 "] OPENED stream for %s", stream->s.id, data->state.url); for(i = 0; i < nheader; ++i) { - infof(data, "[HTTP/3] [%" FMT_PRId64 "] [%.*s: %.*s]", + infof(data, "[HTTP/3] [%" PRId64 "] [%.*s: %.*s]", stream->s.id, (int)nva[i].namelen, nva[i].name, (int)nva[i].valuelen, nva[i].value); @@ -2049,20 +2045,20 @@ static CURLcode cf_osslq_send(struct Curl_cfilter *cf, struct Curl_easy *data, * body. This happens on 30x or 40x responses. * We silently discard the data sent, since this is not a transport * error situation. */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] discarding data" + CURL_TRC_CF(data, cf, "[%" PRId64 "] discarding data" "on closed stream with response", stream->s.id); result = CURLE_OK; *pnwritten = len; goto out; } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] send_body(len=%zu) " + CURL_TRC_CF(data, cf, "[%" PRId64 "] send_body(len=%zu) " "-> stream closed", stream->s.id, len); result = CURLE_HTTP3; goto out; } else { result = Curl_bufq_write(&stream->sendbuf, buf, len, pnwritten); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_send, add to " + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_send, add to " "sendbuf(len=%zu) -> %d, %zu", stream->s.id, len, result, *pnwritten); if(result) @@ -2075,7 +2071,7 @@ static CURLcode cf_osslq_send(struct Curl_cfilter *cf, struct Curl_easy *data, out: result = Curl_1st_err(result, check_and_set_expiry(cf, data)); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_send(len=%zu) -> %d, %zu", + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_send(len=%zu) -> %d, %zu", stream ? stream->s.id : -1, len, result, *pnwritten); CF_DATA_RESTORE(cf, save); return result; @@ -2090,13 +2086,13 @@ static CURLcode recv_closed_stream(struct Curl_cfilter *cf, *pnread = 0; if(stream->reset) { failf(data, - "HTTP/3 stream %" FMT_PRId64 " reset by server", + "HTTP/3 stream %" PRId64 " reset by server", stream->s.id); return data->req.bytecount ? CURLE_PARTIAL_FILE : CURLE_HTTP3; } else if(!stream->resp_hds_complete) { failf(data, - "HTTP/3 stream %" FMT_PRId64 + "HTTP/3 stream %" PRId64 " was closed cleanly, but before getting" " all response header fields, treated as error", stream->s.id); @@ -2128,8 +2124,8 @@ static CURLcode cf_osslq_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(!Curl_bufq_is_empty(&stream->recvbuf)) { result = Curl_bufq_cread(&stream->recvbuf, buf, len, pnread); if(result) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read recvbuf(len=%zu) " - "-> %d, %zu", stream->s.id, len, result, *pnread); + CURL_TRC_CF(data, cf, "[%" PRId64 "] read recvbuf(len=%zu) -> %d, %zu", + stream->s.id, len, result, *pnread); goto out; } } @@ -2142,8 +2138,8 @@ static CURLcode cf_osslq_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(!*pnread && !Curl_bufq_is_empty(&stream->recvbuf)) { result = Curl_bufq_cread(&stream->recvbuf, buf, len, pnread); if(result) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read recvbuf(len=%zu) " - "-> %d, %zu", stream->s.id, len, result, *pnread); + CURL_TRC_CF(data, cf, "[%" PRId64 "] read recvbuf(len=%zu) -> %d, %zu", + stream->s.id, len, result, *pnread); goto out; } } @@ -2163,7 +2159,7 @@ static CURLcode cf_osslq_recv(struct Curl_cfilter *cf, struct Curl_easy *data, result = Curl_1st_err(result, cf_progress_egress(cf, data)); result = Curl_1st_err(result, check_and_set_expiry(cf, data)); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_recv(len=%zu) -> %d, %zu", + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_recv(len=%zu) -> %d, %zu", stream ? stream->s.id : -1, len, result, *pnread); CF_DATA_RESTORE(cf, save); return result; From 4701a6d2ae9f0b66a0feac4061868e944353449b Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Tue, 25 Nov 2025 11:33:38 +0100 Subject: [PATCH 065/140] lib: change uint sets to operate on uint32_t - clarify names and change types - make multi's `mid` a uint32_t - update documentation Closes #19695 --- docs/internals/UINT_SETS.md | 40 ++--- lib/doh.c | 16 +- lib/doh.h | 2 +- lib/easy.c | 6 +- lib/http2.c | 10 +- lib/multi.c | 282 ++++++++++++++++++------------------ lib/multi_ev.c | 36 ++--- lib/multi_ev.h | 4 +- lib/multi_ntfy.c | 22 +-- lib/multi_ntfy.h | 2 +- lib/multihandle.h | 10 +- lib/multiif.h | 2 +- lib/uint-bset.c | 102 ++++++------- lib/uint-bset.h | 38 ++--- lib/uint-hash.c | 94 ++++++------ lib/uint-hash.h | 40 ++--- lib/uint-spbset.c | 128 ++++++++-------- lib/uint-spbset.h | 42 +++--- lib/uint-table.c | 82 +++++------ lib/uint-table.h | 40 ++--- lib/url.c | 10 +- lib/urldata.h | 10 +- lib/vquic/curl_ngtcp2.c | 20 +-- lib/vquic/curl_osslq.c | 24 +-- lib/vquic/curl_quiche.c | 16 +- lib/vquic/vquic_int.h | 2 +- tests/unit/unit1616.c | 18 +-- tests/unit/unit3211.c | 65 +++++---- tests/unit/unit3212.c | 82 ++++++----- tests/unit/unit3213.c | 38 ++--- 30 files changed, 645 insertions(+), 638 deletions(-) diff --git a/docs/internals/UINT_SETS.md b/docs/internals/UINT_SETS.md index de00b9b47a30..85952c9803fe 100644 --- a/docs/internals/UINT_SETS.md +++ b/docs/internals/UINT_SETS.md @@ -4,23 +4,23 @@ Copyright (C) Daniel Stenberg, , et al. SPDX-License-Identifier: curl --> -# Unsigned Int Sets +# `uint32_t` Sets -The multi handle tracks added easy handles via an unsigned int -it calls an `mid`. There are four data structures for unsigned int +The multi handle tracks added easy handles via an `uint32_t` +it calls an `mid`. There are four data structures for `uint32_t` optimized for the multi use case. -## `uint_tbl` +## `uint32_tbl` -`uint_table`, implemented in `uint-table.[ch]` manages an array -of `void *`. The unsigned int are the index into this array. It is +`uint32_table`, implemented in `uint-table.[ch]` manages an array +of `void *`. The `uint32_t` is the index into this array. It is created with a *capacity* which can be *resized*. The table assigns the index when a `void *` is *added*. It keeps track of the last assigned index and uses the next available larger index for a subsequent add. Reaching *capacity* it wraps around. The table *can not* store `NULL` values. The largest possible index -is `UINT_MAX - 1`. +is `UINT32_MAX - 1`. The table is iterated over by asking for the *first* existing index, meaning the smallest number that has an entry, if the table is not @@ -29,10 +29,10 @@ iteration step. It does not matter if the previous index is still in the table. Sample code for a table iteration would look like this: ```c -unsigned int mid; +uint32_t int mid; void *entry; -if(Curl_uint_tbl_first(tbl, &mid, &entry)) { +if(Curl_uint32_tbl_first(tbl, &mid, &entry)) { do { /* operate on entry with index mid */ } @@ -51,7 +51,7 @@ This iteration has the following properties: ### Memory For storing 1000 entries, the table would allocate one block of 8KB on a 64-bit system, -plus the 2 pointers and 3 unsigned int in its base `struct uint_tbl`. A resize +plus the 2 pointers and 3 `uint32_t` in its base `struct uint32_tbl`. A resize allocates a completely new pointer array, copy the existing entries and free the previous one. ### Performance @@ -77,17 +77,17 @@ For these reasons, the simple implementation was preferred. Should this become a concern, there are options like "free index lists" or, alternatively, an internal bitset that scans better. -## `uint_bset` +## `uint32_bset` -A bitset for unsigned integers, allowing fast add/remove operations. It is initialized +A bitset for `uint32_t` values, allowing fast add/remove operations. It is initialized with a *capacity*, meaning it can store only the numbers in the range `[0, capacity-1]`. -It can be *resized* and safely *iterated*. `uint_bset` is designed to operate in combination with `uint_tbl`. +It can be *resized* and safely *iterated*. `uint32_bset` is designed to operate in combination with `uint_tbl`. -The bitset keeps an array of `curl_uint64_t`. The first array entry keeps the numbers 0 to 63, the +The bitset keeps an array of `uint64_t`. The first array entry keeps the numbers 0 to 63, the second 64 to 127 and so on. A bitset with capacity 1024 would therefore allocate an array of 16 64-bit values (128 bytes). Operations for an unsigned int divide it by 64 for the array index and then check/set/clear the bit of the remainder. -Iterator works the same as with `uint_tbl`: ask the bitset for the *first* number present and +Iterator works the same as with `uint32_tbl`: ask the bitset for the *first* number present and then use that to get the *next* higher number present. Like the table, this safe for adds/removes and growing the set while iterating. @@ -102,14 +102,14 @@ Operations for add/remove/check are O(1). Iteration needs to scan for the next b number of scans is small (see memory footprint) and, for checking bits, many compilers offer primitives for special CPU instructions. -## `uint_spbset` +## `uint32_spbset` -While the memory footprint of `uint_bset` is good, it still needs 5KB to store the single number 40000. This +While the memory footprint of `uint32_bset` is good, it still needs 5KB to store the single number 40000. This is not optimal when many are needed. For example, in event based processing, each socket needs to keep track of the transfers involved. There are many sockets potentially, but each one mostly tracks a single transfer or few (on HTTP/2 connection borderline up to 100). -For such uses cases, the `uint_spbset` is intended: track a small number of unsigned int, potentially +For such uses cases, the `uint32_spbset` is intended: track a small number of unsigned int, potentially rather "close" together. It keeps "chunks" with an offset and has no capacity limit. Example: adding the number 40000 to an empty sparse bitset would have one chunk with offset 39936, keeping @@ -121,8 +121,8 @@ would need to be allocated and linked, resulting in overall 4 KB of memory used. Iterating a sparse bitset works the same as for bitset and table. -## `uint_hash` +## `uint32_hash` At last, there are places in libcurl such as the HTTP/2 and HTTP/3 protocol implementations that need -to store their own data related to a transfer. `uint_hash` allows then to associate an unsigned int, +to store their own data related to a transfer. `uint32_hash` allows then to associate an unsigned int, e.g. the transfer's `mid`, to their own data. diff --git a/lib/doh.c b/lib/doh.c index 83a83f534672..0712981a97ec 100644 --- a/lib/doh.c +++ b/lib/doh.c @@ -286,7 +286,7 @@ static CURLcode doh_probe_run(struct Curl_easy *data, DNStype dnstype, const char *host, const char *url, CURLM *multi, - unsigned int *pmid) + uint32_t *pmid) { struct Curl_easy *doh = NULL; CURLcode result = CURLE_OK; @@ -294,7 +294,7 @@ static CURLcode doh_probe_run(struct Curl_easy *data, struct doh_request *doh_req; DOHcode d; - *pmid = UINT_MAX; + *pmid = UINT32_MAX; doh_req = calloc(1, sizeof(*doh_req)); if(!doh_req) @@ -472,7 +472,7 @@ CURLcode Curl_doh(struct Curl_easy *data, const char *hostname, return CURLE_OUT_OF_MEMORY; for(i = 0; i < DOH_SLOT_COUNT; ++i) { - dohp->probe_resp[i].probe_mid = UINT_MAX; + dohp->probe_resp[i].probe_mid = UINT32_MAX; curlx_dyn_init(&dohp->probe_resp[i].body, DYN_DOH_RESPONSE); } @@ -1222,8 +1222,8 @@ CURLcode Curl_doh_is_resolved(struct Curl_easy *data, if(!dohp) return CURLE_OUT_OF_MEMORY; - if(dohp->probe_resp[DOH_SLOT_IPV4].probe_mid == UINT_MAX && - dohp->probe_resp[DOH_SLOT_IPV6].probe_mid == UINT_MAX) { + if(dohp->probe_resp[DOH_SLOT_IPV4].probe_mid == UINT32_MAX && + dohp->probe_resp[DOH_SLOT_IPV6].probe_mid == UINT32_MAX) { failf(data, "Could not DoH-resolve: %s", dohp->host); return CONN_IS_PROXIED(data->conn) ? CURLE_COULDNT_RESOLVE_PROXY : CURLE_COULDNT_RESOLVE_HOST; @@ -1318,13 +1318,13 @@ void Curl_doh_close(struct Curl_easy *data) struct doh_probes *doh = data->state.async.doh; if(doh && data->multi) { struct Curl_easy *probe_data; - unsigned int mid; + uint32_t mid; size_t slot; for(slot = 0; slot < DOH_SLOT_COUNT; slot++) { mid = doh->probe_resp[slot].probe_mid; - if(mid == UINT_MAX) + if(mid == UINT32_MAX) continue; - doh->probe_resp[slot].probe_mid = UINT_MAX; + doh->probe_resp[slot].probe_mid = UINT32_MAX; /* should have been called before data is removed from multi handle */ DEBUGASSERT(data->multi); probe_data = data->multi ? Curl_multi_get_easy(data->multi, mid) : diff --git a/lib/doh.h b/lib/doh.h index 726fb9f73557..ffd0cb087913 100644 --- a/lib/doh.h +++ b/lib/doh.h @@ -96,7 +96,7 @@ struct doh_request { }; struct doh_response { - unsigned int probe_mid; + uint32_t probe_mid; struct dynbuf body; DNStype dnstype; CURLcode result; diff --git a/lib/easy.c b/lib/easy.c index 8c7b9c23da68..db6c419c5771 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -988,8 +988,8 @@ CURL *curl_easy_duphandle(CURL *d) outcurl->state.lastconnect_id = -1; outcurl->state.recent_conn_id = -1; outcurl->id = -1; - outcurl->mid = UINT_MAX; - outcurl->master_mid = UINT_MAX; + outcurl->mid = UINT32_MAX; + outcurl->master_mid = UINT32_MAX; #ifndef CURL_DISABLE_HTTP Curl_llist_init(&outcurl->state.httphdrs, NULL); @@ -1126,7 +1126,7 @@ void curl_easy_reset(CURL *d) #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_DIGEST_AUTH) Curl_http_auth_cleanup_digest(data); #endif - data->master_mid = UINT_MAX; + data->master_mid = UINT32_MAX; } /* diff --git a/lib/http2.c b/lib/http2.c index 5d1a502810fb..7b94930a21a7 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -140,7 +140,7 @@ static void cf_h2_ctx_init(struct cf_h2_ctx *ctx, bool via_h1_upgrade) Curl_bufq_initp(&ctx->inbufq, &ctx->stream_bufcp, H2_NW_RECV_CHUNKS, 0); Curl_bufq_initp(&ctx->outbufq, &ctx->stream_bufcp, H2_NW_SEND_CHUNKS, 0); curlx_dyn_init(&ctx->scratch, CURL_MAX_HTTP_HEADER); - Curl_uint_hash_init(&ctx->streams, 63, h2_stream_hash_free); + Curl_uint32_hash_init(&ctx->streams, 63, h2_stream_hash_free); ctx->remote_max_sid = 2147483647; ctx->via_h1_upgrade = via_h1_upgrade; #ifdef DEBUGBUILD @@ -165,7 +165,7 @@ static void cf_h2_ctx_free(struct cf_h2_ctx *ctx) Curl_bufq_free(&ctx->outbufq); Curl_bufcp_free(&ctx->stream_bufcp); curlx_dyn_free(&ctx->scratch); - Curl_uint_hash_destroy(&ctx->streams); + Curl_uint32_hash_destroy(&ctx->streams); memset(ctx, 0, sizeof(*ctx)); } free(ctx); @@ -269,7 +269,7 @@ struct h2_stream_ctx { #define H2_STREAM_CTX(ctx,data) \ ((struct h2_stream_ctx *)( \ - data? Curl_uint_hash_get(&(ctx)->streams, (data)->mid) : NULL)) + data? Curl_uint32_hash_get(&(ctx)->streams, (data)->mid) : NULL)) static struct h2_stream_ctx *h2_stream_ctx_create(struct cf_h2_ctx *ctx) { @@ -426,7 +426,7 @@ static CURLcode http2_data_setup(struct Curl_cfilter *cf, if(!stream) return CURLE_OUT_OF_MEMORY; - if(!Curl_uint_hash_set(&ctx->streams, data->mid, stream)) { + if(!Curl_uint32_hash_set(&ctx->streams, data->mid, stream)) { h2_stream_ctx_free(stream); return CURLE_OUT_OF_MEMORY; } @@ -466,7 +466,7 @@ static void http2_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) } } - Curl_uint_hash_remove(&ctx->streams, data->mid); + Curl_uint32_hash_remove(&ctx->streams, data->mid); } static int h2_client_new(struct Curl_cfilter *cf, diff --git a/lib/multi.c b/lib/multi.c index 5789861026af..57c574a68176 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -180,11 +180,11 @@ static void mstate(struct Curl_easy *data, CURLMstate state if(oldstate < MSTATE_DONE) CURLM_NTFY(data, CURLMNOTIFY_EASY_DONE); /* changing to COMPLETED means it is in process and needs to go */ - DEBUGASSERT(Curl_uint_bset_contains(&data->multi->process, data->mid)); - Curl_uint_bset_remove(&data->multi->process, data->mid); - Curl_uint_bset_remove(&data->multi->pending, data->mid); /* to be sure */ + DEBUGASSERT(Curl_uint32_bset_contains(&data->multi->process, data->mid)); + Curl_uint32_bset_remove(&data->multi->process, data->mid); + Curl_uint32_bset_remove(&data->multi->pending, data->mid); /* to be sure */ - if(Curl_uint_bset_empty(&data->multi->process)) { + if(Curl_uint32_bset_empty(&data->multi->process)) { /* free the transfer buffer when we have no more active transfers */ multi_xfer_bufs_free(data->multi); } @@ -229,7 +229,7 @@ static void multi_addmsg(struct Curl_multi *multi, struct Curl_message *msg) Curl_llist_append(&multi->msglist, msg, &msg->list); } -struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, +struct Curl_multi *Curl_multi_handle(uint32_t xfer_table_size, size_t ev_hashsize, /* event hash */ size_t chashsize, /* connection hash */ size_t dnssize, /* dns hash */ @@ -245,11 +245,11 @@ struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, Curl_dnscache_init(&multi->dnscache, dnssize); Curl_mntfy_init(multi); Curl_multi_ev_init(multi, ev_hashsize); - Curl_uint_tbl_init(&multi->xfers, NULL); - Curl_uint_bset_init(&multi->process); - Curl_uint_bset_init(&multi->dirty); - Curl_uint_bset_init(&multi->pending); - Curl_uint_bset_init(&multi->msgsent); + Curl_uint32_tbl_init(&multi->xfers, NULL); + Curl_uint32_bset_init(&multi->process); + Curl_uint32_bset_init(&multi->dirty); + Curl_uint32_bset_init(&multi->pending); + Curl_uint32_bset_init(&multi->msgsent); Curl_hash_init(&multi->proto_hash, 23, Curl_hash_str, curlx_str_key_compare, ph_freeentry); Curl_llist_init(&multi->msglist, NULL); @@ -259,11 +259,11 @@ struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, multi->last_timeout_ms = -1; if(Curl_mntfy_resize(multi) || - Curl_uint_bset_resize(&multi->process, xfer_table_size) || - Curl_uint_bset_resize(&multi->pending, xfer_table_size) || - Curl_uint_bset_resize(&multi->dirty, xfer_table_size) || - Curl_uint_bset_resize(&multi->msgsent, xfer_table_size) || - Curl_uint_tbl_resize(&multi->xfers, xfer_table_size)) + Curl_uint32_bset_resize(&multi->process, xfer_table_size) || + Curl_uint32_bset_resize(&multi->pending, xfer_table_size) || + Curl_uint32_bset_resize(&multi->dirty, xfer_table_size) || + Curl_uint32_bset_resize(&multi->msgsent, xfer_table_size) || + Curl_uint32_tbl_resize(&multi->xfers, xfer_table_size)) goto error; multi->admin = curl_easy_init(); @@ -278,8 +278,8 @@ struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, if(getenv("CURL_DEBUG")) multi->admin->set.verbose = TRUE; #endif - Curl_uint_tbl_add(&multi->xfers, multi->admin, &multi->admin->mid); - Curl_uint_bset_add(&multi->process, multi->admin->mid); + Curl_uint32_tbl_add(&multi->xfers, multi->admin, &multi->admin->mid); + Curl_uint32_bset_add(&multi->process, multi->admin->mid); if(Curl_cshutdn_init(&multi->cshutdn, multi)) goto error; @@ -322,11 +322,11 @@ struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, } Curl_mntfy_cleanup(multi); - Curl_uint_bset_destroy(&multi->process); - Curl_uint_bset_destroy(&multi->dirty); - Curl_uint_bset_destroy(&multi->pending); - Curl_uint_bset_destroy(&multi->msgsent); - Curl_uint_tbl_destroy(&multi->xfers); + Curl_uint32_bset_destroy(&multi->process); + Curl_uint32_bset_destroy(&multi->dirty); + Curl_uint32_bset_destroy(&multi->pending); + Curl_uint32_bset_destroy(&multi->msgsent); + Curl_uint32_tbl_destroy(&multi->xfers); free(multi); return NULL; @@ -359,12 +359,12 @@ static void multi_warn_debug(struct Curl_multi *multi, struct Curl_easy *data) static CURLMcode multi_xfers_add(struct Curl_multi *multi, struct Curl_easy *data) { - unsigned int capacity = Curl_uint_tbl_capacity(&multi->xfers); - unsigned int new_size = 0; + uint32_t capacity = Curl_uint32_tbl_capacity(&multi->xfers); + uint32_t new_size = 0; /* Prepare to make this into a CURLMOPT_MAX_TRANSFERS, because some * applications may want to prevent a run-away of their memory use. */ /* UINT_MAX is our "invalid" id, do not let the table grow up to that. */ - const unsigned int max_capacity = UINT_MAX - 1; + const uint32_t max_capacity = UINT_MAX - 1; if(capacity < max_capacity) { /* We want `multi->xfers` to have "sufficient" free rows, so that we do @@ -372,9 +372,9 @@ static CURLMcode multi_xfers_add(struct Curl_multi *multi, * Since uint_tbl and uint_bset are quite memory efficient, * regard less than 25% free as insufficient. * (for low capacities, e.g. multi_easy, 4 or less). */ - unsigned int used = Curl_uint_tbl_count(&multi->xfers); - unsigned int unused = capacity - used; - unsigned int min_unused = CURLMAX(capacity >> 2, 4); + uint32_t used = Curl_uint32_tbl_count(&multi->xfers); + uint32_t unused = capacity - used; + uint32_t min_unused = CURLMAX(capacity >> 2, 4); if(unused <= min_unused) { /* Make sure the uint arithmetic here works on the corner * cases where we are close to max_capacity or UINT_MAX */ @@ -397,19 +397,19 @@ static CURLMcode multi_xfers_add(struct Curl_multi *multi, * to work properly when larger than the table, but not * the other way around. */ CURL_TRC_M(data, "increasing xfer table size to %u", new_size); - if(Curl_uint_bset_resize(&multi->process, new_size) || - Curl_uint_bset_resize(&multi->dirty, new_size) || - Curl_uint_bset_resize(&multi->pending, new_size) || - Curl_uint_bset_resize(&multi->msgsent, new_size) || - Curl_uint_tbl_resize(&multi->xfers, new_size)) + if(Curl_uint32_bset_resize(&multi->process, new_size) || + Curl_uint32_bset_resize(&multi->dirty, new_size) || + Curl_uint32_bset_resize(&multi->pending, new_size) || + Curl_uint32_bset_resize(&multi->msgsent, new_size) || + Curl_uint32_tbl_resize(&multi->xfers, new_size)) return CURLM_OUT_OF_MEMORY; } /* Insert the easy into the table now */ - if(!Curl_uint_tbl_add(&multi->xfers, data, &data->mid)) { + if(!Curl_uint32_tbl_add(&multi->xfers, data, &data->mid)) { /* MUST only happen when table is full */ - DEBUGASSERT(Curl_uint_tbl_capacity(&multi->xfers) <= - Curl_uint_tbl_count(&multi->xfers)); + DEBUGASSERT(Curl_uint32_tbl_capacity(&multi->xfers) <= + Curl_uint32_tbl_count(&multi->xfers)); return CURLM_OUT_OF_MEMORY; } return CURLM_OK; @@ -441,14 +441,14 @@ CURLMcode curl_multi_add_handle(CURLM *m, CURL *d) handles are still alive - but if there are none alive anymore, it is fine to start over and unmark the "deadness" of this handle. This means only the admin handle MUST be present. */ - if((Curl_uint_tbl_count(&multi->xfers) != 1) || - !Curl_uint_tbl_contains(&multi->xfers, 0)) + if((Curl_uint32_tbl_count(&multi->xfers) != 1) || + !Curl_uint32_tbl_contains(&multi->xfers, 0)) return CURLM_ABORTED_BY_CALLBACK; multi->dead = FALSE; - Curl_uint_bset_clear(&multi->process); - Curl_uint_bset_clear(&multi->dirty); - Curl_uint_bset_clear(&multi->pending); - Curl_uint_bset_clear(&multi->msgsent); + Curl_uint32_bset_clear(&multi->process); + Curl_uint32_bset_clear(&multi->dirty); + Curl_uint32_bset_clear(&multi->pending); + Curl_uint32_bset_clear(&multi->msgsent); } if(data->multi_easy) { @@ -492,7 +492,7 @@ CURLMcode curl_multi_add_handle(CURLM *m, CURL *d) #endif /* add the easy handle to the process set */ - Curl_uint_bset_add(&multi->process, data->mid); + Curl_uint32_bset_add(&multi->process, data->mid); ++multi->xfers_alive; ++multi->xfers_total_ever; @@ -507,8 +507,8 @@ CURLMcode curl_multi_add_handle(CURLM *m, CURL *d) rc = Curl_update_timer(multi); if(rc) { data->multi = NULL; /* not anymore */ - Curl_uint_tbl_remove(&multi->xfers, data->mid); - data->mid = UINT_MAX; + Curl_uint32_tbl_remove(&multi->xfers, data->mid); + data->mid = UINT32_MAX; return rc; } @@ -523,7 +523,7 @@ CURLMcode curl_multi_add_handle(CURLM *m, CURL *d) CURL_TRC_M(data, "added to multi, mid=%u, running=%u, total=%u", data->mid, Curl_multi_xfers_running(multi), - Curl_uint_tbl_count(&multi->xfers)); + Curl_uint32_tbl_count(&multi->xfers)); return CURLM_OK; } @@ -572,11 +572,11 @@ static void multi_done_locked(struct connectdata *conn, Curl_detach_connection(data); CURL_TRC_M(data, "multi_done_locked, in use=%u", - Curl_uint_spbset_count(&conn->xfers_attached)); + Curl_uint32_spbset_count(&conn->xfers_attached)); if(CONN_INUSE(conn)) { /* Stop if still used. */ CURL_TRC_M(data, "Connection still in use %u, no more multi_done now!", - Curl_uint_spbset_count(&conn->xfers_attached)); + Curl_uint32_spbset_count(&conn->xfers_attached)); return; } @@ -740,7 +740,7 @@ CURLMcode curl_multi_remove_handle(CURLM *m, CURL *d) struct Curl_llist_node *e; CURLMcode rc; bool removed_timer = FALSE; - unsigned int mid; + uint32_t mid; /* First, make some basic checks that the CURLM handle is a good handle */ if(!GOOD_MULTI_HANDLE(multi)) @@ -758,11 +758,11 @@ CURLMcode curl_multi_remove_handle(CURLM *m, CURL *d) if(data->multi != multi) return CURLM_BAD_EASY_HANDLE; - if(data->mid == UINT_MAX) { + if(data->mid == UINT32_MAX) { DEBUGASSERT(0); return CURLM_INTERNAL_ERROR; } - if(Curl_uint_tbl_get(&multi->xfers, data->mid) != data) { + if(Curl_uint32_tbl_get(&multi->xfers, data->mid) != data) { DEBUGASSERT(0); return CURLM_INTERNAL_ERROR; } @@ -797,7 +797,7 @@ CURLMcode curl_multi_remove_handle(CURLM *m, CURL *d) removed_timer = Curl_expire_clear(data); /* If in `msgsent`, it was deducted from `multi->xfers_alive` already. */ - if(!Curl_uint_bset_contains(&multi->msgsent, data->mid)) + if(!Curl_uint32_bset_contains(&multi->msgsent, data->mid)) --multi->xfers_alive; Curl_wildcard_dtor(&data->wildcard); @@ -853,15 +853,15 @@ CURLMcode curl_multi_remove_handle(CURLM *m, CURL *d) /* clear the association to this multi handle */ mid = data->mid; - DEBUGASSERT(Curl_uint_tbl_contains(&multi->xfers, mid)); - Curl_uint_tbl_remove(&multi->xfers, mid); - Curl_uint_bset_remove(&multi->process, mid); - Curl_uint_bset_remove(&multi->dirty, mid); - Curl_uint_bset_remove(&multi->pending, mid); - Curl_uint_bset_remove(&multi->msgsent, mid); + DEBUGASSERT(Curl_uint32_tbl_contains(&multi->xfers, mid)); + Curl_uint32_tbl_remove(&multi->xfers, mid); + Curl_uint32_bset_remove(&multi->process, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->pending, mid); + Curl_uint32_bset_remove(&multi->msgsent, mid); data->multi = NULL; - data->mid = UINT_MAX; - data->master_mid = UINT_MAX; + data->mid = UINT32_MAX; + data->master_mid = UINT32_MAX; /* NOTE NOTE NOTE We do not touch the easy handle here! */ @@ -875,7 +875,7 @@ CURLMcode curl_multi_remove_handle(CURLM *m, CURL *d) CURL_TRC_M(data, "removed from multi, mid=%u, running=%u, total=%u", mid, Curl_multi_xfers_running(multi), - Curl_uint_tbl_count(&multi->xfers)); + Curl_uint32_tbl_count(&multi->xfers)); return CURLM_OK; } @@ -895,8 +895,8 @@ void Curl_detach_connection(struct Curl_easy *data) { struct connectdata *conn = data->conn; if(conn) { - Curl_uint_spbset_remove(&conn->xfers_attached, data->mid); - if(Curl_uint_spbset_empty(&conn->xfers_attached)) + Curl_uint32_spbset_remove(&conn->xfers_attached, data->mid); + if(Curl_uint32_spbset_empty(&conn->xfers_attached)) conn->attached_multi = NULL; } data->conn = NULL; @@ -914,7 +914,7 @@ void Curl_attach_connection(struct Curl_easy *data, DEBUGASSERT(!data->conn); DEBUGASSERT(conn); data->conn = conn; - Curl_uint_spbset_add(&conn->xfers_attached, data->mid); + Curl_uint32_spbset_add(&conn->xfers_attached, data->mid); /* all attached transfers must be from the same multi */ if(!conn->attached_multi) conn->attached_multi = data->multi; @@ -1219,7 +1219,7 @@ CURLMcode curl_multi_fdset(CURLM *m, return CURLM_RECURSIVE_API_CALL; Curl_pollset_init(&ps); - if(Curl_uint_bset_first(&multi->process, &mid)) { + if(Curl_uint32_bset_first(&multi->process, &mid)) { do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); @@ -1248,7 +1248,7 @@ CURLMcode curl_multi_fdset(CURLM *m, this_max_fd = (int)ps.sockets[i]; } } - while(Curl_uint_bset_next(&multi->process, mid, &mid)); + while(Curl_uint32_bset_next(&multi->process, mid, &mid)); } Curl_cshutdn_setfds(&multi->cshutdn, multi->admin, @@ -1282,19 +1282,19 @@ CURLMcode curl_multi_waitfds(CURLM *m, Curl_pollset_init(&ps); Curl_waitfds_init(&cwfds, ufds, size); - if(Curl_uint_bset_first(&multi->process, &mid)) { + if(Curl_uint32_bset_first(&multi->process, &mid)) { do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); if(!data) { DEBUGASSERT(0); - Curl_uint_bset_remove(&multi->process, mid); - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->process, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); continue; } Curl_multi_pollset(data, &ps); need += Curl_waitfds_add_ps(&cwfds, &ps); } - while(Curl_uint_bset_next(&multi->process, mid, &mid)); + while(Curl_uint32_bset_next(&multi->process, mid, &mid)); } need += Curl_cshutdn_add_waitfds(&multi->cshutdn, multi->admin, &cwfds); @@ -1345,7 +1345,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi, unsigned int curl_nfds = 0; /* how many pfds are for curl transfers */ struct Curl_easy *data = NULL; CURLMcode result = CURLM_OK; - unsigned int mid; + uint32_t mid; #ifdef USE_WINSOCK WSANETWORKEVENTS wsa_events; @@ -1368,13 +1368,13 @@ static CURLMcode multi_wait(struct Curl_multi *multi, Curl_pollfds_init(&cpfds, a_few_on_stack, NUM_POLLS_ON_STACK); /* Add the curl handles to our pollfds first */ - if(Curl_uint_bset_first(&multi->process, &mid)) { + if(Curl_uint32_bset_first(&multi->process, &mid)) { do { data = Curl_multi_get_easy(multi, mid); if(!data) { DEBUGASSERT(0); - Curl_uint_bset_remove(&multi->process, mid); - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->process, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); continue; } Curl_multi_pollset(data, &ps); @@ -1383,7 +1383,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi, goto out; } } - while(Curl_uint_bset_next(&multi->process, mid, &mid)); + while(Curl_uint32_bset_next(&multi->process, mid, &mid)); } if(Curl_cshutdn_add_pollfds(&multi->cshutdn, multi->admin, &cpfds)) { @@ -2330,9 +2330,9 @@ static CURLMcode state_connect(struct Curl_multi *multi, wait for an available connection. */ multistate(data, MSTATE_PENDING); /* move from process to pending set */ - Curl_uint_bset_remove(&multi->process, data->mid); - Curl_uint_bset_remove(&multi->dirty, data->mid); - Curl_uint_bset_add(&multi->pending, data->mid); + Curl_uint32_bset_remove(&multi->process, data->mid); + Curl_uint32_bset_remove(&multi->dirty, data->mid); + Curl_uint32_bset_add(&multi->pending, data->mid); *resultp = CURLE_OK; return rc; } @@ -2395,7 +2395,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, /* transfer runs now, clear the dirty bit. This may be set * again during processing, triggering a re-run later. */ - Curl_uint_bset_remove(&multi->dirty, data->mid); + Curl_uint32_bset_remove(&multi->dirty, data->mid); if(data == multi->admin) { Curl_cshutdn_perform(&multi->cshutdn, multi->admin, CURL_SOCKET_TIMEOUT); @@ -2742,7 +2742,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, } if(MSTATE_COMPLETED == data->mstate) { - if(data->master_mid != UINT_MAX) { + if(data->master_mid != UINT32_MAX) { /* A sub transfer, not for msgsent to application */ struct Curl_easy *mdata; @@ -2773,10 +2773,10 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, multistate(data, MSTATE_MSGSENT); /* remove from the other sets, add to msgsent */ - Curl_uint_bset_remove(&multi->process, data->mid); - Curl_uint_bset_remove(&multi->dirty, data->mid); - Curl_uint_bset_remove(&multi->pending, data->mid); - Curl_uint_bset_add(&multi->msgsent, data->mid); + Curl_uint32_bset_remove(&multi->process, data->mid); + Curl_uint32_bset_remove(&multi->dirty, data->mid); + Curl_uint32_bset_remove(&multi->pending, data->mid); + Curl_uint32_bset_add(&multi->msgsent, data->mid); --multi->xfers_alive; return CURLM_OK; } @@ -2793,7 +2793,7 @@ CURLMcode curl_multi_perform(CURLM *m, int *running_handles) struct Curl_tree *t = NULL; struct curltime now = curlx_now(); struct Curl_multi *multi = m; - unsigned int mid; + uint32_t mid; SIGPIPE_VARIABLE(pipe_st); if(!GOOD_MULTI_HANDLE(multi)) @@ -2806,7 +2806,7 @@ CURLMcode curl_multi_perform(CURLM *m, int *running_handles) return CURLM_RECURSIVE_API_CALL; sigpipe_init(&pipe_st); - if(Curl_uint_bset_first(&multi->process, &mid)) { + if(Curl_uint32_bset_first(&multi->process, &mid)) { CURL_TRC_M(multi->admin, "multi_perform(running=%u)", Curl_multi_xfers_running(multi)); do { @@ -2814,8 +2814,8 @@ CURLMcode curl_multi_perform(CURLM *m, int *running_handles) CURLMcode result; if(!data) { DEBUGASSERT(0); - Curl_uint_bset_remove(&multi->process, mid); - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->process, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); continue; } sigpipe_apply(data, &pipe_st); @@ -2823,7 +2823,7 @@ CURLMcode curl_multi_perform(CURLM *m, int *running_handles) if(result) returncode = result; } - while(Curl_uint_bset_next(&multi->process, mid, &mid)); + while(Curl_uint32_bset_next(&multi->process, mid, &mid)); } sigpipe_restore(&pipe_st); @@ -2876,7 +2876,7 @@ CURLMcode curl_multi_cleanup(CURLM *m) struct Curl_multi *multi = m; if(GOOD_MULTI_HANDLE(multi)) { void *entry; - unsigned int mid; + uint32_t mid; if(multi->in_callback) return CURLM_RECURSIVE_API_CALL; if(multi->in_ntfy_callback) @@ -2884,7 +2884,7 @@ CURLMcode curl_multi_cleanup(CURLM *m) /* First remove all remaining easy handles, * close internal ones. admin handle is special */ - if(Curl_uint_tbl_first(&multi->xfers, &mid, &entry)) { + if(Curl_uint32_tbl_first(&multi->xfers, &mid, &entry)) { do { struct Curl_easy *data = entry; if(!GOOD_EASY_HANDLE(data)) @@ -2906,8 +2906,8 @@ CURLMcode curl_multi_cleanup(CURLM *m) (void)multi_done(data, CURLE_OK, TRUE); data->multi = NULL; /* clear the association */ - Curl_uint_tbl_remove(&multi->xfers, mid); - data->mid = UINT_MAX; + Curl_uint32_tbl_remove(&multi->xfers, mid); + data->mid = UINT32_MAX; #ifdef USE_LIBPSL if(data->psl == &multi->psl) @@ -2916,7 +2916,7 @@ CURLMcode curl_multi_cleanup(CURLM *m) if(data->state.internal) Curl_close(&data); } - while(Curl_uint_tbl_next(&multi->xfers, mid, &mid, &entry)); + while(Curl_uint32_tbl_next(&multi->xfers, mid, &mid, &entry)); } Curl_cpool_destroy(&multi->cpool); @@ -2924,7 +2924,7 @@ CURLMcode curl_multi_cleanup(CURLM *m) if(multi->admin) { CURL_TRC_M(multi->admin, "multi_cleanup, closing admin handle, done"); multi->admin->multi = NULL; - Curl_uint_tbl_remove(&multi->xfers, multi->admin->mid); + Curl_uint32_tbl_remove(&multi->xfers, multi->admin->mid); Curl_close(&multi->admin); } @@ -2952,16 +2952,16 @@ CURLMcode curl_multi_cleanup(CURLM *m) multi_xfer_bufs_free(multi); Curl_mntfy_cleanup(multi); #ifdef DEBUGBUILD - if(Curl_uint_tbl_count(&multi->xfers)) { + if(Curl_uint32_tbl_count(&multi->xfers)) { multi_xfer_tbl_dump(multi); DEBUGASSERT(0); } #endif - Curl_uint_bset_destroy(&multi->process); - Curl_uint_bset_destroy(&multi->dirty); - Curl_uint_bset_destroy(&multi->pending); - Curl_uint_bset_destroy(&multi->msgsent); - Curl_uint_tbl_destroy(&multi->xfers); + Curl_uint32_bset_destroy(&multi->process); + Curl_uint32_bset_destroy(&multi->dirty); + Curl_uint32_bset_destroy(&multi->pending); + Curl_uint32_bset_destroy(&multi->msgsent); + Curl_uint32_tbl_destroy(&multi->xfers); free(multi); return CURLM_OK; @@ -3120,17 +3120,17 @@ static CURLMcode multi_run_dirty(struct multi_run_ctx *mrc) { struct Curl_multi *multi = mrc->multi; CURLMcode result = CURLM_OK; - unsigned int mid; + uint32_t mid; - if(Curl_uint_bset_first(&multi->dirty, &mid)) { + if(Curl_uint32_bset_first(&multi->dirty, &mid)) { do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); if(data) { CURL_TRC_M(data, "multi_run_dirty"); - if(!Curl_uint_bset_contains(&multi->process, mid)) { + if(!Curl_uint32_bset_contains(&multi->process, mid)) { /* We are no longer processing this transfer */ - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); continue; } @@ -3148,10 +3148,10 @@ static CURLMcode multi_run_dirty(struct multi_run_ctx *mrc) } else { CURL_TRC_M(multi->admin, "multi_run_dirty, %u no longer found", mid); - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); } } - while(Curl_uint_bset_next(&multi->dirty, mid, &mid)); + while(Curl_uint32_bset_next(&multi->dirty, mid, &mid)); } out: @@ -3364,22 +3364,22 @@ CURLMcode curl_multi_socket_all(CURLM *m, int *running_handles) static bool multi_has_dirties(struct Curl_multi *multi) { - unsigned int mid; - if(Curl_uint_bset_first(&multi->dirty, &mid)) { + uint32_t mid; + if(Curl_uint32_bset_first(&multi->dirty, &mid)) { do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); if(data) { - if(Curl_uint_bset_contains(&multi->process, mid)) + if(Curl_uint32_bset_contains(&multi->process, mid)) return TRUE; /* We are no longer processing this transfer */ - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); } else { CURL_TRC_M(multi->admin, "dirty transfer %u no longer found", mid); - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); } } - while(Curl_uint_bset_next(&multi->dirty, mid, &mid)); + while(Curl_uint32_bset_next(&multi->dirty, mid, &mid)); } return FALSE; } @@ -3739,8 +3739,8 @@ static void move_pending_to_connect(struct Curl_multi *multi, DEBUGASSERT(data->mstate == MSTATE_PENDING); /* Remove this node from the pending set, add into process set */ - Curl_uint_bset_remove(&multi->pending, data->mid); - Curl_uint_bset_add(&multi->process, data->mid); + Curl_uint32_bset_remove(&multi->pending, data->mid); + Curl_uint32_bset_add(&multi->process, data->mid); multistate(data, MSTATE_CONNECT); Curl_multi_mark_dirty(data); /* make it run */ @@ -3762,8 +3762,8 @@ static void move_pending_to_connect(struct Curl_multi *multi, */ static void process_pending_handles(struct Curl_multi *multi) { - unsigned int mid; - if(Curl_uint_bset_first(&multi->pending, &mid)) { + uint32_t mid; + if(Curl_uint32_bset_first(&multi->pending, &mid)) { do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); if(data) { @@ -3771,10 +3771,10 @@ static void process_pending_handles(struct Curl_multi *multi) break; } /* transfer no longer known, should not happen */ - Curl_uint_bset_remove(&multi->pending, mid); + Curl_uint32_bset_remove(&multi->pending, mid); DEBUGASSERT(0); } - while(Curl_uint_bset_next(&multi->pending, mid, &mid)); + while(Curl_uint32_bset_next(&multi->pending, mid, &mid)); } } @@ -3799,19 +3799,19 @@ CURL **curl_multi_get_handles(CURLM *m) { struct Curl_multi *multi = m; void *entry; - unsigned int count = Curl_uint_tbl_count(&multi->xfers); + unsigned int count = Curl_uint32_tbl_count(&multi->xfers); CURL **a = malloc(sizeof(struct Curl_easy *) * (count + 1)); if(a) { unsigned int i = 0, mid; - if(Curl_uint_tbl_first(&multi->xfers, &mid, &entry)) { + if(Curl_uint32_tbl_first(&multi->xfers, &mid, &entry)) { do { struct Curl_easy *data = entry; DEBUGASSERT(i < count); if(!data->state.internal) a[i++] = data; } - while(Curl_uint_tbl_next(&multi->xfers, mid, &mid, &entry)); + while(Curl_uint32_tbl_next(&multi->xfers, mid, &mid, &entry)); } a[i] = NULL; /* last entry is a NULL */ } @@ -3823,7 +3823,7 @@ CURLMcode curl_multi_get_offt(CURLM *m, curl_off_t *pvalue) { struct Curl_multi *multi = m; - unsigned int n; + uint32_t n; if(!GOOD_MULTI_HANDLE(multi)) return CURLM_BAD_HANDLE; @@ -3832,22 +3832,22 @@ CURLMcode curl_multi_get_offt(CURLM *m, switch(info) { case CURLMINFO_XFERS_CURRENT: - n = Curl_uint_tbl_count(&multi->xfers); + n = Curl_uint32_tbl_count(&multi->xfers); if(n && multi->admin) --n; *pvalue = (curl_off_t)n; return CURLM_OK; case CURLMINFO_XFERS_RUNNING: - n = Curl_uint_bset_count(&multi->process); - if(n && Curl_uint_bset_contains(&multi->process, multi->admin->mid)) + n = Curl_uint32_bset_count(&multi->process); + if(n && Curl_uint32_bset_contains(&multi->process, multi->admin->mid)) --n; *pvalue = (curl_off_t)n; return CURLM_OK; case CURLMINFO_XFERS_PENDING: - *pvalue = (curl_off_t)Curl_uint_bset_count(&multi->pending); + *pvalue = (curl_off_t)Curl_uint32_bset_count(&multi->pending); return CURLM_OK; case CURLMINFO_XFERS_DONE: - *pvalue = (curl_off_t)Curl_uint_bset_count(&multi->msgsent); + *pvalue = (curl_off_t)Curl_uint32_bset_count(&multi->msgsent); return CURLM_OK; case CURLMINFO_XFERS_ADDED: *pvalue = multi->xfers_total_ever; @@ -4025,14 +4025,14 @@ static void multi_xfer_bufs_free(struct Curl_multi *multi) } struct Curl_easy *Curl_multi_get_easy(struct Curl_multi *multi, - unsigned int mid) + uint32_t mid) { - struct Curl_easy *data = Curl_uint_tbl_get(&multi->xfers, mid); + struct Curl_easy *data = Curl_uint32_tbl_get(&multi->xfers, mid); if(data && GOOD_EASY_HANDLE(data)) return data; CURL_TRC_M(multi->admin, "invalid easy handle in xfer table for mid=%u", mid); - Curl_uint_tbl_remove(&multi->xfers, mid); + Curl_uint32_tbl_remove(&multi->xfers, mid); return NULL; } @@ -4043,14 +4043,14 @@ unsigned int Curl_multi_xfers_running(struct Curl_multi *multi) void Curl_multi_mark_dirty(struct Curl_easy *data) { - if(data->multi && data->mid != UINT_MAX) - Curl_uint_bset_add(&data->multi->dirty, data->mid); + if(data->multi && data->mid != UINT32_MAX) + Curl_uint32_bset_add(&data->multi->dirty, data->mid); } void Curl_multi_clear_dirty(struct Curl_easy *data) { - if(data->multi && data->mid != UINT_MAX) - Curl_uint_bset_remove(&data->multi->dirty, data->mid); + if(data->multi && data->mid != UINT32_MAX) + Curl_uint32_bset_remove(&data->multi->dirty, data->mid); } CURLMcode curl_multi_notify_enable(CURLM *m, unsigned int notification) @@ -4072,7 +4072,7 @@ CURLMcode curl_multi_notify_disable(CURLM *m, unsigned int notification) } #ifdef DEBUGBUILD -static void multi_xfer_dump(struct Curl_multi *multi, unsigned int mid, +static void multi_xfer_dump(struct Curl_multi *multi, uint32_t mid, void *entry) { struct Curl_easy *data = entry; @@ -4092,14 +4092,14 @@ static void multi_xfer_dump(struct Curl_multi *multi, unsigned int mid, static void multi_xfer_tbl_dump(struct Curl_multi *multi) { - unsigned int mid; + uint32_t mid; void *entry; curl_mfprintf(stderr, "=== multi xfer table (count=%u, capacity=%u\n", - Curl_uint_tbl_count(&multi->xfers), - Curl_uint_tbl_capacity(&multi->xfers)); - if(Curl_uint_tbl_first(&multi->xfers, &mid, &entry)) { + Curl_uint32_tbl_count(&multi->xfers), + Curl_uint32_tbl_capacity(&multi->xfers)); + if(Curl_uint32_tbl_first(&multi->xfers, &mid, &entry)) { multi_xfer_dump(multi, mid, entry); - while(Curl_uint_tbl_next(&multi->xfers, mid, &mid, &entry)) + while(Curl_uint32_tbl_next(&multi->xfers, mid, &mid, &entry)) multi_xfer_dump(multi, mid, entry); } curl_mfprintf(stderr, "===\n"); diff --git a/lib/multi_ev.c b/lib/multi_ev.c index 086b037527a4..d5db331cf1f1 100644 --- a/lib/multi_ev.c +++ b/lib/multi_ev.c @@ -55,7 +55,7 @@ static void mev_in_callback(struct Curl_multi *multi, bool value) * what to supervise (CURL_POLL_IN/CURL_POLL_OUT/CURL_POLL_REMOVE) */ struct mev_sh_entry { - struct uint_spbset xfers; /* bitset of transfers `mid`s on this socket */ + struct uint32_spbset xfers; /* bitset of transfers `mid`s on this socket */ struct connectdata *conn; /* connection using this socket or NULL */ void *user_data; /* libcurl app data via curl_multi_assign() */ unsigned int action; /* CURL_POLL_IN/CURL_POLL_OUT we last told the @@ -84,7 +84,7 @@ static size_t mev_sh_entry_compare(void *k1, size_t k1_len, static void mev_sh_entry_dtor(void *freethis) { struct mev_sh_entry *entry = (struct mev_sh_entry *)freethis; - Curl_uint_spbset_destroy(&entry->xfers); + Curl_uint32_spbset_destroy(&entry->xfers); free(entry); } @@ -116,7 +116,7 @@ mev_sh_entry_add(struct Curl_hash *sh, curl_socket_t s) if(!check) return NULL; /* major failure */ - Curl_uint_spbset_init(&check->xfers); + Curl_uint32_spbset_init(&check->xfers); /* make/add new hash entry */ if(!Curl_hash_add(sh, (char *)&s, sizeof(curl_socket_t), check)) { @@ -135,13 +135,13 @@ static void mev_sh_entry_kill(struct Curl_multi *multi, curl_socket_t s) static size_t mev_sh_entry_user_count(struct mev_sh_entry *e) { - return Curl_uint_spbset_count(&e->xfers) + (e->conn ? 1 : 0); + return Curl_uint32_spbset_count(&e->xfers) + (e->conn ? 1 : 0); } static bool mev_sh_entry_xfer_known(struct mev_sh_entry *e, struct Curl_easy *data) { - return Curl_uint_spbset_contains(&e->xfers, data->mid); + return Curl_uint32_spbset_contains(&e->xfers, data->mid); } static bool mev_sh_entry_conn_known(struct mev_sh_entry *e, @@ -155,7 +155,7 @@ static bool mev_sh_entry_xfer_add(struct mev_sh_entry *e, { /* detect weird values */ DEBUGASSERT(mev_sh_entry_user_count(e) < 100000); - return Curl_uint_spbset_add(&e->xfers, data->mid); + return Curl_uint32_spbset_add(&e->xfers, data->mid); } static bool mev_sh_entry_conn_add(struct mev_sh_entry *e, @@ -174,9 +174,9 @@ static bool mev_sh_entry_conn_add(struct mev_sh_entry *e, static bool mev_sh_entry_xfer_remove(struct mev_sh_entry *e, struct Curl_easy *data) { - bool present = Curl_uint_spbset_contains(&e->xfers, data->mid); + bool present = Curl_uint32_spbset_contains(&e->xfers, data->mid); if(present) - Curl_uint_spbset_remove(&e->xfers, data->mid); + Curl_uint32_spbset_remove(&e->xfers, data->mid); return present; } @@ -356,7 +356,7 @@ static CURLMcode mev_pollset_diff(struct Curl_multi *multi, ", total=%u/%d (xfer/conn)", s, conn ? "connection" : "transfer", conn ? conn->connection_id : data->mid, - Curl_uint_spbset_count(&entry->xfers), + Curl_uint32_spbset_count(&entry->xfers), entry->conn ? 1 : 0); } else { @@ -424,7 +424,7 @@ static CURLMcode mev_pollset_diff(struct Curl_multi *multi, return mresult; CURL_TRC_M(data, "ev entry fd=%" FMT_SOCKET_T ", removed transfer, " "total=%u/%d (xfer/conn)", s, - Curl_uint_spbset_count(&entry->xfers), + Curl_uint32_spbset_count(&entry->xfers), entry->conn ? 1 : 0); } else { @@ -545,18 +545,18 @@ CURLMcode Curl_multi_ev_assess_conn(struct Curl_multi *multi, } CURLMcode Curl_multi_ev_assess_xfer_bset(struct Curl_multi *multi, - struct uint_bset *set) + struct uint32_bset *set) { - unsigned int mid; + uint32_t mid; CURLMcode result = CURLM_OK; - if(multi && multi->socket_cb && Curl_uint_bset_first(set, &mid)) { + if(multi && multi->socket_cb && Curl_uint32_bset_first(set, &mid)) { do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); if(data) result = Curl_multi_ev_assess_xfer(multi, data); } - while(!result && Curl_uint_bset_next(set, mid, &mid)); + while(!result && Curl_uint32_bset_next(set, mid, &mid)); } return result; } @@ -588,9 +588,9 @@ void Curl_multi_ev_dirty_xfers(struct Curl_multi *multi, and just move on. */ if(entry) { struct Curl_easy *data; - unsigned int mid; + uint32_t mid; - if(Curl_uint_spbset_first(&entry->xfers, &mid)) { + if(Curl_uint32_spbset_first(&entry->xfers, &mid)) { do { data = Curl_multi_get_easy(multi, mid); if(data) { @@ -598,10 +598,10 @@ void Curl_multi_ev_dirty_xfers(struct Curl_multi *multi, } else { CURL_TRC_M(multi->admin, "socket transfer %u no longer found", mid); - Curl_uint_spbset_remove(&entry->xfers, mid); + Curl_uint32_spbset_remove(&entry->xfers, mid); } } - while(Curl_uint_spbset_next(&entry->xfers, mid, &mid)); + while(Curl_uint32_spbset_next(&entry->xfers, mid, &mid)); } if(entry->conn) diff --git a/lib/multi_ev.h b/lib/multi_ev.h index 34548c323232..4e5b2a454d26 100644 --- a/lib/multi_ev.h +++ b/lib/multi_ev.h @@ -29,7 +29,7 @@ struct Curl_easy; struct Curl_multi; struct easy_pollset; -struct uint_bset; +struct uint32_bset; /* meta key for event pollset at easy handle or connection */ #define CURL_META_MEV_POLLSET "meta:mev:ps" @@ -55,7 +55,7 @@ CURLMcode Curl_multi_ev_assess_xfer(struct Curl_multi *multi, struct Curl_easy *data); /* Assess all easy handles on the list */ CURLMcode Curl_multi_ev_assess_xfer_bset(struct Curl_multi *multi, - struct uint_bset *set); + struct uint32_bset *set); /* Assess the connection by getting its current pollset */ CURLMcode Curl_multi_ev_assess_conn(struct Curl_multi *multi, struct Curl_easy *data, diff --git a/lib/multi_ntfy.c b/lib/multi_ntfy.c index fe7cc0503a76..d7913bbbfc97 100644 --- a/lib/multi_ntfy.c +++ b/lib/multi_ntfy.c @@ -39,8 +39,8 @@ struct mntfy_entry { - unsigned int mid; - unsigned int type; + uint32_t mid; + uint32_t type; }; #define CURL_MNTFY_CHUNK_SIZE 128 @@ -69,7 +69,7 @@ static void mnfty_chunk_reset(struct mntfy_chunk *chunk) static bool mntfy_chunk_append(struct mntfy_chunk *chunk, struct Curl_easy *data, - unsigned int type) + uint32_t type) { struct mntfy_entry *e; @@ -116,7 +116,7 @@ static void mntfy_chunk_dispatch_all(struct Curl_multi *multi, e = &chunk->entries[chunk->r_offset]; data = e->mid ? Curl_multi_get_easy(multi, e->mid) : multi->admin; /* only when notification has not been disabled in the meantime */ - if(data && Curl_uint_bset_contains(&multi->ntfy.enabled, e->type)) { + if(data && Curl_uint32_bset_contains(&multi->ntfy.enabled, e->type)) { /* this may cause new notifications to be added! */ CURL_TRC_M(multi->admin, "[NTFY] dispatch %d to xfer %u", e->type, e->mid); @@ -132,12 +132,12 @@ static void mntfy_chunk_dispatch_all(struct Curl_multi *multi, void Curl_mntfy_init(struct Curl_multi *multi) { memset(&multi->ntfy, 0, sizeof(multi->ntfy)); - Curl_uint_bset_init(&multi->ntfy.enabled); + Curl_uint32_bset_init(&multi->ntfy.enabled); } CURLMcode Curl_mntfy_resize(struct Curl_multi *multi) { - if(Curl_uint_bset_resize(&multi->ntfy.enabled, CURLMNOTIFY_EASY_DONE + 1)) + if(Curl_uint32_bset_resize(&multi->ntfy.enabled, CURLMNOTIFY_EASY_DONE + 1)) return CURLM_OUT_OF_MEMORY; return CURLM_OK; } @@ -150,14 +150,14 @@ void Curl_mntfy_cleanup(struct Curl_multi *multi) mnfty_chunk_destroy(chunk); } multi->ntfy.tail = NULL; - Curl_uint_bset_destroy(&multi->ntfy.enabled); + Curl_uint32_bset_destroy(&multi->ntfy.enabled); } CURLMcode Curl_mntfy_enable(struct Curl_multi *multi, unsigned int type) { if(type > CURLMNOTIFY_EASY_DONE) return CURLM_UNKNOWN_OPTION; - Curl_uint_bset_add(&multi->ntfy.enabled, type); + Curl_uint32_bset_add(&multi->ntfy.enabled, type); return CURLM_OK; } @@ -165,7 +165,7 @@ CURLMcode Curl_mntfy_disable(struct Curl_multi *multi, unsigned int type) { if(type > CURLMNOTIFY_EASY_DONE) return CURLM_UNKNOWN_OPTION; - Curl_uint_bset_remove(&multi->ntfy.enabled, type); + Curl_uint32_bset_remove(&multi->ntfy.enabled, (uint32_t)type); return CURLM_OK; } @@ -173,12 +173,12 @@ void Curl_mntfy_add(struct Curl_easy *data, unsigned int type) { struct Curl_multi *multi = data ? data->multi : NULL; if(multi && multi->ntfy.ntfy_cb && !multi->ntfy.failure && - Curl_uint_bset_contains(&multi->ntfy.enabled, type)) { + Curl_uint32_bset_contains(&multi->ntfy.enabled, (uint32_t)type)) { /* append to list of outstanding notifications */ struct mntfy_chunk *tail = mntfy_non_full_tail(&multi->ntfy); CURL_TRC_M(data, "[NTFY] add %d for xfer %u", type, data->mid); if(tail) - mntfy_chunk_append(tail, data, type); + mntfy_chunk_append(tail, data, (uint32_t)type); else multi->ntfy.failure = CURLM_OUT_OF_MEMORY; } diff --git a/lib/multi_ntfy.h b/lib/multi_ntfy.h index d920b3295d4b..c3094a9ebe71 100644 --- a/lib/multi_ntfy.h +++ b/lib/multi_ntfy.h @@ -32,7 +32,7 @@ struct Curl_multi; struct curl_multi_ntfy { curl_notify_callback ntfy_cb; void *ntfy_cb_data; - struct uint_bset enabled; + struct uint32_bset enabled; CURLMcode failure; struct mntfy_chunk *head; struct mntfy_chunk *tail; diff --git a/lib/multihandle.h b/lib/multihandle.h index fbb8bdfeeb59..a267a209ee56 100644 --- a/lib/multihandle.h +++ b/lib/multihandle.h @@ -91,12 +91,12 @@ struct Curl_multi { unsigned int xfers_alive; /* amount of added transfers that have not yet reached COMPLETE state */ curl_off_t xfers_total_ever; /* total of added transfers, ever. */ - struct uint_tbl xfers; /* transfers added to this multi */ + struct uint32_tbl xfers; /* transfers added to this multi */ /* Each transfer's mid may be present in at most one of these */ - struct uint_bset process; /* transfer being processed */ - struct uint_bset dirty; /* transfer to be run NOW, e.g. ASAP. */ - struct uint_bset pending; /* transfers in waiting (conn limit etc.) */ - struct uint_bset msgsent; /* transfers done with message for application */ + struct uint32_bset process; /* transfer being processed */ + struct uint32_bset dirty; /* transfer to be run NOW, e.g. ASAP. */ + struct uint32_bset pending; /* transfers in waiting (conn limit etc.) */ + struct uint32_bset msgsent; /* transfers done with message for application */ struct Curl_llist msglist; /* a list of messages from completed transfers */ diff --git a/lib/multiif.h b/lib/multiif.h index 81cf665bd3d8..62c68c9cedf3 100644 --- a/lib/multiif.h +++ b/lib/multiif.h @@ -153,7 +153,7 @@ void Curl_multi_xfer_sockbuf_release(struct Curl_easy *data, char *buf); * Returns NULL if not found. */ struct Curl_easy *Curl_multi_get_easy(struct Curl_multi *multi, - unsigned int mid); + uint32_t mid); /* Get the # of transfers current in process/pending. */ unsigned int Curl_multi_xfers_running(struct Curl_multi *multi); diff --git a/lib/uint-bset.c b/lib/uint-bset.c index 7b822344c1f6..82440c56378a 100644 --- a/lib/uint-bset.c +++ b/lib/uint-bset.c @@ -30,32 +30,32 @@ #include "memdebug.h" #ifdef DEBUGBUILD -#define CURL_UINT_BSET_MAGIC 0x62757473 +#define CURL_UINT32_BSET_MAGIC 0x62757473 #endif -void Curl_uint_bset_init(struct uint_bset *bset) +void Curl_uint32_bset_init(struct uint32_bset *bset) { memset(bset, 0, sizeof(*bset)); #ifdef DEBUGBUILD - bset->init = CURL_UINT_BSET_MAGIC; + bset->init = CURL_UINT32_BSET_MAGIC; #endif } -CURLcode Curl_uint_bset_resize(struct uint_bset *bset, unsigned int nmax) +CURLcode Curl_uint32_bset_resize(struct uint32_bset *bset, uint32_t nmax) { - unsigned int nslots = (nmax < (UINT_MAX-63)) ? - ((nmax + 63) / 64) : (UINT_MAX / 64); + uint32_t nslots = (nmax < (UINT32_MAX-63)) ? + ((nmax + 63) / 64) : (UINT32_MAX / 64); - DEBUGASSERT(bset->init == CURL_UINT_BSET_MAGIC); + DEBUGASSERT(bset->init == CURL_UINT32_BSET_MAGIC); if(nslots != bset->nslots) { - curl_uint64_t *slots = calloc(nslots, sizeof(curl_uint64_t)); + uint64_t *slots = calloc(nslots, sizeof(uint64_t)); if(!slots) return CURLE_OUT_OF_MEMORY; if(bset->slots) { memcpy(slots, bset->slots, - (CURLMIN(nslots, bset->nslots) * sizeof(curl_uint64_t))); + (CURLMIN(nslots, bset->nslots) * sizeof(uint64_t))); free(bset->slots); } bset->slots = slots; @@ -66,24 +66,24 @@ CURLcode Curl_uint_bset_resize(struct uint_bset *bset, unsigned int nmax) } -void Curl_uint_bset_destroy(struct uint_bset *bset) +void Curl_uint32_bset_destroy(struct uint32_bset *bset) { - DEBUGASSERT(bset->init == CURL_UINT_BSET_MAGIC); + DEBUGASSERT(bset->init == CURL_UINT32_BSET_MAGIC); free(bset->slots); memset(bset, 0, sizeof(*bset)); } #ifdef UNITTESTS -UNITTEST unsigned int Curl_uint_bset_capacity(struct uint_bset *bset) +UNITTEST uint32_t Curl_uint32_bset_capacity(struct uint32_bset *bset) { return bset->nslots * 64; } #endif -unsigned int Curl_uint_bset_count(struct uint_bset *bset) +uint32_t Curl_uint32_bset_count(struct uint32_bset *bset) { - unsigned int i; - unsigned int n = 0; + uint32_t i; + uint32_t n = 0; for(i = 0; i < bset->nslots; ++i) { if(bset->slots[i]) n += CURL_POPCOUNT64(bset->slots[i]); @@ -91,9 +91,9 @@ unsigned int Curl_uint_bset_count(struct uint_bset *bset) return n; } -bool Curl_uint_bset_empty(struct uint_bset *bset) +bool Curl_uint32_bset_empty(struct uint32_bset *bset) { - unsigned int i; + uint32_t i; for(i = bset->first_slot_used; i < bset->nslots; ++i) { if(bset->slots[i]) return FALSE; @@ -102,47 +102,47 @@ bool Curl_uint_bset_empty(struct uint_bset *bset) } -void Curl_uint_bset_clear(struct uint_bset *bset) +void Curl_uint32_bset_clear(struct uint32_bset *bset) { if(bset->nslots) { - memset(bset->slots, 0, bset->nslots * sizeof(curl_uint64_t)); - bset->first_slot_used = UINT_MAX; + memset(bset->slots, 0, bset->nslots * sizeof(uint64_t)); + bset->first_slot_used = UINT32_MAX; } } -bool Curl_uint_bset_add(struct uint_bset *bset, unsigned int i) +bool Curl_uint32_bset_add(struct uint32_bset *bset, uint32_t i) { - unsigned int islot = i / 64; + uint32_t islot = i / 64; if(islot >= bset->nslots) return FALSE; - bset->slots[islot] |= ((curl_uint64_t)1 << (i % 64)); + bset->slots[islot] |= ((uint64_t)1 << (i % 64)); if(islot < bset->first_slot_used) bset->first_slot_used = islot; return TRUE; } -void Curl_uint_bset_remove(struct uint_bset *bset, unsigned int i) +void Curl_uint32_bset_remove(struct uint32_bset *bset, uint32_t i) { size_t islot = i / 64; if(islot < bset->nslots) - bset->slots[islot] &= ~((curl_uint64_t)1 << (i % 64)); + bset->slots[islot] &= ~((uint64_t)1 << (i % 64)); } -bool Curl_uint_bset_contains(struct uint_bset *bset, unsigned int i) +bool Curl_uint32_bset_contains(struct uint32_bset *bset, uint32_t i) { - unsigned int islot = i / 64; + uint32_t islot = i / 64; if(islot >= bset->nslots) return FALSE; - return (bset->slots[islot] & ((curl_uint64_t)1 << (i % 64))) != 0; + return (bset->slots[islot] & ((uint64_t)1 << (i % 64))) != 0; } -bool Curl_uint_bset_first(struct uint_bset *bset, unsigned int *pfirst) +bool Curl_uint32_bset_first(struct uint32_bset *bset, uint32_t *pfirst) { - unsigned int i; + uint32_t i; for(i = bset->first_slot_used; i < bset->nslots; ++i) { if(bset->slots[i]) { *pfirst = (i * 64) + CURL_CTZ64(bset->slots[i]); @@ -150,15 +150,15 @@ bool Curl_uint_bset_first(struct uint_bset *bset, unsigned int *pfirst) return TRUE; } } - bset->first_slot_used = *pfirst = UINT_MAX; + bset->first_slot_used = *pfirst = UINT32_MAX; return FALSE; } -bool Curl_uint_bset_next(struct uint_bset *bset, unsigned int last, - unsigned int *pnext) +bool Curl_uint32_bset_next(struct uint32_bset *bset, uint32_t last, + uint32_t *pnext) { - unsigned int islot; - curl_uint64_t x; + uint32_t islot; + uint64_t x; ++last; /* look for number one higher than last */ islot = last / 64; /* the slot this would be in */ @@ -178,42 +178,42 @@ bool Curl_uint_bset_next(struct uint_bset *bset, unsigned int last, } } } - *pnext = UINT_MAX; /* a value we cannot store */ + *pnext = UINT32_MAX; /* a value we cannot store */ return FALSE; } #ifdef CURL_POPCOUNT64_IMPLEMENT -unsigned int Curl_popcount64(curl_uint64_t x) +uint32_t Curl_popcount64(uint64_t x) { /* Compute the "Hamming Distance" between 'x' and 0, * which is the number of set bits in 'x'. * See: https://en.wikipedia.org/wiki/Hamming_weight */ - const curl_uint64_t m1 = 0x5555555555555555LL; /* 0101+ */ - const curl_uint64_t m2 = 0x3333333333333333LL; /* 00110011+ */ - const curl_uint64_t m4 = 0x0f0f0f0f0f0f0f0fLL; /* 00001111+ */ + const uint64_t m1 = 0x5555555555555555LL; /* 0101+ */ + const uint64_t m2 = 0x3333333333333333LL; /* 00110011+ */ + const uint64_t m4 = 0x0f0f0f0f0f0f0f0fLL; /* 00001111+ */ /* 1 + 256^1 + 256^2 + 256^3 + ... + 256^7 */ - const curl_uint64_t h01 = 0x0101010101010101LL; + const uint64_t h01 = 0x0101010101010101LL; x -= (x >> 1) & m1; /* replace every 2 bits with bits present */ x = (x & m2) + ((x >> 2) & m2); /* replace every nibble with bits present */ x = (x + (x >> 4)) & m4; /* replace every byte with bits present */ /* top 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ... which makes the * top byte the sum of all individual 8 bytes, throw away the rest */ - return (unsigned int)((x * h01) >> 56); + return (uint32_t)((x * h01) >> 56); } #endif /* CURL_POPCOUNT64_IMPLEMENT */ #ifdef CURL_CTZ64_IMPLEMENT -unsigned int Curl_ctz64(curl_uint64_t x) +uint32_t Curl_ctz64(uint64_t x) { - /* count trailing zeros in a curl_uint64_t. + /* count trailing zeros in a uint64_t. * divide and conquer to find the number of lower 0 bits */ - const curl_uint64_t ml32 = 0xFFFFFFFF; /* lower 32 bits */ - const curl_uint64_t ml16 = 0x0000FFFF; /* lower 16 bits */ - const curl_uint64_t ml8 = 0x000000FF; /* lower 8 bits */ - const curl_uint64_t ml4 = 0x0000000F; /* lower 4 bits */ - const curl_uint64_t ml2 = 0x00000003; /* lower 2 bits */ - unsigned int n; + const uint64_t ml32 = 0xFFFFFFFF; /* lower 32 bits */ + const uint64_t ml16 = 0x0000FFFF; /* lower 16 bits */ + const uint64_t ml8 = 0x000000FF; /* lower 8 bits */ + const uint64_t ml4 = 0x0000000F; /* lower 4 bits */ + const uint64_t ml2 = 0x00000003; /* lower 2 bits */ + uint32_t n; if(!x) return 64; @@ -238,6 +238,6 @@ unsigned int Curl_ctz64(curl_uint64_t x) n = n + 2; x = x >> 2; } - return n - (unsigned int)(x & 1); + return n - (uint32_t)(x & 1); } #endif /* CURL_CTZ64_IMPLEMENT */ diff --git a/lib/uint-bset.h b/lib/uint-bset.h index cc405cc656e3..5e5bbdb8fc0b 100644 --- a/lib/uint-bset.h +++ b/lib/uint-bset.h @@ -39,51 +39,51 @@ * the price of slightly slower operations. */ -struct uint_bset { - curl_uint64_t *slots; - unsigned int nslots; - unsigned int first_slot_used; +struct uint32_bset { + uint64_t *slots; + uint32_t nslots; + uint32_t first_slot_used; #ifdef DEBUGBUILD int init; #endif }; /* Initialize the bitset with capacity 0. */ -void Curl_uint_bset_init(struct uint_bset *bset); +void Curl_uint32_bset_init(struct uint32_bset *bset); /* Resize the bitset capacity to hold numbers from 0 to `nmax`, * which rounds up `nmax` to the next multiple of 64. */ -CURLcode Curl_uint_bset_resize(struct uint_bset *bset, unsigned int nmax); +CURLcode Curl_uint32_bset_resize(struct uint32_bset *bset, uint32_t nmax); /* Destroy the bitset, freeing all resources. */ -void Curl_uint_bset_destroy(struct uint_bset *bset); +void Curl_uint32_bset_destroy(struct uint32_bset *bset); /* Get the bitset capacity, e.g. can hold numbers from 0 to capacity - 1. */ -unsigned int Curl_uint_bset_capacity(struct uint_bset *bset); +uint32_t Curl_uint32_bset_capacity(struct uint32_bset *bset); /* Get the cardinality of the bitset, e.g. numbers present in the set. */ -unsigned int Curl_uint_bset_count(struct uint_bset *bset); +uint32_t Curl_uint32_bset_count(struct uint32_bset *bset); /* TRUE of bitset is empty */ -bool Curl_uint_bset_empty(struct uint_bset *bset); +bool Curl_uint32_bset_empty(struct uint32_bset *bset); /* Clear the bitset, making it empty. */ -void Curl_uint_bset_clear(struct uint_bset *bset); +void Curl_uint32_bset_clear(struct uint32_bset *bset); /* Add the number `i` to the bitset. Return FALSE if the number is * outside the set's capacity. * Numbers can be added more than once, without making a difference. */ -bool Curl_uint_bset_add(struct uint_bset *bset, unsigned int i); +bool Curl_uint32_bset_add(struct uint32_bset *bset, uint32_t i); /* Remove the number `i` from the bitset. */ -void Curl_uint_bset_remove(struct uint_bset *bset, unsigned int i); +void Curl_uint32_bset_remove(struct uint32_bset *bset, uint32_t i); /* Return TRUE if the bitset contains number `i`. */ -bool Curl_uint_bset_contains(struct uint_bset *bset, unsigned int i); +bool Curl_uint32_bset_contains(struct uint32_bset *bset, uint32_t i); /* Get the first number in the bitset, e.g. the smallest. * Returns FALSE when the bitset is empty. */ -bool Curl_uint_bset_first(struct uint_bset *bset, unsigned int *pfirst); +bool Curl_uint32_bset_first(struct uint32_bset *bset, uint32_t *pfirst); /* Get the next number in the bitset, following `last` in natural order. * Put another way, this is the smallest number greater than `last` in @@ -96,20 +96,20 @@ bool Curl_uint_bset_first(struct uint_bset *bset, unsigned int *pfirst); * - added numbers lower than 'last' will not show up. * - removed numbers lower or equal to 'last' will not show up. * - removed numbers higher than 'last' will not be visited. */ -bool Curl_uint_bset_next(struct uint_bset *bset, unsigned int last, - unsigned int *pnext); +bool Curl_uint32_bset_next(struct uint32_bset *bset, uint32_t last, + uint32_t *pnext); #ifndef CURL_POPCOUNT64 #define CURL_POPCOUNT64(x) Curl_popcount64(x) #define CURL_POPCOUNT64_IMPLEMENT -unsigned int Curl_popcount64(curl_uint64_t x); +uint32_t Curl_popcount64(uint64_t x); #endif /* !CURL_POPCOUNT64 */ #ifndef CURL_CTZ64 #define CURL_CTZ64(x) Curl_ctz64(x) #define CURL_CTZ64_IMPLEMENT -unsigned int Curl_ctz64(curl_uint64_t x); +uint32_t Curl_ctz64(uint64_t x); #endif /* !CURL_CTZ64 */ #endif /* HEADER_CURL_UINT_BSET_H */ diff --git a/lib/uint-hash.c b/lib/uint-hash.c index 6c665078876c..4677c6ac9128 100644 --- a/lib/uint-hash.c +++ b/lib/uint-hash.c @@ -34,10 +34,10 @@ /* random patterns for API verification */ #ifdef DEBUGBUILD -#define CURL_UINTHASHINIT 0x7117e779 +#define CURL_UINT32_HASHINIT 0x7117e779 #endif -static unsigned int uint_hash_hash(unsigned int id, unsigned int slots) +static uint32_t uint32_hash_hash(uint32_t id, uint32_t slots) { return (id % slots); } @@ -46,12 +46,12 @@ static unsigned int uint_hash_hash(unsigned int id, unsigned int slots) struct uint_hash_entry { struct uint_hash_entry *next; void *value; - unsigned int id; + uint32_t id; }; -void Curl_uint_hash_init(struct uint_hash *h, - unsigned int slots, - Curl_uint_hash_dtor *dtor) +void Curl_uint32_hash_init(struct uint_hash *h, + uint32_t slots, + Curl_uint32_hash_dtor *dtor) { DEBUGASSERT(h); DEBUGASSERT(slots); @@ -61,11 +61,11 @@ void Curl_uint_hash_init(struct uint_hash *h, h->size = 0; h->slots = slots; #ifdef DEBUGBUILD - h->init = CURL_UINTHASHINIT; + h->init = CURL_UINT32_HASHINIT; #endif } -static struct uint_hash_entry *uint_hash_mk_entry(unsigned int id, void *value) +static struct uint_hash_entry *uint32_hash_mk_entry(uint32_t id, void *value) { struct uint_hash_entry *e; @@ -79,8 +79,8 @@ static struct uint_hash_entry *uint_hash_mk_entry(unsigned int id, void *value) return e; } -static void uint_hash_entry_clear(struct uint_hash *h, - struct uint_hash_entry *e) +static void uint32_hash_entry_clear(struct uint_hash *h, + struct uint_hash_entry *e) { DEBUGASSERT(h); DEBUGASSERT(e); @@ -91,78 +91,78 @@ static void uint_hash_entry_clear(struct uint_hash *h, } } -static void uint_hash_entry_destroy(struct uint_hash *h, - struct uint_hash_entry *e) +static void uint32_hash_entry_destroy(struct uint_hash *h, + struct uint_hash_entry *e) { - uint_hash_entry_clear(h, e); + uint32_hash_entry_clear(h, e); free(e); } -static void uint_hash_entry_unlink(struct uint_hash *h, - struct uint_hash_entry **he_anchor, - struct uint_hash_entry *he) +static void uint32_hash_entry_unlink(struct uint_hash *h, + struct uint_hash_entry **he_anchor, + struct uint_hash_entry *he) { *he_anchor = he->next; --h->size; } -static void uint_hash_elem_link(struct uint_hash *h, - struct uint_hash_entry **he_anchor, - struct uint_hash_entry *he) +static void uint32_hash_elem_link(struct uint_hash *h, + struct uint_hash_entry **he_anchor, + struct uint_hash_entry *he) { he->next = *he_anchor; *he_anchor = he; ++h->size; } -#define CURL_UINT_HASH_SLOT(h,id) h->table[uint_hash_hash(id, h->slots)] -#define CURL_UINT_HASH_SLOT_ADDR(h,id) &CURL_UINT_HASH_SLOT(h,id) +#define CURL_UINT32_HASH_SLOT(h,id) h->table[uint32_hash_hash(id, h->slots)] +#define CURL_UINT32_HASH_SLOT_ADDR(h,id) &CURL_UINT32_HASH_SLOT(h,id) -bool Curl_uint_hash_set(struct uint_hash *h, unsigned int id, void *value) +bool Curl_uint32_hash_set(struct uint_hash *h, uint32_t id, void *value) { struct uint_hash_entry *he, **slot; DEBUGASSERT(h); DEBUGASSERT(h->slots); - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); if(!h->table) { h->table = calloc(h->slots, sizeof(*he)); if(!h->table) return FALSE; /* OOM */ } - slot = CURL_UINT_HASH_SLOT_ADDR(h, id); + slot = CURL_UINT32_HASH_SLOT_ADDR(h, id); for(he = *slot; he; he = he->next) { if(he->id == id) { /* existing key entry, overwrite by clearing old pointer */ - uint_hash_entry_clear(h, he); + uint32_hash_entry_clear(h, he); he->value = value; return TRUE; } } - he = uint_hash_mk_entry(id, value); + he = uint32_hash_mk_entry(id, value); if(!he) return FALSE; /* OOM */ - uint_hash_elem_link(h, slot, he); + uint32_hash_elem_link(h, slot, he); return TRUE; } -bool Curl_uint_hash_remove(struct uint_hash *h, unsigned int id) +bool Curl_uint32_hash_remove(struct uint_hash *h, uint32_t id) { DEBUGASSERT(h); DEBUGASSERT(h->slots); - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); if(h->table) { struct uint_hash_entry *he, **he_anchor; - he_anchor = CURL_UINT_HASH_SLOT_ADDR(h, id); + he_anchor = CURL_UINT32_HASH_SLOT_ADDR(h, id); while(*he_anchor) { he = *he_anchor; if(id == he->id) { - uint_hash_entry_unlink(h, he_anchor, he); - uint_hash_entry_destroy(h, he); + uint32_hash_entry_unlink(h, he_anchor, he); + uint32_hash_entry_destroy(h, he); return TRUE; } he_anchor = &he->next; @@ -171,14 +171,14 @@ bool Curl_uint_hash_remove(struct uint_hash *h, unsigned int id) return FALSE; } -void *Curl_uint_hash_get(struct uint_hash *h, unsigned int id) +void *Curl_uint32_hash_get(struct uint_hash *h, uint32_t id) { DEBUGASSERT(h); - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); if(h->table) { struct uint_hash_entry *he; DEBUGASSERT(h->slots); - he = CURL_UINT_HASH_SLOT(h, id); + he = CURL_UINT32_HASH_SLOT(h, id); while(he) { if(id == he->id) { return he->value; @@ -194,28 +194,28 @@ static void uint_hash_clear(struct uint_hash *h) if(h && h->table) { struct uint_hash_entry *he, **he_anchor; size_t i; - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); for(i = 0; i < h->slots; ++i) { he_anchor = &h->table[i]; while(*he_anchor) { he = *he_anchor; - uint_hash_entry_unlink(h, he_anchor, he); - uint_hash_entry_destroy(h, he); + uint32_hash_entry_unlink(h, he_anchor, he); + uint32_hash_entry_destroy(h, he); } } } } #ifdef UNITTESTS -UNITTEST void Curl_uint_hash_clear(struct uint_hash *h) +UNITTEST void Curl_uint32_hash_clear(struct uint_hash *h) { uint_hash_clear(h); } #endif -void Curl_uint_hash_destroy(struct uint_hash *h) +void Curl_uint32_hash_destroy(struct uint_hash *h) { - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); if(h->table) { uint_hash_clear(h); Curl_safefree(h->table); @@ -224,20 +224,20 @@ void Curl_uint_hash_destroy(struct uint_hash *h) h->slots = 0; } -unsigned int Curl_uint_hash_count(struct uint_hash *h) +uint32_t Curl_uint32_hash_count(struct uint_hash *h) { - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); return h->size; } -void Curl_uint_hash_visit(struct uint_hash *h, - Curl_uint_hash_visit_cb *cb, - void *user_data) +void Curl_uint32_hash_visit(struct uint_hash *h, + Curl_uint32_hash_visit_cb *cb, + void *user_data) { if(h && h->table && cb) { struct uint_hash_entry *he; size_t i; - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); for(i = 0; i < h->slots; ++i) { for(he = h->table[i]; he; he = he->next) { if(!cb(he->id, he->value, user_data)) diff --git a/lib/uint-hash.h b/lib/uint-hash.h index 1b52dba4c470..330f61208bfa 100644 --- a/lib/uint-hash.h +++ b/lib/uint-hash.h @@ -30,39 +30,39 @@ #include "llist.h" -/* A version with unsigned int as key */ -typedef void Curl_uint_hash_dtor(unsigned int id, void *value); +/* A version with uint32_t as key */ +typedef void Curl_uint32_hash_dtor(uint32_t id, void *value); struct uint_hash_entry; -/* Hash for `unsigned int` as key */ +/* Hash for `uint32_t` as key */ struct uint_hash { struct uint_hash_entry **table; - Curl_uint_hash_dtor *dtor; - unsigned int slots; - unsigned int size; + Curl_uint32_hash_dtor *dtor; + uint32_t slots; + uint32_t size; #ifdef DEBUGBUILD int init; #endif }; -void Curl_uint_hash_init(struct uint_hash *h, - unsigned int slots, - Curl_uint_hash_dtor *dtor); -void Curl_uint_hash_destroy(struct uint_hash *h); -void Curl_uint_hash_clear(struct uint_hash *h); +void Curl_uint32_hash_init(struct uint_hash *h, + uint32_t slots, + Curl_uint32_hash_dtor *dtor); +void Curl_uint32_hash_destroy(struct uint_hash *h); +void Curl_uint32_hash_clear(struct uint_hash *h); -bool Curl_uint_hash_set(struct uint_hash *h, unsigned int id, void *value); -bool Curl_uint_hash_remove(struct uint_hash *h, unsigned int id); -void *Curl_uint_hash_get(struct uint_hash *h, unsigned int id); -unsigned int Curl_uint_hash_count(struct uint_hash *h); +bool Curl_uint32_hash_set(struct uint_hash *h, uint32_t id, void *value); +bool Curl_uint32_hash_remove(struct uint_hash *h, uint32_t id); +void *Curl_uint32_hash_get(struct uint_hash *h, uint32_t id); +uint32_t Curl_uint32_hash_count(struct uint_hash *h); -typedef bool Curl_uint_hash_visit_cb(unsigned int id, void *value, - void *user_data); +typedef bool Curl_uint32_hash_visit_cb(uint32_t id, void *value, + void *user_data); -void Curl_uint_hash_visit(struct uint_hash *h, - Curl_uint_hash_visit_cb *cb, - void *user_data); +void Curl_uint32_hash_visit(struct uint_hash *h, + Curl_uint32_hash_visit_cb *cb, + void *user_data); #endif /* HEADER_CURL_UINT_HASH_H */ diff --git a/lib/uint-spbset.c b/lib/uint-spbset.c index 2e8e2a139e74..f250bcb1b43f 100644 --- a/lib/uint-spbset.c +++ b/lib/uint-spbset.c @@ -31,33 +31,33 @@ #include "memdebug.h" #ifdef DEBUGBUILD -#define CURL_UINT_SPBSET_MAGIC 0x70737362 +#define CURL_UINT32_SPBSET_MAGIC 0x70737362 #endif /* Clear the bitset, making it empty. */ -UNITTEST void Curl_uint_spbset_clear(struct uint_spbset *bset); +UNITTEST void Curl_uint32_spbset_clear(struct uint32_spbset *bset); -void Curl_uint_spbset_init(struct uint_spbset *bset) +void Curl_uint32_spbset_init(struct uint32_spbset *bset) { memset(bset, 0, sizeof(*bset)); #ifdef DEBUGBUILD - bset->init = CURL_UINT_SPBSET_MAGIC; + bset->init = CURL_UINT32_SPBSET_MAGIC; #endif } -void Curl_uint_spbset_destroy(struct uint_spbset *bset) +void Curl_uint32_spbset_destroy(struct uint32_spbset *bset) { - DEBUGASSERT(bset->init == CURL_UINT_SPBSET_MAGIC); - Curl_uint_spbset_clear(bset); + DEBUGASSERT(bset->init == CURL_UINT32_SPBSET_MAGIC); + Curl_uint32_spbset_clear(bset); } -unsigned int Curl_uint_spbset_count(struct uint_spbset *bset) +uint32_t Curl_uint32_spbset_count(struct uint32_spbset *bset) { - struct uint_spbset_chunk *chunk; - unsigned int i, n = 0; + struct uint32_spbset_chunk *chunk; + uint32_t i, n = 0; for(chunk = &bset->head; chunk; chunk = chunk->next) { - for(i = 0; i < CURL_UINT_SPBSET_CH_SLOTS; ++i) { + for(i = 0; i < CURL_UINT32_SPBSET_CH_SLOTS; ++i) { if(chunk->slots[i]) n += CURL_POPCOUNT64(chunk->slots[i]); } @@ -65,13 +65,13 @@ unsigned int Curl_uint_spbset_count(struct uint_spbset *bset) return n; } -bool Curl_uint_spbset_empty(struct uint_spbset *bset) +bool Curl_uint32_spbset_empty(struct uint32_spbset *bset) { - struct uint_spbset_chunk *chunk; - unsigned int i; + struct uint32_spbset_chunk *chunk; + uint32_t i; for(chunk = &bset->head; chunk; chunk = chunk->next) { - for(i = 0; i < CURL_UINT_SPBSET_CH_SLOTS; ++i) { + for(i = 0; i < CURL_UINT32_SPBSET_CH_SLOTS; ++i) { if(chunk->slots[i]) return FALSE; } @@ -79,9 +79,9 @@ bool Curl_uint_spbset_empty(struct uint_spbset *bset) return TRUE; } -UNITTEST void Curl_uint_spbset_clear(struct uint_spbset *bset) +UNITTEST void Curl_uint32_spbset_clear(struct uint32_spbset *bset) { - struct uint_spbset_chunk *next, *chunk; + struct uint32_spbset_chunk *next, *chunk; for(chunk = bset->head.next; chunk; chunk = next) { next = chunk->next; @@ -91,11 +91,11 @@ UNITTEST void Curl_uint_spbset_clear(struct uint_spbset *bset) } -static struct uint_spbset_chunk * -uint_spbset_get_chunk(struct uint_spbset *bset, unsigned int i, bool grow) +static struct uint32_spbset_chunk * +uint32_spbset_get_chunk(struct uint32_spbset *bset, uint32_t i, bool grow) { - struct uint_spbset_chunk *chunk, **panchor = NULL; - unsigned int i_offset = (i & ~CURL_UINT_SPBSET_CH_MASK); + struct uint32_spbset_chunk *chunk, **panchor = NULL; + uint32_t i_offset = (i & ~CURL_UINT32_SPBSET_CH_MASK); if(!bset) return NULL; @@ -134,61 +134,61 @@ uint_spbset_get_chunk(struct uint_spbset *bset, unsigned int i, bool grow) } -bool Curl_uint_spbset_add(struct uint_spbset *bset, unsigned int i) +bool Curl_uint32_spbset_add(struct uint32_spbset *bset, uint32_t i) { - struct uint_spbset_chunk *chunk; - unsigned int i_chunk; + struct uint32_spbset_chunk *chunk; + uint32_t i_chunk; - chunk = uint_spbset_get_chunk(bset, i, TRUE); + chunk = uint32_spbset_get_chunk(bset, i, TRUE); if(!chunk) return FALSE; DEBUGASSERT(i >= chunk->offset); i_chunk = (i - chunk->offset); - DEBUGASSERT((i_chunk / 64) < CURL_UINT_SPBSET_CH_SLOTS); - chunk->slots[(i_chunk / 64)] |= ((curl_uint64_t)1 << (i_chunk % 64)); + DEBUGASSERT((i_chunk / 64) < CURL_UINT32_SPBSET_CH_SLOTS); + chunk->slots[(i_chunk / 64)] |= ((uint64_t)1 << (i_chunk % 64)); return TRUE; } -void Curl_uint_spbset_remove(struct uint_spbset *bset, unsigned int i) +void Curl_uint32_spbset_remove(struct uint32_spbset *bset, uint32_t i) { - struct uint_spbset_chunk *chunk; - unsigned int i_chunk; + struct uint32_spbset_chunk *chunk; + uint32_t i_chunk; - chunk = uint_spbset_get_chunk(bset, i, FALSE); + chunk = uint32_spbset_get_chunk(bset, i, FALSE); if(chunk) { DEBUGASSERT(i >= chunk->offset); i_chunk = (i - chunk->offset); - DEBUGASSERT((i_chunk / 64) < CURL_UINT_SPBSET_CH_SLOTS); - chunk->slots[(i_chunk / 64)] &= ~((curl_uint64_t)1 << (i_chunk % 64)); + DEBUGASSERT((i_chunk / 64) < CURL_UINT32_SPBSET_CH_SLOTS); + chunk->slots[(i_chunk / 64)] &= ~((uint64_t)1 << (i_chunk % 64)); } } -bool Curl_uint_spbset_contains(struct uint_spbset *bset, unsigned int i) +bool Curl_uint32_spbset_contains(struct uint32_spbset *bset, uint32_t i) { - struct uint_spbset_chunk *chunk; - unsigned int i_chunk; + struct uint32_spbset_chunk *chunk; + uint32_t i_chunk; - chunk = uint_spbset_get_chunk(bset, i, FALSE); + chunk = uint32_spbset_get_chunk(bset, i, FALSE); if(chunk) { DEBUGASSERT(i >= chunk->offset); i_chunk = (i - chunk->offset); - DEBUGASSERT((i_chunk / 64) < CURL_UINT_SPBSET_CH_SLOTS); + DEBUGASSERT((i_chunk / 64) < CURL_UINT32_SPBSET_CH_SLOTS); return (chunk->slots[i_chunk / 64] & - ((curl_uint64_t)1 << (i_chunk % 64))) != 0; + ((uint64_t)1 << (i_chunk % 64))) != 0; } return FALSE; } -bool Curl_uint_spbset_first(struct uint_spbset *bset, unsigned int *pfirst) +bool Curl_uint32_spbset_first(struct uint32_spbset *bset, uint32_t *pfirst) { - struct uint_spbset_chunk *chunk; - unsigned int i; + struct uint32_spbset_chunk *chunk; + uint32_t i; for(chunk = &bset->head; chunk; chunk = chunk->next) { - for(i = 0; i < CURL_UINT_SPBSET_CH_SLOTS; ++i) { + for(i = 0; i < CURL_UINT32_SPBSET_CH_SLOTS; ++i) { if(chunk->slots[i]) { *pfirst = chunk->offset + ((i * 64) + CURL_CTZ64(chunk->slots[i])); return TRUE; @@ -200,29 +200,29 @@ bool Curl_uint_spbset_first(struct uint_spbset *bset, unsigned int *pfirst) } -static bool uint_spbset_chunk_first(struct uint_spbset_chunk *chunk, - unsigned int *pfirst) +static bool uint32_spbset_chunk_first(struct uint32_spbset_chunk *chunk, + uint32_t *pfirst) { - unsigned int i; - for(i = 0; i < CURL_UINT_SPBSET_CH_SLOTS; ++i) { + uint32_t i; + for(i = 0; i < CURL_UINT32_SPBSET_CH_SLOTS; ++i) { if(chunk->slots[i]) { *pfirst = chunk->offset + ((i * 64) + CURL_CTZ64(chunk->slots[i])); return TRUE; } } - *pfirst = UINT_MAX; /* a value we cannot store */ + *pfirst = UINT32_MAX; /* a value we cannot store */ return FALSE; } -static bool uint_spbset_chunk_next(struct uint_spbset_chunk *chunk, - unsigned int last, - unsigned int *pnext) +static bool uint32_spbset_chunk_next(struct uint32_spbset_chunk *chunk, + uint32_t last, + uint32_t *pnext) { if(chunk->offset <= last) { - curl_uint64_t x; - unsigned int i = ((last - chunk->offset) / 64); - if(i < CURL_UINT_SPBSET_CH_SLOTS) { + uint64_t x; + uint32_t i = ((last - chunk->offset) / 64); + if(i < CURL_UINT32_SPBSET_CH_SLOTS) { x = (chunk->slots[i] >> (last % 64)); if(x) { /* more bits set, next is `last` + trailing0s of the shifted slot */ @@ -230,7 +230,7 @@ static bool uint_spbset_chunk_next(struct uint_spbset_chunk *chunk, return TRUE; } /* no more bits set in the last slot, scan forward */ - for(i = i + 1; i < CURL_UINT_SPBSET_CH_SLOTS; ++i) { + for(i = i + 1; i < CURL_UINT32_SPBSET_CH_SLOTS; ++i) { if(chunk->slots[i]) { *pnext = chunk->offset + ((i * 64) + CURL_CTZ64(chunk->slots[i])); return TRUE; @@ -238,18 +238,18 @@ static bool uint_spbset_chunk_next(struct uint_spbset_chunk *chunk, } } } - *pnext = UINT_MAX; + *pnext = UINT32_MAX; return FALSE; } -bool Curl_uint_spbset_next(struct uint_spbset *bset, unsigned int last, - unsigned int *pnext) +bool Curl_uint32_spbset_next(struct uint32_spbset *bset, uint32_t last, + uint32_t *pnext) { - struct uint_spbset_chunk *chunk; - unsigned int last_offset; + struct uint32_spbset_chunk *chunk; + uint32_t last_offset; ++last; /* look for the next higher number */ - last_offset = (last & ~CURL_UINT_SPBSET_CH_MASK); + last_offset = (last & ~CURL_UINT32_SPBSET_CH_MASK); for(chunk = &bset->head; chunk; chunk = chunk->next) { if(chunk->offset >= last_offset) { @@ -259,17 +259,17 @@ bool Curl_uint_spbset_next(struct uint_spbset *bset, unsigned int last, if(chunk && (chunk->offset == last_offset)) { /* is there a number higher than last in this chunk? */ - if(uint_spbset_chunk_next(chunk, last, pnext)) + if(uint32_spbset_chunk_next(chunk, last, pnext)) return TRUE; /* not in this chunk */ chunk = chunk->next; } /* look for the first in the "higher" chunks, if there are any. */ while(chunk) { - if(uint_spbset_chunk_first(chunk, pnext)) + if(uint32_spbset_chunk_first(chunk, pnext)) return TRUE; chunk = chunk->next; } - *pnext = UINT_MAX; + *pnext = UINT32_MAX; return FALSE; } diff --git a/lib/uint-spbset.h b/lib/uint-spbset.h index bd2347902c3b..8c46ce4aa8ea 100644 --- a/lib/uint-spbset.h +++ b/lib/uint-spbset.h @@ -27,8 +27,8 @@ #include -/* A "sparse" bitset for unsigned int values. - * It can hold any unsigned int value. +/* A "sparse" bitset for uint32_t values. + * It can hold any uint32_t value. * * Optimized for the case where only a small set of numbers need * to be kept, especially when "close" together. Then storage space @@ -36,48 +36,48 @@ */ /* 4 slots = 256 bits, keep this a 2^n value. */ -#define CURL_UINT_SPBSET_CH_SLOTS 4 -#define CURL_UINT_SPBSET_CH_MASK ((CURL_UINT_SPBSET_CH_SLOTS * 64) - 1) +#define CURL_UINT32_SPBSET_CH_SLOTS 4 +#define CURL_UINT32_SPBSET_CH_MASK ((CURL_UINT32_SPBSET_CH_SLOTS * 64) - 1) /* store the uint value from offset to - * (offset + (CURL_UINT_SPBSET_CHUNK_SLOTS * 64) - 1 */ -struct uint_spbset_chunk { - struct uint_spbset_chunk *next; - curl_uint64_t slots[CURL_UINT_SPBSET_CH_SLOTS]; - unsigned int offset; + * (offset + (CURL_UINT32_SPBSET_CHUNK_SLOTS * 64) - 1 */ +struct uint32_spbset_chunk { + struct uint32_spbset_chunk *next; + uint64_t slots[CURL_UINT32_SPBSET_CH_SLOTS]; + uint32_t offset; }; -struct uint_spbset { - struct uint_spbset_chunk head; +struct uint32_spbset { + struct uint32_spbset_chunk head; #ifdef DEBUGBUILD int init; #endif }; -void Curl_uint_spbset_init(struct uint_spbset *bset); +void Curl_uint32_spbset_init(struct uint32_spbset *bset); -void Curl_uint_spbset_destroy(struct uint_spbset *bset); +void Curl_uint32_spbset_destroy(struct uint32_spbset *bset); /* Get the cardinality of the bitset, e.g. numbers present in the set. */ -unsigned int Curl_uint_spbset_count(struct uint_spbset *bset); +uint32_t Curl_uint32_spbset_count(struct uint32_spbset *bset); /* TRUE of bitset is empty */ -bool Curl_uint_spbset_empty(struct uint_spbset *bset); +bool Curl_uint32_spbset_empty(struct uint32_spbset *bset); /* Add the number `i` to the bitset. * Numbers can be added more than once, without making a difference. * Returns FALSE if allocations failed. */ -bool Curl_uint_spbset_add(struct uint_spbset *bset, unsigned int i); +bool Curl_uint32_spbset_add(struct uint32_spbset *bset, uint32_t i); /* Remove the number `i` from the bitset. */ -void Curl_uint_spbset_remove(struct uint_spbset *bset, unsigned int i); +void Curl_uint32_spbset_remove(struct uint32_spbset *bset, uint32_t i); /* Return TRUE if the bitset contains number `i`. */ -bool Curl_uint_spbset_contains(struct uint_spbset *bset, unsigned int i); +bool Curl_uint32_spbset_contains(struct uint32_spbset *bset, uint32_t i); /* Get the first number in the bitset, e.g. the smallest. * Returns FALSE when the bitset is empty. */ -bool Curl_uint_spbset_first(struct uint_spbset *bset, unsigned int *pfirst); +bool Curl_uint32_spbset_first(struct uint32_spbset *bset, uint32_t *pfirst); /* Get the next number in the bitset, following `last` in natural order. * Put another way, this is the smallest number greater than `last` in @@ -90,7 +90,7 @@ bool Curl_uint_spbset_first(struct uint_spbset *bset, unsigned int *pfirst); * - added numbers lower than 'last' will not show up. * - removed numbers lower or equal to 'last' will not show up. * - removed numbers higher than 'last' will not be visited. */ -bool Curl_uint_spbset_next(struct uint_spbset *bset, unsigned int last, - unsigned int *pnext); +bool Curl_uint32_spbset_next(struct uint32_spbset *bset, uint32_t last, + uint32_t *pnext); #endif /* HEADER_CURL_UINT_SPBSET_H */ diff --git a/lib/uint-table.c b/lib/uint-table.c index 5077363ab0f3..5516ab634bf1 100644 --- a/lib/uint-table.c +++ b/lib/uint-table.c @@ -30,29 +30,29 @@ #include "memdebug.h" #ifdef DEBUGBUILD -#define CURL_UINT_TBL_MAGIC 0x62757473 +#define CURL_UINT32_TBL_MAGIC 0x62757473 #endif /* Clear the table, making it empty. */ -UNITTEST void Curl_uint_tbl_clear(struct uint_tbl *tbl); +UNITTEST void Curl_uint32_tbl_clear(struct uint32_tbl *tbl); -void Curl_uint_tbl_init(struct uint_tbl *tbl, - Curl_uint_tbl_entry_dtor *entry_dtor) +void Curl_uint32_tbl_init(struct uint32_tbl *tbl, + Curl_uint32_tbl_entry_dtor *entry_dtor) { memset(tbl, 0, sizeof(*tbl)); tbl->entry_dtor = entry_dtor; - tbl->last_key_added = UINT_MAX; + tbl->last_key_added = UINT32_MAX; #ifdef DEBUGBUILD - tbl->init = CURL_UINT_TBL_MAGIC; + tbl->init = CURL_UINT32_TBL_MAGIC; #endif } -static void uint_tbl_clear_rows(struct uint_tbl *tbl, - unsigned int from, - unsigned int upto_excluding) +static void uint32_tbl_clear_rows(struct uint32_tbl *tbl, + uint32_t from, + uint32_t upto_excluding) { - unsigned int i, end; + uint32_t i, end; end = CURLMIN(upto_excluding, tbl->nrows); for(i = from; i < end; ++i) { @@ -66,10 +66,10 @@ static void uint_tbl_clear_rows(struct uint_tbl *tbl, } -CURLcode Curl_uint_tbl_resize(struct uint_tbl *tbl, unsigned int nrows) +CURLcode Curl_uint32_tbl_resize(struct uint32_tbl *tbl, uint32_t nrows) { /* we use `tbl->nrows + 1` during iteration, want that to work */ - DEBUGASSERT(tbl->init == CURL_UINT_TBL_MAGIC); + DEBUGASSERT(tbl->init == CURL_UINT32_TBL_MAGIC); if(!nrows) return CURLE_BAD_FUNCTION_ARGUMENT; if(nrows != tbl->nrows) { @@ -79,7 +79,7 @@ CURLcode Curl_uint_tbl_resize(struct uint_tbl *tbl, unsigned int nrows) if(tbl->rows) { memcpy(rows, tbl->rows, (CURLMIN(nrows, tbl->nrows) * sizeof(void *))); if(nrows < tbl->nrows) - uint_tbl_clear_rows(tbl, nrows, tbl->nrows); + uint32_tbl_clear_rows(tbl, nrows, tbl->nrows); free(tbl->rows); } tbl->rows = rows; @@ -89,49 +89,49 @@ CURLcode Curl_uint_tbl_resize(struct uint_tbl *tbl, unsigned int nrows) } -void Curl_uint_tbl_destroy(struct uint_tbl *tbl) +void Curl_uint32_tbl_destroy(struct uint32_tbl *tbl) { - DEBUGASSERT(tbl->init == CURL_UINT_TBL_MAGIC); - Curl_uint_tbl_clear(tbl); + DEBUGASSERT(tbl->init == CURL_UINT32_TBL_MAGIC); + Curl_uint32_tbl_clear(tbl); free(tbl->rows); memset(tbl, 0, sizeof(*tbl)); } -UNITTEST void Curl_uint_tbl_clear(struct uint_tbl *tbl) +UNITTEST void Curl_uint32_tbl_clear(struct uint32_tbl *tbl) { - DEBUGASSERT(tbl->init == CURL_UINT_TBL_MAGIC); - uint_tbl_clear_rows(tbl, 0, tbl->nrows); + DEBUGASSERT(tbl->init == CURL_UINT32_TBL_MAGIC); + uint32_tbl_clear_rows(tbl, 0, tbl->nrows); DEBUGASSERT(!tbl->nentries); - tbl->last_key_added = UINT_MAX; + tbl->last_key_added = UINT32_MAX; } -unsigned int Curl_uint_tbl_capacity(struct uint_tbl *tbl) +uint32_t Curl_uint32_tbl_capacity(struct uint32_tbl *tbl) { return tbl->nrows; } -unsigned int Curl_uint_tbl_count(struct uint_tbl *tbl) +uint32_t Curl_uint32_tbl_count(struct uint32_tbl *tbl) { return tbl->nentries; } -void *Curl_uint_tbl_get(struct uint_tbl *tbl, unsigned int key) +void *Curl_uint32_tbl_get(struct uint32_tbl *tbl, uint32_t key) { return (key < tbl->nrows) ? tbl->rows[key] : NULL; } -bool Curl_uint_tbl_add(struct uint_tbl *tbl, void *entry, unsigned int *pkey) +bool Curl_uint32_tbl_add(struct uint32_tbl *tbl, void *entry, uint32_t *pkey) { - unsigned int key, start_pos; + uint32_t key, start_pos; - DEBUGASSERT(tbl->init == CURL_UINT_TBL_MAGIC); + DEBUGASSERT(tbl->init == CURL_UINT32_TBL_MAGIC); if(!entry || !pkey) return FALSE; - *pkey = UINT_MAX; + *pkey = UINT32_MAX; if(tbl->nentries == tbl->nrows) /* full */ return FALSE; @@ -161,20 +161,20 @@ bool Curl_uint_tbl_add(struct uint_tbl *tbl, void *entry, unsigned int *pkey) } -void Curl_uint_tbl_remove(struct uint_tbl *tbl, unsigned int key) +void Curl_uint32_tbl_remove(struct uint32_tbl *tbl, uint32_t key) { - uint_tbl_clear_rows(tbl, key, key + 1); + uint32_tbl_clear_rows(tbl, key, key + 1); } -bool Curl_uint_tbl_contains(struct uint_tbl *tbl, unsigned int key) +bool Curl_uint32_tbl_contains(struct uint32_tbl *tbl, uint32_t key) { return (key < tbl->nrows) ? !!tbl->rows[key] : FALSE; } -static bool uint_tbl_next_at(struct uint_tbl *tbl, unsigned int key, - unsigned int *pkey, void **pentry) +static bool uint32_tbl_next_at(struct uint32_tbl *tbl, uint32_t key, + uint32_t *pkey, void **pentry) { for(; key < tbl->nrows; ++key) { if(tbl->rows[key]) { @@ -183,33 +183,33 @@ static bool uint_tbl_next_at(struct uint_tbl *tbl, unsigned int key, return TRUE; } } - *pkey = UINT_MAX; /* always invalid */ + *pkey = UINT32_MAX; /* always invalid */ *pentry = NULL; return FALSE; } -bool Curl_uint_tbl_first(struct uint_tbl *tbl, - unsigned int *pkey, void **pentry) +bool Curl_uint32_tbl_first(struct uint32_tbl *tbl, + uint32_t *pkey, void **pentry) { if(!pkey || !pentry) return FALSE; - if(tbl->nentries && uint_tbl_next_at(tbl, 0, pkey, pentry)) + if(tbl->nentries && uint32_tbl_next_at(tbl, 0, pkey, pentry)) return TRUE; DEBUGASSERT(!tbl->nentries); - *pkey = UINT_MAX; /* always invalid */ + *pkey = UINT32_MAX; /* always invalid */ *pentry = NULL; return FALSE; } -bool Curl_uint_tbl_next(struct uint_tbl *tbl, unsigned int last_key, - unsigned int *pkey, void **pentry) +bool Curl_uint32_tbl_next(struct uint32_tbl *tbl, uint32_t last_key, + uint32_t *pkey, void **pentry) { if(!pkey || !pentry) return FALSE; - if(uint_tbl_next_at(tbl, last_key + 1, pkey, pentry)) + if(uint32_tbl_next_at(tbl, last_key + 1, pkey, pentry)) return TRUE; - *pkey = UINT_MAX; /* always invalid */ + *pkey = UINT32_MAX; /* always invalid */ *pentry = NULL; return FALSE; } diff --git a/lib/uint-table.h b/lib/uint-table.h index c74ec7ad634d..f3169fbc8fa2 100644 --- a/lib/uint-table.h +++ b/lib/uint-table.h @@ -28,14 +28,14 @@ #include /* Destructor for a single table entry */ -typedef void Curl_uint_tbl_entry_dtor(unsigned int key, void *entry); +typedef void Curl_uint32_tbl_entry_dtor(uint32_t key, void *entry); -struct uint_tbl { +struct uint32_tbl { void **rows; /* array of void* holding entries */ - Curl_uint_tbl_entry_dtor *entry_dtor; - unsigned int nrows; /* length of `rows` array */ - unsigned int nentries; /* entries in table */ - unsigned int last_key_added; /* UINT_MAX or last key added */ + Curl_uint32_tbl_entry_dtor *entry_dtor; + uint32_t nrows; /* length of `rows` array */ + uint32_t nentries; /* entries in table */ + uint32_t last_key_added; /* UINT_MAX or last key added */ #ifdef DEBUGBUILD int init; #endif @@ -44,42 +44,42 @@ struct uint_tbl { /* Initialize the table with 0 capacity. * The optional `entry_dtor` is called when a table entry is removed, * Passing NULL means no action is taken on removal. */ -void Curl_uint_tbl_init(struct uint_tbl *tbl, - Curl_uint_tbl_entry_dtor *entry_dtor); +void Curl_uint32_tbl_init(struct uint32_tbl *tbl, + Curl_uint32_tbl_entry_dtor *entry_dtor); /* Resize the table to change capacity `nmax`. When `nmax` is reduced, * all present entries with key equal or larger to `nmax` are removed. */ -CURLcode Curl_uint_tbl_resize(struct uint_tbl *tbl, unsigned int nmax); +CURLcode Curl_uint32_tbl_resize(struct uint32_tbl *tbl, uint32_t nmax); /* Destroy the table, freeing all entries. */ -void Curl_uint_tbl_destroy(struct uint_tbl *tbl); +void Curl_uint32_tbl_destroy(struct uint32_tbl *tbl); /* Get the table capacity. */ -unsigned int Curl_uint_tbl_capacity(struct uint_tbl *tbl); +uint32_t Curl_uint32_tbl_capacity(struct uint32_tbl *tbl); /* Get the number of entries in the table. */ -unsigned int Curl_uint_tbl_count(struct uint_tbl *tbl); +uint32_t Curl_uint32_tbl_count(struct uint32_tbl *tbl); /* Get the entry for key or NULL if not present */ -void *Curl_uint_tbl_get(struct uint_tbl *tbl, unsigned int key); +void *Curl_uint32_tbl_get(struct uint32_tbl *tbl, uint32_t key); /* Add a new entry to the table and assign it a free key. * Returns FALSE if the table is full. * * Keys are assigned in a round-robin manner. * No matter the capacity, UINT_MAX is never assigned. */ -bool Curl_uint_tbl_add(struct uint_tbl *tbl, void *entry, unsigned int *pkey); +bool Curl_uint32_tbl_add(struct uint32_tbl *tbl, void *entry, uint32_t *pkey); /* Remove the entry with `key`. */ -void Curl_uint_tbl_remove(struct uint_tbl *tbl, unsigned int key); +void Curl_uint32_tbl_remove(struct uint32_tbl *tbl, uint32_t key); /* Return TRUE if the table contains an tryn with that keys. */ -bool Curl_uint_tbl_contains(struct uint_tbl *tbl, unsigned int key); +bool Curl_uint32_tbl_contains(struct uint32_tbl *tbl, uint32_t key); /* Get the first entry in the table (with the smallest `key`). * Returns FALSE if the table is empty. */ -bool Curl_uint_tbl_first(struct uint_tbl *tbl, - unsigned int *pkey, void **pentry); +bool Curl_uint32_tbl_first(struct uint32_tbl *tbl, + uint32_t *pkey, void **pentry); /* Get the next key in the table, following `last_key` in natural order. * Put another way, this is the smallest key greater than `last_key` in @@ -92,7 +92,7 @@ bool Curl_uint_tbl_first(struct uint_tbl *tbl, * - added keys lower than 'last_key' will not show up. * - removed keys lower or equal to 'last_key' will not show up. * - removed keys higher than 'last_key' will not be visited. */ -bool Curl_uint_tbl_next(struct uint_tbl *tbl, unsigned int last_key, - unsigned int *pkey, void **pentry); +bool Curl_uint32_tbl_next(struct uint32_tbl *tbl, uint32_t last_key, + uint32_t *pkey, void **pentry); #endif /* HEADER_CURL_UINT_TABLE_H */ diff --git a/lib/url.c b/lib/url.c index d953734dce9b..8b3f7f5ab738 100644 --- a/lib/url.c +++ b/lib/url.c @@ -513,8 +513,8 @@ CURLcode Curl_open(struct Curl_easy **curl) data->state.recent_conn_id = -1; /* and not assigned an id yet */ data->id = -1; - data->mid = UINT_MAX; - data->master_mid = UINT_MAX; + data->mid = UINT32_MAX; + data->master_mid = UINT32_MAX; data->progress.hide = TRUE; data->state.current_speed = -1; /* init to negative == impossible */ @@ -575,7 +575,7 @@ void Curl_conn_free(struct Curl_easy *data, struct connectdata *conn) Curl_safefree(conn->unix_domain_socket); #endif Curl_safefree(conn->destination); - Curl_uint_spbset_destroy(&conn->xfers_attached); + Curl_uint32_spbset_destroy(&conn->xfers_attached); Curl_hash_destroy(&conn->meta_hash); free(conn); /* free all the connection oriented data */ @@ -1407,7 +1407,7 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) conn->transport_wanted = TRNSPRT_TCP; /* most of them are TCP streams */ /* Initialize the attached xfers bitset */ - Curl_uint_spbset_init(&conn->xfers_attached); + Curl_uint32_spbset_init(&conn->xfers_attached); /* Store the local bind parameters that will be used for this connection */ if(data->set.str[STRING_DEVICE]) { @@ -3685,7 +3685,7 @@ static CURLcode create_conn(struct Curl_easy *data, connections_available = FALSE; break; case CPOOL_LIMIT_TOTAL: - if(data->master_mid != UINT_MAX) + if(data->master_mid != UINT32_MAX) CURL_TRC_M(data, "Allowing sub-requests (like DoH) to override " "max connection limit"); else { diff --git a/lib/urldata.h b/lib/urldata.h index e4fc49753fd4..c71607ea7d2b 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -610,8 +610,8 @@ struct connectdata { handle is still used by one or more easy handles and can only used by any other easy handle without careful consideration (== only for multiplexing) and it cannot be used by another multi handle! */ -#define CONN_INUSE(c) (!Curl_uint_spbset_empty(&(c)->xfers_attached)) -#define CONN_ATTACHED(c) Curl_uint_spbset_count(&(c)->xfers_attached) +#define CONN_INUSE(c) (!Curl_uint32_spbset_empty(&(c)->xfers_attached)) +#define CONN_ATTACHED(c) Curl_uint32_spbset_count(&(c)->xfers_attached) /**** Fields set when inited and not modified again */ curl_off_t connection_id; /* Contains a unique number to make it easier to @@ -671,7 +671,7 @@ struct connectdata { was used on this connection. */ struct curltime keepalive; - struct uint_spbset xfers_attached; /* mids of attached transfers */ + struct uint32_spbset xfers_attached; /* mids of attached transfers */ /* A connection cache from a SHARE might be used in several multi handles. * We MUST not reuse connections that are running in another multi, * for concurrency reasons. That multi might run in another thread. @@ -1631,8 +1631,8 @@ struct Curl_easy { /* once an easy handle is added to a multi, either explicitly by the * libcurl application or implicitly during `curl_easy_perform()`, * a unique identifier inside this one multi instance. */ - unsigned int mid; - unsigned int master_mid; /* if set, this transfer belongs to a master */ + uint32_t mid; + uint32_t master_mid; /* if set, this transfer belongs to a master */ multi_sub_xfer_done_cb *sub_xfer_done; struct connectdata *conn; diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index d6439287846e..ad1f2b2b25c8 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -168,7 +168,7 @@ static void cf_ngtcp2_ctx_init(struct cf_ngtcp2_ctx *ctx) Curl_bufcp_init(&ctx->stream_bufcp, H3_STREAM_CHUNK_SIZE, H3_STREAM_POOL_SPARES); curlx_dyn_init(&ctx->scratch, CURL_MAX_HTTP_HEADER); - Curl_uint_hash_init(&ctx->streams, 63, h3_stream_hash_free); + Curl_uint32_hash_init(&ctx->streams, 63, h3_stream_hash_free); ctx->initialized = TRUE; } @@ -179,7 +179,7 @@ static void cf_ngtcp2_ctx_free(struct cf_ngtcp2_ctx *ctx) vquic_ctx_free(&ctx->q); Curl_bufcp_free(&ctx->stream_bufcp); curlx_dyn_free(&ctx->scratch); - Curl_uint_hash_destroy(&ctx->streams); + Curl_uint32_hash_destroy(&ctx->streams); Curl_ssl_peer_cleanup(&ctx->peer); } free(ctx); @@ -207,7 +207,7 @@ static void cf_ngtcp2_setup_keep_alive(struct Curl_cfilter *cf, ngtcp2_conn_set_keep_alive_timeout(ctx->qconn, UINT64_MAX); CURL_TRC_CF(data, cf, "no peer idle timeout, unset keep-alive"); } - else if(!Curl_uint_hash_count(&ctx->streams)) { + else if(!Curl_uint32_hash_count(&ctx->streams)) { ngtcp2_conn_set_keep_alive_timeout(ctx->qconn, UINT64_MAX); CURL_TRC_CF(data, cf, "no active streams, unset keep-alive"); } @@ -288,12 +288,12 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, stream->sendbuf_len_in_flight = 0; Curl_h1_req_parse_init(&stream->h1, H1_PARSE_DEFAULT_MAX_LINE_LEN); - if(!Curl_uint_hash_set(&ctx->streams, data->mid, stream)) { + if(!Curl_uint32_hash_set(&ctx->streams, data->mid, stream)) { h3_stream_ctx_free(stream); return CURLE_OUT_OF_MEMORY; } - if(Curl_uint_hash_count(&ctx->streams) == 1) + if(Curl_uint32_hash_count(&ctx->streams) == 1) cf_ngtcp2_setup_keep_alive(cf, data); return CURLE_OK; @@ -303,10 +303,10 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, struct cf_ngtcp2_sfind_ctx { int64_t stream_id; struct h3_stream_ctx *stream; - unsigned int mid; + uint32_t mid; }; -static bool cf_ngtcp2_sfind(unsigned int mid, void *value, void *user_data) +static bool cf_ngtcp2_sfind(uint32_t mid, void *value, void *user_data) { struct cf_ngtcp2_sfind_ctx *fctx = user_data; struct h3_stream_ctx *stream = value; @@ -325,7 +325,7 @@ cf_ngtcp2_get_stream(struct cf_ngtcp2_ctx *ctx, int64_t stream_id) struct cf_ngtcp2_sfind_ctx fctx; fctx.stream_id = stream_id; fctx.stream = NULL; - Curl_uint_hash_visit(&ctx->streams, cf_ngtcp2_sfind, &fctx); + Curl_uint32_hash_visit(&ctx->streams, cf_ngtcp2_sfind, &fctx); return fctx.stream; } #else @@ -374,8 +374,8 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) CURL_TRC_CF(data, cf, "[%" PRId64 "] easy handle is done", stream->id); cf_ngtcp2_stream_close(cf, data, stream); - Curl_uint_hash_remove(&ctx->streams, data->mid); - if(!Curl_uint_hash_count(&ctx->streams)) + Curl_uint32_hash_remove(&ctx->streams, data->mid); + if(!Curl_uint32_hash_count(&ctx->streams)) cf_ngtcp2_setup_keep_alive(cf, data); } } diff --git a/lib/vquic/curl_osslq.c b/lib/vquic/curl_osslq.c index 9d0193d55440..ade94bf40aa7 100644 --- a/lib/vquic/curl_osslq.c +++ b/lib/vquic/curl_osslq.c @@ -305,7 +305,7 @@ static void cf_osslq_ctx_init(struct cf_osslq_ctx *ctx) DEBUGASSERT(!ctx->initialized); Curl_bufcp_init(&ctx->stream_bufcp, H3_STREAM_CHUNK_SIZE, H3_STREAM_POOL_SPARES); - Curl_uint_hash_init(&ctx->streams, 63, h3_stream_hash_free); + Curl_uint32_hash_init(&ctx->streams, 63, h3_stream_hash_free); ctx->poll_items = NULL; ctx->curl_items = NULL; ctx->items_max = 0; @@ -316,7 +316,7 @@ static void cf_osslq_ctx_free(struct cf_osslq_ctx *ctx) { if(ctx && ctx->initialized) { Curl_bufcp_free(&ctx->stream_bufcp); - Curl_uint_hash_destroy(&ctx->streams); + Curl_uint32_hash_destroy(&ctx->streams); Curl_ssl_peer_cleanup(&ctx->peer); free(ctx->poll_items); free(ctx->curl_items); @@ -634,7 +634,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, stream->recv_buf_nonflow = 0; Curl_h1_req_parse_init(&stream->h1, H1_PARSE_DEFAULT_MAX_LINE_LEN); - if(!Curl_uint_hash_set(&ctx->streams, data->mid, stream)) { + if(!Curl_uint32_hash_set(&ctx->streams, data->mid, stream)) { h3_stream_ctx_free(stream); return CURLE_OUT_OF_MEMORY; } @@ -659,7 +659,7 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) stream->closed = TRUE; } - Curl_uint_hash_remove(&ctx->streams, data->mid); + Curl_uint32_hash_remove(&ctx->streams, data->mid); } } @@ -668,7 +668,7 @@ struct cf_ossq_find_ctx { struct h3_stream_ctx *stream; }; -static bool cf_osslq_find_stream(unsigned int mid, void *val, void *user_data) +static bool cf_osslq_find_stream(uint32_t mid, void *val, void *user_data) { struct h3_stream_ctx *stream = val; struct cf_ossq_find_ctx *fctx = user_data; @@ -704,7 +704,7 @@ static struct cf_osslq_stream *cf_osslq_get_qstream(struct Curl_cfilter *cf, struct cf_ossq_find_ctx fctx; fctx.stream_id = stream_id; fctx.stream = NULL; - Curl_uint_hash_visit(&ctx->streams, cf_osslq_find_stream, &fctx); + Curl_uint32_hash_visit(&ctx->streams, cf_osslq_find_stream, &fctx); if(fctx.stream) return &fctx.stream->s; } @@ -1392,7 +1392,7 @@ struct cf_ossq_recv_ctx { CURLcode result; }; -static bool cf_osslq_iter_recv(unsigned int mid, void *val, void *user_data) +static bool cf_osslq_iter_recv(uint32_t mid, void *val, void *user_data) { struct h3_stream_ctx *stream = val; struct cf_ossq_recv_ctx *rctx = user_data; @@ -1455,7 +1455,7 @@ static CURLcode cf_progress_ingress(struct Curl_cfilter *cf, rctx.cf = cf; rctx.multi = data->multi; rctx.result = CURLE_OK; - Curl_uint_hash_visit(&ctx->streams, cf_osslq_iter_recv, &rctx); + Curl_uint32_hash_visit(&ctx->streams, cf_osslq_iter_recv, &rctx); result = rctx.result; } @@ -1470,7 +1470,7 @@ struct cf_ossq_fill_ctx { size_t n; }; -static bool cf_osslq_collect_block_send(unsigned int mid, void *val, +static bool cf_osslq_collect_block_send(uint32_t mid, void *val, void *user_data) { struct h3_stream_ctx *stream = val; @@ -1508,8 +1508,8 @@ static CURLcode cf_osslq_check_and_unblock(struct Curl_cfilter *cf, if(ctx->h3.conn) { struct cf_ossq_fill_ctx fill_ctx; - if(ctx->items_max < Curl_uint_hash_count(&ctx->streams)) { - size_t nmax = Curl_uint_hash_count(&ctx->streams); + if(ctx->items_max < Curl_uint32_hash_count(&ctx->streams)) { + size_t nmax = Curl_uint32_hash_count(&ctx->streams); ctx->items_max = 0; tmpptr = realloc(ctx->poll_items, nmax * sizeof(SSL_POLL_ITEM)); if(!tmpptr) { @@ -1534,7 +1534,7 @@ static CURLcode cf_osslq_check_and_unblock(struct Curl_cfilter *cf, fill_ctx.ctx = ctx; fill_ctx.multi = data->multi; fill_ctx.n = 0; - Curl_uint_hash_visit(&ctx->streams, cf_osslq_collect_block_send, + Curl_uint32_hash_visit(&ctx->streams, cf_osslq_collect_block_send, &fill_ctx); poll_count = fill_ctx.n; if(poll_count) { diff --git a/lib/vquic/curl_quiche.c b/lib/vquic/curl_quiche.c index 51cadd2e6ead..5082dc750bb5 100644 --- a/lib/vquic/curl_quiche.c +++ b/lib/vquic/curl_quiche.c @@ -125,7 +125,7 @@ static void cf_quiche_ctx_init(struct cf_quiche_ctx *ctx) #endif Curl_bufcp_init(&ctx->stream_bufcp, H3_STREAM_CHUNK_SIZE, H3_STREAM_POOL_SPARES); - Curl_uint_hash_init(&ctx->streams, 63, h3_stream_hash_free); + Curl_uint32_hash_init(&ctx->streams, 63, h3_stream_hash_free); ctx->data_recvd = 0; ctx->initialized = TRUE; } @@ -139,7 +139,7 @@ static void cf_quiche_ctx_free(struct cf_quiche_ctx *ctx) Curl_ssl_peer_cleanup(&ctx->peer); vquic_ctx_free(&ctx->q); Curl_bufcp_free(&ctx->stream_bufcp); - Curl_uint_hash_destroy(&ctx->streams); + Curl_uint32_hash_destroy(&ctx->streams); } free(ctx); } @@ -210,7 +210,7 @@ struct cf_quiche_visit_ctx { void *user_data; }; -static bool cf_quiche_stream_do(unsigned int mid, void *val, void *user_data) +static bool cf_quiche_stream_do(uint32_t mid, void *val, void *user_data) { struct cf_quiche_visit_ctx *vctx = user_data; struct h3_stream_ctx *stream = val; @@ -231,7 +231,7 @@ static void cf_quiche_for_all_streams(struct Curl_cfilter *cf, vctx.multi = multi; vctx.cb = do_cb; vctx.user_data = user_data; - Curl_uint_hash_visit(&ctx->streams, cf_quiche_stream_do, &vctx); + Curl_uint32_hash_visit(&ctx->streams, cf_quiche_stream_do, &vctx); } static bool cf_quiche_do_resume(struct Curl_cfilter *cf, @@ -278,7 +278,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, H3_STREAM_RECV_CHUNKS, BUFQ_OPT_SOFT_LIMIT); Curl_h1_req_parse_init(&stream->h1, H1_PARSE_DEFAULT_MAX_LINE_LEN); - if(!Curl_uint_hash_set(&ctx->streams, data->mid, stream)) { + if(!Curl_uint32_hash_set(&ctx->streams, data->mid, stream)) { h3_stream_ctx_free(stream); return CURLE_OUT_OF_MEMORY; } @@ -308,7 +308,7 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) if(result) CURL_TRC_CF(data, cf, "data_done, flush egress -> %d", result); } - Curl_uint_hash_remove(&ctx->streams, data->mid); + Curl_uint32_hash_remove(&ctx->streams, data->mid); } } @@ -558,7 +558,7 @@ struct cf_quich_disp_ctx { CURLcode result; }; -static bool cf_quiche_disp_event(unsigned int mid, void *val, void *user_data) +static bool cf_quiche_disp_event(uint32_t mid, void *val, void *user_data) { struct cf_quich_disp_ctx *dctx = user_data; struct h3_stream_ctx *stream = val; @@ -607,7 +607,7 @@ static CURLcode cf_poll_events(struct Curl_cfilter *cf, else { /* another transfer, do not return errors, as they are not for * the calling transfer */ - Curl_uint_hash_visit(&ctx->streams, cf_quiche_disp_event, &dctx); + Curl_uint32_hash_visit(&ctx->streams, cf_quiche_disp_event, &dctx); quiche_h3_event_free(ev); } } diff --git a/lib/vquic/vquic_int.h b/lib/vquic/vquic_int.h index 4e5959a4f803..ef92ab21b730 100644 --- a/lib/vquic/vquic_int.h +++ b/lib/vquic/vquic_int.h @@ -52,7 +52,7 @@ struct cf_quic_ctx { }; #define H3_STREAM_CTX(ctx,data) \ - (data ? Curl_uint_hash_get(&(ctx)->streams, (data)->mid) : NULL) + (data ? Curl_uint32_hash_get(&(ctx)->streams, (data)->mid) : NULL) CURLcode vquic_ctx_init(struct cf_quic_ctx *qctx); void vquic_ctx_free(struct cf_quic_ctx *qctx); diff --git a/tests/unit/unit1616.c b/tests/unit/unit1616.c index 7641cbeace94..5d1e6f247e76 100644 --- a/tests/unit/unit1616.c +++ b/tests/unit/unit1616.c @@ -36,13 +36,13 @@ static void t1616_mydtor(unsigned int id, void *elem) static CURLcode t1616_setup(struct uint_hash *hash) { - Curl_uint_hash_init(hash, 15, t1616_mydtor); + Curl_uint32_hash_init(hash, 15, t1616_mydtor); return CURLE_OK; } static void t1616_stop(struct uint_hash *hash) { - Curl_uint_hash_destroy(hash); + Curl_uint32_hash_destroy(hash); } static CURLcode test_unit1616(const char *arg) @@ -61,27 +61,27 @@ static CURLcode test_unit1616(const char *arg) value = malloc(sizeof(int)); abort_unless(value != NULL, "Out of memory"); *value = 199; - ok = Curl_uint_hash_set(&hash, key, value); + ok = Curl_uint32_hash_set(&hash, key, value); if(!ok) free(value); abort_unless(ok, "insertion into hash failed"); - v = Curl_uint_hash_get(&hash, key); + v = Curl_uint32_hash_get(&hash, key); abort_unless(v == value, "lookup present entry failed"); - v = Curl_uint_hash_get(&hash, key2); + v = Curl_uint32_hash_get(&hash, key2); abort_unless(!v, "lookup missing entry failed"); - Curl_uint_hash_clear(&hash); + Curl_uint32_hash_clear(&hash); /* Attempt to add another key/value pair */ value2 = malloc(sizeof(int)); abort_unless(value2 != NULL, "Out of memory"); *value2 = 204; - ok = Curl_uint_hash_set(&hash, key2, value2); + ok = Curl_uint32_hash_set(&hash, key2, value2); if(!ok) free(value2); abort_unless(ok, "insertion into hash failed"); - v = Curl_uint_hash_get(&hash, key2); + v = Curl_uint32_hash_get(&hash, key2); abort_unless(v == value2, "lookup present entry failed"); - v = Curl_uint_hash_get(&hash, key); + v = Curl_uint32_hash_get(&hash, key); abort_unless(!v, "lookup missing entry failed"); UNITTEST_END(t1616_stop(&hash)) diff --git a/tests/unit/unit3211.c b/tests/unit/unit3211.c index c2fac4bbc52c..1ec30ac9a2af 100644 --- a/tests/unit/unit3211.c +++ b/tests/unit/unit3211.c @@ -30,36 +30,38 @@ static void check_set(const char *name, unsigned int capacity, const unsigned int *s, size_t slen) { - struct uint_bset bset; + struct uint32_bset bset; size_t i, j; unsigned int n, c; curl_mfprintf(stderr, "test %s, capacity=%u, %zu numbers\n", name, capacity, slen); - Curl_uint_bset_init(&bset); - fail_unless(!Curl_uint_bset_resize(&bset, capacity), "bset resize failed"); - c = Curl_uint_bset_capacity(&bset); + Curl_uint32_bset_init(&bset); + fail_unless(!Curl_uint32_bset_resize(&bset, capacity), "bset resize failed"); + c = Curl_uint32_bset_capacity(&bset); fail_unless(c == (((capacity + 63) / 64) * 64), "wrong capacity"); - Curl_uint_bset_clear(&bset); - c = Curl_uint_bset_count(&bset); + Curl_uint32_bset_clear(&bset); + c = Curl_uint32_bset_count(&bset); fail_unless(c == 0, "set count is not 0"); for(i = 0; i < slen; ++i) { /* add all */ - fail_unless(Curl_uint_bset_add(&bset, s[i]), "failed to add"); + fail_unless(Curl_uint32_bset_add(&bset, s[i]), "failed to add"); for(j = i + 1; j < slen; ++j) - fail_unless(!Curl_uint_bset_contains(&bset, s[j]), "unexpectedly found"); + fail_unless(!Curl_uint32_bset_contains(&bset, s[j]), + "unexpectedly found"); } for(i = 0; i < slen; ++i) { /* all present */ - fail_unless(Curl_uint_bset_contains(&bset, s[i]), "failed presence check"); + fail_unless(Curl_uint32_bset_contains(&bset, s[i]), + "failed presence check"); } /* iterator over all numbers */ - fail_unless(Curl_uint_bset_first(&bset, &n), "first failed"); + fail_unless(Curl_uint32_bset_first(&bset, &n), "first failed"); fail_unless(n == s[0], "first not correct number"); for(i = 1; i < slen; ++i) { - fail_unless(Curl_uint_bset_next(&bset, n, &n), "next failed"); + fail_unless(Curl_uint32_bset_next(&bset, n, &n), "next failed"); if(n != s[i]) { curl_mfprintf(stderr, "expected next to be %u, not %u\n", s[i], n); fail_unless(n == s[i], "next not correct number"); @@ -67,57 +69,58 @@ static void check_set(const char *name, unsigned int capacity, } /* Adding capacity number does not work (0 - capacity-1) */ - c = Curl_uint_bset_capacity(&bset); - fail_unless(!Curl_uint_bset_add(&bset, c), "add out of range worked"); + c = Curl_uint32_bset_capacity(&bset); + fail_unless(!Curl_uint32_bset_add(&bset, c), "add out of range worked"); /* The count it correct */ - c = Curl_uint_bset_count(&bset); + c = Curl_uint32_bset_count(&bset); fail_unless(c == slen, "set count is wrong"); for(i = 0; i < slen; i += 2) { /* remove every 2nd */ - Curl_uint_bset_remove(&bset, s[i]); - fail_unless(!Curl_uint_bset_contains(&bset, s[i]), "unexpectedly found"); + Curl_uint32_bset_remove(&bset, s[i]); + fail_unless(!Curl_uint32_bset_contains(&bset, s[i]), "unexpectedly found"); } for(i = 1; i < slen; i += 2) { /* others still there */ - fail_unless(Curl_uint_bset_contains(&bset, s[i]), "unexpectedly gone"); + fail_unless(Curl_uint32_bset_contains(&bset, s[i]), "unexpectedly gone"); } /* The count is half */ - c = Curl_uint_bset_count(&bset); + c = Curl_uint32_bset_count(&bset); fail_unless(c == slen/2, "set count is wrong"); - Curl_uint_bset_clear(&bset); - c = Curl_uint_bset_count(&bset); + Curl_uint32_bset_clear(&bset); + c = Curl_uint32_bset_count(&bset); fail_unless(c == 0, "set count is not 0"); for(i = 0; i < slen; i++) { /* none present any longer */ - fail_unless(!Curl_uint_bset_contains(&bset, s[i]), "unexpectedly there"); + fail_unless(!Curl_uint32_bset_contains(&bset, s[i]), "unexpectedly there"); } for(i = 0; i < slen; ++i) { /* add all again */ - fail_unless(Curl_uint_bset_add(&bset, s[i]), "failed to add"); + fail_unless(Curl_uint32_bset_add(&bset, s[i]), "failed to add"); } - fail_unless(!Curl_uint_bset_resize(&bset, capacity * 2), + fail_unless(!Curl_uint32_bset_resize(&bset, capacity * 2), "resize double failed"); for(i = 0; i < slen; i++) { /* all still present after resize */ - fail_unless(Curl_uint_bset_contains(&bset, s[i]), "unexpectedly lost"); + fail_unless(Curl_uint32_bset_contains(&bset, s[i]), "unexpectedly lost"); } - fail_unless(!Curl_uint_bset_resize(&bset, capacity), "resize back failed"); + fail_unless(!Curl_uint32_bset_resize(&bset, capacity), "resize back failed"); for(i = 0; i < slen; i++) /* all still present after resize back */ - fail_unless(Curl_uint_bset_contains(&bset, s[i]), "unexpectedly lost"); + fail_unless(Curl_uint32_bset_contains(&bset, s[i]), "unexpectedly lost"); - fail_unless(!Curl_uint_bset_resize(&bset, capacity/2), "resize half failed"); + fail_unless(!Curl_uint32_bset_resize(&bset, capacity/2), + "resize half failed"); /* halved the size, what numbers remain in set? */ - c = Curl_uint_bset_capacity(&bset); + c = Curl_uint32_bset_capacity(&bset); n = 0; for(i = 0; i < slen; ++i) { if(s[i] < c) ++n; } - fail_unless(n == Curl_uint_bset_count(&bset), "set count(halved) wrong"); + fail_unless(n == Curl_uint32_bset_count(&bset), "set count(halved) wrong"); for(i = 0; i < n; i++) /* still present after resize half */ - fail_unless(Curl_uint_bset_contains(&bset, s[i]), "unexpectedly lost"); + fail_unless(Curl_uint32_bset_contains(&bset, s[i]), "unexpectedly lost"); - Curl_uint_bset_destroy(&bset); + Curl_uint32_bset_destroy(&bset); } static CURLcode test_unit3211(const char *arg) diff --git a/tests/unit/unit3212.c b/tests/unit/unit3212.c index 261d294528fe..0bffd1f79ce3 100644 --- a/tests/unit/unit3212.c +++ b/tests/unit/unit3212.c @@ -30,20 +30,20 @@ #define TBL_SIZE 100 -static CURLcode t3212_setup(struct uint_tbl *tbl) +static CURLcode t3212_setup(struct uint32_tbl *tbl) { - Curl_uint_tbl_init(tbl, NULL); - return Curl_uint_tbl_resize(tbl, TBL_SIZE); + Curl_uint32_tbl_init(tbl, NULL); + return Curl_uint32_tbl_resize(tbl, TBL_SIZE); } -static void t3212_stop(struct uint_tbl *tbl) +static void t3212_stop(struct uint32_tbl *tbl) { - Curl_uint_tbl_destroy(tbl); + Curl_uint32_tbl_destroy(tbl); } static CURLcode test_unit3212(const char *arg) { - struct uint_tbl tbl; + struct uint32_tbl tbl; int dummy; UNITTEST_BEGIN(t3212_setup(&tbl)) @@ -51,83 +51,85 @@ static CURLcode test_unit3212(const char *arg) unsigned int i, key, n; void *entry; - fail_unless(Curl_uint_tbl_capacity(&tbl) == TBL_SIZE, "wrong capacity"); + fail_unless(Curl_uint32_tbl_capacity(&tbl) == TBL_SIZE, "wrong capacity"); for(i = 0; i < TBL_SIZE; ++i) { - fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add"); + fail_unless(Curl_uint32_tbl_add(&tbl, &dummy, &key), "failed to add"); fail_unless(key == i, "unexpected key assigned"); } /* table should be full now */ - fail_unless(Curl_uint_tbl_count(&tbl) == TBL_SIZE, "wrong count"); - fail_unless(!Curl_uint_tbl_add(&tbl, &dummy, &key), "could add more"); + fail_unless(Curl_uint32_tbl_count(&tbl) == TBL_SIZE, "wrong count"); + fail_unless(!Curl_uint32_tbl_add(&tbl, &dummy, &key), "could add more"); /* remove every 2nd entry, from full table */ n = TBL_SIZE; for(i = 0; i < TBL_SIZE; i += 2) { - Curl_uint_tbl_remove(&tbl, i); + Curl_uint32_tbl_remove(&tbl, i); --n; - fail_unless(Curl_uint_tbl_count(&tbl) == n, "wrong count after remove"); + fail_unless(Curl_uint32_tbl_count(&tbl) == n, "wrong count after remove"); } /* remove same again, should not change count */ for(i = 0; i < TBL_SIZE; i += 2) { - Curl_uint_tbl_remove(&tbl, i); - fail_unless(Curl_uint_tbl_count(&tbl) == n, "wrong count after remove"); + Curl_uint32_tbl_remove(&tbl, i); + fail_unless(Curl_uint32_tbl_count(&tbl) == n, "wrong count after remove"); } /* still contains all odd entries */ for(i = 1; i < TBL_SIZE; i += 2) { - fail_unless(Curl_uint_tbl_contains(&tbl, i), "does not contain"); - fail_unless(Curl_uint_tbl_get(&tbl, i) == &dummy, + fail_unless(Curl_uint32_tbl_contains(&tbl, i), "does not contain"); + fail_unless(Curl_uint32_tbl_get(&tbl, i) == &dummy, "does not contain dummy"); } /* get the first key */ - fail_unless(Curl_uint_tbl_first(&tbl, &key, &entry), "first failed"); + fail_unless(Curl_uint32_tbl_first(&tbl, &key, &entry), "first failed"); fail_unless(key == 1, "unexpected first key"); fail_unless(entry == &dummy, "unexpected first entry"); /* get the second key */ - fail_unless(Curl_uint_tbl_next(&tbl, 1, &key, &entry), "next1 failed"); + fail_unless(Curl_uint32_tbl_next(&tbl, 1, &key, &entry), "next1 failed"); fail_unless(key == 3, "unexpected second key"); fail_unless(entry == &dummy, "unexpected second entry"); /* get the key after 42 */ - fail_unless(Curl_uint_tbl_next(&tbl, 42, &key, &entry), "next42 failed"); + fail_unless(Curl_uint32_tbl_next(&tbl, 42, &key, &entry), "next42 failed"); fail_unless(key == 43, "unexpected next42 key"); fail_unless(entry == &dummy, "unexpected next42 entry"); /* double capacity */ - n = Curl_uint_tbl_count(&tbl); - fail_unless(!Curl_uint_tbl_resize(&tbl, TBL_SIZE * 2), + n = Curl_uint32_tbl_count(&tbl); + fail_unless(!Curl_uint32_tbl_resize(&tbl, TBL_SIZE * 2), "error doubling size"); - fail_unless(Curl_uint_tbl_count(&tbl) == n, "wrong resize count"); + fail_unless(Curl_uint32_tbl_count(&tbl) == n, "wrong resize count"); /* resize to half of original */ - fail_unless(!Curl_uint_tbl_resize(&tbl, TBL_SIZE / 2), "error halving size"); - fail_unless(Curl_uint_tbl_count(&tbl) == n / 2, "wrong half size count"); + fail_unless(!Curl_uint32_tbl_resize(&tbl, TBL_SIZE / 2), + "error halving size"); + fail_unless(Curl_uint32_tbl_count(&tbl) == n / 2, "wrong half size count"); for(i = 1; i < TBL_SIZE / 2; i += 2) { - fail_unless(Curl_uint_tbl_contains(&tbl, i), "does not contain"); - fail_unless(Curl_uint_tbl_get(&tbl, i) == &dummy, + fail_unless(Curl_uint32_tbl_contains(&tbl, i), "does not contain"); + fail_unless(Curl_uint32_tbl_get(&tbl, i) == &dummy, "does not contain dummy"); } /* clear */ - Curl_uint_tbl_clear(&tbl); - fail_unless(!Curl_uint_tbl_count(&tbl), "count not 0 after clear"); + Curl_uint32_tbl_clear(&tbl); + fail_unless(!Curl_uint32_tbl_count(&tbl), "count not 0 after clear"); for(i = 0; i < TBL_SIZE / 2; ++i) { - fail_unless(!Curl_uint_tbl_contains(&tbl, i), "does contain, should not"); + fail_unless(!Curl_uint32_tbl_contains(&tbl, i), + "does contain, should not"); } /* add after clear gets key 0 again */ - fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add"); + fail_unless(Curl_uint32_tbl_add(&tbl, &dummy, &key), "failed to add"); fail_unless(key == 0, "unexpected key assigned"); /* remove it again and add, should get key 1 */ - Curl_uint_tbl_remove(&tbl, key); - fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add"); + Curl_uint32_tbl_remove(&tbl, key); + fail_unless(Curl_uint32_tbl_add(&tbl, &dummy, &key), "failed to add"); fail_unless(key == 1, "unexpected key assigned"); /* clear, fill, remove one, add, should get the removed key again */ - Curl_uint_tbl_clear(&tbl); - for(i = 0; i < Curl_uint_tbl_capacity(&tbl); ++i) - fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add"); - fail_unless(!Curl_uint_tbl_add(&tbl, &dummy, &key), "add on full"); - Curl_uint_tbl_remove(&tbl, 17); - fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add again"); + Curl_uint32_tbl_clear(&tbl); + for(i = 0; i < Curl_uint32_tbl_capacity(&tbl); ++i) + fail_unless(Curl_uint32_tbl_add(&tbl, &dummy, &key), "failed to add"); + fail_unless(!Curl_uint32_tbl_add(&tbl, &dummy, &key), "add on full"); + Curl_uint32_tbl_remove(&tbl, 17); + fail_unless(Curl_uint32_tbl_add(&tbl, &dummy, &key), "failed to add again"); fail_unless(key == 17, "unexpected key assigned"); /* and again, triggering key search wrap around */ - Curl_uint_tbl_remove(&tbl, 17); - fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add again"); + Curl_uint32_tbl_remove(&tbl, 17); + fail_unless(Curl_uint32_tbl_add(&tbl, &dummy, &key), "failed to add again"); fail_unless(key == 17, "unexpected key assigned"); UNITTEST_END(t3212_stop(&tbl)) diff --git a/tests/unit/unit3213.c b/tests/unit/unit3213.c index 850b275c86cf..b0d4d2ced557 100644 --- a/tests/unit/unit3213.c +++ b/tests/unit/unit3213.c @@ -30,35 +30,35 @@ static void check_spbset(const char *name, const unsigned int *s, size_t slen) { - struct uint_spbset bset; + struct uint32_spbset bset; size_t i, j; unsigned int n, c; curl_mfprintf(stderr, "test %s, %zu numbers\n", name, slen); - Curl_uint_spbset_init(&bset); + Curl_uint32_spbset_init(&bset); - Curl_uint_spbset_clear(&bset); - c = Curl_uint_spbset_count(&bset); + Curl_uint32_spbset_clear(&bset); + c = Curl_uint32_spbset_count(&bset); fail_unless(c == 0, "set count is not 0"); for(i = 0; i < slen; ++i) { /* add all */ - fail_unless(Curl_uint_spbset_add(&bset, s[i]), "failed to add"); + fail_unless(Curl_uint32_spbset_add(&bset, s[i]), "failed to add"); for(j = i + 1; j < slen; ++j) - fail_unless(!Curl_uint_spbset_contains(&bset, s[j]), + fail_unless(!Curl_uint32_spbset_contains(&bset, s[j]), "unexpectedly found"); } for(i = 0; i < slen; ++i) { /* all present */ - fail_unless(Curl_uint_spbset_contains(&bset, s[i]), + fail_unless(Curl_uint32_spbset_contains(&bset, s[i]), "failed presence check"); } /* iterator over all numbers */ - fail_unless(Curl_uint_spbset_first(&bset, &n), "first failed"); + fail_unless(Curl_uint32_spbset_first(&bset, &n), "first failed"); fail_unless(n == s[0], "first not correct number"); for(i = 1; i < slen; ++i) { - fail_unless(Curl_uint_spbset_next(&bset, n, &n), "next failed"); + fail_unless(Curl_uint32_spbset_next(&bset, n, &n), "next failed"); if(n != s[i]) { curl_mfprintf(stderr, "expected next to be %u, not %u\n", s[i], n); fail_unless(n == s[i], "next not correct number"); @@ -66,28 +66,30 @@ static void check_spbset(const char *name, const unsigned int *s, size_t slen) } for(i = 0; i < slen; i += 2) { /* remove every 2nd */ - Curl_uint_spbset_remove(&bset, s[i]); - fail_unless(!Curl_uint_spbset_contains(&bset, s[i]), "unexpectedly found"); + Curl_uint32_spbset_remove(&bset, s[i]); + fail_unless(!Curl_uint32_spbset_contains(&bset, s[i]), + "unexpectedly found"); } for(i = 1; i < slen; i += 2) { /* others still there */ - fail_unless(Curl_uint_spbset_contains(&bset, s[i]), "unexpectedly gone"); + fail_unless(Curl_uint32_spbset_contains(&bset, s[i]), "unexpectedly gone"); } /* The count is half */ - c = Curl_uint_spbset_count(&bset); + c = Curl_uint32_spbset_count(&bset); fail_unless(c == slen/2, "set count is wrong"); - Curl_uint_spbset_clear(&bset); - c = Curl_uint_spbset_count(&bset); + Curl_uint32_spbset_clear(&bset); + c = Curl_uint32_spbset_count(&bset); fail_unless(c == 0, "set count is not 0"); for(i = 0; i < slen; i++) { /* none present any longer */ - fail_unless(!Curl_uint_spbset_contains(&bset, s[i]), "unexpectedly there"); + fail_unless(!Curl_uint32_spbset_contains(&bset, s[i]), + "unexpectedly there"); } for(i = 0; i < slen; ++i) { /* add all again */ - fail_unless(Curl_uint_spbset_add(&bset, s[i]), "failed to add"); + fail_unless(Curl_uint32_spbset_add(&bset, s[i]), "failed to add"); } - Curl_uint_spbset_destroy(&bset); + Curl_uint32_spbset_destroy(&bset); } static CURLcode test_unit3213(const char *arg) From 31b1527c1d78d7d91c60abdd132f0d788ec95cfd Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 25 Nov 2025 23:03:33 +0100 Subject: [PATCH 066/140] hostip: only store negative response for CURLE_COULDNT_RESOLVE_HOST Follow-up from ce06fe77710525 This allows us to drop the 'keep_negative' variable completely. Closes #19701 --- lib/hostip.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/hostip.c b/lib/hostip.c index 4c1bb9236776..58a7712cf485 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -806,7 +806,6 @@ CURLcode Curl_resolv(struct Curl_easy *data, struct Curl_addrinfo *addr = NULL; bool respwait = FALSE; size_t hostname_len; - bool keep_negative = TRUE; /* cache a negative result */ CURLcode result = CURLE_COULDNT_RESOLVE_HOST; *entry = NULL; @@ -858,7 +857,6 @@ CURLcode Curl_resolv(struct Curl_easy *data, data->set.resolver_start_client); Curl_set_in_callback(data, FALSE); if(st) { - keep_negative = FALSE; result = CURLE_ABORTED_BY_CALLBACK; goto error; } @@ -928,7 +926,6 @@ CURLcode Curl_resolv(struct Curl_easy *data, if(dns) /* avoid a dangling pointer to addr in the dying dns entry */ dns->addr = NULL; - keep_negative = FALSE; result = CURLE_OUT_OF_MEMORY; goto error; } @@ -947,7 +944,7 @@ CURLcode Curl_resolv(struct Curl_easy *data, if(dns) Curl_resolv_unlink(data, &dns); Curl_async_shutdown(data); - if(keep_negative) + if(result == CURLE_COULDNT_RESOLVE_HOST) store_negative_resolve(data, hostname, port); DEBUGASSERT(result); return result; From 4041eea61edd8cf66c6f85c47a430bb5774f017c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 25 Nov 2025 02:34:26 +0100 Subject: [PATCH 067/140] GHA/http3-linux: build nettle manually for GnuTLS 3.8.11+ GnuTLS 3.8.11 started requiring a nettle version new enough to be missing from Ubuntu LTS released a year ago. To keep up testing it, build nettle from source. Besides the necessary one time effort this has the downside that nettle updates now need to be done manually a couple of times per year when renovate detects one. (if I got the renovate formula correct to catch the tag format). Also: - switch the local GnuTLS build to use the release tarball instead of the Git repo and calling the script `bootstrap`. The script could potentially download source code using the cleartext `git:` protocol. It's also downloading lots of content, including a full OpenSSL repo. Ref: https://github.com/gnutls/gnutls/blob/955f7a7fc223642d1ede6d55f094961cb97bfa68/NEWS#L41-L44 Follow-up to 905b718de3fb9287c7c0037b2737aa395f01ad3c #19642 Follow-up to a439fc0e372c3de7df3b8ae3ca7752bc3cbca826 #19613 Closes #19680 --- .github/workflows/http3-linux.yml | 78 +++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 20 deletions(-) diff --git a/.github/workflows/http3-linux.yml b/.github/workflows/http3-linux.yml index 3f52c146563e..06e8e2e97507 100644 --- a/.github/workflows/http3-linux.yml +++ b/.github/workflows/http3-linux.yml @@ -46,8 +46,10 @@ env: AWSLC_VERSION: 1.63.0 # renovate: datasource=github-tags depName=google/boringssl versioning=semver registryUrl=https://github.com BORINGSSL_VERSION: 0.20251110.0 - # renovate: datasource=github-tags depName=gnutls/gnutls versioning=semver registryUrl=https://github.com - GNUTLS_VERSION: 3.8.10 + # renovate: datasource=github-tags depName=gnutls/nettle versioning=semver registryUrl=https://github.com + NETTLE_VERSION: 3.10.2 + # renovate: datasource=github-tags depName=gnutls/gnutls versioning=semver extractVersion=^nettle_?(?.+)_release_.+$ registryUrl=https://github.com + GNUTLS_VERSION: 3.8.11 # renovate: datasource=github-tags depName=wolfSSL/wolfssl versioning=semver extractVersion=^v?(?.+)-stable$ registryUrl=https://github.com WOLFSSL_VERSION: 5.8.4 # renovate: datasource=github-tags depName=ngtcp2/nghttp3 versioning=semver registryUrl=https://github.com @@ -101,6 +103,15 @@ jobs: path: ~/boringssl/build key: ${{ runner.os }}-http3-build-${{ env.cache-name }}-${{ env.BORINGSSL_VERSION }} + - name: 'cache nettle' + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + id: cache-nettle + env: + cache-name: cache-nettle + with: + path: ~/nettle/build + key: ${{ runner.os }}-http3-build-${{ env.cache-name }}-${{ env.NETTLE_VERSION }} + - name: 'cache gnutls' uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 id: cache-gnutls @@ -108,7 +119,7 @@ jobs: cache-name: cache-gnutls with: path: ~/gnutls/build - key: ${{ runner.os }}-http3-build-${{ env.cache-name }}-${{ env.GNUTLS_VERSION }} + key: ${{ runner.os }}-http3-build-${{ env.cache-name }}-${{ env.GNUTLS_VERSION }}-${{ env.NETTLE_VERSION }} - name: 'cache wolfssl' uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 @@ -135,7 +146,7 @@ jobs: cache-name: cache-ngtcp2 with: path: ~/ngtcp2/build - key: ${{ runner.os }}-http3-build-${{ env.cache-name }}-${{ env.NGTCP2_VERSION }}-${{ env.OPENSSL_VERSION }}-${{ env.LIBRESSL_VERSION }}-${{ env.AWSLC_VERSION }}-${{ env.GNUTLS_VERSION }}-${{ env.WOLFSSL_VERSION }} + key: ${{ runner.os }}-http3-build-${{ env.cache-name }}-${{ env.NGTCP2_VERSION }}-${{ env.OPENSSL_VERSION }}-${{ env.LIBRESSL_VERSION }}-${{ env.AWSLC_VERSION }}-${{ env.NETTLE_VERSION }}-${{ env.GNUTLS_VERSION }}-${{ env.WOLFSSL_VERSION }} - name: 'cache ngtcp2 boringssl' uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 @@ -161,6 +172,7 @@ jobs: steps.cache-libressl.outputs.cache-hit != 'true' || steps.cache-awslc.outputs.cache-hit != 'true' || steps.cache-boringssl.outputs.cache-hit != 'true' || + steps.cache-nettle.outputs.cache-hit != 'true' || steps.cache-gnutls.outputs.cache-hit != 'true' || steps.cache-wolfssl.outputs.cache-hit != 'true' || steps.cache-nghttp3.outputs.cache-hit != 'true' || @@ -181,7 +193,7 @@ jobs: libbrotli-dev libzstd-dev zlib1g-dev \ libev-dev \ libc-ares-dev \ - nettle-dev libp11-kit-dev autopoint bison gperf gtk-doc-tools libtasn1-bin # for GnuTLS + libp11-kit-dev autopoint bison gperf gtk-doc-tools libtasn1-bin # for GnuTLS echo 'CC=gcc-12' >> "$GITHUB_ENV" echo 'CXX=g++-12' >> "$GITHUB_ENV" @@ -228,19 +240,30 @@ jobs: cmake --build . cmake --install . + - name: 'build nettle' + if: ${{ steps.cache-nettle.outputs.cache-hit != 'true' }} + run: | + cd ~ + curl --disable --fail --silent --show-error --connect-timeout 15 --max-time 120 --retry 6 --retry-connrefused \ + --location "https://ftpmirror.gnu.org/nettle/nettle-${NETTLE_VERSION}.tar.gz" | tar -xz + cd "nettle-${NETTLE_VERSION}" + ./configure --disable-dependency-tracking --prefix=/home/runner/nettle/build \ + --disable-silent-rules --disable-static --disable-openssl --disable-documentation + make install + - name: 'build gnutls' if: ${{ steps.cache-gnutls.outputs.cache-hit != 'true' }} run: | cd ~ - git clone --quiet --depth 1 -b "${GNUTLS_VERSION}" https://github.com/gnutls/gnutls - cd gnutls - # required: nettle-dev libp11-kit-dev libev-dev autopoint bison gperf gtk-doc-tools libtasn1-bin - ./bootstrap - ./configure --disable-dependency-tracking --prefix="$PWD"/build \ - LDFLAGS="-Wl,-rpath,$PWD/build/lib -L$PWD/build/lib" \ + curl --disable --fail --silent --show-error --connect-timeout 15 --max-time 120 --retry 6 --retry-connrefused \ + "https://www.gnupg.org/ftp/gcrypt/gnutls/v${GNUTLS_VERSION%.*}/gnutls-${GNUTLS_VERSION}.tar.xz" | tar -xJ + cd "gnutls-${GNUTLS_VERSION}" + # required: libp11-kit-dev libev-dev autopoint bison gperf gtk-doc-tools libtasn1-bin + ./configure --disable-dependency-tracking --prefix=/home/runner/gnutls/build \ + PKG_CONFIG_PATH=/home/runner/nettle/build/lib64/pkgconfig \ + LDFLAGS=-Wl,-rpath,/home/runner/nettle/build/lib64 \ --with-included-libtasn1 --with-included-unistring \ --disable-guile --disable-doc --disable-tests --disable-tools - make make install - name: 'build wolfssl' @@ -280,7 +303,7 @@ jobs: make install make clean ./configure --disable-dependency-tracking --prefix="$PWD"/build \ - PKG_CONFIG_PATH=/home/runner/openssl/build/lib/pkgconfig:/home/runner/gnutls/build/lib/pkgconfig:/home/runner/wolfssl/build/lib/pkgconfig \ + PKG_CONFIG_PATH=/home/runner/openssl/build/lib/pkgconfig:/home/runner/nettle/build/lib64/pkgconfig:/home/runner/gnutls/build/lib/pkgconfig:/home/runner/wolfssl/build/lib/pkgconfig \ --enable-lib-only --with-openssl --with-gnutls --with-wolfssl --with-boringssl \ BORINGSSL_LIBS='-L/home/runner/awslc/build/lib -lssl -lcrypto' \ BORINGSSL_CFLAGS='-I/home/runner/awslc/build/include' @@ -383,16 +406,18 @@ jobs: -DCMAKE_UNITY_BUILD=ON - name: 'gnutls' - install_packages: nettle-dev libp11-kit-dev + install_packages: libp11-kit-dev install_steps: skipall - PKG_CONFIG_PATH: /home/runner/gnutls/build/lib/pkgconfig:/home/runner/nghttp3/build/lib/pkgconfig:/home/runner/ngtcp2/build/lib/pkgconfig:/home/runner/nghttp2/build/lib/pkgconfig + PKG_CONFIG_PATH: /home/runner/nettle/build/lib64/pkgconfig:/home/runner/gnutls/build/lib/pkgconfig:/home/runner/nghttp3/build/lib/pkgconfig:/home/runner/ngtcp2/build/lib/pkgconfig:/home/runner/nghttp2/build/lib/pkgconfig + LDFLAGS: -Wl,-rpath,/home/runner/gnutls/build/lib -Wl,-rpath,/home/runner/nettle/build/lib64 -L/home/runner/nettle/build/lib64 -Wl,-rpath,/home/runner/ngtcp2/build/lib + CPPFLAGS: -I/home/runner/nettle/build/include configure: >- - LDFLAGS=-Wl,-rpath,/home/runner/gnutls/build/lib --with-gnutls=/home/runner/gnutls/build --with-ngtcp2 --enable-ssls-export - name: 'gnutls' - install_packages: nettle-dev libp11-kit-dev - PKG_CONFIG_PATH: /home/runner/gnutls/build/lib/pkgconfig:/home/runner/nghttp3/build/lib/pkgconfig:/home/runner/ngtcp2/build/lib/pkgconfig:/home/runner/nghttp2/build/lib/pkgconfig + install_packages: libp11-kit-dev + PKG_CONFIG_PATH: /home/runner/nettle/build/lib64/pkgconfig:/home/runner/gnutls/build/lib/pkgconfig:/home/runner/nghttp3/build/lib/pkgconfig:/home/runner/ngtcp2/build/lib/pkgconfig:/home/runner/nghttp2/build/lib/pkgconfig + LDFLAGS: -Wl,-rpath,/home/runner/gnutls/build/lib generate: >- -DCURL_USE_GNUTLS=ON -DUSE_NGTCP2=ON -DCMAKE_UNITY_BUILD=ON @@ -502,6 +527,17 @@ jobs: key: ${{ runner.os }}-http3-build-${{ env.cache-name }}-${{ env.BORINGSSL_VERSION }} fail-on-cache-miss: true + - name: 'cache nettle' + if: ${{ matrix.build.name == 'gnutls' }} + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + id: cache-nettle + env: + cache-name: cache-nettle + with: + path: ~/nettle/build + key: ${{ runner.os }}-http3-build-${{ env.cache-name }}-${{ env.NETTLE_VERSION }} + fail-on-cache-miss: true + - name: 'cache gnutls' if: ${{ matrix.build.name == 'gnutls' }} uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 @@ -510,7 +546,7 @@ jobs: cache-name: cache-gnutls with: path: ~/gnutls/build - key: ${{ runner.os }}-http3-build-${{ env.cache-name }}-${{ env.GNUTLS_VERSION }} + key: ${{ runner.os }}-http3-build-${{ env.cache-name }}-${{ env.GNUTLS_VERSION }}-${{ env.NETTLE_VERSION }} fail-on-cache-miss: true - name: 'cache wolfssl' @@ -541,7 +577,7 @@ jobs: cache-name: cache-ngtcp2 with: path: ~/ngtcp2/build - key: ${{ runner.os }}-http3-build-${{ env.cache-name }}-${{ env.NGTCP2_VERSION }}-${{ env.OPENSSL_VERSION }}-${{ env.LIBRESSL_VERSION }}-${{ env.AWSLC_VERSION }}-${{ env.GNUTLS_VERSION }}-${{ env.WOLFSSL_VERSION }} + key: ${{ runner.os }}-http3-build-${{ env.cache-name }}-${{ env.NGTCP2_VERSION }}-${{ env.OPENSSL_VERSION }}-${{ env.LIBRESSL_VERSION }}-${{ env.AWSLC_VERSION }}-${{ env.NETTLE_VERSION }}-${{ env.GNUTLS_VERSION }}-${{ env.WOLFSSL_VERSION }} fail-on-cache-miss: true - name: 'cache ngtcp2 boringssl' @@ -604,6 +640,8 @@ jobs: - name: 'configure' env: + CPPFLAGS: '${{ matrix.build.CPPFLAGS }}' + LDFLAGS: '${{ matrix.build.LDFLAGS }}' MATRIX_CONFIGURE: '${{ matrix.build.configure }}' MATRIX_GENERATE: '${{ matrix.build.generate }}' MATRIX_PKG_CONFIG_PATH: '${{ matrix.build.PKG_CONFIG_PATH }}' From ea7df8d07671240536f6ab03eaee5ffb49ddc5f7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 26 Nov 2025 00:47:04 +0100 Subject: [PATCH 068/140] docs: spell it Rustls with a capital R I believe this is how the project itself uses it. Closes #19702 --- docs/INSTALL.md | 2 +- docs/cmdline-opts/ca-native.md | 4 ++-- docs/cmdline-opts/tls-earlydata.md | 2 +- docs/libcurl/opts/CURLINFO_CERTINFO.md | 2 +- docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md | 2 +- docs/libcurl/opts/CURLOPT_CERTINFO.md | 2 +- docs/libcurl/opts/CURLOPT_CRLFILE.md | 2 +- docs/libcurl/opts/CURLOPT_ECH.md | 4 ++-- docs/libcurl/opts/CURLOPT_PROXY_CAINFO_BLOB.md | 2 +- docs/libcurl/opts/CURLOPT_PROXY_SSL_CIPHER_LIST.md | 2 +- docs/libcurl/opts/CURLOPT_PROXY_TLS13_CIPHERS.md | 2 +- docs/libcurl/opts/CURLOPT_SSL_CIPHER_LIST.md | 2 +- docs/libcurl/opts/CURLOPT_SSL_OPTIONS.md | 4 ++-- docs/libcurl/opts/CURLOPT_TLS13_CIPHERS.md | 2 +- scripts/cd2nroff | 2 +- 15 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/INSTALL.md b/docs/INSTALL.md index f3db34da280a..1859dc21ae7f 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -141,7 +141,7 @@ These options are provided to select the TLS backend to use. - GnuTLS: `--with-gnutls`. - mbedTLS: `--with-mbedtls` - OpenSSL: `--with-openssl` (also for BoringSSL, AWS-LC, LibreSSL, and quictls) - - rustls: `--with-rustls` + - Rustls: `--with-rustls` - Schannel: `--with-schannel` - wolfSSL: `--with-wolfssl` diff --git a/docs/cmdline-opts/ca-native.md b/docs/cmdline-opts/ca-native.md index a8e8c5e9a8ae..4a887df558a6 100644 --- a/docs/cmdline-opts/ca-native.md +++ b/docs/cmdline-opts/ca-native.md @@ -34,8 +34,8 @@ Fedora, RHEL), macOS, Android and iOS. (Added in 8.3.0) This option works with GnuTLS (Added in 8.5.0) and also uses Apple SecTrust when libcurl is built with it. (Added in 8.17.0) -This option works with rustls on Windows, macOS, Android and iOS. On Linux it -is equivalent to using the Mozilla CA certificate bundle. When used with rustls +This option works with Rustls on Windows, macOS, Android and iOS. On Linux it +is equivalent to using the Mozilla CA certificate bundle. When used with Rustls _only_ the native CA store is consulted, not other locations set at run time or build time. (Added in 8.13.0) diff --git a/docs/cmdline-opts/tls-earlydata.md b/docs/cmdline-opts/tls-earlydata.md index 642897798304..8e344758be5e 100644 --- a/docs/cmdline-opts/tls-earlydata.md +++ b/docs/cmdline-opts/tls-earlydata.md @@ -21,7 +21,7 @@ Enable the use of TLSv1.3 early data, also known as '0RTT' where possible. This has security implications for the requests sent that way. This option can be used when curl is built to use GnuTLS, wolfSSL, quictls and -OpenSSL as a TLS provider (but not BoringSSL, AWS-LC, or rustls). +OpenSSL as a TLS provider (but not BoringSSL, AWS-LC, or Rustls). If a server supports this TLSv1.3 feature, and to what extent, is announced as part of the TLS "session" sent back to curl. Until curl has seen such diff --git a/docs/libcurl/opts/CURLINFO_CERTINFO.md b/docs/libcurl/opts/CURLINFO_CERTINFO.md index f9fd0ad51c6d..d97c311cc8cd 100644 --- a/docs/libcurl/opts/CURLINFO_CERTINFO.md +++ b/docs/libcurl/opts/CURLINFO_CERTINFO.md @@ -14,7 +14,7 @@ TLS-backend: - OpenSSL - GnuTLS - Schannel - - rustls + - Rustls Added-in: 7.19.1 --- diff --git a/docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md b/docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md index 99bfaf11e673..eb0e24f36aff 100644 --- a/docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md +++ b/docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md @@ -15,7 +15,7 @@ TLS-backend: - OpenSSL - GnuTLS - mbedTLS - - rustls + - Rustls - wolfSSL - Schannel Added-in: 7.77.0 diff --git a/docs/libcurl/opts/CURLOPT_CERTINFO.md b/docs/libcurl/opts/CURLOPT_CERTINFO.md index 7c6641a9fd3e..baddc3079702 100644 --- a/docs/libcurl/opts/CURLOPT_CERTINFO.md +++ b/docs/libcurl/opts/CURLOPT_CERTINFO.md @@ -16,7 +16,7 @@ TLS-backend: - OpenSSL - GnuTLS - Schannel - - rustls + - Rustls Added-in: 7.19.1 --- diff --git a/docs/libcurl/opts/CURLOPT_CRLFILE.md b/docs/libcurl/opts/CURLOPT_CRLFILE.md index d5452db19bdc..0c4eca6c784f 100644 --- a/docs/libcurl/opts/CURLOPT_CRLFILE.md +++ b/docs/libcurl/opts/CURLOPT_CRLFILE.md @@ -14,7 +14,7 @@ TLS-backend: - GnuTLS - mbedTLS - OpenSSL - - rustls + - Rustls Added-in: 7.19.0 --- diff --git a/docs/libcurl/opts/CURLOPT_ECH.md b/docs/libcurl/opts/CURLOPT_ECH.md index 9ac65a73a05d..0cb2d7e4fd75 100644 --- a/docs/libcurl/opts/CURLOPT_ECH.md +++ b/docs/libcurl/opts/CURLOPT_ECH.md @@ -11,7 +11,7 @@ Protocol: TLS-backend: - OpenSSL - wolfSSL - - rustls + - Rustls Added-in: 8.8.0 --- @@ -33,7 +33,7 @@ ECH is only compatible with TLSv1.3. This experimental feature requires a special build of OpenSSL, as ECH is not yet supported in OpenSSL releases. In contrast ECH is supported by the latest -BoringSSL, wolfSSL and rustls-ffi releases. +BoringSSL, wolfSSL and Rustls-ffi releases. There is also a known issue with using wolfSSL which does not support ECH when the HelloRetryRequest mechanism is used. diff --git a/docs/libcurl/opts/CURLOPT_PROXY_CAINFO_BLOB.md b/docs/libcurl/opts/CURLOPT_PROXY_CAINFO_BLOB.md index a352886e061f..16af56e5cda6 100644 --- a/docs/libcurl/opts/CURLOPT_PROXY_CAINFO_BLOB.md +++ b/docs/libcurl/opts/CURLOPT_PROXY_CAINFO_BLOB.md @@ -18,7 +18,7 @@ Protocol: - TLS TLS-backend: - OpenSSL - - rustls + - Rustls - Schannel Added-in: 7.77.0 --- diff --git a/docs/libcurl/opts/CURLOPT_PROXY_SSL_CIPHER_LIST.md b/docs/libcurl/opts/CURLOPT_PROXY_SSL_CIPHER_LIST.md index 239ce03c73dd..718b2617491c 100644 --- a/docs/libcurl/opts/CURLOPT_PROXY_SSL_CIPHER_LIST.md +++ b/docs/libcurl/opts/CURLOPT_PROXY_SSL_CIPHER_LIST.md @@ -17,7 +17,7 @@ TLS-backend: - Schannel - wolfSSL - mbedTLS - - rustls + - Rustls Added-in: 7.52.0 --- diff --git a/docs/libcurl/opts/CURLOPT_PROXY_TLS13_CIPHERS.md b/docs/libcurl/opts/CURLOPT_PROXY_TLS13_CIPHERS.md index ee17d27e99c1..18b5516c5e65 100644 --- a/docs/libcurl/opts/CURLOPT_PROXY_TLS13_CIPHERS.md +++ b/docs/libcurl/opts/CURLOPT_PROXY_TLS13_CIPHERS.md @@ -16,7 +16,7 @@ TLS-backend: - OpenSSL - wolfSSL - mbedTLS - - rustls + - Rustls Added-in: 7.61.0 --- diff --git a/docs/libcurl/opts/CURLOPT_SSL_CIPHER_LIST.md b/docs/libcurl/opts/CURLOPT_SSL_CIPHER_LIST.md index c71a58d6850d..a177d5231722 100644 --- a/docs/libcurl/opts/CURLOPT_SSL_CIPHER_LIST.md +++ b/docs/libcurl/opts/CURLOPT_SSL_CIPHER_LIST.md @@ -17,7 +17,7 @@ TLS-backend: - Schannel - wolfSSL - mbedTLS - - rustls + - Rustls - GnuTLS Added-in: 7.9 --- diff --git a/docs/libcurl/opts/CURLOPT_SSL_OPTIONS.md b/docs/libcurl/opts/CURLOPT_SSL_OPTIONS.md index 79ced71ea76d..ddd7965ee2ef 100644 --- a/docs/libcurl/opts/CURLOPT_SSL_OPTIONS.md +++ b/docs/libcurl/opts/CURLOPT_SSL_OPTIONS.md @@ -79,8 +79,8 @@ Works with wolfSSL on Windows, Linux (Debian, Ubuntu, Gentoo, Fedora, RHEL), macOS, Android and iOS (added in 8.3.0); with GnuTLS (added in 8.5.0) and with OpenSSL and its forks (LibreSSL, BoringSSL, etc) on Windows (Added in 7.71.0). -This works with rustls on Windows, macOS, Android and iOS. On Linux it is -equivalent to using the Mozilla CA certificate bundle. When used with rustls +This works with Rustls on Windows, macOS, Android and iOS. On Linux it is +equivalent to using the Mozilla CA certificate bundle. When used with Rustls _only_ the native CA store is consulted, not other locations set at run time or build time. (Added in 8.13.0) diff --git a/docs/libcurl/opts/CURLOPT_TLS13_CIPHERS.md b/docs/libcurl/opts/CURLOPT_TLS13_CIPHERS.md index 62f734f9633b..41cdec07bc51 100644 --- a/docs/libcurl/opts/CURLOPT_TLS13_CIPHERS.md +++ b/docs/libcurl/opts/CURLOPT_TLS13_CIPHERS.md @@ -17,7 +17,7 @@ TLS-backend: - OpenSSL - wolfSSL - mbedTLS - - rustls + - Rustls Added-in: 7.61.0 --- diff --git a/scripts/cd2nroff b/scripts/cd2nroff index 3f1162a7396c..e97d1299ddbd 100755 --- a/scripts/cd2nroff +++ b/scripts/cd2nroff @@ -189,7 +189,7 @@ my %knowntls = ( 'GnuTLS' => 1, 'mbedTLS' => 1, 'OpenSSL' => 1, - 'rustls' => 1, + 'Rustls' => 1, 'Schannel' => 1, 'wolfSSL' => 1, 'All' => 1, From cb722b32ad163ecdf12b408f2ea86346fe83e199 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 26 Nov 2025 08:23:04 +0100 Subject: [PATCH 069/140] urlapi: handle OOM properly when setting URL Closes #19704 --- lib/urlapi.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/urlapi.c b/lib/urlapi.c index a3d9efdb919f..9d3eb0f8cf0f 100644 --- a/lib/urlapi.c +++ b/lib/urlapi.c @@ -1687,22 +1687,31 @@ static CURLUcode set_url(CURLU *u, const char *url, size_t part_size, if(!part_size) { /* a blank URL is not a valid URL unless we already have a complete one and this is a redirect */ - if(!curl_url_get(u, CURLUPART_URL, &oldurl, flags)) { + uc = curl_url_get(u, CURLUPART_URL, &oldurl, flags); + if(!uc) { /* success, meaning the "" is a fine relative URL, but nothing changes */ free(oldurl); return CURLUE_OK; } + if(uc == CURLUE_OUT_OF_MEMORY) + return uc; return CURLUE_MALFORMED_INPUT; } - /* if the new thing is absolute or the old one is not (we could not get an - * absolute URL in 'oldurl'), then replace the existing with the new. */ + /* if the new URL is absolute replace the existing with the new. */ if(Curl_is_absolute_url(url, NULL, 0, - flags & (CURLU_GUESS_SCHEME|CURLU_DEFAULT_SCHEME)) - || curl_url_get(u, CURLUPART_URL, &oldurl, flags)) { + flags & (CURLU_GUESS_SCHEME|CURLU_DEFAULT_SCHEME))) return parseurl_and_replace(url, u, flags); - } + + /* if the old URL is incomplete (we cannot get an absolute URL in + 'oldurl'), replace the existing with the new */ + uc = curl_url_get(u, CURLUPART_URL, &oldurl, flags); + if(uc == CURLUE_OUT_OF_MEMORY) + return uc; + else if(uc) + return parseurl_and_replace(url, u, flags); + DEBUGASSERT(oldurl); /* it is set here */ /* apply the relative part to create a new URL */ uc = redirect_url(oldurl, url, u, flags); From 0d2bb9c7c6d6ccdc48bb0414b80204acbd29f923 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 26 Nov 2025 11:01:09 +0100 Subject: [PATCH 070/140] http: fix OOM exit in Curl_http_follow Spotted by "strict torture" tests. Closes #19705 --- lib/http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http.c b/lib/http.c index ae932cd7c93a..144a898ea0eb 100644 --- a/lib/http.c +++ b/lib/http.c @@ -1282,7 +1282,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, CURLU_ALLOW_SPACE | (data->set.path_as_is ? CURLU_PATH_AS_IS : 0))); if(uc) { - if(type != FOLLOW_FAKE) { + if((uc == CURLUE_OUT_OF_MEMORY) || (type != FOLLOW_FAKE)) { failf(data, "The redirect target URL could not be parsed: %s", curl_url_strerror(uc)); return Curl_uc_to_curlcode(uc); From 2acdc4f549ac4aee691ed5782b32a1c5c9f86dbe Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 26 Nov 2025 02:03:29 +0100 Subject: [PATCH 071/140] autotools: add nettle library detection via pkg-config (for GnuTLS) Also: - fix to restore full state when gnutls canary function is not found. - fix indentation. Closes #19703 --- .github/workflows/http3-linux.yml | 4 +- m4/curl-gnutls.m4 | 73 ++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 15 deletions(-) diff --git a/.github/workflows/http3-linux.yml b/.github/workflows/http3-linux.yml index 06e8e2e97507..87738dd79138 100644 --- a/.github/workflows/http3-linux.yml +++ b/.github/workflows/http3-linux.yml @@ -409,8 +409,7 @@ jobs: install_packages: libp11-kit-dev install_steps: skipall PKG_CONFIG_PATH: /home/runner/nettle/build/lib64/pkgconfig:/home/runner/gnutls/build/lib/pkgconfig:/home/runner/nghttp3/build/lib/pkgconfig:/home/runner/ngtcp2/build/lib/pkgconfig:/home/runner/nghttp2/build/lib/pkgconfig - LDFLAGS: -Wl,-rpath,/home/runner/gnutls/build/lib -Wl,-rpath,/home/runner/nettle/build/lib64 -L/home/runner/nettle/build/lib64 -Wl,-rpath,/home/runner/ngtcp2/build/lib - CPPFLAGS: -I/home/runner/nettle/build/include + LDFLAGS: -Wl,-rpath,/home/runner/gnutls/build/lib -Wl,-rpath,/home/runner/nettle/build/lib64 -Wl,-rpath,/home/runner/ngtcp2/build/lib configure: >- --with-gnutls=/home/runner/gnutls/build --with-ngtcp2 --enable-ssls-export @@ -640,7 +639,6 @@ jobs: - name: 'configure' env: - CPPFLAGS: '${{ matrix.build.CPPFLAGS }}' LDFLAGS: '${{ matrix.build.LDFLAGS }}' MATRIX_CONFIGURE: '${{ matrix.build.configure }}' MATRIX_GENERATE: '${{ matrix.build.generate }}' diff --git a/m4/curl-gnutls.m4 b/m4/curl-gnutls.m4 index 9fa7e2451570..f1aa04d3faf6 100644 --- a/m4/curl-gnutls.m4 +++ b/m4/curl-gnutls.m4 @@ -100,18 +100,20 @@ if test "x$OPT_GNUTLS" != xno; then dnl this function is selected since it was introduced in 3.1.10 AC_CHECK_LIB(gnutls, gnutls_x509_crt_get_dn2, - [ + [ AC_DEFINE(USE_GNUTLS, 1, [if GnuTLS is enabled]) GNUTLS_ENABLED=1 USE_GNUTLS="yes" ssl_msg="GnuTLS" QUIC_ENABLED=yes test gnutls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes - ], - [ - LIBS="$CLEANLIBS" - CPPFLAGS="$CLEANCPPFLAGS" - ]) + ], + [ + LIBS="$CLEANLIBS" + CPPFLAGS="$CLEANCPPFLAGS" + LDFLAGS="$CLEANLDFLAGS" + LDFLAGSPC="$CLEANLDFLAGSPC" + ]) if test "x$USE_GNUTLS" = "xyes"; then AC_MSG_NOTICE([detected GnuTLS version $version]) @@ -127,9 +129,8 @@ if test "x$OPT_GNUTLS" != xno; then AC_MSG_NOTICE([Added $gtlslib to CURL_LIBRARY_PATH]) fi fi - LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE gnutls nettle" + LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE gnutls" fi - fi fi dnl GNUTLS not disabled @@ -147,12 +148,60 @@ if test "$GNUTLS_ENABLED" = "1"; then # If not, try linking directly to both of them to see if they are available if test "$USE_GNUTLS_NETTLE" = ""; then - AC_CHECK_LIB(nettle, nettle_MD5Init, [ USE_GNUTLS_NETTLE=1 ]) + + dnl this is with no particular path given + CURL_CHECK_PKGCONFIG(nettle) + + if test "$PKGCONFIG" != "no" ; then + addlib=`$PKGCONFIG --libs-only-l nettle` + addld=`$PKGCONFIG --libs-only-L nettle` + addcflags=`$PKGCONFIG --cflags-only-I nettle` + version=`$PKGCONFIG --modversion nettle` + gtlslib=`echo $addld | $SED -e 's/^-L//'` + + if test -n "$addlib"; then + + CLEANLIBS="$LIBS" + CLEANCPPFLAGS="$CPPFLAGS" + CLEANLDFLAGS="$LDFLAGS" + CLEANLDFLAGSPC="$LDFLAGSPC" + + LIBS="$addlib $LIBS" + LDFLAGS="$LDFLAGS $addld" + LDFLAGSPC="$LDFLAGSPC $addld" + if test "$addcflags" != "-I/usr/include"; then + CPPFLAGS="$CPPFLAGS $addcflags" + fi + + AC_CHECK_LIB(nettle, nettle_MD5Init, + [ + USE_GNUTLS_NETTLE=1 + ], + [ + LIBS="$CLEANLIBS" + CPPFLAGS="$CLEANCPPFLAGS" + LDFLAGS="$CLEANLDFLAGS" + LDFLAGSPC="$CLEANLDFLAGSPC" + ]) + + if test "$USE_GNUTLS_NETTLE" = "1"; then + if test -z "$version"; then + version="unknown" + fi + AC_MSG_NOTICE([detected nettle version $version]) + fi + fi + fi + if test "$USE_GNUTLS_NETTLE" = ""; then + AC_MSG_ERROR([GnuTLS found, but nettle was not found]) + fi + else + LIBS="-lnettle $LIBS" fi - if test "$USE_GNUTLS_NETTLE" = ""; then - AC_MSG_ERROR([GnuTLS found, but nettle was not found]) + + if test "$USE_GNUTLS_NETTLE" = "1"; then + LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE nettle" fi - LIBS="-lnettle $LIBS" dnl --- dnl We require GnuTLS with SRP support. From c722346518365c401b572f8dbe5fa6792ba923cd Mon Sep 17 00:00:00 2001 From: BANADDA Date: Sat, 15 Nov 2025 02:08:10 +0000 Subject: [PATCH 072/140] examples/multi-uv: fix invalid req->data access The on_uv_timeout callback was trying to access req->data as a curl_context pointer, but uv.timeout.data was never initialized, making it always NULL. This rendered the code inside the if(context) block unreachable. Fixes #19462 Closes #19538 --- docs/examples/multi-uv.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/examples/multi-uv.c b/docs/examples/multi-uv.c index 190bed3ef475..75fec20199b3 100644 --- a/docs/examples/multi-uv.c +++ b/docs/examples/multi-uv.c @@ -160,12 +160,19 @@ static void on_uv_socket(uv_poll_t *req, int status, int events) /* callback from libuv when timeout expires */ static void on_uv_timeout(uv_timer_t *req) { - struct curl_context *context = (struct curl_context *) req->data; - if(context) { - int running_handles; - curl_multi_socket_action(context->uv->multi, CURL_SOCKET_TIMEOUT, 0, - &running_handles); - check_multi_info(context); + /* get the datauv struct from the timer handle */ + struct datauv *uv = (struct datauv *)req; + int running_handles; + + curl_multi_socket_action(uv->multi, CURL_SOCKET_TIMEOUT, 0, + &running_handles); + + /* We do not have a curl_context here, so we need to check messages + differently. Create a temporary context just for the check. */ + if(running_handles) { + struct curl_context temp_context; + temp_context.uv = uv; + check_multi_info(&temp_context); } } From 0b09ad8ecbb1e80bc5f621fc012080ab2abf61c4 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 26 Nov 2025 12:56:44 +0100 Subject: [PATCH 073/140] examples/multi-uv: simplify passing `uv` struct Reported-by: st751228051 on github Follow-up to c722346518365c401b572f8dbe5fa6792ba923cd #19538 #19462 Closes #19707 --- docs/examples/multi-uv.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/docs/examples/multi-uv.c b/docs/examples/multi-uv.c index 75fec20199b3..1dac32048927 100644 --- a/docs/examples/multi-uv.c +++ b/docs/examples/multi-uv.c @@ -104,7 +104,7 @@ static void add_download(const char *url, int num, CURLM *multi) fprintf(stderr, "Added download %s -> %s\n", url, filename); } -static void check_multi_info(struct curl_context *context) +static void check_multi_info(struct datauv *uv) { char *done_url; CURLMsg *message; @@ -112,7 +112,7 @@ static void check_multi_info(struct curl_context *context) CURL *curl; FILE *file; - while((message = curl_multi_info_read(context->uv->multi, &pending))) { + while((message = curl_multi_info_read(uv->multi, &pending))) { switch(message->msg) { case CURLMSG_DONE: /* Do not use message data after calling curl_multi_remove_handle() and @@ -126,7 +126,7 @@ static void check_multi_info(struct curl_context *context) curl_easy_getinfo(curl, CURLINFO_PRIVATE, &file); printf("%s DONE\n", done_url); - curl_multi_remove_handle(context->uv->multi, curl); + curl_multi_remove_handle(uv->multi, curl); curl_easy_cleanup(curl); if(file) { fclose(file); @@ -154,7 +154,7 @@ static void on_uv_socket(uv_poll_t *req, int status, int events) curl_multi_socket_action(context->uv->multi, context->sockfd, flags, &running_handles); - check_multi_info(context); + check_multi_info(context->uv); } /* callback from libuv when timeout expires */ @@ -167,13 +167,8 @@ static void on_uv_timeout(uv_timer_t *req) curl_multi_socket_action(uv->multi, CURL_SOCKET_TIMEOUT, 0, &running_handles); - /* We do not have a curl_context here, so we need to check messages - differently. Create a temporary context just for the check. */ - if(running_handles) { - struct curl_context temp_context; - temp_context.uv = uv; - check_multi_info(&temp_context); - } + if(running_handles) + check_multi_info(uv); } /* callback from libcurl to update the timeout expiry */ From 94ce87c39124d9845aa1e3ce170b9b227ddece89 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Wed, 26 Nov 2025 12:02:02 +0100 Subject: [PATCH 074/140] types: remove curl_int64_t/curl_uint64_t These types and the definitions surrounding them are no longer needed. Closes #19706 --- lib/curl_setup.h | 14 ---- lib/curl_sha512_256.c | 180 ++++++++++++++++++++--------------------- lib/vquic/curl_osslq.c | 7 +- src/tool_util.c | 8 +- 4 files changed, 97 insertions(+), 112 deletions(-) diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 664aa1432532..48b9ea9ea9f9 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -571,20 +571,6 @@ #endif #define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - 1) -#if (SIZEOF_CURL_OFF_T != 8) -# error "curl_off_t must be exactly 64 bits" -#else - typedef unsigned CURL_TYPEOF_CURL_OFF_T curl_uint64_t; - typedef CURL_TYPEOF_CURL_OFF_T curl_int64_t; -# ifndef CURL_SUFFIX_CURL_OFF_TU -# error "CURL_SUFFIX_CURL_OFF_TU must be defined" -# endif -# define CURL_UINT64_SUFFIX CURL_SUFFIX_CURL_OFF_TU -# define CURL_UINT64_C(val) CURL_CONC_MACROS(val,CURL_UINT64_SUFFIX) -# define FMT_PRId64 CURL_FORMAT_CURL_OFF_T -# define FMT_PRIu64 CURL_FORMAT_CURL_OFF_TU -#endif - #define FMT_OFF_T CURL_FORMAT_CURL_OFF_T #define FMT_OFF_TU CURL_FORMAT_CURL_OFF_TU diff --git a/lib/curl_sha512_256.c b/lib/curl_sha512_256.c index 070d1722cbce..af768fd2aa5f 100644 --- a/lib/curl_sha512_256.c +++ b/lib/curl_sha512_256.c @@ -287,30 +287,30 @@ static CURLcode Curl_sha512_256_finish(unsigned char *digest, Can be moved to other headers to reuse. */ #define CURL_GET_64BIT_BE(ptr) \ - ( ((curl_uint64_t)(((const unsigned char*)(ptr))[0]) << 56) | \ - ((curl_uint64_t)(((const unsigned char*)(ptr))[1]) << 48) | \ - ((curl_uint64_t)(((const unsigned char*)(ptr))[2]) << 40) | \ - ((curl_uint64_t)(((const unsigned char*)(ptr))[3]) << 32) | \ - ((curl_uint64_t)(((const unsigned char*)(ptr))[4]) << 24) | \ - ((curl_uint64_t)(((const unsigned char*)(ptr))[5]) << 16) | \ - ((curl_uint64_t)(((const unsigned char*)(ptr))[6]) << 8) | \ - (curl_uint64_t)(((const unsigned char*)(ptr))[7]) ) + ( ((uint64_t)(((const uint8_t*)(ptr))[0]) << 56) | \ + ((uint64_t)(((const uint8_t*)(ptr))[1]) << 48) | \ + ((uint64_t)(((const uint8_t*)(ptr))[2]) << 40) | \ + ((uint64_t)(((const uint8_t*)(ptr))[3]) << 32) | \ + ((uint64_t)(((const uint8_t*)(ptr))[4]) << 24) | \ + ((uint64_t)(((const uint8_t*)(ptr))[5]) << 16) | \ + ((uint64_t)(((const uint8_t*)(ptr))[6]) << 8) | \ + (uint64_t)(((const uint8_t*)(ptr))[7]) ) #define CURL_PUT_64BIT_BE(ptr,val) do { \ - ((unsigned char*)(ptr))[7]=(unsigned char)((curl_uint64_t)(val)); \ - ((unsigned char*)(ptr))[6]=(unsigned char)(((curl_uint64_t)(val)) >> 8); \ - ((unsigned char*)(ptr))[5]=(unsigned char)(((curl_uint64_t)(val)) >> 16); \ - ((unsigned char*)(ptr))[4]=(unsigned char)(((curl_uint64_t)(val)) >> 24); \ - ((unsigned char*)(ptr))[3]=(unsigned char)(((curl_uint64_t)(val)) >> 32); \ - ((unsigned char*)(ptr))[2]=(unsigned char)(((curl_uint64_t)(val)) >> 40); \ - ((unsigned char*)(ptr))[1]=(unsigned char)(((curl_uint64_t)(val)) >> 48); \ - ((unsigned char*)(ptr))[0]=(unsigned char)(((curl_uint64_t)(val)) >> 56); \ + ((uint8_t*)(ptr))[7]=(uint8_t)((uint64_t)(val)); \ + ((uint8_t*)(ptr))[6]=(uint8_t)(((uint64_t)(val)) >> 8); \ + ((uint8_t*)(ptr))[5]=(uint8_t)(((uint64_t)(val)) >> 16); \ + ((uint8_t*)(ptr))[4]=(uint8_t)(((uint64_t)(val)) >> 24); \ + ((uint8_t*)(ptr))[3]=(uint8_t)(((uint64_t)(val)) >> 32); \ + ((uint8_t*)(ptr))[2]=(uint8_t)(((uint64_t)(val)) >> 40); \ + ((uint8_t*)(ptr))[1]=(uint8_t)(((uint64_t)(val)) >> 48); \ + ((uint8_t*)(ptr))[0]=(uint8_t)(((uint64_t)(val)) >> 56); \ } while(0) /* Defined as a function. The macro version may duplicate the binary code * size as each argument is used twice, so if any calculation is used * as an argument, the calculation could be done twice. */ -static CURL_FORCEINLINE curl_uint64_t Curl_rotr64(curl_uint64_t value, +static CURL_FORCEINLINE uint64_t Curl_rotr64(uint64_t value, unsigned int bits) { bits %= 64; @@ -376,22 +376,22 @@ struct Curl_sha512_256ctx { * compilers may automatically use fast load/store instruction for big * endian data on little endian machine. */ - curl_uint64_t H[SHA512_256_HASH_SIZE_WORDS]; + uint64_t H[SHA512_256_HASH_SIZE_WORDS]; /** * SHA-512/256 input data buffer. The buffer is properly aligned. Smart * compilers may automatically use fast load/store instruction for big * endian data on little endian machine. */ - curl_uint64_t buffer[SHA512_256_BLOCK_SIZE_WORDS]; + uint64_t buffer[SHA512_256_BLOCK_SIZE_WORDS]; /** * The number of bytes, lower part */ - curl_uint64_t count; + uint64_t count; /** * The number of bits, high part. Unlike lower part, this counts the number * of bits, not bytes. */ - curl_uint64_t count_bits_hi; + uint64_t count_bits_hi; }; /** @@ -413,23 +413,23 @@ static CURLcode Curl_sha512_256_init(void *context) /* Check whether the header and this file use the same numbers */ DEBUGASSERT(CURL_SHA512_256_DIGEST_LENGTH == CURL_SHA512_256_DIGEST_SIZE); - DEBUGASSERT(sizeof(curl_uint64_t) == 8); + DEBUGASSERT(sizeof(uint64_t) == 8); /* Initial hash values, see FIPS PUB 180-4 section 5.3.6.2 */ /* Values generated by "IV Generation Function" as described in * section 5.3.6 */ - ctx->H[0] = CURL_UINT64_C(0x22312194FC2BF72C); - ctx->H[1] = CURL_UINT64_C(0x9F555FA3C84C64C2); - ctx->H[2] = CURL_UINT64_C(0x2393B86B6F53B151); - ctx->H[3] = CURL_UINT64_C(0x963877195940EABD); - ctx->H[4] = CURL_UINT64_C(0x96283EE2A88EFFE3); - ctx->H[5] = CURL_UINT64_C(0xBE5E1E2553863992); - ctx->H[6] = CURL_UINT64_C(0x2B0199FC2C85B8AA); - ctx->H[7] = CURL_UINT64_C(0x0EB72DDC81C52CA2); + ctx->H[0] = UINT64_C(0x22312194FC2BF72C); + ctx->H[1] = UINT64_C(0x9F555FA3C84C64C2); + ctx->H[2] = UINT64_C(0x2393B86B6F53B151); + ctx->H[3] = UINT64_C(0x963877195940EABD); + ctx->H[4] = UINT64_C(0x96283EE2A88EFFE3); + ctx->H[5] = UINT64_C(0xBE5E1E2553863992); + ctx->H[6] = UINT64_C(0x2B0199FC2C85B8AA); + ctx->H[7] = UINT64_C(0x0EB72DDC81C52CA2); /* Initialise number of bytes and high part of number of bits. */ - ctx->count = CURL_UINT64_C(0); - ctx->count_bits_hi = CURL_UINT64_C(0); + ctx->count = UINT64_C(0); + ctx->count_bits_hi = UINT64_C(0); return CURLE_OK; } @@ -442,23 +442,23 @@ static CURLcode Curl_sha512_256_init(void *context) * @param data the data buffer with #CURL_SHA512_256_BLOCK_SIZE bytes block */ static -void Curl_sha512_256_transform(curl_uint64_t H[SHA512_256_HASH_SIZE_WORDS], +void Curl_sha512_256_transform(uint64_t H[SHA512_256_HASH_SIZE_WORDS], const void *data) { /* Working variables, see FIPS PUB 180-4 section 6.7, 6.4. */ - curl_uint64_t a = H[0]; - curl_uint64_t b = H[1]; - curl_uint64_t c = H[2]; - curl_uint64_t d = H[3]; - curl_uint64_t e = H[4]; - curl_uint64_t f = H[5]; - curl_uint64_t g = H[6]; - curl_uint64_t h = H[7]; + uint64_t a = H[0]; + uint64_t b = H[1]; + uint64_t c = H[2]; + uint64_t d = H[3]; + uint64_t e = H[4]; + uint64_t f = H[5]; + uint64_t g = H[6]; + uint64_t h = H[7]; /* Data buffer, used as a cyclic buffer. See FIPS PUB 180-4 section 5.2.2, 6.7, 6.4. */ - curl_uint64_t W[16]; + uint64_t W[16]; /* 'Ch' and 'Maj' macro functions are defined with widely-used optimization. See FIPS PUB 180-4 formulae 4.8, 4.9. */ @@ -480,47 +480,47 @@ void Curl_sha512_256_transform(curl_uint64_t H[SHA512_256_HASH_SIZE_WORDS], unsigned int t; /* K constants array. See FIPS PUB 180-4 section 4.2.3 for K values. */ - static const curl_uint64_t K[80] = { - CURL_UINT64_C(0x428a2f98d728ae22), CURL_UINT64_C(0x7137449123ef65cd), - CURL_UINT64_C(0xb5c0fbcfec4d3b2f), CURL_UINT64_C(0xe9b5dba58189dbbc), - CURL_UINT64_C(0x3956c25bf348b538), CURL_UINT64_C(0x59f111f1b605d019), - CURL_UINT64_C(0x923f82a4af194f9b), CURL_UINT64_C(0xab1c5ed5da6d8118), - CURL_UINT64_C(0xd807aa98a3030242), CURL_UINT64_C(0x12835b0145706fbe), - CURL_UINT64_C(0x243185be4ee4b28c), CURL_UINT64_C(0x550c7dc3d5ffb4e2), - CURL_UINT64_C(0x72be5d74f27b896f), CURL_UINT64_C(0x80deb1fe3b1696b1), - CURL_UINT64_C(0x9bdc06a725c71235), CURL_UINT64_C(0xc19bf174cf692694), - CURL_UINT64_C(0xe49b69c19ef14ad2), CURL_UINT64_C(0xefbe4786384f25e3), - CURL_UINT64_C(0x0fc19dc68b8cd5b5), CURL_UINT64_C(0x240ca1cc77ac9c65), - CURL_UINT64_C(0x2de92c6f592b0275), CURL_UINT64_C(0x4a7484aa6ea6e483), - CURL_UINT64_C(0x5cb0a9dcbd41fbd4), CURL_UINT64_C(0x76f988da831153b5), - CURL_UINT64_C(0x983e5152ee66dfab), CURL_UINT64_C(0xa831c66d2db43210), - CURL_UINT64_C(0xb00327c898fb213f), CURL_UINT64_C(0xbf597fc7beef0ee4), - CURL_UINT64_C(0xc6e00bf33da88fc2), CURL_UINT64_C(0xd5a79147930aa725), - CURL_UINT64_C(0x06ca6351e003826f), CURL_UINT64_C(0x142929670a0e6e70), - CURL_UINT64_C(0x27b70a8546d22ffc), CURL_UINT64_C(0x2e1b21385c26c926), - CURL_UINT64_C(0x4d2c6dfc5ac42aed), CURL_UINT64_C(0x53380d139d95b3df), - CURL_UINT64_C(0x650a73548baf63de), CURL_UINT64_C(0x766a0abb3c77b2a8), - CURL_UINT64_C(0x81c2c92e47edaee6), CURL_UINT64_C(0x92722c851482353b), - CURL_UINT64_C(0xa2bfe8a14cf10364), CURL_UINT64_C(0xa81a664bbc423001), - CURL_UINT64_C(0xc24b8b70d0f89791), CURL_UINT64_C(0xc76c51a30654be30), - CURL_UINT64_C(0xd192e819d6ef5218), CURL_UINT64_C(0xd69906245565a910), - CURL_UINT64_C(0xf40e35855771202a), CURL_UINT64_C(0x106aa07032bbd1b8), - CURL_UINT64_C(0x19a4c116b8d2d0c8), CURL_UINT64_C(0x1e376c085141ab53), - CURL_UINT64_C(0x2748774cdf8eeb99), CURL_UINT64_C(0x34b0bcb5e19b48a8), - CURL_UINT64_C(0x391c0cb3c5c95a63), CURL_UINT64_C(0x4ed8aa4ae3418acb), - CURL_UINT64_C(0x5b9cca4f7763e373), CURL_UINT64_C(0x682e6ff3d6b2b8a3), - CURL_UINT64_C(0x748f82ee5defb2fc), CURL_UINT64_C(0x78a5636f43172f60), - CURL_UINT64_C(0x84c87814a1f0ab72), CURL_UINT64_C(0x8cc702081a6439ec), - CURL_UINT64_C(0x90befffa23631e28), CURL_UINT64_C(0xa4506cebde82bde9), - CURL_UINT64_C(0xbef9a3f7b2c67915), CURL_UINT64_C(0xc67178f2e372532b), - CURL_UINT64_C(0xca273eceea26619c), CURL_UINT64_C(0xd186b8c721c0c207), - CURL_UINT64_C(0xeada7dd6cde0eb1e), CURL_UINT64_C(0xf57d4f7fee6ed178), - CURL_UINT64_C(0x06f067aa72176fba), CURL_UINT64_C(0x0a637dc5a2c898a6), - CURL_UINT64_C(0x113f9804bef90dae), CURL_UINT64_C(0x1b710b35131c471b), - CURL_UINT64_C(0x28db77f523047d84), CURL_UINT64_C(0x32caab7b40c72493), - CURL_UINT64_C(0x3c9ebe0a15c9bebc), CURL_UINT64_C(0x431d67c49c100d4c), - CURL_UINT64_C(0x4cc5d4becb3e42b6), CURL_UINT64_C(0x597f299cfc657e2a), - CURL_UINT64_C(0x5fcb6fab3ad6faec), CURL_UINT64_C(0x6c44198c4a475817) + static const uint64_t K[80] = { + UINT64_C(0x428a2f98d728ae22), UINT64_C(0x7137449123ef65cd), + UINT64_C(0xb5c0fbcfec4d3b2f), UINT64_C(0xe9b5dba58189dbbc), + UINT64_C(0x3956c25bf348b538), UINT64_C(0x59f111f1b605d019), + UINT64_C(0x923f82a4af194f9b), UINT64_C(0xab1c5ed5da6d8118), + UINT64_C(0xd807aa98a3030242), UINT64_C(0x12835b0145706fbe), + UINT64_C(0x243185be4ee4b28c), UINT64_C(0x550c7dc3d5ffb4e2), + UINT64_C(0x72be5d74f27b896f), UINT64_C(0x80deb1fe3b1696b1), + UINT64_C(0x9bdc06a725c71235), UINT64_C(0xc19bf174cf692694), + UINT64_C(0xe49b69c19ef14ad2), UINT64_C(0xefbe4786384f25e3), + UINT64_C(0x0fc19dc68b8cd5b5), UINT64_C(0x240ca1cc77ac9c65), + UINT64_C(0x2de92c6f592b0275), UINT64_C(0x4a7484aa6ea6e483), + UINT64_C(0x5cb0a9dcbd41fbd4), UINT64_C(0x76f988da831153b5), + UINT64_C(0x983e5152ee66dfab), UINT64_C(0xa831c66d2db43210), + UINT64_C(0xb00327c898fb213f), UINT64_C(0xbf597fc7beef0ee4), + UINT64_C(0xc6e00bf33da88fc2), UINT64_C(0xd5a79147930aa725), + UINT64_C(0x06ca6351e003826f), UINT64_C(0x142929670a0e6e70), + UINT64_C(0x27b70a8546d22ffc), UINT64_C(0x2e1b21385c26c926), + UINT64_C(0x4d2c6dfc5ac42aed), UINT64_C(0x53380d139d95b3df), + UINT64_C(0x650a73548baf63de), UINT64_C(0x766a0abb3c77b2a8), + UINT64_C(0x81c2c92e47edaee6), UINT64_C(0x92722c851482353b), + UINT64_C(0xa2bfe8a14cf10364), UINT64_C(0xa81a664bbc423001), + UINT64_C(0xc24b8b70d0f89791), UINT64_C(0xc76c51a30654be30), + UINT64_C(0xd192e819d6ef5218), UINT64_C(0xd69906245565a910), + UINT64_C(0xf40e35855771202a), UINT64_C(0x106aa07032bbd1b8), + UINT64_C(0x19a4c116b8d2d0c8), UINT64_C(0x1e376c085141ab53), + UINT64_C(0x2748774cdf8eeb99), UINT64_C(0x34b0bcb5e19b48a8), + UINT64_C(0x391c0cb3c5c95a63), UINT64_C(0x4ed8aa4ae3418acb), + UINT64_C(0x5b9cca4f7763e373), UINT64_C(0x682e6ff3d6b2b8a3), + UINT64_C(0x748f82ee5defb2fc), UINT64_C(0x78a5636f43172f60), + UINT64_C(0x84c87814a1f0ab72), UINT64_C(0x8cc702081a6439ec), + UINT64_C(0x90befffa23631e28), UINT64_C(0xa4506cebde82bde9), + UINT64_C(0xbef9a3f7b2c67915), UINT64_C(0xc67178f2e372532b), + UINT64_C(0xca273eceea26619c), UINT64_C(0xd186b8c721c0c207), + UINT64_C(0xeada7dd6cde0eb1e), UINT64_C(0xf57d4f7fee6ed178), + UINT64_C(0x06f067aa72176fba), UINT64_C(0x0a637dc5a2c898a6), + UINT64_C(0x113f9804bef90dae), UINT64_C(0x1b710b35131c471b), + UINT64_C(0x28db77f523047d84), UINT64_C(0x32caab7b40c72493), + UINT64_C(0x3c9ebe0a15c9bebc), UINT64_C(0x431d67c49c100d4c), + UINT64_C(0x4cc5d4becb3e42b6), UINT64_C(0x597f299cfc657e2a), + UINT64_C(0x5fcb6fab3ad6faec), UINT64_C(0x6c44198c4a475817) }; /* One step of SHA-512/256 computation, @@ -541,7 +541,7 @@ void Curl_sha512_256_transform(curl_uint64_t H[SHA512_256_HASH_SIZE_WORDS], see FIPS PUB 180-4 section 6.4.2 step 3. This macro version reassigns all working variables on each step. */ #define SHA2STEP64RV(vA,vB,vC,vD,vE,vF,vG,vH,kt,wt) do { \ - curl_uint64_t tmp_h_ = (vH); \ + uint64_t tmp_h_ = (vH); \ SHA2STEP64((vA),(vB),(vC),(vD),(vE),(vF),(vG),tmp_h_,(kt),(wt)); \ (vH) = (vG); \ (vG) = (vF); \ @@ -558,7 +558,7 @@ void Curl_sha512_256_transform(curl_uint64_t H[SHA512_256_HASH_SIZE_WORDS], see FIPS PUB 180-4 section 3.1.2. */ #define SHA512_GET_W_FROM_DATA(buf,t) \ CURL_GET_64BIT_BE( \ - ((const unsigned char*) (buf)) + (t) * SHA512_256_BYTES_IN_WORD) + ((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 @@ -573,9 +573,9 @@ void Curl_sha512_256_transform(curl_uint64_t H[SHA512_256_HASH_SIZE_WORDS], As only the last 16 'W' are used in calculations, it is possible to use 16 elements array of W as a cyclic buffer. Note: ((t-16) & 15) have same value as (t & 15) */ -#define Wgen(w,t) \ - (curl_uint64_t)( (w)[(t - 16) & 15] + sig1((w)[((t) - 2) & 15]) \ - + (w)[((t) - 7) & 15] + sig0((w)[((t) - 15) & 15]) ) +#define Wgen(w,t) \ + (uint64_t)( (w)[(t - 16) & 15] + sig1((w)[((t) - 2) & 15]) \ + + (w)[((t) - 7) & 15] + sig0((w)[((t) - 15) & 15]) ) /* During the last 64 steps, before making any calculation on each step, current W element is generated from other W elements of the cyclic @@ -628,7 +628,7 @@ static CURLcode Curl_sha512_256_update(void *context, if(length > ctx->count) ctx->count_bits_hi += 1U << 3; /* Value wrap */ ctx->count_bits_hi += ctx->count >> 61; - ctx->count &= CURL_UINT64_C(0x1FFFFFFFFFFFFFFF); + ctx->count &= UINT64_C(0x1FFFFFFFFFFFFFFF); if(bytes_have) { unsigned int bytes_left = CURL_SHA512_256_BLOCK_SIZE - bytes_have; @@ -685,7 +685,7 @@ static CURLcode Curl_sha512_256_update(void *context, static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context) { struct Curl_sha512_256ctx *const ctx = (struct Curl_sha512_256ctx *)context; - curl_uint64_t num_bits; /**< Number of processed bits */ + uint64_t num_bits; /**< Number of processed bits */ unsigned int bytes_have; /**< Number of bytes in the context buffer */ /* the void pointer here is required to mute Intel compiler warning */ void *const ctx_buf = ctx->buffer; diff --git a/lib/vquic/curl_osslq.c b/lib/vquic/curl_osslq.c index ade94bf40aa7..0f7cc7a91a2a 100644 --- a/lib/vquic/curl_osslq.c +++ b/lib/vquic/curl_osslq.c @@ -1272,8 +1272,8 @@ static CURLcode h3_quic_recv(void *reader_ctx, } else { CURL_TRC_CF(x->data, x->cf, "[%" PRId64 "] h3_quic_recv -> RESET, " - "rv=%d, app_err=%" FMT_PRIu64, - x->s->id, rv, (curl_uint64_t)app_error_code); + "rv=%d, app_err=%" PRIu64, + x->s->id, rv, app_error_code); if(app_error_code != NGHTTP3_H3_NO_ERROR) x->s->reset = TRUE; } @@ -2246,8 +2246,7 @@ static bool cf_osslq_conn_is_alive(struct Curl_cfilter *cf, "assume connection is dead."); goto out; } - CURL_TRC_CF(data, cf, "negotiated idle timeout: %" FMT_PRIu64 "ms", - (curl_uint64_t)idle_ms); + CURL_TRC_CF(data, cf, "negotiated idle timeout: %" PRIu64 "ms", idle_ms); idletime = curlx_timediff_ms(curlx_now(), ctx->q.last_io); if(idle_ms && idletime > 0 && (uint64_t)idletime > idle_ms) goto out; diff --git a/src/tool_util.c b/src/tool_util.c index a2798876ea06..cb64f9a0b921 100644 --- a/src/tool_util.c +++ b/src/tool_util.c @@ -31,16 +31,16 @@ struct timeval tvrealnow(void) { /* UNIX EPOCH (1970-01-01) in FILETIME (1601-01-01) as 64-bit value */ - static const curl_uint64_t EPOCH = (curl_uint64_t)116444736000000000ULL; + static const uint64_t EPOCH = UINT64_C(116444736000000000); SYSTEMTIME systime; FILETIME ftime; /* 100ns since 1601-01-01, as double 32-bit value */ - curl_uint64_t time; /* 100ns since 1601-01-01, as 64-bit value */ + uint64_t time; /* 100ns since 1601-01-01, as 64-bit value */ struct timeval now; GetSystemTime(&systime); SystemTimeToFileTime(&systime, &ftime); - time = ((curl_uint64_t)ftime.dwLowDateTime); - time += ((curl_uint64_t)ftime.dwHighDateTime) << 32; + time = ((uint64_t)ftime.dwLowDateTime); + time += ((uint64_t)ftime.dwHighDateTime) << 32; now.tv_sec = (long)((time - EPOCH) / 10000000L); /* unit is 100ns */ now.tv_usec = (long)(systime.wMilliseconds * 1000); From 9ea6f2bc6979addeaaab94f8012ad96ae5abfc83 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Wed, 26 Nov 2025 15:58:40 +0200 Subject: [PATCH 075/140] docs: add rustls to supported backends for CERT and KEY Followup to 1c8c93ae15c692c547e3238c4f067f76616a53e8 Closes #19709 --- docs/libcurl/opts/CURLOPT_SSLCERT.md | 6 +----- docs/libcurl/opts/CURLOPT_SSLKEY.md | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/libcurl/opts/CURLOPT_SSLCERT.md b/docs/libcurl/opts/CURLOPT_SSLCERT.md index 20e7d1a17649..40c3a21c25af 100644 --- a/docs/libcurl/opts/CURLOPT_SSLCERT.md +++ b/docs/libcurl/opts/CURLOPT_SSLCERT.md @@ -11,11 +11,7 @@ See-also: Protocol: - TLS TLS-backend: - - OpenSSL - - GnuTLS - - mbedTLS - - Schannel - - wolfSSL + - All Added-in: 7.1 --- diff --git a/docs/libcurl/opts/CURLOPT_SSLKEY.md b/docs/libcurl/opts/CURLOPT_SSLKEY.md index 7d311aeec89d..bbc486d21fb3 100644 --- a/docs/libcurl/opts/CURLOPT_SSLKEY.md +++ b/docs/libcurl/opts/CURLOPT_SSLKEY.md @@ -15,6 +15,7 @@ TLS-backend: - mbedTLS - Schannel - wolfSSL + - Rustls Added-in: 7.9.3 --- From c273de193e6072c4123c4aa95cae316cd728a69f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 25 Nov 2025 16:14:43 +0100 Subject: [PATCH 076/140] test433: verify "Note: Read config file from..." Which was added in fc09a2da4ad0595292 Closes #19699 --- tests/data/test2080 | 1 + tests/data/test433 | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/data/test2080 b/tests/data/test2080 index 44d16b6ee331..52860addb053 100644 --- a/tests/data/test2080 +++ b/tests/data/test2080 @@ -3,6 +3,7 @@ FILE config +--config diff --git a/tests/data/test433 b/tests/data/test433 index 63c884fdbe48..034f84e0b6db 100644 --- a/tests/data/test433 +++ b/tests/data/test433 @@ -36,8 +36,12 @@ CURL_HOME Verify XDG_CONFIG_HOME use to find curlrc +# set the terminal wide to avoid word wrap in the message + +COLUMNS=300 + -%HOSTIP:%HTTPPORT/%TESTNUMBER +%HOSTIP:%HTTPPORT/%TESTNUMBER --no-progress-meter @@ -55,5 +59,13 @@ Content-Type: application/x-www-form-urlencoded curlrc read + +# On Windows curl may use a backslash, convert that for the comparison + +s:\\:/:g + + +Note: Read config file from '%PWD/%LOGDIR/curlrc' + From 9bb5c0578b39e5b086b6a9db5c6eb299a0fe1c5c Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Thu, 27 Nov 2025 12:11:39 +0100 Subject: [PATCH 077/140] ngtcp2+openssl: fix leak of session Fix return value indicating to OpenSSL if reference to session is kept (it is not), so OpenSSL frees it. Reported-by: Aleksei Bavshin Fixes #19717 Closes #19718 --- lib/vquic/curl_ngtcp2.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index ad1f2b2b25c8..61b233e4ffc0 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -2277,7 +2277,6 @@ static int quic_ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) #endif Curl_ossl_add_session(cf, data, ctx->peer.scache_key, ssl_sessionid, SSL_version(ssl), "h3", quic_tp, quic_tp_len); - return 1; } return 0; } From a9e7a027ed866b791c12a3c701dc40304f4e00cb Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Thu, 27 Nov 2025 10:23:43 +0100 Subject: [PATCH 078/140] vquic: do_sendmsg full init When passing a `msg_ctrl` to sendmsg() as part of GSO handling, zero the complete array. This fixes any false positives by valgrind that complain about uninitialised memory, even though the kernel only ever accesses the first two bytes. Reported-by: Aleksei Bavshin Fixes #19714 Closes #19715 --- lib/vquic/vquic.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/vquic/vquic.c b/lib/vquic/vquic.c index 562a99e4fee0..aa0011c577c4 100644 --- a/lib/vquic/vquic.c +++ b/lib/vquic/vquic.c @@ -145,6 +145,7 @@ static CURLcode do_sendmsg(struct Curl_cfilter *cf, if(pktlen > gsolen) { /* Only set this, when we need it. macOS, for example, * does not seem to like a msg_control of length 0. */ + memset(msg_ctrl, 0, sizeof(msg_ctrl)); msg.msg_control = msg_ctrl; assert(sizeof(msg_ctrl) >= CMSG_SPACE(sizeof(int))); msg.msg_controllen = CMSG_SPACE(sizeof(int)); From feea96851230c7a5a11feaffa0a5e4a4d30e5e63 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Mon, 3 Nov 2025 13:12:50 +0100 Subject: [PATCH 079/140] conncontrol: reuse handling Add protocol handler flag `PROTOPT_CONN_REUSE` to indicate that the protocol allows reusing connections for other tranfers. Add that to all handlers that support it. Create connections with `conn->bits.close = FALSE` and remove all the `connkeep()` calls in protocol handlers setup/connect implementations. `PROTOPT_CONN_REUSE` assures that the default behaviour applies at the end of a transfer without need to juggle the close bit. `conn->bits.close` now serves as an additional indication that a connection cannot be reused. Only protocol handles that allow reuse need to set it to override the default behaviour. Remove all `connclose()` and `connkeep()` calls from connection filters. Filters should not modify connection flags. They are supposed to run in eyeballing situations where a filter is just one of many determining the outcome. Fix http response header handling to only honour `Connection: close` for HTTP/1.x versions. Closes #19333 --- lib/cf-h1-proxy.c | 4 --- lib/cf-h2-proxy.c | 6 +--- lib/conncache.c | 1 - lib/ftp.c | 9 +++--- lib/http.c | 17 ++++------ lib/http2.c | 9 +++--- lib/imap.c | 11 +++---- lib/multi.c | 70 ++++++++++++++++++++++++----------------- lib/openldap.c | 7 +++-- lib/pop3.c | 11 +++---- lib/rtsp.c | 2 +- lib/smb.c | 7 ++--- lib/smtp.c | 11 +++---- lib/url.c | 9 +++--- lib/urldata.h | 1 + lib/vquic/curl_ngtcp2.c | 1 - lib/vquic/curl_osslq.c | 1 - lib/vquic/curl_quiche.c | 4 --- lib/vssh/libssh.c | 11 +++---- lib/vssh/libssh2.c | 12 +++---- lib/vtls/openssl.c | 3 +- 21 files changed, 93 insertions(+), 114 deletions(-) diff --git a/lib/cf-h1-proxy.c b/lib/cf-h1-proxy.c index 985500f23e06..e496d7634dce 100644 --- a/lib/cf-h1-proxy.c +++ b/lib/cf-h1-proxy.c @@ -127,7 +127,6 @@ static CURLcode tunnel_init(struct Curl_cfilter *cf, Curl_httpchunk_init(data, &ts->ch, TRUE); *pts = ts; - connkeep(cf->conn, "HTTP proxy CONNECT"); return tunnel_reinit(cf, data, ts); } @@ -591,7 +590,6 @@ static CURLcode H1_CONNECT(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "CONNECT need to close+open"); infof(data, "Connect me again please"); Curl_conn_cf_close(cf, data); - connkeep(conn, "HTTP proxy CONNECT"); result = Curl_conn_cf_connect(cf->next, data, &done); goto out; } @@ -612,8 +610,6 @@ static CURLcode H1_CONNECT(struct Curl_cfilter *cf, if(data->info.httpproxycode/100 != 2) { /* a non-2xx response and we have no next URL to try. */ Curl_safefree(data->req.newurl); - /* failure, close this connection to avoid reuse */ - streamclose(conn, "proxy CONNECT failure"); h1_tunnel_go_state(cf, ts, H1_TUNNEL_FAILED, data); failf(data, "CONNECT tunnel failed, response %d", data->req.httpcode); return CURLE_RECV_ERROR; diff --git a/lib/cf-h2-proxy.c b/lib/cf-h2-proxy.c index b963bb718ce9..89bc7cc23f48 100644 --- a/lib/cf-h2-proxy.c +++ b/lib/cf-h2-proxy.c @@ -488,10 +488,6 @@ static CURLcode proxy_h2_progress_ingress(struct Curl_cfilter *cf, return result; } - if(ctx->conn_closed && Curl_bufq_is_empty(&ctx->inbufq)) { - connclose(cf->conn, "GOAWAY received"); - } - return CURLE_OK; } @@ -1265,7 +1261,7 @@ static CURLcode h2_handle_tunnel_close(struct Curl_cfilter *cf, if(ctx->tunnel.error == NGHTTP2_REFUSED_STREAM) { CURL_TRC_CF(data, cf, "[%d] REFUSED_STREAM, try again on a new " "connection", ctx->tunnel.stream_id); - connclose(cf->conn, "REFUSED_STREAM"); /* do not use this anymore */ + failf(data, "proxy server refused HTTP/2 stream"); return CURLE_RECV_ERROR; /* trigger Curl_retry_request() later */ } else if(ctx->tunnel.error != NGHTTP2_NO_ERROR) { diff --git a/lib/conncache.c b/lib/conncache.c index 275e490f23e8..9d3b69bec356 100644 --- a/lib/conncache.c +++ b/lib/conncache.c @@ -220,7 +220,6 @@ void Curl_cpool_destroy(struct cpool *cpool) while(conn) { cpool_remove_conn(cpool, conn); sigpipe_apply(cpool->idata, &pipe_st); - connclose(conn, "kill all"); cpool_discard_conn(cpool, cpool->idata, conn, FALSE); conn = cpool_get_first(cpool); } diff --git a/lib/ftp.c b/lib/ftp.c index c289581fd5a4..ce4001226823 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -270,7 +270,8 @@ const struct Curl_handler Curl_handler_ftp = { CURLPROTO_FTP, /* family */ PROTOPT_DUAL | PROTOPT_CLOSEACTION | PROTOPT_NEEDSPWD | PROTOPT_NOURLQUERY | PROTOPT_PROXY_AS_HTTP | - PROTOPT_WILDCARD | PROTOPT_SSL_REUSE /* flags */ + PROTOPT_WILDCARD | PROTOPT_SSL_REUSE | + PROTOPT_CONN_REUSE /* flags */ }; @@ -302,7 +303,8 @@ const struct Curl_handler Curl_handler_ftps = { CURLPROTO_FTPS, /* protocol */ CURLPROTO_FTP, /* family */ PROTOPT_SSL | PROTOPT_DUAL | PROTOPT_CLOSEACTION | - PROTOPT_NEEDSPWD | PROTOPT_NOURLQUERY | PROTOPT_WILDCARD /* flags */ + PROTOPT_NEEDSPWD | PROTOPT_NOURLQUERY | PROTOPT_WILDCARD | + PROTOPT_CONN_REUSE /* flags */ }; #endif @@ -3183,9 +3185,6 @@ static CURLcode ftp_connect(struct Curl_easy *data, if(!ftpc) return CURLE_FAILED_INIT; pp = &ftpc->pp; - /* We always support persistent connections on ftp */ - connkeep(conn, "FTP default"); - PINGPONG_SETUP(pp, ftp_pp_statemachine, ftp_endofresp); if(Curl_conn_is_ssl(conn, FIRSTSOCKET)) { diff --git a/lib/http.c b/lib/http.c index 144a898ea0eb..0319be3b657b 100644 --- a/lib/http.c +++ b/lib/http.c @@ -142,7 +142,8 @@ const struct Curl_handler Curl_handler_http = { CURLPROTO_HTTP, /* protocol */ CURLPROTO_HTTP, /* family */ PROTOPT_CREDSPERREQUEST | /* flags */ - PROTOPT_USERPWDCTRL + PROTOPT_USERPWDCTRL | PROTOPT_CONN_REUSE + }; #ifdef USE_SSL @@ -172,7 +173,7 @@ const struct Curl_handler Curl_handler_https = { CURLPROTO_HTTPS, /* protocol */ CURLPROTO_HTTP, /* family */ PROTOPT_SSL | PROTOPT_CREDSPERREQUEST | PROTOPT_ALPN | /* flags */ - PROTOPT_USERPWDCTRL + PROTOPT_USERPWDCTRL | PROTOPT_CONN_REUSE }; #endif @@ -220,7 +221,6 @@ CURLcode Curl_http_setup_conn(struct Curl_easy *data, { /* allocate the HTTP-specific struct for the Curl_easy, only to survive during this request */ - connkeep(conn, "HTTP default"); if(data->state.http_neg.wanted == CURL_HTTP_V3x) { /* only HTTP/3, needs to work */ CURLcode result = Curl_conn_may_http3(data, conn, conn->transport_wanted); @@ -1548,12 +1548,6 @@ Curl_compareheader(const char *headerline, /* line to check */ */ CURLcode Curl_http_connect(struct Curl_easy *data, bool *done) { - struct connectdata *conn = data->conn; - - /* We default to persistent connections. We set this already in this connect - function to make the reuse checks properly be able to check this bit. */ - connkeep(conn, "HTTP default"); - return Curl_conn_connect(data, FIRSTSOCKET, FALSE, done); } @@ -3257,14 +3251,15 @@ static CURLcode http_header_c(struct Curl_easy *data, } return CURLE_OK; } - if(HD_IS_AND_SAYS(hd, hdlen, "Connection:", "close")) { + if((k->httpversion < 20) && + HD_IS_AND_SAYS(hd, hdlen, "Connection:", "close")) { /* * [RFC 2616, section 8.1.2.1] * "Connection: close" is HTTP/1.1 language and means that * the connection will close when this request has been * served. */ - streamclose(conn, "Connection: close used"); + connclose(conn, "Connection: close used"); return CURLE_OK; } if((k->httpversion == 10) && diff --git a/lib/http2.c b/lib/http2.c index 7b94930a21a7..4f5f5ea52dd3 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -2071,7 +2071,7 @@ static CURLcode h2_progress_ingress(struct Curl_cfilter *cf, size_t nread; if(should_close_session(ctx)) { - CURL_TRC_CF(data, cf, "progress ingress, session is closed"); + CURL_TRC_CF(data, cf, "[0] ingress: session is closed"); return CURLE_HTTP2; } @@ -2128,15 +2128,16 @@ static CURLcode h2_progress_ingress(struct Curl_cfilter *cf, result = h2_process_pending_input(cf, data); if(result) return result; - CURL_TRC_CF(data, cf, "[0] progress ingress: inbufg=%zu", + CURL_TRC_CF(data, cf, "[0] ingress: nw-in buffered %zu", Curl_bufq_len(&ctx->inbufq)); } if(ctx->conn_closed && Curl_bufq_is_empty(&ctx->inbufq)) { - connclose(cf->conn, "GOAWAY received"); + connclose(cf->conn, ctx->rcvd_goaway ? "server closed with GOAWAY" : + "server closed abruptly"); } - CURL_TRC_CF(data, cf, "[0] progress ingress: done"); + CURL_TRC_CF(data, cf, "[0] ingress: done"); return CURLE_OK; } diff --git a/lib/imap.c b/lib/imap.c index 181b0d7009d6..af9b124d1e72 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -210,9 +210,9 @@ const struct Curl_handler Curl_handler_imap = { PORT_IMAP, /* defport */ CURLPROTO_IMAP, /* protocol */ CURLPROTO_IMAP, /* family */ - PROTOPT_CLOSEACTION| /* flags */ - PROTOPT_URLOPTIONS| - PROTOPT_SSL_REUSE + PROTOPT_CLOSEACTION | /* flags */ + PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE | + PROTOPT_CONN_REUSE }; #ifdef USE_SSL @@ -243,7 +243,7 @@ const struct Curl_handler Curl_handler_imaps = { CURLPROTO_IMAPS, /* protocol */ CURLPROTO_IMAP, /* family */ PROTOPT_CLOSEACTION | PROTOPT_SSL | /* flags */ - PROTOPT_URLOPTIONS + PROTOPT_URLOPTIONS | PROTOPT_CONN_REUSE }; #endif @@ -1680,9 +1680,6 @@ static CURLcode imap_connect(struct Curl_easy *data, bool *done) if(!imapc) return CURLE_FAILED_INIT; - /* We always support persistent connections in IMAP */ - connkeep(data->conn, "IMAP default"); - /* Parse the URL options */ result = imap_parse_url_options(data->conn, imapc); if(result) diff --git a/lib/multi.c b/lib/multi.c index 57c574a68176..f7265a94a9ec 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -547,6 +547,47 @@ struct multi_done_ctx { BIT(premature); }; +static bool multi_conn_should_close(struct connectdata *conn, + struct Curl_easy *data, + bool premature) +{ + /* if conn->bits.close is TRUE, it means that the connection should be + closed in spite of everything else. */ + if(conn->bits.close) + return TRUE; + + /* if data->set.reuse_forbid is TRUE, it means the libcurl client has + forced us to close this connection. This is ignored for requests taking + place in a NTLM/NEGOTIATE authentication handshake. */ + if(data->set.reuse_forbid +#ifdef USE_NTLM + && !(conn->http_ntlm_state == NTLMSTATE_TYPE2 || + conn->proxy_ntlm_state == NTLMSTATE_TYPE2) +#endif +#ifdef USE_SPNEGO + && !(conn->http_negotiate_state == GSS_AUTHRECV || + conn->proxy_negotiate_state == GSS_AUTHRECV) +#endif + ) + return TRUE; + + /* Unless this connection is for a "connect-only" transfer, it + * needs to be closed if the protocol handler does not support reuse. */ + if(!data->set.connect_only && conn->handler && + !(conn->handler->flags & PROTOPT_CONN_REUSE)) + return TRUE; + + /* if premature is TRUE, it means this connection was said to be DONE before + the entire request operation is complete and thus we cannot know in what + state it is for reusing, so we are forced to close it. In a perfect world + we can add code that keep track of if we really must close it here or not, + but currently we have no such detail knowledge. */ + if(premature && !Curl_conn_is_multiplex(conn, FIRSTSOCKET)) + return TRUE; + + return FALSE; +} + static void multi_done_locked(struct connectdata *conn, struct Curl_easy *data, void *userdata) @@ -587,32 +628,7 @@ static void multi_done_locked(struct connectdata *conn, Curl_resolv_unlink(data, &data->state.dns[1]); Curl_dnscache_prune(data); - /* if data->set.reuse_forbid is TRUE, it means the libcurl client has - forced us to close this connection. This is ignored for requests taking - place in a NTLM/NEGOTIATE authentication handshake - - if conn->bits.close is TRUE, it means that the connection should be - closed in spite of all our efforts to be nice, due to protocol - restrictions in our or the server's end - - if premature is TRUE, it means this connection was said to be DONE before - the entire request operation is complete and thus we cannot know in what - state it is for reusing, so we are forced to close it. In a perfect world - we can add code that keep track of if we really must close it here or not, - but currently we have no such detail knowledge. - */ - - if((data->set.reuse_forbid -#ifdef USE_NTLM - && !(conn->http_ntlm_state == NTLMSTATE_TYPE2 || - conn->proxy_ntlm_state == NTLMSTATE_TYPE2) -#endif -#ifdef USE_SPNEGO - && !(conn->http_negotiate_state == GSS_AUTHRECV || - conn->proxy_negotiate_state == GSS_AUTHRECV) -#endif - ) || conn->bits.close - || (mdctx->premature && !Curl_conn_is_multiplex(conn, FIRSTSOCKET))) { + if(multi_conn_should_close(conn, data, mdctx->premature)) { #ifndef CURL_DISABLE_VERBOSE_STRINGS CURL_TRC_M(data, "multi_done, terminating conn #%" FMT_OFF_T " to %s:%d, " "forbid=%d, close=%d, premature=%d, conn_multiplex=%d", @@ -2127,8 +2143,6 @@ static CURLMcode state_do(struct Curl_easy *data, } if(data->set.connect_only && !data->set.connect_only_ws) { - /* keep connection open for application to use the socket */ - connkeep(data->conn, "CONNECT_ONLY"); multistate(data, MSTATE_DONE); rc = CURLM_CALL_MULTI_PERFORM; } diff --git a/lib/openldap.c b/lib/openldap.c index 9d6174defe37..41419df21b20 100644 --- a/lib/openldap.c +++ b/lib/openldap.c @@ -139,7 +139,8 @@ const struct Curl_handler Curl_handler_ldap = { PORT_LDAP, /* defport */ CURLPROTO_LDAP, /* protocol */ CURLPROTO_LDAP, /* family */ - PROTOPT_SSL_REUSE /* flags */ + PROTOPT_SSL_REUSE | /* flags */ + PROTOPT_CONN_REUSE }; #ifdef USE_SSL @@ -169,7 +170,8 @@ const struct Curl_handler Curl_handler_ldaps = { PORT_LDAPS, /* defport */ CURLPROTO_LDAPS, /* protocol */ CURLPROTO_LDAP, /* family */ - PROTOPT_SSL /* flags */ + PROTOPT_SSL | /* flags */ + PROTOPT_CONN_REUSE }; #endif @@ -992,7 +994,6 @@ static CURLcode oldap_do(struct Curl_easy *data, bool *done) if(!li) return CURLE_FAILED_INIT; - connkeep(conn, "OpenLDAP do"); infof(data, "LDAP local: %s", data->state.url); diff --git a/lib/pop3.c b/lib/pop3.c index 05203c1a074e..503f4ecb2bd5 100644 --- a/lib/pop3.c +++ b/lib/pop3.c @@ -200,7 +200,8 @@ const struct Curl_handler Curl_handler_pop3 = { CURLPROTO_POP3, /* protocol */ CURLPROTO_POP3, /* family */ PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY | /* flags */ - PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE + PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE | + PROTOPT_CONN_REUSE }; #ifdef USE_SSL @@ -230,8 +231,9 @@ const struct Curl_handler Curl_handler_pop3s = { PORT_POP3S, /* defport */ CURLPROTO_POP3S, /* protocol */ CURLPROTO_POP3, /* family */ - PROTOPT_CLOSEACTION | PROTOPT_SSL - | PROTOPT_NOURLQUERY | PROTOPT_URLOPTIONS /* flags */ + PROTOPT_CLOSEACTION | PROTOPT_SSL | /* flags */ + PROTOPT_NOURLQUERY | PROTOPT_URLOPTIONS | + PROTOPT_CONN_REUSE }; #endif @@ -1295,9 +1297,6 @@ static CURLcode pop3_connect(struct Curl_easy *data, bool *done) if(!pop3c) return CURLE_FAILED_INIT; - /* We always support persistent connections in POP3 */ - connkeep(conn, "POP3 default"); - PINGPONG_SETUP(pp, pop3_statemachine, pop3_endofresp); /* Set the default preferred authentication type and mechanism */ diff --git a/lib/rtsp.c b/lib/rtsp.c index b4b3d6dd556d..dd49ebc42b4d 100644 --- a/lib/rtsp.c +++ b/lib/rtsp.c @@ -152,7 +152,7 @@ const struct Curl_handler Curl_handler_rtsp = { PORT_RTSP, /* defport */ CURLPROTO_RTSP, /* protocol */ CURLPROTO_RTSP, /* family */ - PROTOPT_NONE /* flags */ + PROTOPT_CONN_REUSE /* flags */ }; #define MAX_RTP_BUFFERSIZE 1000000 /* arbitrary */ diff --git a/lib/smb.c b/lib/smb.c index 4ef35c295d15..e5fca3ec0bef 100644 --- a/lib/smb.c +++ b/lib/smb.c @@ -329,7 +329,7 @@ const struct Curl_handler Curl_handler_smb = { PORT_SMB, /* defport */ CURLPROTO_SMB, /* protocol */ CURLPROTO_SMB, /* family */ - PROTOPT_NONE /* flags */ + PROTOPT_CONN_REUSE /* flags */ }; #ifdef USE_SSL @@ -358,7 +358,7 @@ const struct Curl_handler Curl_handler_smbs = { PORT_SMBS, /* defport */ CURLPROTO_SMBS, /* protocol */ CURLPROTO_SMB, /* family */ - PROTOPT_SSL /* flags */ + PROTOPT_SSL | PROTOPT_CONN_REUSE /* flags */ }; #endif @@ -513,9 +513,6 @@ static CURLcode smb_connect(struct Curl_easy *data, bool *done) if(!smbc->send_buf) return CURLE_OUT_OF_MEMORY; - /* Multiple requests are allowed with this connection */ - connkeep(conn, "SMB default"); - /* Parse the username, domain, and password */ slash = strchr(conn->user, '/'); if(!slash) diff --git a/lib/smtp.c b/lib/smtp.c index af4676dc182d..eca27f146525 100644 --- a/lib/smtp.c +++ b/lib/smtp.c @@ -205,7 +205,8 @@ const struct Curl_handler Curl_handler_smtp = { CURLPROTO_SMTP, /* protocol */ CURLPROTO_SMTP, /* family */ PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY | /* flags */ - PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE + PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE | + PROTOPT_CONN_REUSE }; #ifdef USE_SSL @@ -235,8 +236,9 @@ const struct Curl_handler Curl_handler_smtps = { PORT_SMTPS, /* defport */ CURLPROTO_SMTPS, /* protocol */ CURLPROTO_SMTP, /* family */ - PROTOPT_CLOSEACTION | PROTOPT_SSL - | PROTOPT_NOURLQUERY | PROTOPT_URLOPTIONS /* flags */ + PROTOPT_CLOSEACTION | PROTOPT_SSL | /* flags */ + PROTOPT_NOURLQUERY | PROTOPT_URLOPTIONS | + PROTOPT_CONN_REUSE }; #endif @@ -1440,9 +1442,6 @@ static CURLcode smtp_connect(struct Curl_easy *data, bool *done) if(!smtpc) return CURLE_FAILED_INIT; - /* We always support persistent connections in SMTP */ - connkeep(data->conn, "SMTP default"); - PINGPONG_SETUP(&smtpc->pp, smtp_pp_statemachine, smtp_endofresp); /* Initialize the SASL storage */ diff --git a/lib/url.c b/lib/url.c index 8b3f7f5ab738..b6a60feb38b2 100644 --- a/lib/url.c +++ b/lib/url.c @@ -1364,11 +1364,6 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) conn->connection_id = -1; /* no ID */ conn->remote_port = -1; /* unknown at this point */ - /* Default protocol-independent behavior does not support persistent - connections, so we set this to force-close. Protocols that support - this need to set this to FALSE in their "curl_do" functions. */ - connclose(conn, "Default to force-close"); - /* Store creation time to help future close decision making */ conn->created = curlx_now(); @@ -1428,6 +1423,7 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) #ifdef HAVE_GSSAPI conn->gssapi_delegation = data->set.gssapi_delegation; #endif + DEBUGF(infof(data, "alloc connection, bits.close=%d", conn->bits.close)); return conn; error: @@ -2035,11 +2031,13 @@ static CURLcode setup_connection_internals(struct Curl_easy *data, int port; CURLcode result; + DEBUGF(infof(data, "setup connection, bits.close=%d", conn->bits.close)); if(conn->handler->setup_connection) { result = conn->handler->setup_connection(data, conn); if(result) return result; } + DEBUGF(infof(data, "setup connection, bits.close=%d", conn->bits.close)); /* Now create the destination name */ #ifndef CURL_DISABLE_PROXY @@ -3664,6 +3662,7 @@ static CURLcode create_conn(struct Curl_easy *data, /* We have decided that we want a new connection. However, we may not be able to do that if we have reached the limit of how many connections we are allowed to open. */ + DEBUGF(infof(data, "new connection, bits.close=%d", conn->bits.close)); if(conn->handler->flags & PROTOPT_ALPN) { /* The protocol wants it, so set the bits if enabled in the easy handle diff --git a/lib/urldata.h b/lib/urldata.h index c71607ea7d2b..37ecd1ff9db7 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -567,6 +567,7 @@ struct Curl_handler { #define PROTOPT_SSL_REUSE (1<<15) /* this protocol may reuse an existing SSL connection in the same family without having PROTOPT_SSL. */ +#define PROTOPT_CONN_REUSE (1<<16) /* this protocol can reuse connections */ #define CONNCHECK_NONE 0 /* No checks */ #define CONNCHECK_ISDEAD (1<<0) /* Check if the connection is dead. */ diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index 61b233e4ffc0..de767f28dc04 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -2647,7 +2647,6 @@ static CURLcode cf_ngtcp2_connect(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "peer verified"); cf->connected = TRUE; *done = TRUE; - connkeep(cf->conn, "HTTP/3 default"); } } diff --git a/lib/vquic/curl_osslq.c b/lib/vquic/curl_osslq.c index 0f7cc7a91a2a..376705e51667 100644 --- a/lib/vquic/curl_osslq.c +++ b/lib/vquic/curl_osslq.c @@ -1816,7 +1816,6 @@ static CURLcode cf_osslq_connect(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "peer verified"); cf->connected = TRUE; *done = TRUE; - connkeep(cf->conn, "HTTP/3 default"); } } else { diff --git a/lib/vquic/curl_quiche.c b/lib/vquic/curl_quiche.c index 5082dc750bb5..927492979013 100644 --- a/lib/vquic/curl_quiche.c +++ b/lib/vquic/curl_quiche.c @@ -446,7 +446,6 @@ static CURLcode cf_recv_body(struct Curl_cfilter *cf, stream->closed = TRUE; stream->reset = TRUE; stream->send_closed = TRUE; - streamclose(cf->conn, "Reset of stream"); return result; } return CURLE_OK; @@ -510,7 +509,6 @@ static CURLcode h3_process_event(struct Curl_cfilter *cf, stream->closed = TRUE; stream->reset = TRUE; stream->send_closed = TRUE; - streamclose(cf->conn, "Reset of stream"); break; case QUICHE_H3_EVENT_FINISHED: @@ -522,7 +520,6 @@ static CURLcode h3_process_event(struct Curl_cfilter *cf, stream->resp_hds_complete = TRUE; } stream->closed = TRUE; - streamclose(cf->conn, "End of stream"); break; case QUICHE_H3_EVENT_GOAWAY: @@ -1415,7 +1412,6 @@ static CURLcode cf_quiche_connect(struct Curl_cfilter *cf, } cf->connected = TRUE; *done = TRUE; - connkeep(cf->conn, "HTTP/3 default"); } } else if(quiche_conn_is_draining(ctx->qconn)) { diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index 77a915884aaf..c76478bc2a57 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -156,7 +156,8 @@ const struct Curl_handler Curl_handler_scp = { PORT_SSH, /* defport */ CURLPROTO_SCP, /* protocol */ CURLPROTO_SCP, /* family */ - PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY /* flags */ + PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | /* flags */ + PROTOPT_NOURLQUERY | PROTOPT_CONN_REUSE }; /* @@ -185,8 +186,8 @@ const struct Curl_handler Curl_handler_sftp = { PORT_SSH, /* defport */ CURLPROTO_SFTP, /* protocol */ CURLPROTO_SFTP, /* family */ - PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION - | PROTOPT_NOURLQUERY /* flags */ + PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | /* flags */ + PROTOPT_NOURLQUERY | PROTOPT_CONN_REUSE }; static CURLcode sftp_error_to_CURLE(int err) @@ -2572,10 +2573,6 @@ static CURLcode myssh_connect(struct Curl_easy *data, bool *done) if(!sshc || !ssh) return CURLE_FAILED_INIT; - /* We default to persistent connections. We set this already in this connect - function to make the reuse checks properly be able to check this bit. */ - connkeep(conn, "SSH default"); - if(conn->handler->protocol & CURLPROTO_SCP) { conn->recv[FIRSTSOCKET] = scp_recv; conn->send[FIRSTSOCKET] = scp_send; diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index 714e3953730a..1c9fe5ac0154 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -123,8 +123,8 @@ const struct Curl_handler Curl_handler_scp = { PORT_SSH, /* defport */ CURLPROTO_SCP, /* protocol */ CURLPROTO_SCP, /* family */ - PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION - | PROTOPT_NOURLQUERY /* flags */ + PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | /* flags */ + PROTOPT_NOURLQUERY | PROTOPT_CONN_REUSE }; @@ -154,8 +154,8 @@ const struct Curl_handler Curl_handler_sftp = { PORT_SSH, /* defport */ CURLPROTO_SFTP, /* protocol */ CURLPROTO_SFTP, /* family */ - PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION - | PROTOPT_NOURLQUERY /* flags */ + PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | /* flags */ + PROTOPT_NOURLQUERY | PROTOPT_CONN_REUSE }; static void @@ -3323,10 +3323,6 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done) if(!sshc) return CURLE_FAILED_INIT; - /* We default to persistent connections. We set this already in this connect - function to make the reuse checks properly be able to check this bit. */ - connkeep(conn, "SSH default"); - infof(data, "User: '%s'", conn->user); #ifdef CURL_LIBSSH2_DEBUG infof(data, "Password: %s", conn->passwd); diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index 8991d965d9be..2f526479c5f4 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -5175,7 +5175,6 @@ static CURLcode ossl_recv(struct Curl_cfilter *cf, char error_buffer[256]; unsigned long sslerror; int buffsize; - struct connectdata *conn = cf->conn; struct ssl_connect_data *connssl = cf->ctx; struct ossl_ctx *octx = (struct ossl_ctx *)connssl->backend; CURLcode result = CURLE_OK; @@ -5205,7 +5204,7 @@ static CURLcode ossl_recv(struct Curl_cfilter *cf, if(cf->sockindex == FIRSTSOCKET) /* mark the connection for close if it is indeed the control connection */ - connclose(conn, "TLS close_notify"); + CURL_TRC_CF(data, cf, "TLS close_notify"); break; case SSL_ERROR_WANT_READ: connssl->io_need = CURL_SSL_IO_NEED_RECV; From c4f29cc5081b4b70ba435c64bd8ee81f02b3ceeb Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Wed, 26 Nov 2025 14:05:46 +0100 Subject: [PATCH 080/140] ip_quadruple/proxy: make port uint16_t Make `port` member in these struct of type `uint16_t`. add `uint8_t transport` to `struct ip_quadruple Define TRNSPRT_NONE as 0. By assigning a valid transport only on a successful connection, it is clear when the ip_quadruple members are valid. Also, for transports not involving ports, the getinfos for `CURLINFO_PRIMARY_PORT` and `CURLINFO_LOCAL_PORT` will now always return -1. Make all `transport` members and parameters of type `uint8_t`. Document the return value of `CURLINFO_LOCAL_PORT` and `CURLINFO_PRIMARY_PORT` in this regard. Add tests that writeout stats report ports correctly. Closes #19708 --- docs/libcurl/opts/CURLINFO_LOCAL_PORT.md | 3 +++ docs/libcurl/opts/CURLINFO_PRIMARY_PORT.md | 5 +++++ lib/cf-https-connect.c | 10 ++++----- lib/cf-ip-happy.c | 24 ++++++++++---------- lib/cf-ip-happy.h | 6 ++--- lib/cf-socket.c | 17 +++++++------- lib/cf-socket.h | 8 +++---- lib/connect.c | 16 ++++++------- lib/connect.h | 4 ++-- lib/getinfo.c | 12 ++++++---- lib/setopt.c | 4 ++-- lib/url.c | 14 +++++------- lib/urldata.h | 26 +++++++++++++--------- lib/vquic/vquic.c | 2 +- lib/vquic/vquic.h | 2 +- tests/http/test_01_basic.py | 3 +++ tests/http/test_11_unix.py | 6 +++++ tests/unit/unit1607.c | 2 +- tests/unit/unit1609.c | 2 +- tests/unit/unit2600.c | 4 ++-- 20 files changed, 97 insertions(+), 73 deletions(-) diff --git a/docs/libcurl/opts/CURLINFO_LOCAL_PORT.md b/docs/libcurl/opts/CURLINFO_LOCAL_PORT.md index 67d73b71650e..40d1f5fb6a87 100644 --- a/docs/libcurl/opts/CURLINFO_LOCAL_PORT.md +++ b/docs/libcurl/opts/CURLINFO_LOCAL_PORT.md @@ -35,6 +35,9 @@ connection done with this **curl** handle. If the connection was done using QUIC, the port number is a UDP port number, otherwise it is a TCP port number. +If no connection was established or if the protocol does not use ports, -1 +is returned. + # %PROTOCOLS% # EXAMPLE diff --git a/docs/libcurl/opts/CURLINFO_PRIMARY_PORT.md b/docs/libcurl/opts/CURLINFO_PRIMARY_PORT.md index b98f246042da..85f5767423a4 100644 --- a/docs/libcurl/opts/CURLINFO_PRIMARY_PORT.md +++ b/docs/libcurl/opts/CURLINFO_PRIMARY_PORT.md @@ -36,6 +36,11 @@ If a proxy was used for the most recent transfer, this is the port number of the proxy, if no proxy was used it is the port number of the most recently accessed URL. +If the connection was done using QUIC, the port number is a UDP port number. + +If no connection was established or if the protocol does not use ports, -1 +is returned. + # %PROTOCOLS% # EXAMPLE diff --git a/lib/cf-https-connect.c b/lib/cf-https-connect.c index dfd82bd9a117..5491d7968d7e 100644 --- a/lib/cf-https-connect.c +++ b/lib/cf-https-connect.c @@ -55,7 +55,7 @@ struct cf_hc_baller { CURLcode result; struct curltime started; int reply_ms; - unsigned char transport; + uint8_t transport; enum alpnid alpn_id; BIT(shutdown); }; @@ -124,7 +124,7 @@ struct cf_hc_ctx { static void cf_hc_baller_assign(struct cf_hc_baller *b, enum alpnid alpn_id, - unsigned char def_transport) + uint8_t def_transport) { b->alpn_id = alpn_id; b->transport = def_transport; @@ -148,7 +148,7 @@ static void cf_hc_baller_assign(struct cf_hc_baller *b, static void cf_hc_baller_init(struct cf_hc_baller *b, struct Curl_cfilter *cf, struct Curl_easy *data, - int transport) + uint8_t transport) { struct Curl_cfilter *save = cf->next; @@ -581,7 +581,7 @@ struct Curl_cftype Curl_cft_http_connect = { static CURLcode cf_hc_create(struct Curl_cfilter **pcf, struct Curl_easy *data, enum alpnid *alpnids, size_t alpn_count, - unsigned char def_transport) + uint8_t def_transport) { struct Curl_cfilter *cf = NULL; struct cf_hc_ctx *ctx; @@ -626,7 +626,7 @@ static CURLcode cf_http_connect_add(struct Curl_easy *data, struct connectdata *conn, int sockindex, enum alpnid *alpn_ids, size_t alpn_count, - unsigned char def_transport) + uint8_t def_transport) { struct Curl_cfilter *cf; CURLcode result = CURLE_OK; diff --git a/lib/cf-ip-happy.c b/lib/cf-ip-happy.c index 2e522322c384..eb62cd4c73d3 100644 --- a/lib/cf-ip-happy.c +++ b/lib/cf-ip-happy.c @@ -66,7 +66,7 @@ struct transport_provider { - int transport; + uint8_t transport; cf_ip_connect_create *cf_create; }; @@ -87,7 +87,7 @@ struct transport_provider transport_providers[] = { #endif }; -static cf_ip_connect_create *get_cf_create(int transport) +static cf_ip_connect_create *get_cf_create(uint8_t transport) { size_t i; for(i = 0; i < CURL_ARRAYSIZE(transport_providers); ++i) { @@ -99,7 +99,7 @@ static cf_ip_connect_create *get_cf_create(int transport) #ifdef UNITTESTS /* used by unit2600.c */ -void Curl_debug_set_transport_provider(int transport, +void Curl_debug_set_transport_provider(uint8_t transport, cf_ip_connect_create *cf_create) { size_t i; @@ -172,7 +172,7 @@ struct cf_ip_attempt { struct curltime started; /* start of current attempt */ CURLcode result; int ai_family; - int transport; + uint8_t transport; int error; BIT(connected); /* cf has connected */ BIT(shutdown); /* cf has shutdown */ @@ -195,7 +195,7 @@ static CURLcode cf_ip_attempt_new(struct cf_ip_attempt **pa, struct Curl_easy *data, const struct Curl_addrinfo *addr, int ai_family, - int transport, + uint8_t transport, cf_ip_connect_create *cf_create) { struct Curl_cfilter *wcf; @@ -264,7 +264,7 @@ struct cf_ip_ballers { struct curltime last_attempt_started; timediff_t attempt_delay_ms; int last_attempt_ai_family; - int transport; + uint8_t transport; }; static CURLcode cf_ip_attempt_restart(struct cf_ip_attempt *a, @@ -315,7 +315,7 @@ static void cf_ip_ballers_clear(struct Curl_cfilter *cf, static CURLcode cf_ip_ballers_init(struct cf_ip_ballers *bs, int ip_version, const struct Curl_addrinfo *addr_list, cf_ip_connect_create *cf_create, - int transport, + uint8_t transport, timediff_t attempt_delay_ms) { memset(bs, 0, sizeof(*bs)); @@ -626,7 +626,7 @@ typedef enum { } cf_connect_state; struct cf_ip_happy_ctx { - int transport; + uint8_t transport; cf_ip_connect_create *cf_create; cf_connect_state state; struct cf_ip_ballers ballers; @@ -713,7 +713,7 @@ static CURLcode start_connect(struct Curl_cfilter *cf, return CURLE_OPERATION_TIMEDOUT; } - CURL_TRC_CF(data, cf, "init ip ballers for transport %d", ctx->transport); + CURL_TRC_CF(data, cf, "init ip ballers for transport %u", ctx->transport); ctx->started = curlx_now(); return cf_ip_ballers_init(&ctx->ballers, cf->conn->ip_version, dns->addr, ctx->cf_create, ctx->transport, @@ -933,7 +933,7 @@ static CURLcode cf_ip_happy_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, cf_ip_connect_create *cf_create, - int transport) + uint8_t transport) { struct cf_ip_happy_ctx *ctx = NULL; CURLcode result; @@ -961,7 +961,7 @@ static CURLcode cf_ip_happy_create(struct Curl_cfilter **pcf, CURLcode cf_ip_happy_insert_after(struct Curl_cfilter *cf_at, struct Curl_easy *data, - int transport) + uint8_t transport) { cf_ip_connect_create *cf_create; struct Curl_cfilter *cf; @@ -971,7 +971,7 @@ CURLcode cf_ip_happy_insert_after(struct Curl_cfilter *cf_at, DEBUGASSERT(cf_at); cf_create = get_cf_create(transport); if(!cf_create) { - CURL_TRC_CF(data, cf_at, "unsupported transport type %d", transport); + CURL_TRC_CF(data, cf_at, "unsupported transport type %u", transport); return CURLE_UNSUPPORTED_PROTOCOL; } result = cf_ip_happy_create(&cf, data, cf_at->conn, cf_create, transport); diff --git a/lib/cf-ip-happy.h b/lib/cf-ip-happy.h index 96e619ae4303..2930f21418bf 100644 --- a/lib/cf-ip-happy.h +++ b/lib/cf-ip-happy.h @@ -43,16 +43,16 @@ typedef CURLcode cf_ip_connect_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport); + uint8_t transport); CURLcode cf_ip_happy_insert_after(struct Curl_cfilter *cf_at, struct Curl_easy *data, - int transport); + uint8_t transport); extern struct Curl_cftype Curl_cft_ip_happy; #ifdef UNITTESTS -void Curl_debug_set_transport_provider(int transport, +void Curl_debug_set_transport_provider(uint8_t transport, cf_ip_connect_create *cf_create); #endif diff --git a/lib/cf-socket.c b/lib/cf-socket.c index 2930f95fe24c..c657330ec6ed 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -303,7 +303,7 @@ tcpkeepalive(struct Curl_cfilter *cf, */ static CURLcode sock_assign_addr(struct Curl_sockaddr_ex *dest, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { /* * The Curl_sockaddr_ex structure is basically libcurl's external API @@ -404,7 +404,7 @@ static CURLcode socket_open(struct Curl_easy *data, CURLcode Curl_socket_open(struct Curl_easy *data, const struct Curl_addrinfo *ai, struct Curl_sockaddr_ex *addr, - int transport, + uint8_t transport, curl_socket_t *sockfd) { struct Curl_sockaddr_ex dummy; @@ -909,7 +909,7 @@ static CURLcode socket_connect_result(struct Curl_easy *data, } struct cf_socket_ctx { - int transport; + uint8_t transport; struct Curl_sockaddr_ex addr; /* address to connect to */ curl_socket_t sock; /* current attempt socket */ struct ip_quadruple ip; /* The IP quadruple 2x(addr+port) */ @@ -936,7 +936,7 @@ struct cf_socket_ctx { static CURLcode cf_socket_ctx_init(struct cf_socket_ctx *ctx, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { CURLcode result; @@ -1035,7 +1035,7 @@ static void set_local_ip(struct Curl_cfilter *cf, { struct cf_socket_ctx *ctx = cf->ctx; ctx->ip.local_ip[0] = 0; - ctx->ip.local_port = -1; + ctx->ip.local_port = 0; #ifdef HAVE_GETSOCKNAME if((ctx->sock != CURL_SOCKET_BAD) && @@ -1069,6 +1069,7 @@ static CURLcode set_remote_ip(struct Curl_cfilter *cf, struct cf_socket_ctx *ctx = cf->ctx; /* store remote address and port used in this connection attempt */ + ctx->ip.transport = ctx->transport; if(!Curl_addr2string(&ctx->addr.curl_sa_addr, (curl_socklen_t)ctx->addr.addrlen, ctx->ip.remote_ip, &ctx->ip.remote_port)) { @@ -1743,7 +1744,7 @@ CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { struct cf_socket_ctx *ctx = NULL; struct Curl_cfilter *cf = NULL; @@ -1910,7 +1911,7 @@ CURLcode Curl_cf_udp_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { struct cf_socket_ctx *ctx = NULL; struct Curl_cfilter *cf = NULL; @@ -1964,7 +1965,7 @@ CURLcode Curl_cf_unix_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { struct cf_socket_ctx *ctx = NULL; struct Curl_cfilter *cf = NULL; diff --git a/lib/cf-socket.h b/lib/cf-socket.h index e5fc176ee19c..432b0870451d 100644 --- a/lib/cf-socket.h +++ b/lib/cf-socket.h @@ -71,7 +71,7 @@ CURLcode Curl_parse_interface(const char *input, CURLcode Curl_socket_open(struct Curl_easy *data, const struct Curl_addrinfo *ai, struct Curl_sockaddr_ex *addr, - int transport, + uint8_t transport, curl_socket_t *sockfd); int Curl_socket_close(struct Curl_easy *data, struct connectdata *conn, @@ -103,7 +103,7 @@ CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport); + uint8_t transport); /** * Creates a cfilter that opens a UDP socket to the given address @@ -116,7 +116,7 @@ CURLcode Curl_cf_udp_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport); + uint8_t transport); /** * Creates a cfilter that opens a UNIX socket to the given address @@ -129,7 +129,7 @@ CURLcode Curl_cf_unix_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport); + uint8_t transport); /** * Creates a cfilter that keeps a listening socket. diff --git a/lib/connect.c b/lib/connect.c index fbb5dcabff26..e29c2f51bcf8 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -238,7 +238,7 @@ bool Curl_shutdown_started(struct Curl_easy *data, int sockindex) /* retrieves ip address and port from a sockaddr structure. note it calls curlx_inet_ntop which sets errno on fail, not SOCKERRNO. */ bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen, - char *addr, int *port) + char *addr, uint16_t *port) { struct sockaddr_in *si = NULL; #ifdef USE_IPV6 @@ -254,8 +254,7 @@ bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen, case AF_INET: si = (struct sockaddr_in *)(void *) sa; if(curlx_inet_ntop(sa->sa_family, &si->sin_addr, addr, MAX_IPADR_LEN)) { - unsigned short us_port = ntohs(si->sin_port); - *port = us_port; + *port = ntohs(si->sin_port); return TRUE; } break; @@ -264,8 +263,7 @@ bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen, si6 = (struct sockaddr_in6 *)(void *) sa; if(curlx_inet_ntop(sa->sa_family, &si6->sin6_addr, addr, MAX_IPADR_LEN)) { - unsigned short us_port = ntohs(si6->sin6_port); - *port = us_port; + *port = ntohs(si6->sin6_port); return TRUE; } break; @@ -366,7 +364,7 @@ typedef enum { struct cf_setup_ctx { cf_setup_state state; int ssl_mode; - int transport; + uint8_t transport; }; static CURLcode cf_setup_connect(struct Curl_cfilter *cf, @@ -521,7 +519,7 @@ struct Curl_cftype Curl_cft_setup = { static CURLcode cf_setup_create(struct Curl_cfilter **pcf, struct Curl_easy *data, - int transport, + uint8_t transport, int ssl_mode) { struct Curl_cfilter *cf = NULL; @@ -554,7 +552,7 @@ static CURLcode cf_setup_create(struct Curl_cfilter **pcf, static CURLcode cf_setup_add(struct Curl_easy *data, struct connectdata *conn, int sockindex, - int transport, + uint8_t transport, int ssl_mode) { struct Curl_cfilter *cf; @@ -571,7 +569,7 @@ static CURLcode cf_setup_add(struct Curl_easy *data, CURLcode Curl_cf_setup_insert_after(struct Curl_cfilter *cf_at, struct Curl_easy *data, - int transport, + uint8_t transport, int ssl_mode) { struct Curl_cfilter *cf; diff --git a/lib/connect.h b/lib/connect.h index b6d9b8e83698..9060591dcec6 100644 --- a/lib/connect.h +++ b/lib/connect.h @@ -74,7 +74,7 @@ curl_socket_t Curl_getconnectinfo(struct Curl_easy *data, struct connectdata **connp); bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen, - char *addr, int *port); + char *addr, uint16_t *port); /* * Curl_conncontrol() marks the end of a connection/stream. The 'closeit' @@ -111,7 +111,7 @@ void Curl_conncontrol(struct connectdata *conn, CURLcode Curl_cf_setup_insert_after(struct Curl_cfilter *cf_at, struct Curl_easy *data, - int transport, + uint8_t transport, int ssl_mode); /** diff --git a/lib/getinfo.c b/lib/getinfo.c index 6a16258b13e1..01c727935620 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -81,8 +81,6 @@ void Curl_initinfo(struct Curl_easy *data) info->wouldredirect = NULL; memset(&info->primary, 0, sizeof(info->primary)); - info->primary.remote_port = -1; - info->primary.local_port = -1; info->retry_after = 0; info->conn_scheme = 0; @@ -304,11 +302,17 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info, break; case CURLINFO_PRIMARY_PORT: /* Return the (remote) port of the most recent (primary) connection */ - *param_longp = data->info.primary.remote_port; + if(CUR_IP_QUAD_HAS_PORTS(&data->info.primary)) + *param_longp = data->info.primary.remote_port; + else + *param_longp = -1; break; case CURLINFO_LOCAL_PORT: /* Return the local port of the most recent (primary) connection */ - *param_longp = data->info.primary.local_port; + if(CUR_IP_QUAD_HAS_PORTS(&data->info.primary)) + *param_longp = data->info.primary.local_port; + else + *param_longp = -1; break; case CURLINFO_PROXY_ERROR: *param_longp = (long)data->info.pxcode; diff --git a/lib/setopt.c b/lib/setopt.c index fc95389312ad..36f447cdc5bb 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -1001,9 +1001,9 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, #endif #ifndef CURL_DISABLE_PROXY case CURLOPT_PROXYPORT: - if((arg < 0) || (arg > 65535)) + if((arg < 0) || (arg > UINT16_MAX)) return CURLE_BAD_FUNCTION_ARGUMENT; - s->proxyport = (unsigned short)arg; + s->proxyport = (uint16_t)arg; break; case CURLOPT_PROXYAUTH: diff --git a/lib/url.c b/lib/url.c index b6a60feb38b2..e7f39d5471d1 100644 --- a/lib/url.c +++ b/lib/url.c @@ -2171,7 +2171,6 @@ static CURLcode parse_proxy(struct Curl_easy *data, long proxytype) { char *portptr = NULL; - int port = -1; char *proxyuser = NULL; char *proxypasswd = NULL; char *host = NULL; @@ -2293,24 +2292,23 @@ static CURLcode parse_proxy(struct Curl_easy *data, if(portptr) { curl_off_t num; const char *p = portptr; - if(!curlx_str_number(&p, &num, 0xffff)) - port = (int)num; + if(!curlx_str_number(&p, &num, UINT16_MAX)) + proxyinfo->port = (uint16_t)num; + /* Should we not error out when the port number is invalid? */ free(portptr); } else { if(data->set.proxyport) /* None given in the proxy string, then get the default one if it is given */ - port = (int)data->set.proxyport; + proxyinfo->port = data->set.proxyport; else { if(IS_HTTPS_PROXY(proxytype)) - port = CURL_DEFAULT_HTTPS_PROXY_PORT; + proxyinfo->port = CURL_DEFAULT_HTTPS_PROXY_PORT; else - port = CURL_DEFAULT_PROXY_PORT; + proxyinfo->port = CURL_DEFAULT_PROXY_PORT; } } - if(port >= 0) - proxyinfo->port = port; /* now, clone the proxy hostname */ uc = curl_url_get(uhp, CURLUPART_HOST, &host, CURLU_URLDECODE); diff --git a/lib/urldata.h b/lib/urldata.h index 37ecd1ff9db7..debc2a3e0aa0 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -528,7 +528,7 @@ struct Curl_handler { CURLcode (*follow)(struct Curl_easy *data, const char *newurl, followtype type); - int defport; /* Default port. */ + uint16_t defport; /* Default port. */ curl_prot_t protocol; /* See CURLPROTO_* - this needs to be the single specific protocol bit */ curl_prot_t family; /* single bit for protocol family; basically the @@ -576,26 +576,32 @@ struct Curl_handler { #define CONNRESULT_NONE 0 /* No extra information. */ #define CONNRESULT_DEAD (1<<0) /* The connection is dead. */ +#define TRNSPRT_NONE 0 +#define TRNSPRT_TCP 3 +#define TRNSPRT_UDP 4 +#define TRNSPRT_QUIC 5 +#define TRNSPRT_UNIX 6 + struct ip_quadruple { char remote_ip[MAX_IPADR_LEN]; char local_ip[MAX_IPADR_LEN]; - int remote_port; - int local_port; + uint16_t remote_port; + uint16_t local_port; + uint8_t transport; }; +#define CUR_IP_QUAD_HAS_PORTS(x) (((x)->transport == TRNSPRT_TCP) || \ + ((x)->transport == TRNSPRT_UDP) || \ + ((x)->transport == TRNSPRT_QUIC)) + struct proxy_info { struct hostname host; - int port; + uint16_t port; unsigned char proxytype; /* what kind of proxy that is in use */ char *user; /* proxy username string, allocated */ char *passwd; /* proxy password string, allocated */ }; -#define TRNSPRT_TCP 3 -#define TRNSPRT_UDP 4 -#define TRNSPRT_QUIC 5 -#define TRNSPRT_UNIX 6 - /* * The connectdata struct contains all fields and variables that should be * unique for an entire connection. @@ -1364,7 +1370,7 @@ struct UserDefined { #ifndef CURL_DISABLE_PROXY struct ssl_config_data proxy_ssl; /* user defined SSL stuff for proxy */ struct curl_slist *proxyheaders; /* linked list of extra CONNECT headers */ - unsigned short proxyport; /* If non-zero, use this port number by + uint16_t proxyport; /* If non-zero, use this port number by default. If the proxy string features a ":[port]" that one will override this. */ unsigned char proxytype; /* what kind of proxy */ diff --git a/lib/vquic/vquic.c b/lib/vquic/vquic.c index aa0011c577c4..8b4d678d8118 100644 --- a/lib/vquic/vquic.c +++ b/lib/vquic/vquic.c @@ -687,7 +687,7 @@ CURLcode Curl_cf_quic_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { (void)transport; DEBUGASSERT(transport == TRNSPRT_QUIC); diff --git a/lib/vquic/vquic.h b/lib/vquic/vquic.h index 0f81334f2937..fd2dac7c22eb 100644 --- a/lib/vquic/vquic.h +++ b/lib/vquic/vquic.h @@ -45,7 +45,7 @@ CURLcode Curl_cf_quic_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport); + uint8_t transport); extern struct Curl_cftype Curl_cft_http3; diff --git a/tests/http/test_01_basic.py b/tests/http/test_01_basic.py index aa94238c3f01..14a8dec957fc 100644 --- a/tests/http/test_01_basic.py +++ b/tests/http/test_01_basic.py @@ -96,6 +96,9 @@ def test_01_06_timings(self, env: Env, httpd, nghttpx, proto): # there are cases where time_connect is reported as 0 assert r.stats[0]['time_connect'] >= 0, f'{r.stats[0]}' assert r.stats[0]['time_appconnect'] > 0, f'{r.stats[0]}' + # ports are reported correctly + assert r.stats[0]['remote_port'] == env.port_for(proto), f'{r.dump_logs()}' + assert r.stats[0]['local_port'] > 0, f'{r.dump_logs()}' # simple https: HEAD @pytest.mark.parametrize("proto", Env.http_protos()) diff --git a/tests/http/test_11_unix.py b/tests/http/test_11_unix.py index 2f2db483f404..1432797da26c 100644 --- a/tests/http/test_11_unix.py +++ b/tests/http/test_11_unix.py @@ -109,6 +109,8 @@ def test_11_01_unix_connect_http(self, env: Env, httpd, uds_faker): '--unix-socket', uds_faker.path, ]) r.check_response(count=1, http_status=200) + assert r.stats[0]['remote_port'] == -1, f'{r.dump_logs()}' + assert r.stats[0]['local_port'] == -1, f'{r.dump_logs()}' # download https: via Unix socket @pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason="curl without SSL") @@ -120,6 +122,8 @@ def test_11_02_unix_connect_http(self, env: Env, httpd, uds_faker): '--unix-socket', uds_faker.path, ]) r.check_response(exitcode=35, http_status=None) + assert r.stats[0]['remote_port'] == -1, f'{r.dump_logs()}' + assert r.stats[0]['local_port'] == -1, f'{r.dump_logs()}' # download HTTP/3 via Unix socket @pytest.mark.skipif(condition=not Env.have_h3(), reason='h3 not supported') @@ -132,3 +136,5 @@ def test_11_03_unix_connect_quic(self, env: Env, httpd, uds_faker): '--unix-socket', uds_faker.path, ]) r.check_response(exitcode=96, http_status=None) + assert r.stats[0]['remote_port'] == -1, f'{r.dump_logs()}' + assert r.stats[0]['local_port'] == -1, f'{r.dump_logs()}' diff --git a/tests/unit/unit1607.c b/tests/unit/unit1607.c index 3e4d53d0be5e..f60b5b58a1e4 100644 --- a/tests/unit/unit1607.c +++ b/tests/unit/unit1607.c @@ -141,7 +141,7 @@ static CURLcode test_unit1607(const char *arg) addr = dns ? dns->addr : NULL; for(j = 0; j < addressnum; ++j) { - int port = 0; + uint16_t port = 0; char ipaddress[MAX_IPADR_LEN] = {0}; if(!addr && !tests[i].address[j]) diff --git a/tests/unit/unit1609.c b/tests/unit/unit1609.c index f3f318f2cf97..2a3098c6ef2e 100644 --- a/tests/unit/unit1609.c +++ b/tests/unit/unit1609.c @@ -143,7 +143,7 @@ static CURLcode test_unit1609(const char *arg) addr = dns ? dns->addr : NULL; for(j = 0; j < addressnum; ++j) { - int port = 0; + uint16_t port = 0; char ipaddress[MAX_IPADR_LEN] = {0}; if(!addr && !tests[i].address[j]) diff --git a/tests/unit/unit2600.c b/tests/unit/unit2600.c index 6a03c438dcd9..f2adc50eddd4 100644 --- a/tests/unit/unit2600.c +++ b/tests/unit/unit2600.c @@ -110,7 +110,7 @@ static int test_idx; struct cf_test_ctx { int idx; int ai_family; - int transport; + uint8_t transport; char id[16]; struct curltime started; timediff_t fail_delay_ms; @@ -166,7 +166,7 @@ static CURLcode cf_test_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { static const struct Curl_cftype cft_test = { "TEST", From fd5a117a6715326749b0e0d18362c50d767e8268 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Thu, 27 Nov 2025 12:50:04 +0100 Subject: [PATCH 081/140] ws: use uint8_t Convert `unsigned char` use to `uint8_t`. Closes #19721 --- lib/ws.c | 82 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/lib/ws.c b/lib/ws.c index b5c02bda9555..36191b2fac0d 100644 --- a/lib/ws.c +++ b/lib/ws.c @@ -91,7 +91,7 @@ struct ws_decoder { int frame_flags; /* See the CURLWS_* defines */ curl_off_t payload_offset; /* the offset parsing is at */ curl_off_t payload_len; - unsigned char head[10]; + uint8_t head[10]; int head_len, head_total; enum ws_dec_state state; int cont_flags; @@ -103,8 +103,8 @@ struct ws_encoder { curl_off_t payload_len; /* payload length of current frame */ curl_off_t payload_remain; /* remaining payload of current */ unsigned int xori; /* xor index */ - unsigned char mask[4]; /* 32-bit mask for this connection */ - unsigned char firstbyte; /* first byte of frame we encode */ + uint8_t mask[4]; /* 32-bit mask for this connection */ + uint8_t firstbyte; /* first byte of frame we encode */ BIT(contfragment); /* set TRUE if the previous fragment sent was not final */ }; @@ -114,7 +114,7 @@ struct ws_encoder { struct ws_cntrl_frame { unsigned int type; size_t payload_len; - unsigned char payload[WS_MAX_CNTRL_LEN]; + uint8_t payload[WS_MAX_CNTRL_LEN]; }; /* A websocket connection with en- and decoder that treat frames @@ -131,7 +131,7 @@ struct websocket { }; -static const char *ws_frame_name_of_op(unsigned char firstbyte) +static const char *ws_frame_name_of_op(uint8_t firstbyte) { switch(firstbyte & WSBIT_OPCODE_MASK) { case WSBIT_OPCODE_CONT: @@ -152,7 +152,7 @@ static const char *ws_frame_name_of_op(unsigned char firstbyte) } static int ws_frame_firstbyte2flags(struct Curl_easy *data, - unsigned char firstbyte, int cont_flags) + uint8_t firstbyte, int cont_flags) { switch(firstbyte) { /* 0x00 - intermediate TEXT/BINARY fragment */ @@ -233,7 +233,7 @@ static int ws_frame_firstbyte2flags(struct Curl_easy *data, static CURLcode ws_frame_flags2firstbyte(struct Curl_easy *data, unsigned int flags, bool contfragment, - unsigned char *pfirstbyte) + uint8_t *pfirstbyte) { *pfirstbyte = 0; switch(flags & ~CURLWS_OFFSET) { @@ -326,7 +326,7 @@ static CURLcode ws_send_raw_blocking(struct Curl_easy *data, struct websocket *ws, const char *buffer, size_t buflen); -typedef CURLcode ws_write_payload(const unsigned char *buf, size_t buflen, +typedef CURLcode ws_write_payload(const uint8_t *buf, size_t buflen, int frame_age, int frame_flags, curl_off_t payload_offset, curl_off_t payload_len, @@ -364,7 +364,7 @@ static CURLcode ws_dec_read_head(struct ws_decoder *dec, struct Curl_easy *data, struct bufq *inraw) { - const unsigned char *inbuf; + const uint8_t *inbuf; size_t inlen; while(Curl_bufq_peek(inraw, &inbuf, &inlen)) { @@ -486,7 +486,7 @@ static CURLcode ws_dec_pass_payload(struct ws_decoder *dec, ws_write_payload *write_cb, void *write_ctx) { - const unsigned char *inbuf; + const uint8_t *inbuf; size_t inlen; size_t nwritten; CURLcode result; @@ -544,7 +544,7 @@ static CURLcode ws_dec_pass(struct ws_decoder *dec, dec->state = WS_DEC_PAYLOAD; if(dec->payload_len == 0) { size_t nwritten; - const unsigned char tmp = '\0'; + const uint8_t tmp = '\0'; /* special case of a 0 length frame, need to write once */ result = write_cb(&tmp, 0, dec->frame_age, dec->frame_flags, 0, 0, write_ctx, &nwritten); @@ -617,7 +617,7 @@ static CURLcode ws_flush(struct Curl_easy *data, struct websocket *ws, bool blocking); static CURLcode ws_enc_send(struct Curl_easy *data, struct websocket *ws, - const unsigned char *buffer, + const uint8_t *buffer, size_t buflen, curl_off_t fragsize, unsigned int flags, @@ -627,7 +627,7 @@ static CURLcode ws_enc_add_pending(struct Curl_easy *data, static CURLcode ws_enc_add_cntrl(struct Curl_easy *data, struct websocket *ws, - const unsigned char *payload, + const uint8_t *payload, size_t plen, unsigned int frame_type) { @@ -663,7 +663,7 @@ static curl_off_t ws_payload_remain(curl_off_t payload_total, return remain - buffered; } -static CURLcode ws_cw_dec_next(const unsigned char *buf, size_t buflen, +static CURLcode ws_cw_dec_next(const uint8_t *buf, size_t buflen, int frame_age, int frame_flags, curl_off_t payload_offset, curl_off_t payload_len, @@ -729,7 +729,7 @@ static CURLcode ws_cw_write(struct Curl_easy *data, if(nbytes) { size_t nwritten; - result = Curl_bufq_write(&ctx->buf, (const unsigned char *)buf, + result = Curl_bufq_write(&ctx->buf, (const uint8_t *)buf, nbytes, &nwritten); if(result) { infof(data, "[WS] error adding data to buffer %d", result); @@ -827,8 +827,8 @@ static CURLcode ws_enc_add_frame(struct Curl_easy *data, curl_off_t payload_len, struct bufq *out) { - unsigned char firstb = 0; - unsigned char head[14]; + uint8_t firstb = 0; + uint8_t head[14]; CURLcode result; size_t hlen, nwritten; @@ -871,24 +871,24 @@ static CURLcode ws_enc_add_frame(struct Curl_easy *data, head[0] = enc->firstbyte = firstb; if(payload_len > 65535) { head[1] = 127 | WSBIT_MASK; - head[2] = (unsigned char)((payload_len >> 56) & 0xff); - head[3] = (unsigned char)((payload_len >> 48) & 0xff); - head[4] = (unsigned char)((payload_len >> 40) & 0xff); - head[5] = (unsigned char)((payload_len >> 32) & 0xff); - head[6] = (unsigned char)((payload_len >> 24) & 0xff); - head[7] = (unsigned char)((payload_len >> 16) & 0xff); - head[8] = (unsigned char)((payload_len >> 8) & 0xff); - head[9] = (unsigned char)(payload_len & 0xff); + head[2] = (uint8_t)((payload_len >> 56) & 0xff); + head[3] = (uint8_t)((payload_len >> 48) & 0xff); + head[4] = (uint8_t)((payload_len >> 40) & 0xff); + head[5] = (uint8_t)((payload_len >> 32) & 0xff); + head[6] = (uint8_t)((payload_len >> 24) & 0xff); + head[7] = (uint8_t)((payload_len >> 16) & 0xff); + head[8] = (uint8_t)((payload_len >> 8) & 0xff); + head[9] = (uint8_t)(payload_len & 0xff); hlen = 10; } else if(payload_len >= 126) { head[1] = 126 | WSBIT_MASK; - head[2] = (unsigned char)((payload_len >> 8) & 0xff); - head[3] = (unsigned char)(payload_len & 0xff); + head[2] = (uint8_t)((payload_len >> 8) & 0xff); + head[3] = (uint8_t)(payload_len & 0xff); hlen = 4; } else { - head[1] = (unsigned char)payload_len | WSBIT_MASK; + head[1] = (uint8_t)payload_len | WSBIT_MASK; hlen = 2; } @@ -897,7 +897,7 @@ static CURLcode ws_enc_add_frame(struct Curl_easy *data, /* 4 bytes random */ - result = Curl_rand(data, (unsigned char *)&enc->mask, sizeof(enc->mask)); + result = Curl_rand(data, (uint8_t *)&enc->mask, sizeof(enc->mask)); if(result) return result; @@ -943,7 +943,7 @@ static CURLcode ws_enc_write_head(struct Curl_easy *data, static CURLcode ws_enc_write_payload(struct ws_encoder *enc, struct Curl_easy *data, - const unsigned char *buf, size_t buflen, + const uint8_t *buf, size_t buflen, struct bufq *out, size_t *pnwritten) { CURLcode result; @@ -960,7 +960,7 @@ static CURLcode ws_enc_write_payload(struct ws_encoder *enc, len = remain; for(i = 0; i < len; ++i) { - unsigned char c = buf[i] ^ enc->mask[enc->xori]; + uint8_t c = buf[i] ^ enc->mask[enc->xori]; result = Curl_bufq_write(out, &c, 1, &n); if(result) { if((result != CURLE_AGAIN) || !i) @@ -1020,7 +1020,7 @@ static CURLcode ws_enc_add_pending(struct Curl_easy *data, static CURLcode ws_enc_send(struct Curl_easy *data, struct websocket *ws, - const unsigned char *buffer, + const uint8_t *buffer, size_t buflen, curl_off_t fragsize, unsigned int flags, @@ -1198,7 +1198,7 @@ static CURLcode cr_ws_read(struct Curl_easy *data, goto out; } - result = ws_enc_write_payload(&ws->enc, data, (unsigned char *)buf, + result = ws_enc_write_payload(&ws->enc, data, (uint8_t *)buf, nread, &ws->sendbuf, &n); if(result) goto out; @@ -1244,7 +1244,7 @@ CURLcode Curl_ws_request(struct Curl_easy *data, struct dynbuf *req) { unsigned int i; CURLcode result = CURLE_OK; - unsigned char rand[16]; + uint8_t rand[16]; char *randstr; size_t randlen; char keyval[40]; @@ -1273,7 +1273,7 @@ CURLcode Curl_ws_request(struct Curl_easy *data, struct dynbuf *req) heads[2].val = &keyval[0]; /* 16 bytes random */ - result = Curl_rand(data, (unsigned char *)rand, sizeof(rand)); + result = Curl_rand(data, rand, sizeof(rand)); if(result) return result; result = curlx_base64_encode((char *)rand, sizeof(rand), &randstr, &randlen); @@ -1393,7 +1393,7 @@ CURLcode Curl_ws_accept(struct Curl_easy *data, /* In CONNECT_ONLY setup, the payloads from `mem` need to be received * when using `curl_ws_recv` later on after this transfer is already * marked as DONE. */ - result = Curl_bufq_write(&ws->recvbuf, (const unsigned char *)mem, + result = Curl_bufq_write(&ws->recvbuf, (const uint8_t *)mem, nread, &nwritten); if(result) goto out; @@ -1452,7 +1452,7 @@ CURLcode Curl_ws_accept(struct Curl_easy *data, struct ws_collect { struct Curl_easy *data; struct websocket *ws; - unsigned char *buffer; + uint8_t *buffer; size_t buflen; size_t bufidx; int frame_age; @@ -1462,7 +1462,7 @@ struct ws_collect { bool written; }; -static CURLcode ws_client_collect(const unsigned char *buf, size_t buflen, +static CURLcode ws_client_collect(const uint8_t *buf, size_t buflen, int frame_age, int frame_flags, curl_off_t payload_offset, curl_off_t payload_len, @@ -1519,7 +1519,7 @@ static CURLcode ws_client_collect(const unsigned char *buf, size_t buflen, } static CURLcode nw_in_recv(void *reader_ctx, - unsigned char *buf, size_t buflen, + uint8_t *buf, size_t buflen, size_t *pnread) { struct Curl_easy *data = reader_ctx; @@ -1628,7 +1628,7 @@ static CURLcode ws_flush(struct Curl_easy *data, struct websocket *ws, { if(!Curl_bufq_is_empty(&ws->sendbuf)) { CURLcode result; - const unsigned char *out; + const uint8_t *out; size_t outlen, n; #ifdef DEBUGBUILD /* Simulate a blocking send after this chunk has been sent */ @@ -1766,7 +1766,7 @@ CURLcode curl_ws_send(CURL *d, const void *buffer_arg, unsigned int flags) { struct websocket *ws; - const unsigned char *buffer = buffer_arg; + const uint8_t *buffer = buffer_arg; CURLcode result = CURLE_OK; struct Curl_easy *data = d; size_t ndummy; From bbb929112b13643842eb9dbfa060bd83a5b5cf03 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Thu, 27 Nov 2025 13:18:09 +0100 Subject: [PATCH 082/140] curlx_base64_encode: use uint8_t* for input Change `inputbuff` parameter from `const char *` to `const uint8_t *` to reflect the binary nature of the input bytes. Half the code was casting unsigned char to signed already in calling. Closes #19722 --- lib/curl_sasl.c | 2 +- lib/curlx/base64.c | 10 +++++----- lib/curlx/base64.h | 6 +++--- lib/http.c | 3 ++- lib/http2.c | 3 +-- lib/http_ntlm.c | 4 ++-- lib/ldap.c | 3 ++- lib/openldap.c | 3 ++- lib/vauth/digest.c | 2 +- lib/vauth/spnego_sspi.c | 2 +- lib/vssh/libssh2.c | 2 +- lib/vtls/openssl.c | 4 ++-- lib/vtls/vtls.c | 2 +- lib/vtls/wolfssl.c | 2 +- lib/vtls/x509asn1.c | 2 +- lib/ws.c | 2 +- src/tool_ssls.c | 4 ++-- src/var.c | 2 +- tests/unit/unit1302.c | 5 +++-- 19 files changed, 33 insertions(+), 30 deletions(-) diff --git a/lib/curl_sasl.c b/lib/curl_sasl.c index 1c9f259de471..f6ec668bfd45 100644 --- a/lib/curl_sasl.c +++ b/lib/curl_sasl.c @@ -267,7 +267,7 @@ static CURLcode build_message(struct SASL *sasl, struct bufref *msg) char *base64; size_t base64len; - result = curlx_base64_encode((const char *) Curl_bufref_ptr(msg), + result = curlx_base64_encode(Curl_bufref_ptr(msg), Curl_bufref_len(msg), &base64, &base64len); if(!result) Curl_bufref_set(msg, base64, base64len, curl_free); diff --git a/lib/curlx/base64.c b/lib/curlx/base64.c index ef07243dd3c5..3fcd709d1ce8 100644 --- a/lib/curlx/base64.c +++ b/lib/curlx/base64.c @@ -66,7 +66,7 @@ static const unsigned char decodetable[] = * @unittest: 1302 */ CURLcode curlx_base64_decode(const char *src, - unsigned char **outptr, size_t *outlen) + uint8_t **outptr, size_t *outlen) { size_t srclen = 0; size_t padding = 0; @@ -170,8 +170,8 @@ CURLcode curlx_base64_decode(const char *src, } static CURLcode base64_encode(const char *table64, - unsigned char padbyte, - const char *inputbuff, size_t insize, + uint8_t padbyte, + const uint8_t *inputbuff, size_t insize, char **outptr, size_t *outlen) { char *output; @@ -245,7 +245,7 @@ static CURLcode base64_encode(const char *table64, * * @unittest: 1302 */ -CURLcode curlx_base64_encode(const char *inputbuff, size_t insize, +CURLcode curlx_base64_encode(const uint8_t *inputbuff, size_t insize, char **outptr, size_t *outlen) { return base64_encode(Curl_base64encdec, '=', @@ -267,7 +267,7 @@ CURLcode curlx_base64_encode(const char *inputbuff, size_t insize, * * @unittest: 1302 */ -CURLcode curlx_base64url_encode(const char *inputbuff, size_t insize, +CURLcode curlx_base64url_encode(const uint8_t *inputbuff, size_t insize, char **outptr, size_t *outlen) { return base64_encode(base64url, 0, inputbuff, insize, outptr, outlen); diff --git a/lib/curlx/base64.h b/lib/curlx/base64.h index 31cfcb36e767..3c97ecc9fec1 100644 --- a/lib/curlx/base64.h +++ b/lib/curlx/base64.h @@ -24,12 +24,12 @@ * ***************************************************************************/ -CURLcode curlx_base64_encode(const char *inputbuff, size_t insize, +CURLcode curlx_base64_encode(const uint8_t *inputbuff, size_t insize, char **outptr, size_t *outlen); -CURLcode curlx_base64url_encode(const char *inputbuff, size_t insize, +CURLcode curlx_base64url_encode(const uint8_t *inputbuff, size_t insize, char **outptr, size_t *outlen); CURLcode curlx_base64_decode(const char *src, - unsigned char **outptr, size_t *outlen); + uint8_t **outptr, size_t *outlen); extern const char Curl_base64encdec[]; diff --git a/lib/http.c b/lib/http.c index 0319be3b657b..672183db0ef2 100644 --- a/lib/http.c +++ b/lib/http.c @@ -367,7 +367,8 @@ static CURLcode http_output_basic(struct Curl_easy *data, bool proxy) if(!out) return CURLE_OUT_OF_MEMORY; - result = curlx_base64_encode(out, strlen(out), &authorization, &size); + result = curlx_base64_encode((uint8_t *)out, strlen(out), + &authorization, &size); if(result) goto fail; diff --git a/lib/http2.c b/lib/http2.c index 4f5f5ea52dd3..4f49efe768b4 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -1847,8 +1847,7 @@ CURLcode Curl_http2_request_upgrade(struct dynbuf *req, return CURLE_FAILED_INIT; } - result = curlx_base64url_encode((const char *)binsettings, binlen, - &base64, &blen); + result = curlx_base64url_encode(binsettings, binlen, &base64, &blen); if(result) { curlx_dyn_free(req); return result; diff --git a/lib/http_ntlm.c b/lib/http_ntlm.c index fa375b49bfc6..8cb6403fdb8b 100644 --- a/lib/http_ntlm.c +++ b/lib/http_ntlm.c @@ -205,7 +205,7 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy) hostname, ntlm, &ntlmmsg); if(!result) { DEBUGASSERT(Curl_bufref_len(&ntlmmsg) != 0); - result = curlx_base64_encode((const char *) Curl_bufref_ptr(&ntlmmsg), + result = curlx_base64_encode(Curl_bufref_ptr(&ntlmmsg), Curl_bufref_len(&ntlmmsg), &base64, &len); if(!result) { free(*allocuserpwd); @@ -224,7 +224,7 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy) result = Curl_auth_create_ntlm_type3_message(data, userp, passwdp, ntlm, &ntlmmsg); if(!result && Curl_bufref_len(&ntlmmsg)) { - result = curlx_base64_encode((const char *) Curl_bufref_ptr(&ntlmmsg), + result = curlx_base64_encode(Curl_bufref_ptr(&ntlmmsg), Curl_bufref_len(&ntlmmsg), &base64, &len); if(!result) { free(*allocuserpwd); diff --git a/lib/ldap.c b/lib/ldap.c index fa1a4a4d25c5..7f2af3664325 100644 --- a/lib/ldap.c +++ b/lib/ldap.c @@ -626,7 +626,8 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) curl_strequal(";binary", attr + (attr_len - 7)) ) { /* Binary attribute, encode to base64. */ if(vals[i]->bv_len) { - result = curlx_base64_encode(vals[i]->bv_val, vals[i]->bv_len, + result = curlx_base64_encode((uint8_t *)vals[i]->bv_val, + vals[i]->bv_len, &val_b64, &val_b64_sz); if(result) { ldap_value_free_len(vals); diff --git a/lib/openldap.c b/lib/openldap.c index 41419df21b20..806ccb33ccd1 100644 --- a/lib/openldap.c +++ b/lib/openldap.c @@ -1213,7 +1213,8 @@ static CURLcode oldap_recv(struct Curl_easy *data, int sockindex, char *buf, /* Binary value, encode to base64. */ if(bvals[i].bv_len) - result = curlx_base64_encode(bvals[i].bv_val, bvals[i].bv_len, + result = curlx_base64_encode((uint8_t *)bvals[i].bv_val, + bvals[i].bv_len, &val_b64, &val_b64_sz); if(!result) result = client_write(data, STRCONST(": "), val_b64, val_b64_sz, diff --git a/lib/vauth/digest.c b/lib/vauth/digest.c index c1c0ab2ab219..16045707fd1e 100644 --- a/lib/vauth/digest.c +++ b/lib/vauth/digest.c @@ -710,7 +710,7 @@ static CURLcode auth_create_digest_http_message( if(result) return result; - result = curlx_base64_encode(cnoncebuf, sizeof(cnoncebuf), + result = curlx_base64_encode((uint8_t *)cnoncebuf, sizeof(cnoncebuf), &cnonce, &cnonce_sz); if(result) return result; diff --git a/lib/vauth/spnego_sspi.c b/lib/vauth/spnego_sspi.c index 9cf554d3b061..b36535557bd9 100644 --- a/lib/vauth/spnego_sspi.c +++ b/lib/vauth/spnego_sspi.c @@ -301,7 +301,7 @@ CURLcode Curl_auth_create_spnego_message(struct negotiatedata *nego, char **outptr, size_t *outlen) { /* Base64 encode the already generated response */ - CURLcode result = curlx_base64_encode((const char *)nego->output_token, + CURLcode result = curlx_base64_encode(nego->output_token, nego->output_token_length, outptr, outlen); if(!result && (!*outptr || !*outlen)) { diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index 1c9fe5ac0154..e4ceda8c3494 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -602,7 +602,7 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data, /* The length of fingerprint is 32 bytes for SHA256. * See libssh2_hostkey_hash documentation. */ - if(curlx_base64_encode(fingerprint, 32, &fingerprint_b64, + if(curlx_base64_encode((const uint8_t *)fingerprint, 32, &fingerprint_b64, &fingerprint_b64_len) != CURLE_OK) { myssh_state(data, sshc, SSH_SESSION_FREE); return CURLE_PEER_FAILED_VERIFICATION; diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index 2f526479c5f4..7ff5698e7c30 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -4132,7 +4132,7 @@ static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL* ssl, int rv = 1; # ifndef HAVE_BORINGSSL_LIKE char *inner = NULL; - unsigned char *rcs = NULL; + uint8_t *rcs = NULL; char *outer = NULL; # else const char *inner = NULL; @@ -4156,7 +4156,7 @@ static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL* ssl, char *b64str = NULL; size_t blen = 0; - result = curlx_base64_encode((const char *)rcs, rcl, &b64str, &blen); + result = curlx_base64_encode(rcs, rcl, &b64str, &blen); if(!result && b64str) { infof(data, "ECH: retry_configs %s", b64str); free(b64str); diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c index d116ec91edb3..9c76ca7ed32c 100644 --- a/lib/vtls/vtls.c +++ b/lib/vtls/vtls.c @@ -790,7 +790,7 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data, sha256sumdigest, CURL_SHA256_DIGEST_LENGTH); if(!encode) - encode = curlx_base64_encode((char *)sha256sumdigest, + encode = curlx_base64_encode(sha256sumdigest, CURL_SHA256_DIGEST_LENGTH, &cert_hash, &cert_hash_len); Curl_safefree(sha256sumdigest); diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c index c8fc8c4add1a..e622f909e50b 100644 --- a/lib/vtls/wolfssl.c +++ b/lib/vtls/wolfssl.c @@ -1816,7 +1816,7 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, char *b64str = NULL; size_t blen = 0; - result = curlx_base64_encode((const char *)echConfigs, echConfigsLen, + result = curlx_base64_encode(echConfigs, echConfigsLen, &b64str, &blen); if(!result && b64str) infof(data, "ECH: (not yet) retry_configs %s", b64str); diff --git a/lib/vtls/x509asn1.c b/lib/vtls/x509asn1.c index 96eb512b9038..417a5382d873 100644 --- a/lib/vtls/x509asn1.c +++ b/lib/vtls/x509asn1.c @@ -1228,7 +1228,7 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data, curlx_dyn_reset(&out); /* Generate PEM certificate. */ - result = curlx_base64_encode(cert.certificate.beg, + result = curlx_base64_encode((const uint8_t *)cert.certificate.beg, cert.certificate.end - cert.certificate.beg, &certptr, &clen); if(result) diff --git a/lib/ws.c b/lib/ws.c index 36191b2fac0d..15dc2e9aea7e 100644 --- a/lib/ws.c +++ b/lib/ws.c @@ -1276,7 +1276,7 @@ CURLcode Curl_ws_request(struct Curl_easy *data, struct dynbuf *req) result = Curl_rand(data, rand, sizeof(rand)); if(result) return result; - result = curlx_base64_encode((char *)rand, sizeof(rand), &randstr, &randlen); + result = curlx_base64_encode(rand, sizeof(rand), &randstr, &randlen); if(result) return result; DEBUGASSERT(randlen < sizeof(keyval)); diff --git a/src/tool_ssls.c b/src/tool_ssls.c index 40e67a8044c9..2b67be9baaf8 100644 --- a/src/tool_ssls.c +++ b/src/tool_ssls.c @@ -159,7 +159,7 @@ static CURLcode tool_ssls_exp(CURL *easy, void *userptr, "# This file was generated by libcurl! Edit at your own risk.\n", ctx->fp); - r = curlx_base64_encode((const char *)shmac, shmac_len, &enc, &enc_len); + r = curlx_base64_encode(shmac, shmac_len, &enc, &enc_len); if(r) goto out; r = CURLE_WRITE_ERROR; @@ -168,7 +168,7 @@ static CURLcode tool_ssls_exp(CURL *easy, void *userptr, if(EOF == fputc(':', ctx->fp)) goto out; tool_safefree(enc); - r = curlx_base64_encode((const char *)sdata, sdata_len, &enc, &enc_len); + r = curlx_base64_encode(sdata, sdata_len, &enc, &enc_len); if(r) goto out; r = CURLE_WRITE_ERROR; diff --git a/src/var.c b/src/var.c index 94d79695acc9..5cedf1d24a2c 100644 --- a/src/var.c +++ b/src/var.c @@ -150,7 +150,7 @@ static ParameterError varfunc(char *c, /* content */ if(clen) { char *enc; size_t elen; - CURLcode result = curlx_base64_encode(c, clen, &enc, &elen); + CURLcode result = curlx_base64_encode((uint8_t *)c, clen, &enc, &elen); if(result) { err = PARAM_NO_MEM; break; diff --git a/tests/unit/unit1302.c b/tests/unit/unit1302.c index 2c4404d72702..911432a8c833 100644 --- a/tests/unit/unit1302.c +++ b/tests/unit/unit1302.c @@ -133,7 +133,7 @@ static CURLcode test_unit1302(const char *arg) size_t dlen; /* first encode */ - rc = curlx_base64_encode(e->input, e->ilen, &out, &olen); + rc = curlx_base64_encode((const uint8_t *)e->input, e->ilen, &out, &olen); abort_unless(rc == CURLE_OK, "return code should be CURLE_OK"); abort_unless(olen == e->olen, "wrong output size"); if(memcmp(out, e->output, e->olen)) { @@ -166,7 +166,8 @@ static CURLcode test_unit1302(const char *arg) struct etest *e = &url[i]; char *out; size_t olen; - rc = curlx_base64url_encode(e->input, e->ilen, &out, &olen); + rc = curlx_base64url_encode((const uint8_t *)e->input, e->ilen, + &out, &olen); abort_unless(rc == CURLE_OK, "return code should be CURLE_OK"); if(olen != e->olen) { curl_mfprintf(stderr, "Test %u URL encoded output length %zu " From 71e9920fcd2683bc63ba1f227307560010ce7deb Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Nov 2025 14:19:48 +0100 Subject: [PATCH 083/140] GHA: add timeouts to mitigate hung brew install step Ref: https://github.com/curl/curl/actions/runs/19736703410/job/56550251534?pr=19723 Closes #19726 --- .github/workflows/checksrc.yml | 2 ++ .github/workflows/configure-vs-cmake.yml | 1 + .github/workflows/distcheck.yml | 1 + .github/workflows/macos.yml | 2 ++ 4 files changed, 6 insertions(+) diff --git a/.github/workflows/checksrc.yml b/.github/workflows/checksrc.yml index 2f7b0b0e941c..d3ef758b4872 100644 --- a/.github/workflows/checksrc.yml +++ b/.github/workflows/checksrc.yml @@ -73,6 +73,7 @@ jobs: .github/scripts/codespell.sh - name: 'typos' + timeout-minutes: 2 run: | HOMEBREW_NO_AUTO_UPDATE=1 /home/linuxbrew/.linuxbrew/bin/brew install typos-cli eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" @@ -148,6 +149,7 @@ jobs: timeout-minutes: 5 steps: - name: 'install prereqs' + timeout-minutes: 2 run: HOMEBREW_NO_AUTO_UPDATE=1 /home/linuxbrew/.linuxbrew/bin/brew install actionlint shellcheck zizmor - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 diff --git a/.github/workflows/configure-vs-cmake.yml b/.github/workflows/configure-vs-cmake.yml index 53775a44fd83..778b306b65ca 100644 --- a/.github/workflows/configure-vs-cmake.yml +++ b/.github/workflows/configure-vs-cmake.yml @@ -81,6 +81,7 @@ jobs: runs-on: macos-latest steps: - name: 'install packages' + timeout-minutes: 2 run: | # shellcheck disable=SC2181,SC2034 while [[ $? == 0 ]]; do for i in 1 2 3; do if brew update && brew install automake libtool; then break 2; else echo Error: wait to try again; sleep 10; fi; done; false Too many retries; done diff --git a/.github/workflows/distcheck.yml b/.github/workflows/distcheck.yml index 442a7f18a10c..86c05fd0f0cc 100644 --- a/.github/workflows/distcheck.yml +++ b/.github/workflows/distcheck.yml @@ -279,6 +279,7 @@ jobs: mingw-w64-x86_64-zlib mingw-w64-x86_64-zstd mingw-w64-x86_64-libpsl mingw-w64-x86_64-libssh2 mingw-w64-x86_64-nghttp2 mingw-w64-x86_64-openssl - name: 'install prereqs' + timeout-minutes: 3 run: | if [[ "${MATRIX_IMAGE}" = *'windows'* ]]; then cd ~ diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index cd72073155c3..25ac41c61ee1 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -94,6 +94,7 @@ jobs: steps: - name: 'brew install' if: ${{ matrix.build.configure }} + timeout-minutes: 5 run: | # shellcheck disable=SC2181,SC2034 while [[ $? == 0 ]]; do for i in 1 2 3; do if brew update && brew install automake libtool; then break 2; else echo Error: wait to try again; sleep 10; fi; done; false Too many retries; done @@ -350,6 +351,7 @@ jobs: steps: - name: 'brew install' + timeout-minutes: 5 # Run this command with retries because of spurious failures seen # while running the tests, for example # https://github.com/curl/curl/runs/4095721123?check_suite_focus=true From eae2df837e8927bc43ab5b8994252f8b0b0f097a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Nov 2025 13:02:49 +0100 Subject: [PATCH 084/140] runtests: fix showing `nghttpx-h3` in the `Env:` log when detected Ref: #19723 Closes #19728 --- tests/runtests.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/runtests.pl b/tests/runtests.pl index 54ac77e2e963..3d557d1435ed 100755 --- a/tests/runtests.pl +++ b/tests/runtests.pl @@ -891,7 +891,7 @@ sub checksystemfeatures { $valgrind?"Valgrind ":"", $run_duphandle?"test-duphandle ":"", $run_event_based?"event-based ":"", - $nghttpx_h3, + $nghttpx_h3?"nghttpx-h3 " :"", $libtool?"Libtool ":""); if($env) { logmsg "* Env: $env\n"; From 7a10f493222cad24a1625bfb283523e73647a6f0 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 21 Nov 2025 13:46:53 +0100 Subject: [PATCH 085/140] badwords: make some words match case-insensitively Also: - wcurl.md: sync with upstream to pass the badwords check. Ref: https://github.com/curl/wcurl/commit/11f840cddd840e03b4281cb7408b246c0d09da0f Ref: https://github.com/curl/wcurl/pull/79 Closes #19713 --- .github/scripts/badwords.txt | 10 +++++----- docs/wcurl.md | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/scripts/badwords.txt b/.github/scripts/badwords.txt index d8f4461d2675..9e43c03fa827 100644 --- a/.github/scripts/badwords.txt +++ b/.github/scripts/badwords.txt @@ -17,7 +17,7 @@ could've:could have couldn't:could not didn't:did not doesn't:does not -don't=do not +don't:do not haven't:have not i'd:I would i'll:I will @@ -74,10 +74,10 @@ file names\b:filenames \buser names\b:usernames \bpass phrase:passphrase \bwill\b:rewrite to present tense -\b32bit=32-bit -\b64bit=64-bit -32 bit\b=32-bit -64 bit\b=64-bit +\b32bit:32-bit +\b64bit:64-bit +32 bit\b:32-bit +64 bit\b:64-bit 64-bits:64 bits or 64-bit 32-bits:32 bits or 32-bit \bvery\b:rephrase using an alternative word diff --git a/docs/wcurl.md b/docs/wcurl.md index 7d1200b2ea70..ab5c3aaa9722 100644 --- a/docs/wcurl.md +++ b/docs/wcurl.md @@ -87,7 +87,7 @@ last value is considered. ## --no-decode-filename -Don't percent-decode the output filename, even if the percent-encoding in the +Do not percent-decode the output filename, even if the percent-encoding in the URL was done by **wcurl**, e.g.: The URL contained whitespace. ## --dry-run From 0081c5b12627ddfb5d6e71198475dc9f95c0a53e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Nov 2025 15:37:19 +0100 Subject: [PATCH 086/140] pytest: disable two H3 earlydata tests for all platforms (was: macOS) Follow-up to 692c7f133e6f9a5053a87b1fffbf3c41697a7742 #19252 Follow-up to eefd03c572996e5de4dec4fe295ad6f103e0eefc #18703 Ref: #19719 Ref: #19723 Fixes #19724 Closes #19730 --- tests/http/test_02_download.py | 8 ++++---- tests/http/test_07_upload.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/http/test_02_download.py b/tests/http/test_02_download.py index dcfe9690bcb4..9fbc116caf0a 100644 --- a/tests/http/test_02_download.py +++ b/tests/http/test_02_download.py @@ -566,10 +566,10 @@ def test_02_32_earlydata(self, env: Env, httpd, nghttpx, proto): pytest.skip("h3 early data not supported") if proto != 'h3' and sys.platform.startswith('darwin') and env.ci_run: pytest.skip('failing on macOS CI runners') - if proto == 'h3' and sys.platform.startswith('darwin') and env.curl_uses_lib('wolfssl'): - pytest.skip('h3 wolfssl early data failing on macOS') - if proto == 'h3' and sys.platform.startswith('darwin') and env.curl_uses_lib('gnutls'): - pytest.skip('h3 gnutls early data failing on macOS') + if proto == 'h3' and env.curl_uses_lib('wolfssl'): + pytest.skip('h3 wolfssl early data failing') + if proto == 'h3' and env.curl_uses_lib('gnutls'): + pytest.skip('h3 gnutls early data failing') count = 2 docname = 'data-10k' # we want this test to always connect to nghttpx, since it is diff --git a/tests/http/test_07_upload.py b/tests/http/test_07_upload.py index 9e49ad7f4737..495ec7a98955 100644 --- a/tests/http/test_07_upload.py +++ b/tests/http/test_07_upload.py @@ -663,10 +663,10 @@ def test_07_70_put_earlydata(self, env: Env, httpd, nghttpx, proto, upload_size, pytest.skip("h3 not supported") if proto != 'h3' and sys.platform.startswith('darwin') and env.ci_run: pytest.skip('failing on macOS CI runners') - if proto == 'h3' and sys.platform.startswith('darwin') and env.curl_uses_lib('wolfssl'): - pytest.skip('h3 wolfssl early data failing on macOS') - if proto == 'h3' and sys.platform.startswith('darwin') and env.curl_uses_lib('gnutls'): - pytest.skip('h3 gnutls early data failing on macOS') + if proto == 'h3' and env.curl_uses_lib('wolfssl'): + pytest.skip('h3 wolfssl early data failing') + if proto == 'h3' and env.curl_uses_lib('gnutls'): + pytest.skip('h3 gnutls early data failing') count = 2 # we want this test to always connect to nghttpx, since it is # the only server we have that supports TLS earlydata From c8b76ff42f5228b0c8e3a9d51755ec7f318af6ba Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Nov 2025 13:44:27 +0100 Subject: [PATCH 087/140] GHA/http3-linux: fix broken h3 server in non-openssl jobs, for more pytests It also revealed 3 failing earlydata tests with two backends on Linux, seen earlier on macOS: ``` LibreSSL before: 571 passed, 141 skipped in 45.34s LibreSSL after: 736 passed, 95 skipped in 68.08s aws-lc before: 571 passed, 141 skipped in 78.87s aws-lc after: 736 passed, 95 skipped in 66.71s BoringSSL before: 511 passed, 201 skipped in 46.47s BoringSSL after: 676 passed, 155 skipped in 63.96s GnuTLS before: 515 passed, 197 skipped in 48.31s GnuTLS after: 688 passed, 140 skipped in 67.79s (3 failed) wolfSSL before: 541 passed, 171 skipped in 52.49s wolfSSL after: 714 passed, 114 skipped in 83.84s (3 failed) OpenSSL before: 757 passed, 74 skipped in 65.43s OpenSSL after: 757 passed, 74 skipped in 65.06s OpenSSL-quic before: 741 passed, 90 skipped in 62.85s OpenSSL-quic after: 741 passed, 90 skipped in 57.20s quiche before: 511 passed, 201 skipped in 45.94s quiche after: 664 passed, 167 skipped in 59.57s ``` Before: https://github.com/curl/curl/actions/runs/19734972379 After: https://github.com/curl/curl/actions/runs/19736703398?pr=19723 Failures address via: 0081c5b12627ddfb5d6e71198475dc9f95c0a53e #19730 Ref: #19724 Closes #19723 --- .github/workflows/http3-linux.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/http3-linux.yml b/.github/workflows/http3-linux.yml index 87738dd79138..353c36814219 100644 --- a/.github/workflows/http3-linux.yml +++ b/.github/workflows/http3-linux.yml @@ -486,7 +486,6 @@ jobs: echo 'CXX=g++-12' >> "$GITHUB_ENV" - name: 'cache openssl' - if: ${{ matrix.build.name == 'openssl' || matrix.build.name == 'openssl-quic' }} uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 id: cache-openssl-http3-no-deprecated env: From a59a3cc7f1593784e496172b9fb4d82ed6fae487 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 27 Nov 2025 14:25:43 +0100 Subject: [PATCH 088/140] cfilters: make conn_forget_socket a private libssh function It is only used for (old) libssh builds. Closes #19727 --- lib/cfilters.c | 13 ------------- lib/vssh/libssh.c | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/cfilters.c b/lib/cfilters.c index f0da4778a685..31c7b07747c1 100644 --- a/lib/cfilters.c +++ b/lib/cfilters.c @@ -931,19 +931,6 @@ Curl_conn_get_remote_addr(struct Curl_easy *data, int sockindex) return cf ? cf_get_remote_addr(cf, data) : NULL; } -void Curl_conn_forget_socket(struct Curl_easy *data, int sockindex) -{ - struct connectdata *conn = data->conn; - if(conn && CONN_SOCK_IDX_VALID(sockindex)) { - struct Curl_cfilter *cf = conn->cfilter[sockindex]; - if(cf) - (void)Curl_conn_cf_cntrl(cf, data, TRUE, - CF_CTRL_FORGET_SOCKET, 0, NULL); - fake_sclose(conn->sock[sockindex]); - conn->sock[sockindex] = CURL_SOCKET_BAD; - } -} - static CURLcode cf_cntrl_all(struct connectdata *conn, struct Curl_easy *data, bool ignore_result, diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index c76478bc2a57..4b003bd71ca9 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -1874,6 +1874,19 @@ static int myssh_in_SFTP_QUOTE_STAT(struct Curl_easy *data, return SSH_NO_ERROR; } +static void conn_forget_socket(struct Curl_easy *data, int sockindex) +{ + struct connectdata *conn = data->conn; + if(conn && CONN_SOCK_IDX_VALID(sockindex)) { + struct Curl_cfilter *cf = conn->cfilter[sockindex]; + if(cf) + (void)Curl_conn_cf_cntrl(cf, data, TRUE, + CF_CTRL_FORGET_SOCKET, 0, NULL); + fake_sclose(conn->sock[sockindex]); + conn->sock[sockindex] = CURL_SOCKET_BAD; + } +} + /* * ssh_statemach_act() runs the SSH state machine as far as it can without * blocking and without reaching the end. The data the pointer 'block' points @@ -2376,7 +2389,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, /* conn->sock[FIRSTSOCKET] is closed by ssh_disconnect behind our back, tell the connection to forget about it. This libssh bug is fixed in 0.10.0. */ - Curl_conn_forget_socket(data, FIRSTSOCKET); + conn_forget_socket(data, FIRSTSOCKET); } SSH_STRING_FREE_CHAR(sshc->homedir); From 1e048e932acfe8e46a1e33fb5d7d51406b12e23b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 27 Nov 2025 14:19:34 +0100 Subject: [PATCH 089/140] ngtcp2: remove the unused Curl_conn_is_ngtcp2 function Closes #19725 --- lib/vquic/curl_ngtcp2.c | 16 ---------------- lib/vquic/curl_ngtcp2.h | 4 ---- 2 files changed, 20 deletions(-) diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index de767f28dc04..22ea0e3ef493 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -2880,20 +2880,4 @@ CURLcode Curl_cf_ngtcp2_create(struct Curl_cfilter **pcf, return result; } -bool Curl_conn_is_ngtcp2(const struct Curl_easy *data, - const struct connectdata *conn, - int sockindex) -{ - struct Curl_cfilter *cf = conn ? conn->cfilter[sockindex] : NULL; - - (void)data; - for(; cf; cf = cf->next) { - if(cf->cft == &Curl_cft_http3) - return TRUE; - if(cf->cft->flags & CF_TYPE_IP_CONNECT) - return FALSE; - } - return FALSE; -} - #endif diff --git a/lib/vquic/curl_ngtcp2.h b/lib/vquic/curl_ngtcp2.h index 86753a3a6ba8..7933e924e1c7 100644 --- a/lib/vquic/curl_ngtcp2.h +++ b/lib/vquic/curl_ngtcp2.h @@ -55,10 +55,6 @@ CURLcode Curl_cf_ngtcp2_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai); - -bool Curl_conn_is_ngtcp2(const struct Curl_easy *data, - const struct connectdata *conn, - int sockindex); #endif #endif /* HEADER_CURL_VQUIC_CURL_NGTCP2_H */ From 56e88e7c14dd1a529f9a4f23db5f791302bba6e7 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Thu, 27 Nov 2025 15:13:11 +0100 Subject: [PATCH 090/140] cfilter: send uint8_t bytes Change the send parameter from `const void *` to `const uint8_t *` and adapt calling code. Several had already unsigned chars and were casting. Closes #19729 --- lib/cf-h1-proxy.c | 4 ++-- lib/cf-h2-proxy.c | 6 +++--- lib/cf-haproxy.c | 2 +- lib/cf-socket.c | 2 +- lib/cfilters.c | 9 ++++----- lib/cfilters.h | 6 +++--- lib/http2.c | 6 +++--- lib/socks_gssapi.c | 12 +++++------- lib/socks_sspi.c | 13 +++++-------- lib/vquic/curl_ngtcp2.c | 6 +++--- lib/vquic/curl_osslq.c | 6 +++--- lib/vquic/curl_quiche.c | 8 ++++---- lib/vtls/mbedtls.c | 3 +-- lib/vtls/openssl.c | 3 ++- lib/vtls/rustls.c | 2 +- lib/vtls/schannel.c | 12 ++++++++---- lib/vtls/vtls.c | 4 ++-- lib/vtls/wolfssl.c | 3 ++- 18 files changed, 53 insertions(+), 54 deletions(-) diff --git a/lib/cf-h1-proxy.c b/lib/cf-h1-proxy.c index e496d7634dce..417b4df67e29 100644 --- a/lib/cf-h1-proxy.c +++ b/lib/cf-h1-proxy.c @@ -246,7 +246,7 @@ static CURLcode send_CONNECT(struct Curl_cfilter *cf, struct h1_tunnel_state *ts, bool *done) { - char *buf = curlx_dyn_ptr(&ts->request_data); + uint8_t *buf = curlx_dyn_uptr(&ts->request_data); size_t request_len = curlx_dyn_len(&ts->request_data); size_t blen = request_len; CURLcode result = CURLE_OK; @@ -267,7 +267,7 @@ static CURLcode send_CONNECT(struct Curl_cfilter *cf, DEBUGASSERT(blen >= nwritten); ts->nsent += nwritten; - Curl_debug(data, CURLINFO_HEADER_OUT, buf, nwritten); + Curl_debug(data, CURLINFO_HEADER_OUT, (char *)buf, nwritten); out: if(result) diff --git a/lib/cf-h2-proxy.c b/lib/cf-h2-proxy.c index 89bc7cc23f48..fca916a2c24f 100644 --- a/lib/cf-h2-proxy.c +++ b/lib/cf-h2-proxy.c @@ -225,7 +225,7 @@ static void drain_tunnel(struct Curl_cfilter *cf, } static CURLcode proxy_h2_nw_out_writer(void *writer_ctx, - const unsigned char *buf, size_t buflen, + const uint8_t *buf, size_t buflen, size_t *pnwritten) { struct Curl_cfilter *cf = writer_ctx; @@ -233,7 +233,7 @@ static CURLcode proxy_h2_nw_out_writer(void *writer_ctx, if(cf) { struct Curl_easy *data = CF_DATA_CURRENT(cf); CURLcode result; - result = Curl_conn_cf_send(cf->next, data, (const char *)buf, buflen, + result = Curl_conn_cf_send(cf->next, data, buf, buflen, FALSE, pnwritten); CURL_TRC_CF(data, cf, "[0] nw_out_writer(len=%zu) -> %d, %zu", buflen, result, *pnwritten); @@ -1356,7 +1356,7 @@ static CURLcode cf_h2_proxy_recv(struct Curl_cfilter *cf, static CURLcode cf_h2_proxy_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_h2_proxy_ctx *ctx = cf->ctx; diff --git a/lib/cf-haproxy.c b/lib/cf-haproxy.c index 3231791097ed..8912604504d8 100644 --- a/lib/cf-haproxy.c +++ b/lib/cf-haproxy.c @@ -133,7 +133,7 @@ static CURLcode cf_haproxy_connect(struct Curl_cfilter *cf, if(len > 0) { size_t nwritten; result = Curl_conn_cf_send(cf->next, data, - curlx_dyn_ptr(&ctx->data_out), len, FALSE, + curlx_dyn_uptr(&ctx->data_out), len, FALSE, &nwritten); if(result) { if(result != CURLE_AGAIN) diff --git a/lib/cf-socket.c b/lib/cf-socket.c index c657330ec6ed..6e5333602c34 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -1428,7 +1428,7 @@ static void win_update_sndbuf_size(struct cf_socket_ctx *ctx) #endif /* USE_WINSOCK */ static CURLcode cf_socket_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_socket_ctx *ctx = cf->ctx; diff --git a/lib/cfilters.c b/lib/cfilters.c index 31c7b07747c1..7cb10f39282f 100644 --- a/lib/cfilters.c +++ b/lib/cfilters.c @@ -85,7 +85,7 @@ bool Curl_cf_def_data_pending(struct Curl_cfilter *cf, } CURLcode Curl_cf_def_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { if(cf->next) @@ -296,12 +296,11 @@ CURLcode Curl_cf_recv_bufq(struct Curl_cfilter *cf, } static CURLcode cf_bufq_writer(void *writer_ctx, - const unsigned char *buf, size_t buflen, + const uint8_t *buf, size_t buflen, size_t *pnwritten) { struct cf_io_ctx *io = writer_ctx; - return Curl_conn_cf_send(io->cf, io->data, (const char *)buf, - buflen, FALSE, pnwritten); + return Curl_conn_cf_send(io->cf, io->data, buf, buflen, FALSE, pnwritten); } CURLcode Curl_cf_send_bufq(struct Curl_cfilter *cf, @@ -422,7 +421,7 @@ void Curl_conn_cf_close(struct Curl_cfilter *cf, struct Curl_easy *data) } CURLcode Curl_conn_cf_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { if(cf) diff --git a/lib/cfilters.h b/lib/cfilters.h index 6cb4a6909c36..5d39725088ed 100644 --- a/lib/cfilters.h +++ b/lib/cfilters.h @@ -89,7 +89,7 @@ typedef bool Curl_cft_data_pending(struct Curl_cfilter *cf, typedef CURLcode Curl_cft_send(struct Curl_cfilter *cf, struct Curl_easy *data, /* transfer */ - const void *buf, /* data to write */ + const uint8_t *buf, /* data to write */ size_t len, /* amount to write */ bool eos, /* last chunk */ size_t *pnwritten); /* how much sent */ @@ -250,7 +250,7 @@ CURLcode Curl_cf_def_adjust_pollset(struct Curl_cfilter *cf, bool Curl_cf_def_data_pending(struct Curl_cfilter *cf, const struct Curl_easy *data); CURLcode Curl_cf_def_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten); CURLcode Curl_cf_def_recv(struct Curl_cfilter *cf, struct Curl_easy *data, char *buf, size_t len, size_t *pnread); @@ -323,7 +323,7 @@ CURLcode Curl_conn_cf_connect(struct Curl_cfilter *cf, bool *done); void Curl_conn_cf_close(struct Curl_cfilter *cf, struct Curl_easy *data); CURLcode Curl_conn_cf_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten); CURLcode Curl_conn_cf_recv(struct Curl_cfilter *cf, struct Curl_easy *data, char *buf, size_t len, size_t *pnread); diff --git a/lib/http2.c b/lib/http2.c index 4f49efe768b4..2e8649c10502 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -2258,7 +2258,7 @@ static CURLcode cf_h2_body_send(struct Curl_cfilter *cf, static CURLcode h2_submit(struct h2_stream_ctx **pstream, struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_h2_ctx *ctx = cf->ctx; @@ -2281,7 +2281,7 @@ static CURLcode h2_submit(struct h2_stream_ctx **pstream, if(result) goto out; - result = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL, + result = Curl_h1_req_parse_read(&stream->h1, (const char *)buf, len, NULL, !data->state.http_ignorecustom ? data->set.str[STRING_CUSTOMREQUEST] : NULL, 0, &nwritten); @@ -2391,7 +2391,7 @@ static CURLcode h2_submit(struct h2_stream_ctx **pstream, } static CURLcode cf_h2_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_h2_ctx *ctx = cf->ctx; diff --git a/lib/socks_gssapi.c b/lib/socks_gssapi.c index 30fefa5a6d3c..61c88be60528 100644 --- a/lib/socks_gssapi.c +++ b/lib/socks_gssapi.c @@ -211,7 +211,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = htons((unsigned short)gss_send_token.length); memcpy(socksreq + 2, &us_length, sizeof(short)); - code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 4, + code = Curl_conn_cf_send(cf->next, data, socksreq, 4, FALSE, &nwritten); if(code || (nwritten != 4)) { failf(data, "Failed to send GSS-API authentication request."); @@ -222,7 +222,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, } code = Curl_conn_cf_send(cf->next, data, - (char *)gss_send_token.value, + gss_send_token.value, gss_send_token.length, FALSE, &nwritten); if(code || (gss_send_token.length != nwritten)) { failf(data, "Failed to send GSS-API authentication token."); @@ -409,8 +409,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, memcpy(socksreq + 2, &us_length, sizeof(short)); } - code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 4, FALSE, - &nwritten); + code = Curl_conn_cf_send(cf->next, data, socksreq, 4, FALSE, &nwritten); if(code || (nwritten != 4)) { failf(data, "Failed to send GSS-API encryption request."); gss_release_buffer(&gss_status, &gss_w_token); @@ -420,8 +419,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, if(data->set.socks5_gssapi_nec) { memcpy(socksreq, &gss_enc, 1); - code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 1, FALSE, - &nwritten); + code = Curl_conn_cf_send(cf->next, data, socksreq, 1, FALSE, &nwritten); if(code || (nwritten != 1)) { failf(data, "Failed to send GSS-API encryption type."); Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL); @@ -429,7 +427,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, } } else { - code = Curl_conn_cf_send(cf->next, data, (char *)gss_w_token.value, + code = Curl_conn_cf_send(cf->next, data, gss_w_token.value, gss_w_token.length, FALSE, &nwritten); if(code || (gss_w_token.length != nwritten)) { failf(data, "Failed to send GSS-API encryption type."); diff --git a/lib/socks_sspi.c b/lib/socks_sspi.c index 975172576c35..14025371ce37 100644 --- a/lib/socks_sspi.c +++ b/lib/socks_sspi.c @@ -88,7 +88,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, unsigned char socksreq[4]; /* room for GSS-API exchange header only */ const char *service = data->set.str[STRING_PROXY_SERVICE_NAME] ? data->set.str[STRING_PROXY_SERVICE_NAME] : "rcmd"; - char *etbuf; + uint8_t *etbuf; size_t etbuf_size; /* GSS-API request looks like @@ -201,8 +201,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = htons((unsigned short)sspi_send_token.cbBuffer); memcpy(socksreq + 2, &us_length, sizeof(short)); - code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 4, FALSE, - &written); + code = Curl_conn_cf_send(cf->next, data, socksreq, 4, FALSE, &written); if(code || (written != 4)) { failf(data, "Failed to send SSPI authentication request."); result = CURLE_COULDNT_CONNECT; @@ -210,7 +209,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, } code = Curl_conn_cf_send(cf->next, data, - (char *)sspi_send_token.pvBuffer, + sspi_send_token.pvBuffer, sspi_send_token.cbBuffer, FALSE, &written); if(code || (sspi_send_token.cbBuffer != written)) { failf(data, "Failed to send SSPI authentication token."); @@ -433,8 +432,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, memcpy(socksreq + 2, &us_length, sizeof(short)); } - code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 4, FALSE, - &written); + code = Curl_conn_cf_send(cf->next, data, socksreq, 4, FALSE, &written); if(code || (written != 4)) { failf(data, "Failed to send SSPI encryption request."); result = CURLE_COULDNT_CONNECT; @@ -443,8 +441,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, if(data->set.socks5_gssapi_nec) { memcpy(socksreq, &gss_enc, 1); - code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 1, FALSE, - &written); + code = Curl_conn_cf_send(cf->next, data, socksreq, 1, FALSE, &written); if(code || (written != 1)) { failf(data, "Failed to send SSPI encryption type."); result = CURLE_COULDNT_CONNECT; diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index 22ea0e3ef493..86f7428048e1 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -1524,7 +1524,7 @@ cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, static CURLcode h3_stream_open(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, + const uint8_t *buf, size_t len, size_t *pnwritten) { struct cf_ngtcp2_ctx *ctx = cf->ctx; @@ -1552,7 +1552,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, goto out; } - result = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL, + result = Curl_h1_req_parse_read(&stream->h1, (const char *)buf, len, NULL, !data->state.http_ignorecustom ? data->set.str[STRING_CUSTOMREQUEST] : NULL, 0, pnwritten); @@ -1656,7 +1656,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, } static CURLcode cf_ngtcp2_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_ngtcp2_ctx *ctx = cf->ctx; diff --git a/lib/vquic/curl_osslq.c b/lib/vquic/curl_osslq.c index 376705e51667..d6672ce13252 100644 --- a/lib/vquic/curl_osslq.c +++ b/lib/vquic/curl_osslq.c @@ -1877,7 +1877,7 @@ static CURLcode cf_osslq_connect(struct Curl_cfilter *cf, static CURLcode h3_stream_open(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, + const uint8_t *buf, size_t len, size_t *pnwritten) { struct cf_osslq_ctx *ctx = cf->ctx; @@ -1903,7 +1903,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, goto out; } - result = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL, + result = Curl_h1_req_parse_read(&stream->h1, (const char *)buf, len, NULL, !data->state.http_ignorecustom ? data->set.str[STRING_CUSTOMREQUEST] : NULL, 0, pnwritten); @@ -2005,7 +2005,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, } static CURLcode cf_osslq_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_osslq_ctx *ctx = cf->ctx; diff --git a/lib/vquic/curl_quiche.c b/lib/vquic/curl_quiche.c index 927492979013..f8fbadeebb1f 100644 --- a/lib/vquic/curl_quiche.c +++ b/lib/vquic/curl_quiche.c @@ -911,7 +911,7 @@ static CURLcode cf_quiche_recv(struct Curl_cfilter *cf, struct Curl_easy *data, static CURLcode cf_quiche_send_body(struct Curl_cfilter *cf, struct Curl_easy *data, struct h3_stream_ctx *stream, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_quiche_ctx *ctx = cf->ctx; @@ -956,7 +956,7 @@ static CURLcode cf_quiche_send_body(struct Curl_cfilter *cf, static CURLcode h3_open_stream(struct Curl_cfilter *cf, struct Curl_easy *data, - const char *buf, size_t blen, bool eos, + const uint8_t *buf, size_t blen, bool eos, size_t *pnwritten) { struct cf_quiche_ctx *ctx = cf->ctx; @@ -980,7 +980,7 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, DEBUGASSERT(stream); - result = Curl_h1_req_parse_read(&stream->h1, buf, blen, NULL, + result = Curl_h1_req_parse_read(&stream->h1, (const char *)buf, blen, NULL, !data->state.http_ignorecustom ? data->set.str[STRING_CUSTOMREQUEST] : NULL, 0, pnwritten); @@ -1076,7 +1076,7 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, } static CURLcode cf_quiche_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_quiche_ctx *ctx = cf->ctx; diff --git a/lib/vtls/mbedtls.c b/lib/vtls/mbedtls.c index 9a307499595a..2ea3670c1bf2 100644 --- a/lib/vtls/mbedtls.c +++ b/lib/vtls/mbedtls.c @@ -187,8 +187,7 @@ static int mbedtls_bio_cf_write(void *bio, if(!data) return 0; - result = Curl_conn_cf_send(cf->next, data, (const char *)buf, blen, FALSE, - &nwritten); + result = Curl_conn_cf_send(cf->next, data, buf, blen, FALSE, &nwritten); CURL_TRC_CF(data, cf, "mbedtls_bio_cf_out_write(len=%zu) -> %d, %zu", blen, result, nwritten); if(CURLE_AGAIN == result) diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index 7ff5698e7c30..d8f99b21c371 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -597,7 +597,8 @@ static int ossl_bio_cf_out_write(BIO *bio, const char *buf, int blen) if(blen < 0) return 0; - result = Curl_conn_cf_send(cf->next, data, buf, (size_t)blen, FALSE, + result = Curl_conn_cf_send(cf->next, data, + (const uint8_t *)buf, (size_t)blen, FALSE, &nwritten); CURL_TRC_CF(data, cf, "ossl_bio_cf_out_write(len=%d) -> %d, %zu", blen, result, nwritten); diff --git a/lib/vtls/rustls.c b/lib/vtls/rustls.c index 3b5bea2c6fe7..cc19a328eda1 100644 --- a/lib/vtls/rustls.c +++ b/lib/vtls/rustls.c @@ -133,7 +133,7 @@ write_cb(void *userdata, const uint8_t *buf, uintptr_t len, uintptr_t *out_n) size_t nwritten; result = Curl_conn_cf_send(io_ctx->cf->next, io_ctx->data, - (const char *)buf, len, FALSE, &nwritten); + buf, len, FALSE, &nwritten); if(result) { nwritten = 0; if(CURLE_AGAIN == result) diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c index f7e831f002e5..e5fbe40a8c1a 100644 --- a/lib/vtls/schannel.c +++ b/lib/vtls/schannel.c @@ -1074,7 +1074,8 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) /* send initial handshake data which is now stored in output buffer */ result = Curl_conn_cf_send(cf->next, data, - outbuf.pvBuffer, outbuf.cbBuffer, FALSE, + (const uint8_t *)outbuf.pvBuffer, + outbuf.cbBuffer, FALSE, &written); Curl_pSecFn->FreeContextBuffer(outbuf.pvBuffer); if(result || (outbuf.cbBuffer != written)) { @@ -1307,7 +1308,8 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) /* send handshake token to server */ result = Curl_conn_cf_send(cf->next, data, - outbuf[i].pvBuffer, outbuf[i].cbBuffer, + (const uint8_t *)outbuf[i].pvBuffer, + outbuf[i].cbBuffer, FALSE, &written); if(result || (outbuf[i].cbBuffer != written)) { failf(data, "schannel: failed to send next handshake data: " @@ -2004,7 +2006,8 @@ schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, /* socket is writable */ result = Curl_conn_cf_send(cf->next, data, - ptr + *pnwritten, len - *pnwritten, + (const uint8_t *)ptr + *pnwritten, + len - *pnwritten, FALSE, &this_write); if(result == CURLE_AGAIN) continue; @@ -2450,7 +2453,8 @@ static CURLcode schannel_shutdown(struct Curl_cfilter *cf, size_t written; result = Curl_conn_cf_send(cf->next, data, - outbuf.pvBuffer, outbuf.cbBuffer, + (const uint8_t *)outbuf.pvBuffer, + outbuf.cbBuffer, FALSE, &written); Curl_pSecFn->FreeContextBuffer(outbuf.pvBuffer); if(!result) { diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c index 9c76ca7ed32c..3b242fd485d2 100644 --- a/lib/vtls/vtls.c +++ b/lib/vtls/vtls.c @@ -1477,7 +1477,7 @@ static bool ssl_cf_data_pending(struct Curl_cfilter *cf, static CURLcode ssl_cf_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t blen, + const uint8_t *buf, size_t blen, bool eos, size_t *pnwritten) { struct ssl_connect_data *connssl = cf->ctx; @@ -1509,7 +1509,7 @@ static CURLcode ssl_cf_send(struct Curl_cfilter *cf, } else { *pnwritten = connssl->earlydata_skip; - buf = ((const char *)buf) + connssl->earlydata_skip; + buf = buf + connssl->earlydata_skip; blen -= connssl->earlydata_skip; connssl->earlydata_skip = 0; } diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c index e622f909e50b..2ad033f98899 100644 --- a/lib/vtls/wolfssl.c +++ b/lib/vtls/wolfssl.c @@ -334,7 +334,8 @@ static int wssl_bio_cf_out_write(WOLFSSL_BIO *bio, skiplen = (ssize_t)(blen - wssl->io_send_blocked_len); blen = wssl->io_send_blocked_len; } - result = Curl_conn_cf_send(cf->next, data, buf, blen, FALSE, &nwritten); + result = Curl_conn_cf_send(cf->next, data, + (const uint8_t *)buf, blen, FALSE, &nwritten); wssl->io_result = result; CURL_TRC_CF(data, cf, "bio_write(len=%d) -> %d, %zu", blen, result, nwritten); From c1deea4c58f385b172e31a75157931acf278dd74 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Nov 2025 12:17:27 +0100 Subject: [PATCH 091/140] GHA/http3-linux: add H3 valgrind tests Ref: #19714 Ref: #19717 Closes #19719 --- .github/workflows/http3-linux.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/http3-linux.yml b/.github/workflows/http3-linux.yml index 353c36814219..a9117e146ef9 100644 --- a/.github/workflows/http3-linux.yml +++ b/.github/workflows/http3-linux.yml @@ -479,7 +479,7 @@ jobs: sudo rm -f /var/lib/man-db/auto-update sudo apt-get -o Dpkg::Use-Pty=0 install \ libtool autoconf automake pkgconf \ - libpsl-dev libbrotli-dev libzstd-dev zlib1g-dev libidn2-0-dev libldap-dev libuv1-dev \ + libpsl-dev libbrotli-dev libzstd-dev zlib1g-dev libidn2-0-dev libldap-dev libuv1-dev valgrind \ ${INSTALL_PACKAGES} \ ${MATRIX_INSTALL_PACKAGES} echo 'CC=gcc-12' >> "$GITHUB_ENV" @@ -701,6 +701,18 @@ jobs: - name: 'run tests' if: ${{ !contains(matrix.build.install_steps, 'skipall') && !contains(matrix.build.install_steps, 'skiprun') }} run: | + export TFLAGS='-n' + source ~/venv/bin/activate + if [ "${MATRIX_BUILD}" = 'cmake' ]; then + cmake --build bld --verbose --target test-ci + else + make -C bld V=1 test-ci + fi + + - name: 'run tests (valgrind)' + if: ${{ !contains(matrix.build.install_steps, 'skipall') && !contains(matrix.build.install_steps, 'skiprun') }} + run: | + export TFLAGS='-j6 HTTP/3' source ~/venv/bin/activate if [ "${MATRIX_BUILD}" = 'cmake' ]; then cmake --build bld --verbose --target test-ci @@ -714,7 +726,7 @@ jobs: [ -d ~/venv ] || python3 -m venv ~/venv ~/venv/bin/pip --disable-pip-version-check --no-input --no-cache-dir install --progress-bar off --prefer-binary -r tests/http/requirements.txt - - name: 'run pytest event based' + - name: 'run pytest (event based)' if: ${{ !contains(matrix.build.install_steps, 'skipall') && !contains(matrix.build.install_steps, 'skiprun') }} env: CURL_TEST_EVENT: 1 From 53775baa1d6ba0301a6c041a60350d0914065b7f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 27 Nov 2025 15:55:47 +0100 Subject: [PATCH 092/140] tests: allow 2500-2503 to use ~2MB malloc On Linux using UDP_GRO, curl might allocate a (single) 1.5MB buffer for maximum performance. Fixes #19716 Closes #19731 --- tests/data/test2500 | 4 ++++ tests/data/test2501 | 3 +++ tests/data/test2502 | 3 +++ tests/data/test2503 | 3 +++ 4 files changed, 13 insertions(+) diff --git a/tests/data/test2500 b/tests/data/test2500 index f92cabfd32b6..bc6790c2c1f1 100644 --- a/tests/data/test2500 +++ b/tests/data/test2500 @@ -73,5 +73,9 @@ via: 1.1 nghttpx s/^server: nghttpx.*\r?\n// + +Allocations: 150 +Maximum allocated: 1800000 + diff --git a/tests/data/test2501 b/tests/data/test2501 index 99167ec48e86..01505f4ce27f 100644 --- a/tests/data/test2501 +++ b/tests/data/test2501 @@ -65,5 +65,8 @@ Via: 3 nghttpx moo + +Maximum allocated: 1900000 + diff --git a/tests/data/test2502 b/tests/data/test2502 index 627cfdccad8e..ac6cd3cf588c 100644 --- a/tests/data/test2502 +++ b/tests/data/test2502 @@ -101,5 +101,8 @@ Via: 3 nghttpx $_ = '' if(($_ !~ /left intact/) && ($_ !~ /Closing connection/)) + +Maximum allocated: 1800000 + diff --git a/tests/data/test2503 b/tests/data/test2503 index 722d0ceb7adf..9e8d4c3d490c 100644 --- a/tests/data/test2503 +++ b/tests/data/test2503 @@ -65,5 +65,8 @@ via: 1.1 nghttpx "via":["1.1 nghttpx"] } + +Maximum allocated: 1800000 + From aa9342058fbf0ce1d387b7c590e674e6acabbda8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 27 Nov 2025 16:14:37 +0100 Subject: [PATCH 093/140] RELEASE-NOTES: synced --- RELEASE-NOTES | 75 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 10 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 217f8c750446..2dbac34d0f65 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -4,7 +4,7 @@ curl and libcurl 8.18.0 Command line options: 273 curl_easy_setopt() options: 308 Public functions in libcurl: 100 - Contributors: 3549 + Contributors: 3553 This release includes the following changes: @@ -19,8 +19,10 @@ This release includes the following bugfixes: o _PROGRESS.md: add the E unit, mention kibibyte [24] o AmigaOS: increase minimum stack size for tool_main [137] o apple-sectrust: always ask when `native_ca_store` is in use [162] + o asyn-ares: handle Curl_dnscache_mk_entry() OOM error [199] o asyn-ares: remove hostname free on OOM [122] o asyn-thrdd: release rrname if ares_init_options fails [41] + o autotools: add nettle library detection via pkg-config (for GnuTLS) [178] o autotools: drop autoconf <2.59 compatibility code (zz60-xc-ovr) [70] o badwords: fix issues found in scripts and other files [142] o badwords: fix issues found in tests [156] @@ -31,6 +33,7 @@ This release includes the following bugfixes: o cf-https-connect: allocate ctx at first in cf_hc_create() [79] o cf-socket: limit use of `TCP_KEEP*` to Windows 10.0.16299+ at runtime [157] o cf-socket: trace ignored errors [97] + o cfilters: make conn_forget_socket a private libssh function [109] o checksrc.pl: detect assign followed by more than one space [26] o cmake: adjust defaults for target platforms not supporting shared libs [35] o cmake: disable `CURL_CA_PATH` auto-detection if `USE_APPLE_SECTRUST=ON` [16] @@ -39,6 +42,7 @@ This release includes the following bugfixes: o config2setopts: bail out if curl_url_get() returns OOM [102] o config2setopts: exit if curl_url_set() fails on OOM [105] o conncache: silence `-Wnull-dereference` on gcc 14 RISC-V 64 [17] + o conncontrol: reuse handling [170] o connect: reshuffle Curl_timeleft_ms to avoid 'redundant condition' [100] o cookie: propagate errors better, cleanup the internal API [118] o cookie: return error on OOM [131] @@ -53,15 +57,21 @@ This release includes the following bugfixes: o CURLINFO_TLS_SSL_PTR.md: remove CURLINFO_TLS_SESSION text [49] o CURLOPT_READFUNCTION.md: clarify the size of the buffer [47] o CURLOPT_SSH_KEYFUNCTION.md: fix minor indent mistake in example + o curlx/fopen: replace open CRT functions their with `_s` counterparts (Windows) [204] o curlx/strerr: use `strerror_s()` on Windows [75] o curlx: replace `mbstowcs`/`wcstombs` with `_s` counterparts (Windows) [143] + o curlx: replace `sprintf` with `snprintf` [194] o digest_sspi: fix a memory leak on error path [149] o digest_sspi: properly free sspi identity [12] o DISTROS.md: add OpenBSD [126] + o doc: some returned in-memory data may not be altered [196] o docs: fix checksrc `EQUALSPACE` warnings [21] o docs: mention umask need when curl creates files [56] + o docs: spell it Rustls with a capital R [181] o examples/crawler: fix variable [92] + o examples/multi-uv: fix invalid req->data access [177] o examples/multithread: fix race condition [101] + o examples: fix minor typo [203] o examples: make functions/data static where missing [139] o examples: tidy-up headers and includes [138] o file: do not pass invalid mode flags to `open()` on upload (Windows) [83] @@ -73,9 +83,12 @@ This release includes the following bugfixes: o gtls: skip session resumption when verifystatus is set o h2/h3: handle methods with spaces [146] o hostip: don't store negative lookup on OOM [61] + o hostip: make more functions return CURLcode [202] + o hostip: only store negative response for CURLE_COULDNT_RESOLVE_HOST [183] o hsts: propagate and error out correctly on OOM [130] o http: avoid two strdup()s and do minor simplifications [144] o http: error on OOM when creating range header [59] + o http: fix OOM exit in Curl_http_follow [179] o http: replace atoi use in Curl_http_follow with curlx_str_number [65] o http: the :authority header should never contain user+password [147] o INSTALL-CMAKE.md: document static option defaults more [37] @@ -86,6 +99,7 @@ This release includes the following bugfixes: o lib: fix gssapi.h include on IBMi [55] o lib: refactor the type of funcs which have useless return and checks [1] o lib: replace `_tcsncpy`/`wcsncpy`/`wcscpy` with `_s` counterparts (Windows) [164] + o lib: timer stats improvements [190] o libssh2: add paths to error messages for quote commands [114] o libssh2: cleanup ssh_force_knownhost_key_type [64] o libssh2: replace atoi() in ssh_force_knownhost_key_type [63] @@ -93,11 +107,15 @@ This release includes the following bugfixes: o libtests: replace `atoi()` with `curlx_str_number()` [120] o limit-rate: add example using --limit-rate and --max-time together [89] o m4/sectrust: fix test(1) operator [4] + o manage: expand the 'libcurl support required' message [208] o mbedtls: fix potential use of uninitialized `nread` [8] o mk-ca-bundle.pl: default to SHA256 fingerprints with `-t` option [73] o mk-ca-bundle.pl: use `open()` with argument list to replace backticks [71] o mqtt: reject overly big messages [39] o multi: make max_total_* members size_t [158] + o multi: simplify admin handle processing [189] + o ngtcp2+openssl: fix leak of session [172] + o ngtcp2: remove the unused Curl_conn_is_ngtcp2 function [85] o noproxy: replace atoi with curlx_str_number [67] o openssl: exit properly on OOM when getting certchain [133] o openssl: fix a potential memory leak of bio_out [150] @@ -111,7 +129,9 @@ This release includes the following bugfixes: o progress: show fewer digits [78] o projects/README.md: Markdown fixes [148] o pytest fixes and improvements [159] + o pytest: disable two H3 earlydata tests for all platforms (was: macOS) [116] o pytest: skip H2 tests if feature missing from curl [46] + o ratelimit: redesign [209] o rtmp: fix double-free on URL parse errors [27] o rtmp: precaution for a potential integer truncation [54] o runtests: detect bad libssh differently for test 1459 [11] @@ -126,9 +146,11 @@ This release includes the following bugfixes: o setopt: disable CURLOPT_HAPROXY_CLIENT_IP on NULL [30] o setopt: when setting bad protocols, don't store them [9] o sftp: fix range downloads in both SSH backends [82] + o slist: constify Curl_slist_append_nodup() string argument [195] o smb: fix a size check to be overflow safe [161] o socks_sspi: use free() not FreeContextBuffer() [93] o speedcheck: do not trigger low speed cancel on transfers with CURL_READFUNC_PAUSE [113] + o speedlimit: also reset on send unpausing [197] o telnet: replace atoi for BINARY handling with curlx_str_number [66] o TEST-SUITE.md: correct the man page's path [136] o test07_22: fix flakiness [95] @@ -138,11 +160,14 @@ This release includes the following bugfixes: o tests/data: support using native newlines on disk, drop `.gitattributes` [91] o tests/server: do not fall back to original data file in `test2fopen()` [32] o tests/server: replace `atoi()` and `atol()` with `curlx_str_number()` [110] + o tests: allow 2500-2503 to use ~2MB malloc [31] o tftp: release filename if conn_get_remote_addr fails [42] o tftpd: fix/tidy up `open()` mode flags [57] o tidy-up: move `CURL_UNCONST()` out from macro `curl_unicodefree()` [121] o tool: consider (some) curl_easy_setopt errors fatal [7] + o tool: log when loading .curlrc in verbose mode [191] o tool_cfgable: free ssl-sessions at exit [123] + o tool_doswin: clear pointer when thread takes ownership [198] o tool_getparam: verify that a file exists for some options [134] o tool_help: add checks to avoid unsigned wrap around [14] o tool_ipfs: check return codes better [20] @@ -157,9 +182,11 @@ This release includes the following bugfixes: o tool_writeout: bail out proper on OOM [104] o url: if OOM in parse_proxy() return error [132] o urlapi: fix mem-leaks in curl_url_get error paths [22] + o urlapi: handle OOM properly when setting URL [180] o verify-release: update to avoid shellcheck warning SC2034 [88] o vquic-tls/gnutls: call Curl_gtls_verifyserver unconditionally [96] o vquic: do not pass invalid mode flags to `open()` (Windows) [58] + o vquic: do_sendmsg full init [171] o vtls: fix CURLOPT_CAPATH use [51] o vtls: handle possible malicious certs_num from peer [53] o vtls: pinned key check [98] @@ -190,15 +217,16 @@ Planned upcoming removals include: This release would not have looked like this without help, code, reports and advice from friends like these: - Aleksandr Sergeev, Andrew Kirillov, boingball, Brad King, bttrfl on github, - Christian Schmitz, Dan Fandrich, Daniel McCarney, Daniel Stenberg, - Fd929c2CE5fA on github, ffath-vo on github, Gisle Vanem, Jiyong Yang, - Juliusz Sosinowicz, Leonardo Taccari, letshack9707 on hackerone, - Marc Aldorasi, Marcel Raad, nait-furry, ncaklovic on github, Nick Korepanov, - Omdahake on github, Patrick Monnerat, pelioro on hackerone, Ray Satiro, - renovate[bot], Samuel Henrique, Stanislav Fort, Stefan Eissing, - Thomas Klausner, Viktor Szakats, Wesley Moore, Xiaoke Wang - (33 contributors) + Aleksandr Sergeev, Aleksei Bavshin, Andrew Kirillov, BANADDA, boingball, + Brad King, bttrfl on github, Christian Schmitz, Dan Fandrich, + Daniel McCarney, Daniel Stenberg, Fd929c2CE5fA on github, ffath-vo on github, + Gisle Vanem, Jiyong Yang, Juliusz Sosinowicz, Leonardo Taccari, + letshack9707 on hackerone, Marc Aldorasi, Marcel Raad, nait-furry, + ncaklovic on github, Nick Korepanov, Omdahake on github, Patrick Monnerat, + pelioro on hackerone, Ray Satiro, renovate[bot], Samuel Henrique, + st751228051 on github, Stanislav Fort, Stefan Eissing, Sunny, + Thomas Klausner, Viktor Szakats, Wesley Moore, Xiaoke Wang, Yedaya Katsman + (38 contributors) References to bug reports and discussions on issues: @@ -232,6 +260,7 @@ References to bug reports and discussions on issues: [28] = https://curl.se/bug/?i=19354 [29] = https://curl.se/bug/?i=19430 [30] = https://curl.se/bug/?i=19434 + [31] = https://curl.se/bug/?i=19716 [32] = https://curl.se/bug/?i=19429 [33] = https://curl.se/bug/?i=19427 [35] = https://curl.se/bug/?i=19420 @@ -283,6 +312,7 @@ References to bug reports and discussions on issues: [82] = https://curl.se/bug/?i=19460 [83] = https://curl.se/bug/?i=19647 [84] = https://curl.se/bug/?i=19645 + [85] = https://curl.se/bug/?i=19725 [86] = https://curl.se/bug/?i=19451 [87] = https://curl.se/bug/?i=19450 [88] = https://curl.se/bug/?i=19449 @@ -306,11 +336,13 @@ References to bug reports and discussions on issues: [106] = https://curl.se/bug/?i=19144 [107] = https://curl.se/bug/?i=19512 [108] = https://curl.se/bug/?i=19513 + [109] = https://curl.se/bug/?i=19727 [110] = https://curl.se/bug/?i=19510 [111] = https://curl.se/bug/?i=19509 [112] = https://curl.se/bug/?i=19495 [113] = https://curl.se/bug/?i=19653 [114] = https://curl.se/bug/?i=19605 + [116] = https://curl.se/bug/?i=19724 [117] = https://curl.se/bug/?i=19644 [118] = https://curl.se/bug/?i=19493 [119] = https://curl.se/bug/?i=19483 @@ -358,3 +390,26 @@ References to bug reports and discussions on issues: [166] = https://curl.se/bug/?i=19615 [167] = https://curl.se/bug/?i=19609 [168] = https://curl.se/bug/?i=19612 + [170] = https://curl.se/bug/?i=19333 + [171] = https://curl.se/bug/?i=19714 + [172] = https://curl.se/bug/?i=19717 + [177] = https://curl.se/bug/?i=19462 + [178] = https://curl.se/bug/?i=19703 + [179] = https://curl.se/bug/?i=19705 + [180] = https://curl.se/bug/?i=19704 + [181] = https://curl.se/bug/?i=19702 + [183] = https://curl.se/bug/?i=19701 + [189] = https://curl.se/bug/?i=19604 + [190] = https://curl.se/bug/?i=19269 + [191] = https://curl.se/bug/?i=19663 + [194] = https://curl.se/bug/?i=19681 + [195] = https://curl.se/bug/?i=19692 + [196] = https://curl.se/bug/?i=19692 + [197] = https://curl.se/bug/?i=19687 + [198] = https://curl.se/bug/?i=19689 + [199] = https://curl.se/bug/?i=19688 + [202] = https://curl.se/bug/?i=19669 + [203] = https://curl.se/bug/?i=19683 + [204] = https://curl.se/bug/?i=19643 + [208] = https://curl.se/bug/?i=19665 + [209] = https://curl.se/bug/?i=19384 From 5c22bd5384e732755fa00d2fc7fef2ce19e3418b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 27 Nov 2025 17:42:55 +0100 Subject: [PATCH 094/140] mbedtls_threadlock: avoid calloc, use array Closes #19732 --- lib/vtls/mbedtls_threadlock.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/vtls/mbedtls_threadlock.c b/lib/vtls/mbedtls_threadlock.c index ed70308b739d..82590929cd78 100644 --- a/lib/vtls/mbedtls_threadlock.c +++ b/lib/vtls/mbedtls_threadlock.c @@ -44,17 +44,13 @@ /* number of thread locks */ #define NUMT 2 -/* This array will store all of the mutexes available to Mbedtls. */ -static MBEDTLS_MUTEX_T *mutex_buf = NULL; +/* This array stores the mutexes available to Mbedtls */ +static MBEDTLS_MUTEX_T mutex_buf[NUMT]; int Curl_mbedtlsthreadlock_thread_setup(void) { int i; - mutex_buf = calloc(1, NUMT * sizeof(MBEDTLS_MUTEX_T)); - if(!mutex_buf) - return 0; /* error, no number of threads defined */ - for(i = 0; i < NUMT; i++) { #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) if(pthread_mutex_init(&mutex_buf[i], NULL)) @@ -73,9 +69,6 @@ int Curl_mbedtlsthreadlock_thread_cleanup(void) { int i; - if(!mutex_buf) - return 0; /* error, no threads locks defined */ - for(i = 0; i < NUMT; i++) { #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) if(pthread_mutex_destroy(&mutex_buf[i])) @@ -85,8 +78,6 @@ int Curl_mbedtlsthreadlock_thread_cleanup(void) return 0; /* CloseHandle failed */ #endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */ } - free(mutex_buf); - mutex_buf = NULL; return 1; /* OK */ } From 986e6d4eae316f408f188b3079b1af62dce35850 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Nov 2025 18:32:35 +0100 Subject: [PATCH 095/140] CODE_STYLE.md: sync banned function list with checksrc.pl Also alpha sort the list in checksrc.pl. Closes #19733 --- docs/internals/CODE_STYLE.md | 36 +++++++++++++ scripts/checksrc.pl | 102 +++++++++++++++++------------------ 2 files changed, 87 insertions(+), 51 deletions(-) diff --git a/docs/internals/CODE_STYLE.md b/docs/internals/CODE_STYLE.md index 0d072c04c306..7d37df4805ec 100644 --- a/docs/internals/CODE_STYLE.md +++ b/docs/internals/CODE_STYLE.md @@ -334,14 +334,31 @@ This is the full list of functions generally banned. _access _mbscat _mbsncat + _open _tcscat _tcsdup _tcsncat + _tcsncpy _waccess _wcscat _wcsdup _wcsncat + _wfopen + _wfreopen + _wopen + accept + accept4 access + aprintf + atoi + atol + fclose + fdopen + fopen + fprintf + freeaddrinfo + freopen + getaddrinfo gets gmtime LoadLibrary @@ -351,9 +368,19 @@ This is the full list of functions generally banned. LoadLibraryExW LoadLibraryW localtime + mbstowcs + msnprintf + mvsnprintf + open + printf + recv + send snprintf + socket + socketpair sprintf sscanf + stat strcat strerror strncat @@ -362,6 +389,15 @@ This is the full list of functions generally banned. strtok_r strtol strtoul + vaprintf + vfprintf + vprintf vsnprintf vsprintf + wcscpy wcsdup + wcsncpy + wcstombs + WSASocket + WSASocketA + WSASocketW diff --git a/scripts/checksrc.pl b/scripts/checksrc.pl index d38ffecdb9b1..49290ff137a5 100755 --- a/scripts/checksrc.pl +++ b/scripts/checksrc.pl @@ -48,76 +48,76 @@ my @ignore_line; my %banfunc = ( - "gmtime" => 1, - "localtime" => 1, - "gets" => 1, - "strtok" => 1, - "sprintf" => 1, - "snprintf" => 1, - "vsprintf" => 1, - "vsnprintf" => 1, + "_access" => 1, + "_mbscat" => 1, + "_mbsncat" => 1, + "_open" => 1, + "_tcscat" => 1, + "_tcsdup" => 1, + "_tcsncat" => 1, + "_tcsncpy" => 1, + "_waccess" => 1, + "_wcscat" => 1, + "_wcsdup" => 1, + "_wcsncat" => 1, + "_wfopen" => 1, + "_wfreopen" => 1, + "_wopen" => 1, + "accept" => 1, + "accept4" => 1, + "access" => 1, "aprintf" => 1, + "atoi" => 1, + "atol" => 1, + "fclose" => 1, + "fdopen" => 1, + "fopen" => 1, "fprintf" => 1, + "freeaddrinfo" => 1, + "freopen" => 1, + "getaddrinfo" => 1, + "gets" => 1, + "gmtime" => 1, + "LoadLibrary" => 1, + "LoadLibraryA" => 1, + "LoadLibraryEx" => 1, + "LoadLibraryExA" => 1, + "LoadLibraryExW" => 1, + "LoadLibraryW" => 1, + "localtime" => 1, + "mbstowcs" => 1, "msnprintf" => 1, "mvsnprintf" => 1, + "open" => 1, "printf" => 1, - "vaprintf" => 1, - "vfprintf" => 1, - "vprintf" => 1, + "recv" => 1, + "send" => 1, + "snprintf" => 1, + "socket" => 1, + "socketpair" => 1, + "sprintf" => 1, "sscanf" => 1, + "stat" => 1, "strcat" => 1, "strerror" => 1, "strncat" => 1, "strncpy" => 1, "strtok_r" => 1, + "strtok" => 1, "strtol" => 1, "strtoul" => 1, - "atoi" => 1, - "atol" => 1, - "_mbscat" => 1, - "_mbsncat" => 1, - "_tcscat" => 1, - "_tcsdup" => 1, - "_tcsncpy" => 1, - "_tcsncat" => 1, - "_wcscat" => 1, - "_wcsncat" => 1, - "_wcsdup" => 1, - "wcsdup" => 1, + "vaprintf" => 1, + "vfprintf" => 1, + "vprintf" => 1, + "vsnprintf" => 1, + "vsprintf" => 1, "wcscpy" => 1, + "wcsdup" => 1, "wcsncpy" => 1, - "mbstowcs" => 1, "wcstombs" => 1, - "LoadLibrary" => 1, - "LoadLibraryA" => 1, - "LoadLibraryW" => 1, - "LoadLibraryEx" => 1, - "LoadLibraryExA" => 1, - "LoadLibraryExW" => 1, "WSASocket" => 1, "WSASocketA" => 1, "WSASocketW" => 1, - "_waccess" => 1, - "_access" => 1, - "access" => 1, - "accept" => 1, - "accept4" => 1, - "freeaddrinfo" => 1, - "getaddrinfo" => 1, - "recv" => 1, - "send" => 1, - "socket" => 1, - "socketpair" => 1, - "fclose" => 1, - "fdopen" => 1, - "fopen" => 1, - "freopen" => 1, - "open" => 1, - "_open" => 1, - "_wfopen" => 1, - "_wfreopen" => 1, - "_wopen" => 1, - "stat" => 1, ); my %warnings_extended = ( From 63eb0627b1c6cb2fa267585b4c21f839867e19d2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Nov 2025 20:08:43 +0100 Subject: [PATCH 096/140] curl_setup.h: drop superfluous parenthesis from `Curl_safefree` macro Cherry-picked from #19626 Closes #19734 --- lib/curl_setup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 48b9ea9ea9f9..6236a7153923 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -941,7 +941,7 @@ extern curl_calloc_callback Curl_ccalloc; * This macro also assigns NULL to given pointer when free'd. */ #define Curl_safefree(ptr) \ - do { free((ptr)); (ptr) = NULL;} while(0) + do { free(ptr); (ptr) = NULL;} while(0) #include /* for CURL_EXTERN, mprintf.h */ From 6dc82c80468941a3f08646454bceccd839e46e00 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 20 Nov 2025 03:57:45 +0100 Subject: [PATCH 097/140] memdebug: replace `(fwrite)` with `fwrite` Cherry-picked from #19626 Closes #19735 --- lib/memdebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/memdebug.c b/lib/memdebug.c index 6ec292654f80..1121dc26f550 100644 --- a/lib/memdebug.c +++ b/lib/memdebug.c @@ -526,7 +526,7 @@ void curl_dbg_log(const char *format, ...) nchars = (int)sizeof(buf) - 1; if(nchars > 0) - (fwrite)(buf, 1, (size_t)nchars, curl_dbg_logfile); + fwrite(buf, 1, (size_t)nchars, curl_dbg_logfile); } #endif /* CURLDEBUG */ From 376c7bddc48974d30c9bcc82aa183fe92478d67f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Nov 2025 20:48:43 +0100 Subject: [PATCH 098/140] unit1653: replace local macro with `Curl_safefree()` Cherry-picked from #19626 Closes #19736 --- tests/unit/unit1653.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/unit/unit1653.c b/tests/unit/unit1653.c index 714b52a8e60f..8f6a5a51cc55 100644 --- a/tests/unit/unit1653.c +++ b/tests/unit/unit1653.c @@ -27,8 +27,6 @@ #include "curl/urlapi.h" #include "urlapi-int.h" -#define free_and_clear(x) free(x); x = NULL - static CURLUcode parse_port(CURLU *url, char *h, bool has_scheme) { struct dynbuf host; @@ -62,7 +60,7 @@ static CURLcode test_unit1653(const char *arg) fail_unless(ret == CURLUE_OK, "parse_port returned error"); ret = curl_url_get(u, CURLUPART_PORT, &portnum, CURLU_NO_DEFAULT_PORT); fail_unless(ret != CURLUE_OK, "curl_url_get portnum returned something"); - free_and_clear(ipv6port); + Curl_safefree(ipv6port); curl_url_cleanup(u); /* Invalid IPv6 */ @@ -74,7 +72,7 @@ static CURLcode test_unit1653(const char *arg) goto fail; ret = parse_port(u, ipv6port, FALSE); fail_unless(ret != CURLUE_OK, "parse_port true on error"); - free_and_clear(ipv6port); + Curl_safefree(ipv6port); curl_url_cleanup(u); u = curl_url(); @@ -90,7 +88,7 @@ static CURLcode test_unit1653(const char *arg) fail_unless(portnum && !strcmp(portnum, "808"), "Check portnumber"); curl_free(portnum); - free_and_clear(ipv6port); + Curl_safefree(ipv6port); curl_url_cleanup(u); /* Valid IPv6 with zone index and port number */ @@ -106,7 +104,7 @@ static CURLcode test_unit1653(const char *arg) fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error"); fail_unless(portnum && !strcmp(portnum, "80"), "Check portnumber"); curl_free(portnum); - free_and_clear(ipv6port); + Curl_safefree(ipv6port); curl_url_cleanup(u); /* Valid IPv6 with zone index without port number */ @@ -118,7 +116,7 @@ static CURLcode test_unit1653(const char *arg) goto fail; ret = parse_port(u, ipv6port, FALSE); fail_unless(ret == CURLUE_OK, "parse_port returned error"); - free_and_clear(ipv6port); + Curl_safefree(ipv6port); curl_url_cleanup(u); /* Valid IPv6 with port number */ @@ -134,7 +132,7 @@ static CURLcode test_unit1653(const char *arg) fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error"); fail_unless(portnum && !strcmp(portnum, "81"), "Check portnumber"); curl_free(portnum); - free_and_clear(ipv6port); + Curl_safefree(ipv6port); curl_url_cleanup(u); /* Valid IPv6 with syntax error in the port number */ @@ -146,7 +144,7 @@ static CURLcode test_unit1653(const char *arg) goto fail; ret = parse_port(u, ipv6port, FALSE); fail_unless(ret != CURLUE_OK, "parse_port true on error"); - free_and_clear(ipv6port); + Curl_safefree(ipv6port); curl_url_cleanup(u); u = curl_url(); @@ -157,7 +155,7 @@ static CURLcode test_unit1653(const char *arg) goto fail; ret = parse_port(u, ipv6port, FALSE); fail_unless(ret != CURLUE_OK, "parse_port true on error"); - free_and_clear(ipv6port); + Curl_safefree(ipv6port); curl_url_cleanup(u); /* Valid IPv6 with no port after the colon, should use default if a scheme @@ -170,7 +168,7 @@ static CURLcode test_unit1653(const char *arg) goto fail; ret = parse_port(u, ipv6port, TRUE); fail_unless(ret == CURLUE_OK, "parse_port returned error"); - free_and_clear(ipv6port); + Curl_safefree(ipv6port); curl_url_cleanup(u); /* Incorrect zone index syntax, but the port extractor does not care */ @@ -186,7 +184,7 @@ static CURLcode test_unit1653(const char *arg) fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error"); fail_unless(portnum && !strcmp(portnum, "180"), "Check portnumber"); curl_free(portnum); - free_and_clear(ipv6port); + Curl_safefree(ipv6port); curl_url_cleanup(u); /* Non percent-encoded zone index */ @@ -198,7 +196,7 @@ static CURLcode test_unit1653(const char *arg) goto fail; ret = parse_port(u, ipv6port, FALSE); fail_unless(ret == CURLUE_OK, "parse_port returned error"); - free_and_clear(ipv6port); + Curl_safefree(ipv6port); curl_url_cleanup(u); /* No scheme and no digits following the colon - not accepted. Because that From c9e50e9e393508c6a28c695abcf62980b3c1b023 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Nov 2025 23:23:18 +0100 Subject: [PATCH 099/140] appveyor: add support for using custom CMake versions To allow more flexibility and not be limited by defaults offered by the runner machines: - Visual Studio 2013: CMake 3.12.2 - Visual Studio 2015, 2017: CMake 3.16.2 Ref: https://www.appveyor.com/docs/windows-images-software/ Start using 3.18.4, 3.19.8, 3.20.6 in older VS jobs to add variations. Time cost is a couple of seconds per job. Ref: #18704 (Discussion) Ref: #16973 Closes #19737 --- appveyor.sh | 17 +++++++++++++++++ appveyor.yml | 3 +++ 2 files changed, 20 insertions(+) diff --git a/appveyor.sh b/appveyor.sh index b20838da427b..56f8cc35277a 100644 --- a/appveyor.sh +++ b/appveyor.sh @@ -42,6 +42,23 @@ elif [ "${APPVEYOR_BUILD_WORKER_IMAGE}" = 'Visual Studio 2019' ]; then fi if [ "${BUILD_SYSTEM}" = 'CMake' ]; then + # Install custom cmake version + if [ -n "${CMAKE_VERSION:-}" ]; then + cmake_ver=$(printf '%02d%02d' \ + "$(echo "$CMAKE_VERSION" | cut -f1 -d.)" \ + "$(echo "$CMAKE_VERSION" | cut -f2 -d.)") + if [ "${cmake_ver}" -ge '0320' ]; then + fn="cmake-${CMAKE_VERSION}-windows-x86_64" + else + fn="cmake-${CMAKE_VERSION}-win64-x64" + fi + curl --disable --fail --silent --show-error --connect-timeout 15 --max-time 60 --retry 3 --retry-connrefused \ + --location "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${fn}.zip" --output bin.zip + 7z x -y bin.zip >/dev/null + rm -f bin.zip + PATH="$PWD/${fn}/bin:$PATH" + fi + # Set env CHKPREFILL to the value '_chkprefill' to compare feature detection # results with and without the pre-fill feature. They have to match. for _chkprefill in '' ${CHKPREFILL:-}; do diff --git a/appveyor.yml b/appveyor.yml index d10f8d39612f..91a425c7faca 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -79,6 +79,7 @@ environment: SHARED: 'ON' - job_name: 'CM VS2013, Debug, x64, Schannel, Shared, Build-only' APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015' + CMAKE_VERSION: '3.18.4' PRJ_GEN: 'Visual Studio 12 2013' TARGET: '-A x64' PRJ_CFG: Debug @@ -87,6 +88,7 @@ environment: TFLAGS: 'skipall' - job_name: 'CM VS2015, Debug, x64, Schannel, Static, Build-only' APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015' + CMAKE_VERSION: '3.19.8' PRJ_GEN: 'Visual Studio 14 2015' TARGET: '-A x64' PRJ_CFG: Debug @@ -94,6 +96,7 @@ environment: TFLAGS: 'skipall' - job_name: 'CM VS2017, Debug, x64, Schannel, Shared, Build-only' APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2017' + CMAKE_VERSION: '3.20.6' PRJ_GEN: 'Visual Studio 15 2017' TARGET: '-A x64' PRJ_CFG: Debug From 5c275f7fef5337c8e743febc238735298315f902 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 28 Nov 2025 02:40:19 +0100 Subject: [PATCH 100/140] GHA/linux-old: stop installing `groff`, it is unused --- .github/workflows/linux-old.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux-old.yml b/.github/workflows/linux-old.yml index 64958f4bd61c..59da60987c96 100644 --- a/.github/workflows/linux-old.yml +++ b/.github/workflows/linux-old.yml @@ -72,7 +72,7 @@ jobs: dpkg -i freexian-archive-keyring_2022.06.08_all.deb echo 'deb http://deb.freexian.com/extended-lts stretch-lts main contrib non-free' | tee /etc/apt/sources.list.d/extended-lts.list apt-get -o Dpkg::Use-Pty=0 update - apt-get -o Dpkg::Use-Pty=0 install -y --no-install-suggests --no-install-recommends cmake make automake autoconf libtool gcc pkg-config libpsl-dev libzstd-dev zlib1g-dev libc-ares-dev libkrb5-dev libldap2-dev librtmp-dev stunnel4 groff + apt-get -o Dpkg::Use-Pty=0 install -y --no-install-suggests --no-install-recommends cmake make automake autoconf libtool gcc pkg-config libpsl-dev libzstd-dev zlib1g-dev libc-ares-dev libkrb5-dev libldap2-dev librtmp-dev stunnel4 # GitHub's actions/checkout needs newer glibc and libstdc++. The latter also depends on # gcc-8-base, but it does not actually seem used in our situation and is not available in # the main repo, so force the install. From e7c2f5bf53838871be4ebd7a9b2521da2a7f9226 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 26 Nov 2025 01:19:06 +0000 Subject: [PATCH 101/140] GHA: update dependency google/boringssl to v0.20251124.0 Closes #19685 --- .github/workflows/http3-linux.yml | 2 +- .github/workflows/linux.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/http3-linux.yml b/.github/workflows/http3-linux.yml index a9117e146ef9..77fd1edc09aa 100644 --- a/.github/workflows/http3-linux.yml +++ b/.github/workflows/http3-linux.yml @@ -45,7 +45,7 @@ env: # renovate: datasource=github-tags depName=awslabs/aws-lc versioning=semver registryUrl=https://github.com AWSLC_VERSION: 1.63.0 # renovate: datasource=github-tags depName=google/boringssl versioning=semver registryUrl=https://github.com - BORINGSSL_VERSION: 0.20251110.0 + BORINGSSL_VERSION: 0.20251124.0 # renovate: datasource=github-tags depName=gnutls/nettle versioning=semver registryUrl=https://github.com NETTLE_VERSION: 3.10.2 # renovate: datasource=github-tags depName=gnutls/gnutls versioning=semver extractVersion=^nettle_?(?.+)_release_.+$ registryUrl=https://github.com diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 0db8ca33b4ec..390cab72923f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -48,7 +48,7 @@ env: # renovate: datasource=github-tags depName=awslabs/aws-lc versioning=semver registryUrl=https://github.com AWSLC_VERSION: 1.63.0 # renovate: datasource=github-tags depName=google/boringssl versioning=semver registryUrl=https://github.com - BORINGSSL_VERSION: 0.20251110.0 + BORINGSSL_VERSION: 0.20251124.0 # handled in renovate.json OPENSSL_VERSION: 3.6.0 # renovate: datasource=github-tags depName=rustls/rustls-ffi versioning=semver registryUrl=https://github.com From 9d059e27d1dd7d7baa863a6f7673488c965b3756 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 27 Nov 2025 01:01:01 +0000 Subject: [PATCH 102/140] GHA: update dependency pyspelling to v2.12.1 Closes #19712 --- .github/scripts/requirements-docs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/requirements-docs.txt b/.github/scripts/requirements-docs.txt index fa26c105d095..6850461de7bc 100644 --- a/.github/scripts/requirements-docs.txt +++ b/.github/scripts/requirements-docs.txt @@ -2,4 +2,4 @@ # # SPDX-License-Identifier: curl -pyspelling==2.12 +pyspelling==2.12.1 From 48939a4575d5db6e875add0ccae93242f56fe581 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 28 Nov 2025 01:23:57 +0100 Subject: [PATCH 103/140] GHA/linux-old: add support for using custom CMake versions Install CMake from the Kitware GitHub release archive. To allow choosing its version independently from the OS. Switch to 3.7.0 (from 3.7.2) to test the earliest supported version. Also tested OK with 3.18.4 and 3.7.2. The download and install step takes 1-2 seconds. Follow-up to c9e50e9e393508c6a28c695abcf62980b3c1b023 #19737 Closes #19738 --- .github/workflows/linux-old.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux-old.yml b/.github/workflows/linux-old.yml index 59da60987c96..e282b1c47196 100644 --- a/.github/workflows/linux-old.yml +++ b/.github/workflows/linux-old.yml @@ -60,6 +60,8 @@ jobs: runs-on: 'ubuntu-latest' container: 'debian:stretch' + env: + CMAKE_VERSION: '3.7.0' # Earliest version supported by curl steps: - name: 'install prereqs' # Remember, this shell is dash, not bash @@ -72,7 +74,7 @@ jobs: dpkg -i freexian-archive-keyring_2022.06.08_all.deb echo 'deb http://deb.freexian.com/extended-lts stretch-lts main contrib non-free' | tee /etc/apt/sources.list.d/extended-lts.list apt-get -o Dpkg::Use-Pty=0 update - apt-get -o Dpkg::Use-Pty=0 install -y --no-install-suggests --no-install-recommends cmake make automake autoconf libtool gcc pkg-config libpsl-dev libzstd-dev zlib1g-dev libc-ares-dev libkrb5-dev libldap2-dev librtmp-dev stunnel4 + apt-get -o Dpkg::Use-Pty=0 install -y --no-install-suggests --no-install-recommends make automake autoconf libtool gcc pkg-config libpsl-dev libzstd-dev zlib1g-dev libc-ares-dev libkrb5-dev libldap2-dev librtmp-dev stunnel4 # GitHub's actions/checkout needs newer glibc and libstdc++. The latter also depends on # gcc-8-base, but it does not actually seem used in our situation and is not available in # the main repo, so force the install. @@ -80,6 +82,15 @@ jobs: httrack --get https://deb.freexian.com/extended-lts/pool/main/g/gcc-8/libstdc++6_8.3.0-6_amd64.deb dpkg -i --force-depends libc6_*_amd64.deb libstdc++6_*_amd64.deb + - name: 'install prereqs (cmake)' + run: | + cd ~ + fn="cmake-${CMAKE_VERSION}-linux-x86_64" + httrack --get "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${fn}.tar.gz" + tar -xf "${fn}".tar*.gz + rm -f "${fn}".tar*.gz + mv "cmake-${CMAKE_VERSION}-Linux-x86_64" cmake + - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 with: persist-credentials: false @@ -88,7 +99,7 @@ jobs: run: | mkdir bld-1 cd bld-1 - cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \ + "$HOME"/cmake/bin/cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \ -DCURL_ENABLE_SSL=OFF -DENABLE_ARES=OFF -DCURL_ZSTD=OFF -DCURL_USE_GSSAPI=OFF -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=OFF -DUSE_LIBRTMP=ON - name: 'CM build-only build' @@ -112,7 +123,7 @@ jobs: run: | mkdir bld-cares cd bld-cares - cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \ + "$HOME"/cmake/bin/cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \ -DCURL_ENABLE_SSL=OFF -DENABLE_ARES=ON -DCURL_USE_GSSAPI=ON -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=OFF -DUSE_LIBRTMP=ON \ -DCURL_LIBCURL_VERSIONED_SYMBOLS=ON From bfc3d131b6b5be7b7219dc016ff600f58e279c6c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 28 Nov 2025 09:43:27 +0100 Subject: [PATCH 104/140] http: add asserts for null terminator for input strings http_rw_hd() assumes the null terminator is present. These asserts make sure this remains true. Closes #19741 --- lib/http.c | 2 ++ lib/transfer.c | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/http.c b/lib/http.c index 672183db0ef2..8223c6f0e213 100644 --- a/lib/http.c +++ b/lib/http.c @@ -4142,6 +4142,7 @@ static CURLcode http_rw_hd(struct Curl_easy *data, CURLcode result = CURLE_OK; struct SingleRequest *k = &data->req; int writetype; + DEBUGASSERT(!hd[hdlen]); /* null terminated */ *pconsumed = 0; if((0x0a == *hd) || (0x0d == *hd)) { @@ -4426,6 +4427,7 @@ CURLcode Curl_http_write_resp_hd(struct Curl_easy *data, CURLcode result; size_t consumed; char tmp = 0; + DEBUGASSERT(!hd[hdlen]); /* null terminated */ result = http_rw_hd(data, hd, hdlen, &tmp, 0, &consumed); if(!result && is_eos) { diff --git a/lib/transfer.c b/lib/transfer.c index f2df2cef8cba..f0ce3c501271 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -820,6 +820,7 @@ CURLcode Curl_xfer_write_resp_hd(struct Curl_easy *data, const char *hd0, size_t hdlen, bool is_eos) { if(data->conn->handler->write_resp_hd) { + DEBUGASSERT(!hd0[hdlen]); /* null terminated */ /* protocol handlers offering this function take full responsibility * for writing all received download data to the client. */ return data->conn->handler->write_resp_hd(data, hd0, hdlen, is_eos); From 193cb00ce9b47e75d42157c650cc3de3fd96d35d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 8 Oct 2025 02:33:19 +0200 Subject: [PATCH 105/140] build: stop overriding standard memory allocation functions Before this patch curl used the C preprocessor to override standard memory allocation symbols: malloc, calloc, strdup, realloc, free. The goal of these is to replace them with curl's debug wrappers in `CURLDEBUG` builds, another was to replace them with the wrappers calling user-defined allocators in libcurl. This solution needed a bunch of workarounds to avoid breaking external headers: it relied on include order to do the overriding last. For "unity" builds it needed to reset overrides before external includes. Also in test apps, which are always built as single source files. It also needed the `(symbol)` trick to avoid overrides in some places. This would still not fix cases where the standard symbols were macros. It was also fragile and difficult to figure out which was the actual function behind an alloc or free call in a specific piece of code. This in turn caused bugs where the wrong allocator was accidentally called. To avoid these problems, this patch replaces this solution with `curlx_`-prefixed allocator macros, and mapping them _once_ to either the libcurl wrappers, the debug wrappers or the standard ones, matching the rest of the code in libtests. This concludes the long journey to avoid redefining standard functions in the curl codebase. Note: I did not update `packages/OS400/*.c` sources. They did not `#include` `curl_setup.h`, `curl_memory.h` or `memdebug.h`, meaning the overrides were never applied to them. This may or may not have been correct. For now I suppressed the direct use of standard allocators via a local `.checksrc`. Probably they (except for `curlcl.c`) should be updated to include `curl_setup.h` and use the `curlx_` macros. This patch changes mappings in two places: - `lib/curl_threads.c` in libtests: Before this patch it mapped to libcurl allocators. After, it maps to standard allocators, like the rest of libtests code. - `units`: before this patch it mapped to standard allocators. After, it maps to libcurl allocators. Also: - drop all position-dependent `curl_memory.h` and `memdebug.h` includes, and delete the now unnecessary headers. - rename `Curl_tcsdup` macro to `curlx_tcsdup` and define like the other allocators. - map `curlx_strdup()` to `_strdup()` on Windows (was: `strdup()`). To fix warnings silenced via `_CRT_NONSTDC_NO_DEPRECATE`. - multibyte: map `curlx_convert_*()` to `_strdup()` on Windows (was: `strdup()`). - src: do not reuse the `strdup` name for the local replacement. - lib509: call `_strdup()` on Windows (was: `strdup()`). - test1132: delete test obsoleted by this patch. - CHECKSRC.md: update text for `SNPRINTF`. - checksrc: ban standard allocator symbols. Follow-up to b12da22db1f11da51082977dc21a7edee7858911 #18866 Follow-up to db98daab05aec251bcb6615d2d38dfebec291736 #18844 Follow-up to 4deea9396bc7dd25c6362fa746a57bf309c74ada #18814 Follow-up to 9678ff5b1bfea1c847aee4f9edf023e8f01c9293 #18776 Follow-up to 10bac43b873fe45869e15b36aac1c1e5bc89b6e0 #18774 Follow-up to 20142f5d06f7120ba94cbcc25c998e8d81aec85b #18634 Follow-up to bf7375ecc50e857760b0d0a668c436e208a400bd #18503 Follow-up to 9863599d69b79d290928a89bf9160f4e4e023d4e #18502 Follow-up to 3bb5e58c105d7be450b667858d1b8e7ae3ded555 #17827 Closes #19626 --- docs/examples/.checksrc | 5 + docs/internals/CHECKSRC.md | 2 +- docs/internals/CODE_STYLE.md | 5 + lib/Makefile.inc | 3 - lib/altsvc.c | 24 ++-- lib/amigaos.c | 8 +- lib/asyn-ares.c | 8 +- lib/asyn-base.c | 3 - lib/asyn-thrdd.c | 20 ++-- lib/bufq.c | 14 +-- lib/bufref.c | 3 - lib/cf-h1-proxy.c | 12 +- lib/cf-h2-proxy.c | 10 +- lib/cf-haproxy.c | 8 +- lib/cf-https-connect.c | 8 +- lib/cf-ip-happy.c | 12 +- lib/cf-socket.c | 16 +-- lib/cfilters.c | 8 +- lib/conncache.c | 8 +- lib/connect.c | 8 +- lib/content_encoding.c | 10 +- lib/cookie.c | 54 +++++---- lib/cshutdn.c | 4 - lib/curl_addrinfo.c | 17 ++- lib/curl_fnmatch.c | 4 - lib/curl_fopen.c | 8 +- lib/curl_get_line.c | 3 - lib/curl_gssapi.c | 24 ++-- lib/curl_mem_undef.h | 37 ------- lib/curl_memory.h | 89 --------------- lib/curl_memrchr.c | 4 - lib/curl_ntlm_core.c | 16 +-- lib/curl_rtmp.c | 4 - lib/curl_sasl.c | 4 - lib/curl_setup.h | 54 ++++++++- lib/curl_share.c | 10 +- lib/curl_sspi.c | 10 +- lib/curl_threads.c | 17 ++- lib/curl_trc.c | 4 - lib/curlx/base64.c | 12 +- lib/curlx/dynbuf.c | 8 +- lib/curlx/fopen.c | 59 ++++++---- lib/curlx/multibyte.c | 19 ++-- lib/curlx/multibyte.h | 18 +-- lib/curlx/strerr.c | 3 - lib/curlx/version_win32.c | 4 - lib/cw-out.c | 8 +- lib/cw-pause.c | 8 +- lib/dict.c | 11 +- lib/dllmain.c | 4 - lib/doh.c | 18 ++- lib/dynhds.c | 14 +-- lib/easy.c | 24 ++-- lib/escape.c | 10 +- lib/fake_addrinfo.c | 8 +- lib/file.c | 10 +- lib/fileinfo.c | 7 +- lib/formdata.c | 44 ++++---- lib/ftp.c | 68 ++++++------ lib/ftplistparser.c | 14 +-- lib/getenv.c | 11 +- lib/getinfo.c | 10 +- lib/gopher.c | 12 +- lib/hash.c | 10 +- lib/headers.c | 10 +- lib/hmac.c | 10 +- lib/hostip.c | 22 ++-- lib/hostip4.c | 14 +-- lib/hostip6.c | 4 - lib/hsts.c | 24 ++-- lib/http.c | 106 +++++++++--------- lib/http1.c | 4 - lib/http2.c | 30 +++-- lib/http_aws_sigv4.c | 30 +++-- lib/http_chunks.c | 4 - lib/http_digest.c | 10 +- lib/http_negotiate.c | 10 +- lib/http_ntlm.c | 12 +- lib/http_proxy.c | 12 +- lib/httpsrr.c | 14 +-- lib/idn.c | 18 ++- lib/if2ip.c | 4 - lib/imap.c | 42 ++++--- lib/ldap.c | 38 +++---- lib/llist.c | 4 - lib/md4.c | 4 - lib/md5.c | 18 ++- lib/memdebug.c | 4 - lib/memdebug.h | 56 ---------- lib/mime.c | 34 +++--- lib/mprintf.c | 6 +- lib/mqtt.c | 28 ++--- lib/multi.c | 34 +++--- lib/multi_ev.c | 10 +- lib/multi_ntfy.c | 9 +- lib/netrc.c | 28 ++--- lib/openldap.c | 16 +-- lib/pingpong.c | 4 - lib/pop3.c | 12 +- lib/psl.c | 4 - lib/rand.c | 4 - lib/rename.c | 4 - lib/request.c | 4 - lib/rtsp.c | 20 ++-- lib/select.c | 30 +++-- lib/sendf.c | 20 ++-- lib/setopt.c | 26 ++--- lib/sha256.c | 4 - lib/slist.c | 12 +- lib/smb.c | 25 ++--- lib/smtp.c | 32 +++--- lib/socketpair.c | 4 - lib/socks.c | 8 +- lib/socks_gssapi.c | 12 +- lib/socks_sspi.c | 32 +++--- lib/strdup.c | 16 +-- lib/strerror.c | 4 - lib/system_win32.c | 9 +- lib/telnet.c | 8 +- lib/tftp.c | 16 +-- lib/transfer.c | 14 +-- lib/uint-bset.c | 10 +- lib/uint-hash.c | 10 +- lib/uint-spbset.c | 8 +- lib/uint-table.c | 10 +- lib/url.c | 146 ++++++++++++------------- lib/urlapi.c | 86 +++++++-------- lib/vauth/cleartext.c | 4 - lib/vauth/cram.c | 4 - lib/vauth/digest.c | 74 ++++++------- lib/vauth/digest_sspi.c | 52 ++++----- lib/vauth/gsasl.c | 4 - lib/vauth/krb5_gssapi.c | 14 +-- lib/vauth/krb5_sspi.c | 28 ++--- lib/vauth/ntlm.c | 8 +- lib/vauth/ntlm_sspi.c | 14 +-- lib/vauth/oauth2.c | 4 - lib/vauth/spnego_gssapi.c | 8 +- lib/vauth/spnego_sspi.c | 18 ++- lib/vauth/vauth.c | 24 ++-- lib/vquic/curl_ngtcp2.c | 16 +-- lib/vquic/curl_osslq.c | 29 +++-- lib/vquic/curl_quiche.c | 16 +-- lib/vquic/vquic-tls.c | 4 - lib/vquic/vquic.c | 6 +- lib/vssh/libssh.c | 28 +++-- lib/vssh/libssh2.c | 48 ++++---- lib/vssh/vssh.c | 12 +- lib/vtls/apple.c | 10 +- lib/vtls/gtls.c | 25 ++--- lib/vtls/hostcheck.c | 4 - lib/vtls/keylog.c | 4 - lib/vtls/mbedtls.c | 28 ++--- lib/vtls/mbedtls_threadlock.c | 4 - lib/vtls/openssl.c | 36 +++--- lib/vtls/rustls.c | 10 +- lib/vtls/schannel.c | 63 +++++------ lib/vtls/schannel_verify.c | 8 +- lib/vtls/vtls.c | 38 +++---- lib/vtls/vtls_scache.c | 45 ++++---- lib/vtls/vtls_spack.c | 6 +- lib/vtls/wolfssl.c | 24 ++-- lib/vtls/x509asn1.c | 6 +- lib/ws.c | 12 +- packages/Makefile.am | 1 + packages/OS400/.checksrc | 9 ++ scripts/checksrc.pl | 5 + src/mkhelp.pl | 15 ++- src/slist_wc.c | 7 +- src/terminal.c | 1 - src/tool_bname.c | 2 - src/tool_cb_dbg.c | 2 - src/tool_cb_hdr.c | 10 +- src/tool_cb_prg.c | 2 - src/tool_cb_rea.c | 2 - src/tool_cb_see.c | 2 - src/tool_cb_wrt.c | 6 +- src/tool_cfgable.c | 11 +- src/tool_cfgable.h | 2 +- src/tool_dirhie.c | 2 - src/tool_doswin.c | 29 +++-- src/tool_easysrc.c | 2 - src/tool_findfile.c | 4 +- src/tool_formparse.c | 20 ++-- src/tool_getparam.c | 42 ++++--- src/tool_getpass.c | 2 - src/tool_help.c | 6 +- src/tool_helpers.c | 1 - src/tool_ipfs.c | 11 +- src/tool_libinfo.c | 1 - src/tool_libinfo.h | 1 - src/tool_main.c | 9 +- src/tool_msgs.c | 2 - src/tool_operate.c | 46 ++++---- src/tool_operhlp.c | 9 +- src/tool_paramhlp.c | 12 +- src/tool_parsecfg.c | 7 +- src/tool_setopt.c | 17 ++- src/tool_setup.h | 2 + src/tool_ssls.c | 8 +- src/tool_ssls.h | 1 - src/tool_stderr.c | 2 - src/tool_strdup.c | 7 +- src/tool_strdup.h | 2 +- src/tool_urlglob.c | 20 ++-- src/tool_util.c | 1 - src/tool_vms.c | 1 - src/tool_writeout.c | 1 - src/tool_xattr.c | 2 - src/var.c | 15 ++- tests/Makefile.am | 1 - tests/data/Makefile.am | 2 +- tests/data/test1132 | 21 ---- tests/libtest/cli_h2_pausing.c | 1 - tests/libtest/cli_h2_serverpush.c | 1 - tests/libtest/cli_h2_upgrade_extreme.c | 1 - tests/libtest/cli_hx_download.c | 14 +-- tests/libtest/cli_hx_upload.c | 5 +- tests/libtest/cli_tls_session_reuse.c | 1 - tests/libtest/cli_upload_pausing.c | 1 - tests/libtest/cli_ws_data.c | 17 ++- tests/libtest/cli_ws_pingpong.c | 1 - tests/libtest/first.c | 2 - tests/libtest/lib1156.c | 2 - tests/libtest/lib1485.c | 2 - tests/libtest/lib1500.c | 2 - tests/libtest/lib1501.c | 2 - tests/libtest/lib1502.c | 2 - tests/libtest/lib1506.c | 2 - tests/libtest/lib1507.c | 2 - tests/libtest/lib1508.c | 2 - tests/libtest/lib1509.c | 2 - tests/libtest/lib1510.c | 2 - tests/libtest/lib1511.c | 2 - tests/libtest/lib1512.c | 2 - tests/libtest/lib1513.c | 2 - tests/libtest/lib1514.c | 2 - tests/libtest/lib1515.c | 1 - tests/libtest/lib1517.c | 2 - tests/libtest/lib1518.c | 2 - tests/libtest/lib1520.c | 2 - tests/libtest/lib1522.c | 1 - tests/libtest/lib1523.c | 2 - tests/libtest/lib1525.c | 2 - tests/libtest/lib1526.c | 2 - tests/libtest/lib1527.c | 2 - tests/libtest/lib1528.c | 2 - tests/libtest/lib1529.c | 2 - tests/libtest/lib1530.c | 2 - tests/libtest/lib1531.c | 2 - tests/libtest/lib1532.c | 2 - tests/libtest/lib1533.c | 2 - tests/libtest/lib1534.c | 2 - tests/libtest/lib1535.c | 2 - tests/libtest/lib1536.c | 2 - tests/libtest/lib1537.c | 2 - tests/libtest/lib1538.c | 2 - tests/libtest/lib1540.c | 1 - tests/libtest/lib1541.c | 2 - tests/libtest/lib1542.c | 1 - tests/libtest/lib1549.c | 1 - tests/libtest/lib1550.c | 2 - tests/libtest/lib1551.c | 2 - tests/libtest/lib1552.c | 2 - tests/libtest/lib1553.c | 1 - tests/libtest/lib1554.c | 2 - tests/libtest/lib1555.c | 2 - tests/libtest/lib1556.c | 2 - tests/libtest/lib1557.c | 2 - tests/libtest/lib1558.c | 2 - tests/libtest/lib1559.c | 6 +- tests/libtest/lib1560.c | 2 - tests/libtest/lib1564.c | 2 - tests/libtest/lib1565.c | 2 - tests/libtest/lib1567.c | 2 - tests/libtest/lib1568.c | 2 - tests/libtest/lib1569.c | 2 - tests/libtest/lib1571.c | 2 - tests/libtest/lib1576.c | 2 - tests/libtest/lib1582.c | 2 - tests/libtest/lib1591.c | 2 - tests/libtest/lib1593.c | 2 - tests/libtest/lib1594.c | 2 - tests/libtest/lib1597.c | 2 - tests/libtest/lib1598.c | 2 - tests/libtest/lib1900.c | 2 - tests/libtest/lib1901.c | 2 - tests/libtest/lib1902.c | 2 - tests/libtest/lib1903.c | 2 - tests/libtest/lib1905.c | 2 - tests/libtest/lib1906.c | 2 - tests/libtest/lib1907.c | 2 - tests/libtest/lib1908.c | 2 - tests/libtest/lib1910.c | 2 - tests/libtest/lib1911.c | 2 - tests/libtest/lib1912.c | 2 - tests/libtest/lib1913.c | 2 - tests/libtest/lib1915.c | 1 - tests/libtest/lib1916.c | 2 - tests/libtest/lib1918.c | 2 - tests/libtest/lib1919.c | 2 - tests/libtest/lib1933.c | 2 - tests/libtest/lib1934.c | 2 - tests/libtest/lib1935.c | 2 - tests/libtest/lib1936.c | 2 - tests/libtest/lib1937.c | 2 - tests/libtest/lib1938.c | 2 - tests/libtest/lib1939.c | 2 - tests/libtest/lib1940.c | 2 - tests/libtest/lib1945.c | 2 - tests/libtest/lib1947.c | 2 - tests/libtest/lib1955.c | 2 - tests/libtest/lib1956.c | 2 - tests/libtest/lib1957.c | 2 - tests/libtest/lib1958.c | 2 - tests/libtest/lib1959.c | 2 - tests/libtest/lib1960.c | 2 - tests/libtest/lib1964.c | 2 - tests/libtest/lib1970.c | 2 - tests/libtest/lib1971.c | 2 - tests/libtest/lib1972.c | 2 - tests/libtest/lib1973.c | 2 - tests/libtest/lib1974.c | 2 - tests/libtest/lib1975.c | 2 - tests/libtest/lib1977.c | 2 - tests/libtest/lib1978.c | 2 - tests/libtest/lib2023.c | 6 +- tests/libtest/lib2032.c | 8 +- tests/libtest/lib2302.c | 4 +- tests/libtest/lib2402.c | 2 - tests/libtest/lib2404.c | 2 - tests/libtest/lib2405.c | 2 - tests/libtest/lib2502.c | 1 - tests/libtest/lib2700.c | 1 - tests/libtest/lib3010.c | 2 - tests/libtest/lib3025.c | 2 - tests/libtest/lib3027.c | 2 - tests/libtest/lib3033.c | 2 - tests/libtest/lib3100.c | 2 - tests/libtest/lib3101.c | 2 - tests/libtest/lib3102.c | 2 - tests/libtest/lib3103.c | 2 - tests/libtest/lib3104.c | 2 - tests/libtest/lib3105.c | 2 - tests/libtest/lib3207.c | 6 +- tests/libtest/lib3208.c | 2 - tests/libtest/lib500.c | 1 - tests/libtest/lib501.c | 2 - tests/libtest/lib502.c | 2 - tests/libtest/lib503.c | 2 - tests/libtest/lib504.c | 2 - tests/libtest/lib505.c | 2 - tests/libtest/lib506.c | 1 - tests/libtest/lib507.c | 2 - tests/libtest/lib508.c | 2 - tests/libtest/lib509.c | 29 +++-- tests/libtest/lib510.c | 2 - tests/libtest/lib511.c | 2 - tests/libtest/lib512.c | 2 - tests/libtest/lib513.c | 2 - tests/libtest/lib514.c | 2 - tests/libtest/lib515.c | 2 - tests/libtest/lib516.c | 2 - tests/libtest/lib517.c | 2 - tests/libtest/lib518.c | 35 +++--- tests/libtest/lib519.c | 2 - tests/libtest/lib520.c | 2 - tests/libtest/lib521.c | 2 - tests/libtest/lib523.c | 2 - tests/libtest/lib524.c | 2 - tests/libtest/lib525.c | 2 - tests/libtest/lib526.c | 2 - tests/libtest/lib530.c | 14 +-- tests/libtest/lib533.c | 2 - tests/libtest/lib536.c | 2 - tests/libtest/lib537.c | 36 +++--- tests/libtest/lib539.c | 2 - tests/libtest/lib540.c | 2 - tests/libtest/lib541.c | 2 - tests/libtest/lib542.c | 2 - tests/libtest/lib543.c | 2 - tests/libtest/lib544.c | 2 - tests/libtest/lib547.c | 2 - tests/libtest/lib549.c | 2 - tests/libtest/lib552.c | 1 - tests/libtest/lib553.c | 2 - tests/libtest/lib554.c | 2 - tests/libtest/lib555.c | 2 - tests/libtest/lib556.c | 2 - tests/libtest/lib557.c | 2 - tests/libtest/lib558.c | 4 +- tests/libtest/lib559.c | 2 - tests/libtest/lib560.c | 2 - tests/libtest/lib562.c | 2 - tests/libtest/lib564.c | 1 - tests/libtest/lib566.c | 2 - tests/libtest/lib567.c | 2 - tests/libtest/lib568.c | 1 - tests/libtest/lib569.c | 1 - tests/libtest/lib570.c | 1 - tests/libtest/lib571.c | 1 - tests/libtest/lib572.c | 1 - tests/libtest/lib573.c | 1 - tests/libtest/lib574.c | 2 - tests/libtest/lib575.c | 2 - tests/libtest/lib576.c | 2 - tests/libtest/lib578.c | 2 - tests/libtest/lib579.c | 2 - tests/libtest/lib582.c | 8 +- tests/libtest/lib583.c | 2 - tests/libtest/lib586.c | 2 - tests/libtest/lib589.c | 2 - tests/libtest/lib590.c | 2 - tests/libtest/lib591.c | 2 - tests/libtest/lib597.c | 2 - tests/libtest/lib598.c | 2 - tests/libtest/lib599.c | 2 - tests/libtest/lib643.c | 2 - tests/libtest/lib650.c | 2 - tests/libtest/lib651.c | 2 - tests/libtest/lib652.c | 2 - tests/libtest/lib653.c | 2 - tests/libtest/lib654.c | 2 - tests/libtest/lib655.c | 2 - tests/libtest/lib658.c | 2 - tests/libtest/lib659.c | 2 - tests/libtest/lib661.c | 2 - tests/libtest/lib666.c | 2 - tests/libtest/lib667.c | 2 - tests/libtest/lib668.c | 2 - tests/libtest/lib670.c | 2 - tests/libtest/lib674.c | 2 - tests/libtest/lib676.c | 2 - tests/libtest/lib677.c | 2 - tests/libtest/lib678.c | 8 +- tests/libtest/lib694.c | 2 - tests/libtest/lib695.c | 2 - tests/libtest/lib751.c | 2 - tests/libtest/lib753.c | 1 - tests/libtest/lib757.c | 2 - tests/libtest/lib758.c | 12 +- tests/libtest/lib766.c | 2 - tests/libtest/memptr.c | 2 - tests/libtest/mk-lib1521.pl | 1 - tests/libtest/testtrace.c | 2 - tests/libtest/testutil.c | 2 - tests/server/.checksrc | 5 + tests/test1132.pl | 98 ----------------- tests/tunit/tool1394.c | 6 +- tests/tunit/tool1604.c | 16 ++- tests/tunit/tool1621.c | 2 - tests/unit/unit1302.c | 1 - tests/unit/unit1303.c | 1 - tests/unit/unit1304.c | 13 +-- tests/unit/unit1305.c | 13 +-- tests/unit/unit1330.c | 4 +- tests/unit/unit1395.c | 3 +- tests/unit/unit1602.c | 12 +- tests/unit/unit1603.c | 2 - tests/unit/unit1607.c | 4 +- tests/unit/unit1609.c | 4 +- tests/unit/unit1616.c | 12 +- tests/unit/unit1620.c | 8 +- tests/unit/unit1653.c | 28 ++--- tests/unit/unit1661.c | 5 +- tests/unit/unit1663.c | 8 +- tests/unit/unit1664.c | 2 - tests/unit/unit2600.c | 9 +- tests/unit/unit2604.c | 5 +- tests/unit/unit2605.c | 1 - tests/unit/unit3200.c | 1 - 471 files changed, 1456 insertions(+), 2785 deletions(-) delete mode 100644 lib/curl_mem_undef.h delete mode 100644 lib/curl_memory.h delete mode 100644 lib/memdebug.h create mode 100644 packages/OS400/.checksrc delete mode 100644 tests/data/test1132 delete mode 100755 tests/test1132.pl diff --git a/docs/examples/.checksrc b/docs/examples/.checksrc index c47627467ff3..8c7b0c901e80 100644 --- a/docs/examples/.checksrc +++ b/docs/examples/.checksrc @@ -4,17 +4,22 @@ allowfunc atoi allowfunc atol +allowfunc calloc allowfunc fclose allowfunc fdopen allowfunc fopen allowfunc fprintf +allowfunc free allowfunc gmtime allowfunc localtime +allowfunc malloc allowfunc open allowfunc printf +allowfunc realloc allowfunc snprintf allowfunc socket allowfunc sscanf +allowfunc strdup allowfunc strerror allowfunc vsnprintf diff --git a/docs/internals/CHECKSRC.md b/docs/internals/CHECKSRC.md index 1740b2bef591..091a4d3107e6 100644 --- a/docs/internals/CHECKSRC.md +++ b/docs/internals/CHECKSRC.md @@ -107,7 +107,7 @@ warnings are: `sizeof(int)` style. - `SNPRINTF` - Found use of `snprintf()`. Since we use an internal replacement - with a different return code etc, we prefer `msnprintf()`. + with a different return code etc, we prefer `curl_msnprintf()`. - `SPACEAFTERPAREN`: there was a space after open parenthesis, `( text`. diff --git a/docs/internals/CODE_STYLE.md b/docs/internals/CODE_STYLE.md index 7d37df4805ec..43b873be9b37 100644 --- a/docs/internals/CODE_STYLE.md +++ b/docs/internals/CODE_STYLE.md @@ -352,10 +352,12 @@ This is the full list of functions generally banned. aprintf atoi atol + calloc fclose fdopen fopen fprintf + free freeaddrinfo freopen getaddrinfo @@ -368,11 +370,13 @@ This is the full list of functions generally banned. LoadLibraryExW LoadLibraryW localtime + malloc mbstowcs msnprintf mvsnprintf open printf + realloc recv send snprintf @@ -382,6 +386,7 @@ This is the full list of functions generally banned. sscanf stat strcat + strdup strerror strncat strncpy diff --git a/lib/Makefile.inc b/lib/Makefile.inc index 85faa875e072..cdd5587ec80b 100644 --- a/lib/Makefile.inc +++ b/lib/Makefile.inc @@ -300,8 +300,6 @@ LIB_HFILES = \ curl_ldap.h \ curl_md4.h \ curl_md5.h \ - curl_mem_undef.h \ - curl_memory.h \ curl_memrchr.h \ curl_ntlm_core.h \ curl_printf.h \ @@ -353,7 +351,6 @@ LIB_HFILES = \ imap.h \ llist.h \ macos.h \ - memdebug.h \ mime.h \ mqtt.h \ multihandle.h \ diff --git a/lib/altsvc.c b/lib/altsvc.c index c05dff04e2c1..84f6c1b44547 100644 --- a/lib/altsvc.c +++ b/lib/altsvc.c @@ -42,10 +42,6 @@ #include "curlx/strparse.h" #include "connect.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define MAX_ALTSVC_LINE 4095 #define MAX_ALTSVC_DATELEN 256 #define MAX_ALTSVC_HOSTLEN 2048 @@ -71,9 +67,9 @@ const char *Curl_alpnid2str(enum alpnid id) static void altsvc_free(struct altsvc *as) { - free(as->src.host); - free(as->dst.host); - free(as); + curlx_free(as->src.host); + curlx_free(as->dst.host); + curlx_free(as); } static struct altsvc *altsvc_createid(const char *srchost, @@ -85,7 +81,7 @@ static struct altsvc *altsvc_createid(const char *srchost, size_t srcport, size_t dstport) { - struct altsvc *as = calloc(1, sizeof(struct altsvc)); + struct altsvc *as = curlx_calloc(1, sizeof(struct altsvc)); if(!as) return NULL; DEBUGASSERT(hlen); @@ -219,8 +215,8 @@ static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file) /* we need a private copy of the filename so that the altsvc cache file name survives an easy handle reset */ - free(asi->filename); - asi->filename = strdup(file); + curlx_free(asi->filename); + asi->filename = curlx_strdup(file); if(!asi->filename) return CURLE_OUT_OF_MEMORY; @@ -299,7 +295,7 @@ static CURLcode altsvc_out(struct altsvc *as, FILE *fp) */ struct altsvcinfo *Curl_altsvc_init(void) { - struct altsvcinfo *asi = calloc(1, sizeof(struct altsvcinfo)); + struct altsvcinfo *asi = curlx_calloc(1, sizeof(struct altsvcinfo)); if(!asi) return NULL; Curl_llist_init(&asi->list, NULL); @@ -350,8 +346,8 @@ void Curl_altsvc_cleanup(struct altsvcinfo **altsvcp) n = Curl_node_next(e); altsvc_free(as); } - free(altsvc->filename); - free(altsvc); + curlx_free(altsvc->filename); + curlx_free(altsvc); *altsvcp = NULL; /* clear the pointer */ } } @@ -399,7 +395,7 @@ CURLcode Curl_altsvc_save(struct Curl_easy *data, if(result && tempstore) unlink(tempstore); } - free(tempstore); + curlx_free(tempstore); return result; } diff --git a/lib/amigaos.c b/lib/amigaos.c index e51236d1260a..e4b678d54185 100644 --- a/lib/amigaos.c +++ b/lib/amigaos.c @@ -42,10 +42,6 @@ # endif #endif -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef HAVE_PROTO_BSDSOCKET_H #ifdef __amigaos4__ @@ -135,7 +131,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, LONG h_errnop = 0; struct hostent *buf; - buf = calloc(1, CURL_HOSTENT_SIZE); + buf = curlx_calloc(1, CURL_HOSTENT_SIZE); if(buf) { h = gethostbyname_r((STRPTR)hostname, buf, (char *)buf + sizeof(struct hostent), @@ -144,7 +140,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, if(h) { ai = Curl_he2ai(h, port); } - free(buf); + curlx_free(buf); } } else { diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index 1bc0f3247b78..e3ba512b77ff 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -104,10 +104,6 @@ #define HTTPSRR_WORKS #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define CARES_TIMEOUT_PER_ATTEMPT 2000 static int ares_ver = 0; @@ -633,7 +629,7 @@ async_ares_node2addr(struct ares_addrinfo_node *node) if((size_t)ai->ai_addrlen < ss_size) continue; - ca = malloc(sizeof(struct Curl_addrinfo) + ss_size); + ca = curlx_malloc(sizeof(struct Curl_addrinfo) + ss_size); if(!ca) { error = EAI_MEMORY; break; @@ -736,7 +732,7 @@ CURLcode Curl_async_getaddrinfo(struct Curl_easy *data, const char *hostname, data->state.async.dns = NULL; /* clear */ data->state.async.port = port; data->state.async.ip_version = ip_version; - data->state.async.hostname = strdup(hostname); + data->state.async.hostname = curlx_strdup(hostname); if(!data->state.async.hostname) return CURLE_OUT_OF_MEMORY; #ifdef USE_HTTPSRR diff --git a/lib/asyn-base.c b/lib/asyn-base.c index d7e8e7d15b86..6338a3fc6e25 100644 --- a/lib/asyn-base.c +++ b/lib/asyn-base.c @@ -53,9 +53,6 @@ #include "select.h" #include "curl_share.h" #include "url.h" -#include "curl_memory.h" -/* The last #include file should be: */ -#include "memdebug.h" /*********************************************************************** * Only for builds using asynchronous name resolves diff --git a/lib/asyn-thrdd.c b/lib/asyn-thrdd.c index 71e31e6d0d16..6c2e02fd1871 100644 --- a/lib/asyn-thrdd.c +++ b/lib/asyn-thrdd.c @@ -72,10 +72,6 @@ #endif #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Curl_async_global_init() @@ -136,7 +132,7 @@ static void addr_ctx_unlink(struct async_thrdd_addr_ctx **paddr_ctx, if(destroy) { Curl_mutex_destroy(&addr_ctx->mutx); - free(addr_ctx->hostname); + curlx_free(addr_ctx->hostname); if(addr_ctx->res) Curl_freeaddrinfo(addr_ctx->res); #ifndef CURL_DISABLE_SOCKETPAIR @@ -145,7 +141,7 @@ static void addr_ctx_unlink(struct async_thrdd_addr_ctx **paddr_ctx, #endif wakeup_close(addr_ctx->sock_pair[0]); #endif - free(addr_ctx); + curlx_free(addr_ctx); } *paddr_ctx = NULL; } @@ -156,7 +152,7 @@ addr_ctx_create(struct Curl_easy *data, const char *hostname, int port, const struct addrinfo *hints) { - struct async_thrdd_addr_ctx *addr_ctx = calloc(1, sizeof(*addr_ctx)); + struct async_thrdd_addr_ctx *addr_ctx = curlx_calloc(1, sizeof(*addr_ctx)); if(!addr_ctx) return NULL; @@ -186,7 +182,7 @@ addr_ctx_create(struct Curl_easy *data, /* Copying hostname string because original can be destroyed by parent * thread during gethostbyname execution. */ - addr_ctx->hostname = strdup(hostname); + addr_ctx->hostname = curlx_strdup(hostname); if(!addr_ctx->hostname) goto err_exit; @@ -376,7 +372,7 @@ static CURLcode async_rr_start(struct Curl_easy *data, int port) status = ares_init_options(&thrdd->rr.channel, NULL, 0); if(status != ARES_SUCCESS) { thrdd->rr.channel = NULL; - free(rrname); + curlx_free(rrname); return CURLE_FAILED_INIT; } #ifdef CURLDEBUG @@ -384,7 +380,7 @@ static CURLcode async_rr_start(struct Curl_easy *data, int port) const char *servers = getenv("CURL_DNS_SERVER"); status = ares_set_servers_ports_csv(thrdd->rr.channel, servers); if(status) { - free(rrname); + curlx_free(rrname); return CURLE_FAILED_INIT; } } @@ -435,8 +431,8 @@ static bool async_thrdd_init(struct Curl_easy *data, data->state.async.done = FALSE; data->state.async.port = port; data->state.async.ip_version = ip_version; - free(data->state.async.hostname); - data->state.async.hostname = strdup(hostname); + curlx_free(data->state.async.hostname); + data->state.async.hostname = curlx_strdup(hostname); if(!data->state.async.hostname) goto err_exit; diff --git a/lib/bufq.c b/lib/bufq.c index d38b78c6d5b2..5a77fc52d4b3 100644 --- a/lib/bufq.c +++ b/lib/bufq.c @@ -25,10 +25,6 @@ #include "curl_setup.h" #include "bufq.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static bool chunk_is_empty(const struct buf_chunk *chunk) { return chunk->r_offset >= chunk->w_offset; @@ -143,7 +139,7 @@ static void chunk_list_free(struct buf_chunk **anchor) while(*anchor) { chunk = *anchor; *anchor = chunk->next; - free(chunk); + curlx_free(chunk); } } @@ -178,7 +174,7 @@ static CURLcode bufcp_take(struct bufc_pool *pool, return CURLE_OUT_OF_MEMORY; } - chunk = calloc(1, sizeof(*chunk) + pool->chunk_size); + chunk = curlx_calloc(1, sizeof(*chunk) + pool->chunk_size); if(!chunk) { *pchunk = NULL; return CURLE_OUT_OF_MEMORY; @@ -192,7 +188,7 @@ static void bufcp_put(struct bufc_pool *pool, struct buf_chunk *chunk) { if(pool->spare_count >= pool->spare_max) { - free(chunk); + curlx_free(chunk); } else { chunk_reset(chunk); @@ -311,7 +307,7 @@ static struct buf_chunk *get_spare(struct bufq *q) return NULL; } - chunk = calloc(1, sizeof(*chunk) + q->chunk_size); + chunk = curlx_calloc(1, sizeof(*chunk) + q->chunk_size); if(!chunk) return NULL; chunk->dlen = q->chunk_size; @@ -338,7 +334,7 @@ static void prune_head(struct bufq *q) /* SOFT_LIMIT allowed us more than max. free spares until * we are at max again. Or free them if we are configured * to not use spares. */ - free(chunk); + curlx_free(chunk); --q->chunk_count; } else { diff --git a/lib/bufref.c b/lib/bufref.c index ac0612071d6c..d5181a5da662 100644 --- a/lib/bufref.c +++ b/lib/bufref.c @@ -27,9 +27,6 @@ #include "bufref.h" #include "strdup.h" -#include "curl_memory.h" -#include "memdebug.h" - #ifdef DEBUGBUILD #define SIGNATURE 0x5c48e9b2 /* Random pattern. */ #endif diff --git a/lib/cf-h1-proxy.c b/lib/cf-h1-proxy.c index 417b4df67e29..84ba3d6193fa 100644 --- a/lib/cf-h1-proxy.c +++ b/lib/cf-h1-proxy.c @@ -46,10 +46,6 @@ #include "multiif.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - typedef enum { H1_TUNNEL_INIT, /* init/default/no tunnel state */ @@ -116,7 +112,7 @@ static CURLcode tunnel_init(struct Curl_cfilter *cf, return CURLE_UNSUPPORTED_PROTOCOL; } - ts = calloc(1, sizeof(*ts)); + ts = curlx_calloc(1, sizeof(*ts)); if(!ts) return CURLE_OUT_OF_MEMORY; @@ -194,7 +190,7 @@ static void tunnel_free(struct Curl_cfilter *cf, curlx_dyn_free(&ts->rcvbuf); curlx_dyn_free(&ts->request_data); Curl_httpchunk_free(data, &ts->ch); - free(ts); + curlx_free(ts); cf->ctx = NULL; } } @@ -215,7 +211,7 @@ static CURLcode start_CONNECT(struct Curl_cfilter *cf, /* This only happens if we have looped here due to authentication reasons, and we do not really use the newly cloned URL here - then. Just free() it. */ + then. Just free it. */ Curl_safefree(data->req.newurl); result = Curl_http_proxy_create_CONNECT(&req, cf, data, 1); @@ -298,7 +294,7 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "CONNECT: fwd auth header '%s'", header); result = Curl_http_input_auth(data, proxy, auth); - free(auth); + curlx_free(auth); if(result) return result; diff --git a/lib/cf-h2-proxy.c b/lib/cf-h2-proxy.c index fca916a2c24f..7066db3b4c4a 100644 --- a/lib/cf-h2-proxy.c +++ b/lib/cf-h2-proxy.c @@ -45,10 +45,6 @@ #include "curlx/warnless.h" #include "cf-h2-proxy.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define PROXY_H2_CHUNK_SIZE (16*1024) #define PROXY_HTTP2_HUGE_WINDOW_SIZE (100 * 1024 * 1024) @@ -209,7 +205,7 @@ static void cf_h2_proxy_ctx_free(struct cf_h2_proxy_ctx *ctx) { if(ctx) { cf_h2_proxy_ctx_clear(ctx); - free(ctx); + curlx_free(ctx); } } @@ -919,7 +915,7 @@ static CURLcode proxy_h2_submit(int32_t *pstream_id, result = CURLE_OK; out: - free(nva); + curlx_free(nva); Curl_dynhds_free(&h2_headers); *pstream_id = stream_id; return result; @@ -1594,7 +1590,7 @@ CURLcode Curl_cf_h2_proxy_insert_after(struct Curl_cfilter *cf, CURLcode result = CURLE_OUT_OF_MEMORY; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) goto out; diff --git a/lib/cf-haproxy.c b/lib/cf-haproxy.c index 8912604504d8..a1793c0071ec 100644 --- a/lib/cf-haproxy.c +++ b/lib/cf-haproxy.c @@ -34,10 +34,6 @@ #include "multiif.h" #include "select.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - typedef enum { HAPROXY_INIT, /* init/default/no tunnel state */ @@ -61,7 +57,7 @@ static void cf_haproxy_ctx_free(struct cf_haproxy_ctx *ctx) { if(ctx) { curlx_dyn_free(&ctx->data_out); - free(ctx); + curlx_free(ctx); } } @@ -217,7 +213,7 @@ static CURLcode cf_haproxy_create(struct Curl_cfilter **pcf, CURLcode result; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/cf-https-connect.c b/lib/cf-https-connect.c index 5491d7968d7e..ad815a0fe734 100644 --- a/lib/cf-https-connect.c +++ b/lib/cf-https-connect.c @@ -38,10 +38,6 @@ #include "select.h" #include "vquic/vquic.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - typedef enum { CF_HC_INIT, CF_HC_CONNECT, @@ -588,7 +584,7 @@ static CURLcode cf_hc_create(struct Curl_cfilter **pcf, CURLcode result = CURLE_OK; size_t i; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -618,7 +614,7 @@ static CURLcode cf_hc_create(struct Curl_cfilter **pcf, out: *pcf = result ? NULL : cf; - free(ctx); + curlx_free(ctx); return result; } diff --git a/lib/cf-ip-happy.c b/lib/cf-ip-happy.c index eb62cd4c73d3..8901db02c283 100644 --- a/lib/cf-ip-happy.c +++ b/lib/cf-ip-happy.c @@ -60,10 +60,6 @@ #include "select.h" #include "vquic/vquic.h" /* for quic cfilters */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - struct transport_provider { uint8_t transport; @@ -186,7 +182,7 @@ static void cf_ip_attempt_free(struct cf_ip_attempt *a, if(a) { if(a->cf) Curl_conn_cf_discard_chain(&a->cf, data); - free(a); + curlx_free(a); } } @@ -203,7 +199,7 @@ static CURLcode cf_ip_attempt_new(struct cf_ip_attempt **pa, CURLcode result = CURLE_OK; *pa = NULL; - a = calloc(1, sizeof(*a)); + a = curlx_calloc(1, sizeof(*a)); if(!a) return CURLE_OUT_OF_MEMORY; @@ -941,7 +937,7 @@ static CURLcode cf_ip_happy_create(struct Curl_cfilter **pcf, (void)data; (void)conn; *pcf = NULL; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -954,7 +950,7 @@ static CURLcode cf_ip_happy_create(struct Curl_cfilter **pcf, out: if(result) { Curl_safefree(*pcf); - free(ctx); + curlx_free(ctx); } return result; } diff --git a/lib/cf-socket.c b/lib/cf-socket.c index 6e5333602c34..3172aee5b9c9 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -82,10 +82,6 @@ #include "curlx/strerr.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(USE_IPV6) && defined(IPV6_V6ONLY) && defined(_WIN32) /* It makes support for IPv4-mapped IPv6 addresses. @@ -555,7 +551,7 @@ CURLcode Curl_parse_interface(const char *input, ++host_part; *host = Curl_memdup0(host_part, len - (host_part - input)); if(!*host) { - free(*iface); + curlx_free(*iface); *iface = NULL; return CURLE_OUT_OF_MEMORY; } @@ -1026,7 +1022,7 @@ static void cf_socket_destroy(struct Curl_cfilter *cf, struct Curl_easy *data) cf_socket_close(cf, data); CURL_TRC_CF(data, cf, "destroy"); - free(ctx); + curlx_free(ctx); cf->ctx = NULL; } @@ -1758,7 +1754,7 @@ CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf, goto out; } - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1920,7 +1916,7 @@ CURLcode Curl_cf_udp_create(struct Curl_cfilter **pcf, (void)data; (void)conn; DEBUGASSERT(transport == TRNSPRT_UDP || transport == TRNSPRT_QUIC); - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1974,7 +1970,7 @@ CURLcode Curl_cf_unix_create(struct Curl_cfilter **pcf, (void)data; (void)conn; DEBUGASSERT(transport == TRNSPRT_UNIX); - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -2199,7 +2195,7 @@ CURLcode Curl_conn_tcp_listen_set(struct Curl_easy *data, Curl_conn_cf_discard_all(data, conn, sockindex); DEBUGASSERT(conn->sock[sockindex] == CURL_SOCKET_BAD); - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/cfilters.c b/lib/cfilters.c index 7cb10f39282f..7d1f0c3d9e4f 100644 --- a/lib/cfilters.c +++ b/lib/cfilters.c @@ -37,10 +37,6 @@ #include "curlx/warnless.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void cf_cntrl_update_info(struct Curl_easy *data, struct connectdata *conn); @@ -143,7 +139,7 @@ void Curl_conn_cf_discard_chain(struct Curl_cfilter **pcf, */ cf->next = NULL; cf->cft->destroy(cf, data); - free(cf); + curlx_free(cf); cf = cfn; } } @@ -332,7 +328,7 @@ CURLcode Curl_cf_create(struct Curl_cfilter **pcf, CURLcode result = CURLE_OUT_OF_MEMORY; DEBUGASSERT(cft); - cf = calloc(1, sizeof(*cf)); + cf = curlx_calloc(1, sizeof(*cf)); if(!cf) goto out; diff --git a/lib/conncache.c b/lib/conncache.c index 9d3b69bec356..7f38a1875790 100644 --- a/lib/conncache.c +++ b/lib/conncache.c @@ -45,10 +45,6 @@ #include "curlx/strparse.h" #include "uint-table.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define CPOOL_IS_LOCKED(c) ((c) && (c)->locked) @@ -92,7 +88,7 @@ static struct cpool_bundle *cpool_bundle_create(const char *dest) struct cpool_bundle *bundle; size_t dest_len = strlen(dest) + 1; - bundle = calloc(1, sizeof(*bundle) + dest_len - 1); + bundle = curlx_calloc(1, sizeof(*bundle) + dest_len - 1); if(!bundle) return NULL; Curl_llist_init(&bundle->conns, NULL); @@ -104,7 +100,7 @@ static struct cpool_bundle *cpool_bundle_create(const char *dest) static void cpool_bundle_destroy(struct cpool_bundle *bundle) { DEBUGASSERT(!Curl_llist_count(&bundle->conns)); - free(bundle); + curlx_free(bundle); } /* Add a connection to a bundle */ diff --git a/lib/connect.c b/lib/connect.c index e29c2f51bcf8..72a27fae1cd9 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -76,10 +76,6 @@ #include "http_proxy.h" #include "socks.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if !defined(CURL_DISABLE_ALTSVC) || defined(USE_HTTPSRR) enum alpnid Curl_alpn2alpnid(const unsigned char *name, size_t len) @@ -527,7 +523,7 @@ static CURLcode cf_setup_create(struct Curl_cfilter **pcf, CURLcode result = CURLE_OK; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -544,7 +540,7 @@ static CURLcode cf_setup_create(struct Curl_cfilter **pcf, out: *pcf = result ? NULL : cf; if(ctx) { - free(ctx); + curlx_free(ctx); } return result; } diff --git a/lib/content_encoding.c b/lib/content_encoding.c index f128f7565f77..84ed86c1df3d 100644 --- a/lib/content_encoding.c +++ b/lib/content_encoding.c @@ -52,10 +52,6 @@ #include "http.h" #include "content_encoding.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define CONTENT_ENCODING_DEFAULT "identity" #ifndef CURL_DISABLE_HTTP @@ -95,15 +91,15 @@ static voidpf zalloc_cb(voidpf opaque, unsigned int items, unsigned int size) { (void)opaque; - /* not a typo, keep it calloc() */ - return (voidpf) calloc(items, size); + /* not a typo, keep it curlx_calloc() */ + return (voidpf)curlx_calloc(items, size); } static void zfree_cb(voidpf opaque, voidpf ptr) { (void)opaque; - free(ptr); + curlx_free(ptr); } static CURLcode diff --git a/lib/cookie.c b/lib/cookie.c index 6099c6ea560d..250c7390ce12 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -42,10 +42,6 @@ #include "llist.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void strstore(char **str, const char *newstr, size_t len); /* number of seconds in 400 days */ @@ -70,12 +66,12 @@ static void cap_expires(time_t now, struct Cookie *co) static void freecookie(struct Cookie *co) { - free(co->domain); - free(co->path); - free(co->spath); - free(co->name); - free(co->value); - free(co); + curlx_free(co->domain); + curlx_free(co->path); + curlx_free(co->spath); + curlx_free(co->name); + curlx_free(co->value); + curlx_free(co); } static bool cookie_tailmatch(const char *cookie_domain, @@ -246,7 +242,7 @@ static char *sanitize_cookie_path(const char *cookie_path) /* RFC6265 5.2.4 The Path Attribute */ if(cookie_path[0] != '/') /* Let cookie-path be the default-path. */ - return strdup("/"); + return curlx_strdup("/"); /* remove trailing slash when path is non-empty */ /* convert /hoge/ to /hoge */ @@ -268,7 +264,7 @@ static char *sanitize_cookie_path(const char *cookie_path) static void strstore(char **str, const char *newstr, size_t len) { DEBUGASSERT(str); - free(*str); + curlx_free(*str); if(!len) { len++; newstr = ""; @@ -506,7 +502,7 @@ parse_cookie_header(struct Curl_easy *data, strstore(&co->path, curlx_str(&val), curlx_strlen(&val)); if(!co->path) return CURLE_OUT_OF_MEMORY; - free(co->spath); /* if this is set again */ + curlx_free(co->spath); /* if this is set again */ co->spath = sanitize_cookie_path(co->path); if(!co->spath) return CURLE_OUT_OF_MEMORY; @@ -631,7 +627,7 @@ parse_cookie_header(struct Curl_easy *data, if(!co->domain && domain) { /* no domain was given in the header line, set the default */ - co->domain = strdup(domain); + co->domain = curlx_strdup(domain); if(!co->domain) return CURLE_OUT_OF_MEMORY; } @@ -739,10 +735,10 @@ parse_netscape(struct Cookie *co, break; } /* this does not look like a path, make one up! */ - co->path = strdup("/"); + co->path = curlx_strdup("/"); if(!co->path) return CURLE_OUT_OF_MEMORY; - co->spath = strdup("/"); + co->spath = curlx_strdup("/"); if(!co->spath) return CURLE_OUT_OF_MEMORY; fields++; /* add a field and fall down to secure */ @@ -781,7 +777,7 @@ parse_netscape(struct Cookie *co, } if(fields == 6) { /* we got a cookie with blank contents, fix it */ - co->value = strdup(""); + co->value = curlx_strdup(""); if(!co->value) return CURLE_OUT_OF_MEMORY; else @@ -981,7 +977,7 @@ Curl_cookie_add(struct Curl_easy *data, return CURLE_OK; /* silently ignore */ /* First, alloc and init a new struct for it */ - co = calloc(1, sizeof(struct Cookie)); + co = curlx_calloc(1, sizeof(struct Cookie)); if(!co) return CURLE_OUT_OF_MEMORY; /* bail out if we are this low on memory */ @@ -1081,7 +1077,7 @@ Curl_cookie_add(struct Curl_easy *data, struct CookieInfo *Curl_cookie_init(void) { int i; - struct CookieInfo *ci = calloc(1, sizeof(struct CookieInfo)); + struct CookieInfo *ci = curlx_calloc(1, sizeof(struct CookieInfo)); if(!ci) return NULL; @@ -1343,7 +1339,7 @@ CURLcode Curl_cookie_getlist(struct Curl_easy *data, size_t i; /* alloc an array and store all cookie pointers */ - array = malloc(sizeof(struct Cookie *) * matches); + array = curlx_malloc(sizeof(struct Cookie *) * matches); if(!array) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -1363,7 +1359,7 @@ CURLcode Curl_cookie_getlist(struct Curl_easy *data, for(i = 0; i < matches; i++) Curl_llist_append(list, array[i], &array[i]->getnode); - free(array); /* remove the temporary data again */ + curlx_free(array); /* remove the temporary data again */ } *okay = TRUE; @@ -1435,7 +1431,7 @@ void Curl_cookie_cleanup(struct CookieInfo *ci) { if(ci) { Curl_cookie_clearall(ci); - free(ci); /* free the base struct as well */ + curlx_free(ci); /* free the base struct as well */ } } @@ -1518,7 +1514,7 @@ static CURLcode cookie_output(struct Curl_easy *data, struct Cookie **array; struct Curl_llist_node *n; - array = calloc(1, sizeof(struct Cookie *) * ci->numcookies); + array = curlx_calloc(1, sizeof(struct Cookie *) * ci->numcookies); if(!array) { error = CURLE_OUT_OF_MEMORY; goto error; @@ -1540,15 +1536,15 @@ static CURLcode cookie_output(struct Curl_easy *data, for(i = 0; i < nvalid; i++) { char *format_ptr = get_netscape_format(array[i]); if(!format_ptr) { - free(array); + curlx_free(array); error = CURLE_OUT_OF_MEMORY; goto error; } curl_mfprintf(out, "%s\n", format_ptr); - free(format_ptr); + curlx_free(format_ptr); } - free(array); + curlx_free(array); } if(!use_stdout) { @@ -1565,7 +1561,7 @@ static CURLcode cookie_output(struct Curl_easy *data, * no need to inspect the error, any error case should have jumped into the * error block below. */ - free(tempstore); + curlx_free(tempstore); return CURLE_OK; error: @@ -1573,7 +1569,7 @@ static CURLcode cookie_output(struct Curl_easy *data, curlx_fclose(out); if(tempstore) { unlink(tempstore); - free(tempstore); + curlx_free(tempstore); } return error; } @@ -1605,7 +1601,7 @@ static struct curl_slist *cookie_list(struct Curl_easy *data) } beg = Curl_slist_append_nodup(list, line); if(!beg) { - free(line); + curlx_free(line); curl_slist_free_all(list); return NULL; } diff --git a/lib/cshutdn.c b/lib/cshutdn.c index e039d027625b..0a4ab416473f 100644 --- a/lib/cshutdn.c +++ b/lib/cshutdn.c @@ -42,10 +42,6 @@ #include "select.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void cshutdn_run_conn_handler(struct Curl_easy *data, struct connectdata *conn) diff --git a/lib/curl_addrinfo.c b/lib/curl_addrinfo.c index cd9b52febaa7..67c2f4177d5f 100644 --- a/lib/curl_addrinfo.c +++ b/lib/curl_addrinfo.c @@ -54,10 +54,6 @@ #include "curlx/inet_pton.h" #include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Curl_freeaddrinfo() * @@ -83,7 +79,7 @@ Curl_freeaddrinfo(struct Curl_addrinfo *cahead) for(ca = cahead; ca; ca = canext) { canext = ca->ai_next; - free(ca); + curlx_free(ca); } } @@ -146,7 +142,7 @@ Curl_getaddrinfo_ex(const char *nodename, if((size_t)ai->ai_addrlen < ss_size) continue; - ca = malloc(sizeof(struct Curl_addrinfo) + ss_size + namelen); + ca = curlx_malloc(sizeof(struct Curl_addrinfo) + ss_size + namelen); if(!ca) { error = EAI_MEMORY; break; @@ -285,7 +281,7 @@ Curl_he2ai(const struct hostent *he, int port) ss_size = sizeof(struct sockaddr_in); /* allocate memory to hold the struct, the address and the name */ - ai = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + namelen); + ai = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + namelen); if(!ai) { result = CURLE_OUT_OF_MEMORY; break; @@ -382,7 +378,7 @@ ip2addr(struct Curl_addrinfo **addrp, return CURLE_BAD_FUNCTION_ARGUMENT; /* allocate memory to hold the struct, the address and the name */ - ai = calloc(1, sizeof(struct Curl_addrinfo) + addrsize + namelen); + ai = curlx_calloc(1, sizeof(struct Curl_addrinfo) + addrsize + namelen); if(!ai) return CURLE_OUT_OF_MEMORY; /* put the address after the struct */ @@ -471,7 +467,8 @@ struct Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, *longpath = FALSE; - ai = calloc(1, sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_un)); + ai = curlx_calloc(1, + sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_un)); if(!ai) return NULL; ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo)); @@ -482,7 +479,7 @@ struct Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, /* sun_path must be able to store the null-terminated path */ path_len = strlen(path) + 1; if(path_len > sizeof(sa_un->sun_path)) { - free(ai); + curlx_free(ai); *longpath = TRUE; return NULL; } diff --git a/lib/curl_fnmatch.c b/lib/curl_fnmatch.c index 3148c472e299..918be89d4bf1 100644 --- a/lib/curl_fnmatch.c +++ b/lib/curl_fnmatch.c @@ -27,10 +27,6 @@ #include #include "curl_fnmatch.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" #ifndef HAVE_FNMATCH diff --git a/lib/curl_fopen.c b/lib/curl_fopen.c index f16b3d6cde0d..cccf849acb7d 100644 --- a/lib/curl_fopen.c +++ b/lib/curl_fopen.c @@ -31,10 +31,6 @@ #include "rand.h" #include "curl_fopen.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* The dirslash() function breaks a null-terminated pathname string into directory and filename components then returns the directory component up @@ -120,7 +116,7 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename, /* The temp filename should not end up too long for the target file system */ tempstore = curl_maprintf("%s%s.tmp", dir, randbuf); - free(dir); + curlx_free(dir); } if(!tempstore) { @@ -156,7 +152,7 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename, unlink(tempstore); } - free(tempstore); + curlx_free(tempstore); return result; } diff --git a/lib/curl_get_line.c b/lib/curl_get_line.c index d5ab7b842720..ea31eb182fa3 100644 --- a/lib/curl_get_line.c +++ b/lib/curl_get_line.c @@ -28,9 +28,6 @@ !defined(CURL_DISABLE_HSTS) || !defined(CURL_DISABLE_NETRC) #include "curl_get_line.h" -#include "curl_memory.h" -/* The last #include file should be: */ -#include "memdebug.h" #define appendnl(b) \ curlx_dyn_addn(buf, "\n", 1) diff --git a/lib/curl_gssapi.c b/lib/curl_gssapi.c index 947bb9c00631..edd555db7923 100644 --- a/lib/curl_gssapi.c +++ b/lib/curl_gssapi.c @@ -31,10 +31,8 @@ #ifdef DEBUGBUILD #if defined(HAVE_GSSGNU) || !defined(_WIN32) -/* To avoid memdebug macro replacement, wrap the name in parentheses to call - the original version. It is freed via the GSS API gss_release_buffer(). */ -#define Curl_gss_alloc (malloc) -#define Curl_gss_free (free) +#define Curl_gss_alloc malloc /* freed via the GSS API gss_release_buffer() */ +#define Curl_gss_free free /* pair of the above */ #define CURL_GSS_STUB /* For correctness this would be required for all platforms, not only Windows, but, as of v1.22.1, MIT Kerberos uses a special allocator only for Windows, @@ -51,10 +49,6 @@ #endif #endif /* DEBUGBUILD */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef __GNUC__ #define CURL_ALIGN8 __attribute__((aligned(8))) #else @@ -208,7 +202,7 @@ stub_gss_init_sec_context(OM_uint32 *min, return GSS_S_FAILURE; } - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; @@ -225,7 +219,7 @@ stub_gss_init_sec_context(OM_uint32 *min, else if(ctx->have_ntlm) ctx->sent = STUB_GSS_NTLM1; else { - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MECH; return GSS_S_FAILURE; } @@ -236,7 +230,7 @@ stub_gss_init_sec_context(OM_uint32 *min, token = Curl_gss_alloc(length); if(!token) { - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; } @@ -250,14 +244,14 @@ stub_gss_init_sec_context(OM_uint32 *min, &target_desc, &name_type); if(GSS_ERROR(major_status)) { Curl_gss_free(token); - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; } if(strlen(creds) + target_desc.length + 5 >= sizeof(ctx->creds)) { Curl_gss_free(token); - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; } @@ -273,7 +267,7 @@ stub_gss_init_sec_context(OM_uint32 *min, if(used >= length) { Curl_gss_free(token); - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; } @@ -308,7 +302,7 @@ stub_gss_delete_sec_context(OM_uint32 *min, return GSS_S_FAILURE; } - free(*context); + curlx_free(*context); *context = NULL; *min = 0; diff --git a/lib/curl_mem_undef.h b/lib/curl_mem_undef.h deleted file mode 100644 index 2be114cbd5e6..000000000000 --- a/lib/curl_mem_undef.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ - -/* Unset redefined system symbols. */ - -#undef strdup -#undef malloc -#undef calloc -#undef realloc -#undef free -#ifdef _WIN32 -#undef Curl_tcsdup -#endif - -#undef HEADER_CURL_MEMORY_H -#undef HEADER_CURL_MEMDEBUG_H diff --git a/lib/curl_memory.h b/lib/curl_memory.h deleted file mode 100644 index 7793bb63a389..000000000000 --- a/lib/curl_memory.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef HEADER_CURL_MEMORY_H -#define HEADER_CURL_MEMORY_H -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ - -/* - * Nasty internal details ahead... - * - * File curl_memory.h must be included by _all_ *.c source files - * that use memory related functions strdup, malloc, calloc, realloc - * or free, and given source file is used to build libcurl library. - * It should be included immediately before memdebug.h as the last files - * included to avoid undesired interaction with other memory function - * headers in dependent libraries. - * - * There is nearly no exception to above rule. All libcurl source - * files in 'lib' subdirectory as well as those living deep inside - * 'packages' subdirectories and linked together in order to build - * libcurl library shall follow it. - * - * File lib/strdup.c is an exception, given that it provides a strdup - * clone implementation while using malloc. Extra care needed inside - * this one. - * - * The need for curl_memory.h inclusion is due to libcurl's feature - * of allowing library user to provide memory replacement functions, - * memory callbacks, at runtime with curl_global_init_mem() - * - * Any *.c source file used to build libcurl library that does not - * include curl_memory.h and uses any memory function of the five - * mentioned above will compile without any indication, but it will - * trigger weird memory related issues at runtime. - * - */ - -#ifndef CURLDEBUG - -/* - * libcurl's 'memory tracking' system defines strdup, malloc, calloc, - * realloc and free, along with others, in memdebug.h in a different - * way although still using memory callbacks forward declared above. - * When using the 'memory tracking' system (CURLDEBUG defined) we do - * not define here the five memory functions given that definitions - * from memdebug.h are the ones that shall be used. - */ - -#undef strdup -#define strdup(ptr) Curl_cstrdup(ptr) -#undef malloc -#define malloc(size) Curl_cmalloc(size) -#undef calloc -#define calloc(nbelem,size) Curl_ccalloc(nbelem, size) -#undef realloc -#define realloc(ptr,size) Curl_crealloc(ptr, size) -#undef free -#define free(ptr) Curl_cfree(ptr) - -#ifdef _WIN32 -#undef Curl_tcsdup -#ifdef UNICODE -#define Curl_tcsdup(ptr) Curl_wcsdup(ptr) -#else -#define Curl_tcsdup(ptr) Curl_cstrdup(ptr) -#endif -#endif /* _WIN32 */ - -#endif /* CURLDEBUG */ -#endif /* HEADER_CURL_MEMORY_H */ diff --git a/lib/curl_memrchr.c b/lib/curl_memrchr.c index 5b6a39c022cc..81464584070c 100644 --- a/lib/curl_memrchr.c +++ b/lib/curl_memrchr.c @@ -27,10 +27,6 @@ #include #include "curl_memrchr.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" #ifndef HAVE_MEMRCHR /* diff --git a/lib/curl_ntlm_core.c b/lib/curl_ntlm_core.c index d013929d4da6..f2c8c2d2a659 100644 --- a/lib/curl_ntlm_core.c +++ b/lib/curl_ntlm_core.c @@ -122,10 +122,6 @@ #include "curl_endian.h" #include "curl_md4.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef USE_CURL_DES_SET_ODD_PARITY /* * curl_des_set_odd_parity() @@ -437,7 +433,7 @@ CURLcode Curl_ntlm_core_mk_nt_hash(const char *password, CURLcode result; if(len > SIZE_MAX/2) /* avoid integer overflow */ return CURLE_OUT_OF_MEMORY; - pw = len ? malloc(len * 2) : (unsigned char *)strdup(""); + pw = len ? curlx_malloc(len * 2) : (unsigned char *)curlx_strdup(""); if(!pw) return CURLE_OUT_OF_MEMORY; @@ -448,7 +444,7 @@ CURLcode Curl_ntlm_core_mk_nt_hash(const char *password, if(!result) memset(ntbuffer + 16, 0, 21 - 16); - free(pw); + curlx_free(pw); return result; } @@ -525,7 +521,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_hash(const char *user, size_t userlen, return CURLE_OUT_OF_MEMORY; identity_len = (userlen + domlen) * 2; - identity = malloc(identity_len + 1); + identity = curlx_malloc(identity_len + 1); if(!identity) return CURLE_OUT_OF_MEMORY; @@ -535,7 +531,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_hash(const char *user, size_t userlen, result = Curl_hmacit(&Curl_HMAC_MD5, ntlmhash, 16, identity, identity_len, ntlmv2hash); - free(identity); + curlx_free(identity); return result; } @@ -598,7 +594,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, len = HMAC_MD5_LENGTH + NTLMv2_BLOB_LEN; /* Allocate the response */ - ptr = calloc(1, len); + ptr = curlx_calloc(1, len); if(!ptr) return CURLE_OUT_OF_MEMORY; @@ -622,7 +618,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, result = Curl_hmacit(&Curl_HMAC_MD5, ntlmv2hash, HMAC_MD5_LENGTH, ptr + 8, NTLMv2_BLOB_LEN + 8, hmac_output); if(result) { - free(ptr); + curlx_free(ptr); return result; } diff --git a/lib/curl_rtmp.c b/lib/curl_rtmp.c index 2d2daf414897..351c9f494c3f 100644 --- a/lib/curl_rtmp.c +++ b/lib/curl_rtmp.c @@ -37,10 +37,6 @@ #include #include -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(_WIN32) && !defined(USE_LWIPSOCK) #define setsockopt(a,b,c,d,e) (setsockopt)(a,b,c,(const char *)d,(int)e) #define SET_RCVTIMEO(tv,s) int tv = s*1000 diff --git a/lib/curl_sasl.c b/lib/curl_sasl.c index f6ec668bfd45..aef47dc0162e 100644 --- a/lib/curl_sasl.c +++ b/lib/curl_sasl.c @@ -51,10 +51,6 @@ #include "curlx/warnless.h" #include "sendf.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Supported mechanisms */ static const struct { const char *name; /* Name */ diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 6236a7153923..6acac0d17ad0 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -941,7 +941,7 @@ extern curl_calloc_callback Curl_ccalloc; * This macro also assigns NULL to given pointer when free'd. */ #define Curl_safefree(ptr) \ - do { free(ptr); (ptr) = NULL;} while(0) + do { curlx_free(ptr); (ptr) = NULL;} while(0) #include /* for CURL_EXTERN, mprintf.h */ @@ -1077,6 +1077,56 @@ CURL_EXTERN ALLOC_FUNC #endif /* CURLDEBUG */ +/* Allocator macros */ + +#ifdef CURLDEBUG + +#define curlx_strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__) +#define curlx_malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) +#define curlx_calloc(nbelem,size) \ + curl_dbg_calloc(nbelem, size, __LINE__, __FILE__) +#define curlx_realloc(ptr,size) \ + curl_dbg_realloc(ptr, size, __LINE__, __FILE__) +#define curlx_free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__) + +#ifdef _WIN32 +#ifdef UNICODE +#define curlx_tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__) +#else +#define curlx_tcsdup(ptr) curlx_strdup(ptr) +#endif +#endif /* _WIN32 */ + +#else /* !CURLDEBUG */ + +#ifdef BUILDING_LIBCURL +#define curlx_strdup(ptr) Curl_cstrdup(ptr) +#define curlx_malloc(size) Curl_cmalloc(size) +#define curlx_calloc(nbelem,size) Curl_ccalloc(nbelem, size) +#define curlx_realloc(ptr,size) Curl_crealloc(ptr, size) +#define curlx_free(ptr) Curl_cfree(ptr) +#else /* !BUILDING_LIBCURL */ +#ifdef _WIN32 +#define curlx_strdup(ptr) _strdup(ptr) +#else +#define curlx_strdup(ptr) strdup(ptr) +#endif +#define curlx_malloc(size) malloc(size) +#define curlx_calloc(nbelem,size) calloc(nbelem, size) +#define curlx_realloc(ptr,size) realloc(ptr, size) +#define curlx_free(ptr) free(ptr) +#endif /* BUILDING_LIBCURL */ + +#ifdef _WIN32 +#ifdef UNICODE +#define curlx_tcsdup(ptr) Curl_wcsdup(ptr) +#else +#define curlx_tcsdup(ptr) curlx_strdup(ptr) +#endif +#endif /* _WIN32 */ + +#endif /* CURLDEBUG */ + /* Some versions of the Android NDK is missing the declaration */ #if defined(HAVE_GETPWUID_R) && \ defined(__ANDROID_API__) && (__ANDROID_API__ < 21) @@ -1167,5 +1217,3 @@ int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, #endif #endif /* HEADER_CURL_SETUP_H */ - -#include "curl_mem_undef.h" diff --git a/lib/curl_share.c b/lib/curl_share.c index b65d16c6281f..c6b51267046f 100644 --- a/lib/curl_share.c +++ b/lib/curl_share.c @@ -34,21 +34,17 @@ #include "hsts.h" #include "url.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - CURLSH * curl_share_init(void) { - struct Curl_share *share = calloc(1, sizeof(struct Curl_share)); + struct Curl_share *share = curlx_calloc(1, sizeof(struct Curl_share)); if(share) { share->magic = CURL_GOOD_SHARE; share->specifier |= (1 << CURL_LOCK_DATA_SHARE); Curl_dnscache_init(&share->dnscache, 23); share->admin = curl_easy_init(); if(!share->admin) { - free(share); + curlx_free(share); return NULL; } /* admin handles have mid 0 */ @@ -272,7 +268,7 @@ curl_share_cleanup(CURLSH *sh) if(share->unlockfunc) share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); share->magic = 0; - free(share); + curlx_free(share); return CURLSHE_OK; } diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index 369cf18967a3..264703d8cd70 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -33,10 +33,6 @@ #include "system_win32.h" #include "curlx/warnless.h" -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* Pointer to SSPI dispatch table */ PSecurityFunctionTable Curl_pSecFn = NULL; @@ -134,7 +130,7 @@ CURLcode Curl_create_sspi_identity(const char *userp, const char *passwdp, } /* Setup the identity's user and length */ - dup_user.tchar_ptr = Curl_tcsdup(user.tchar_ptr); + dup_user.tchar_ptr = curlx_tcsdup(user.tchar_ptr); if(!dup_user.tchar_ptr) { curlx_unicodefree(useranddomain.tchar_ptr); return CURLE_OUT_OF_MEMORY; @@ -144,7 +140,7 @@ CURLcode Curl_create_sspi_identity(const char *userp, const char *passwdp, dup_user.tchar_ptr = NULL; /* Setup the identity's domain and length */ - dup_domain.tchar_ptr = malloc(sizeof(TCHAR) * (domlen + 1)); + dup_domain.tchar_ptr = curlx_malloc(sizeof(TCHAR) * (domlen + 1)); if(!dup_domain.tchar_ptr) { curlx_unicodefree(useranddomain.tchar_ptr); return CURLE_OUT_OF_MEMORY; @@ -164,7 +160,7 @@ CURLcode Curl_create_sspi_identity(const char *userp, const char *passwdp, passwd.tchar_ptr = curlx_convert_UTF8_to_tchar(passwdp); if(!passwd.tchar_ptr) return CURLE_OUT_OF_MEMORY; - dup_passwd.tchar_ptr = Curl_tcsdup(passwd.tchar_ptr); + dup_passwd.tchar_ptr = curlx_tcsdup(passwd.tchar_ptr); if(!dup_passwd.tchar_ptr) { curlx_unicodefree(passwd.tchar_ptr); return CURLE_OUT_OF_MEMORY; diff --git a/lib/curl_threads.c b/lib/curl_threads.c index a0308f06b2dc..e4536078be39 100644 --- a/lib/curl_threads.c +++ b/lib/curl_threads.c @@ -31,9 +31,6 @@ #endif #include "curl_threads.h" -#include "curl_memory.h" -/* The last #include FILE should be: */ -#include "memdebug.h" #ifdef USE_THREADS_POSIX @@ -48,7 +45,7 @@ static void *curl_thread_create_thunk(void *arg) unsigned int (*func)(void *) = ac->func; void *real_arg = ac->arg; - free(ac); + curlx_free(ac); (*func)(real_arg); @@ -58,8 +55,8 @@ static void *curl_thread_create_thunk(void *arg) curl_thread_t Curl_thread_create(CURL_THREAD_RETURN_T (CURL_STDCALL *func) (void *), void *arg) { - curl_thread_t t = malloc(sizeof(pthread_t)); - struct Curl_actual_call *ac = malloc(sizeof(struct Curl_actual_call)); + curl_thread_t t = curlx_malloc(sizeof(pthread_t)); + struct Curl_actual_call *ac = curlx_malloc(sizeof(struct Curl_actual_call)); int rc; if(!(ac && t)) goto err; @@ -76,8 +73,8 @@ curl_thread_t Curl_thread_create(CURL_THREAD_RETURN_T return t; err: - free(t); - free(ac); + curlx_free(t); + curlx_free(ac); return curl_thread_t_null; } @@ -85,7 +82,7 @@ void Curl_thread_destroy(curl_thread_t *hnd) { if(*hnd != curl_thread_t_null) { pthread_detach(**hnd); - free(*hnd); + curlx_free(*hnd); *hnd = curl_thread_t_null; } } @@ -94,7 +91,7 @@ int Curl_thread_join(curl_thread_t *hnd) { int ret = (pthread_join(**hnd, NULL) == 0); - free(*hnd); + curlx_free(*hnd); *hnd = curl_thread_t_null; return ret; diff --git a/lib/curl_trc.c b/lib/curl_trc.c index 0b91315e3668..cc06c77e9d9a 100644 --- a/lib/curl_trc.c +++ b/lib/curl_trc.c @@ -47,10 +47,6 @@ #include "vtls/vtls.h" #include "vquic/vquic.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void trc_write(struct Curl_easy *data, curl_infotype type, const char *ptr, size_t size) { diff --git a/lib/curlx/base64.c b/lib/curlx/base64.c index 3fcd709d1ce8..6a24c20ebdfb 100644 --- a/lib/curlx/base64.c +++ b/lib/curlx/base64.c @@ -30,12 +30,6 @@ #include "warnless.h" #include "base64.h" -/* The last 2 #include files should be in this order */ -#ifdef BUILDING_LIBCURL -#include "../curl_memory.h" -#endif -#include "../memdebug.h" - /* ---- Base64 Encoding/Decoding Table --- */ const char Curl_base64encdec[]= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -103,7 +97,7 @@ CURLcode curlx_base64_decode(const char *src, rawlen = (numQuantums * 3) - padding; /* Allocate our buffer including room for a null-terminator */ - newstr = malloc(rawlen + 1); + newstr = curlx_malloc(rawlen + 1); if(!newstr) return CURLE_OUT_OF_MEMORY; @@ -165,7 +159,7 @@ CURLcode curlx_base64_decode(const char *src, return CURLE_OK; bad: - free(newstr); + curlx_free(newstr); return CURLE_BAD_CONTENT_ENCODING; } @@ -189,7 +183,7 @@ static CURLcode base64_encode(const char *table64, if(insize > CURL_MAX_BASE64_INPUT) return CURLE_TOO_LARGE; - base64data = output = malloc((insize + 2) / 3 * 4 + 1); + base64data = output = curlx_malloc((insize + 2) / 3 * 4 + 1); if(!output) return CURLE_OUT_OF_MEMORY; diff --git a/lib/curlx/dynbuf.c b/lib/curlx/dynbuf.c index 447203e42a8a..e54865f933c7 100644 --- a/lib/curlx/dynbuf.c +++ b/lib/curlx/dynbuf.c @@ -25,10 +25,6 @@ #include "../curl_setup.h" #include "dynbuf.h" #include "../curl_printf.h" -#ifdef BUILDING_LIBCURL -#include "../curl_memory.h" -#endif -#include "../memdebug.h" #define MIN_FIRST_ALLOC 32 @@ -108,7 +104,7 @@ static CURLcode dyn_nappend(struct dynbuf *s, if(a != s->allc) { /* this logic is not using Curl_saferealloc() to make the tool not have to include that as well when it uses this code */ - void *p = realloc(s->bufr, a); + void *p = curlx_realloc(s->bufr, a); if(!p) { curlx_dyn_free(s); return CURLE_OUT_OF_MEMORY; @@ -212,7 +208,7 @@ CURLcode curlx_dyn_vaddf(struct dynbuf *s, const char *fmt, va_list ap) if(str) { CURLcode result = dyn_nappend(s, (const unsigned char *)str, strlen(str)); - free(str); + curlx_free(str); return result; } /* If we failed, we cleanup the whole buffer and return error */ diff --git a/lib/curlx/fopen.c b/lib/curlx/fopen.c index 0dc9699206cd..c8dff428fc94 100644 --- a/lib/curlx/fopen.c +++ b/lib/curlx/fopen.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) Daniel Stenberg, , et al. + * Copyright (C) Danieal Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -23,11 +23,8 @@ ***************************************************************************/ /* - * This file is 'mem-include-scan' clean, which means its memory allocations - * are not tracked by the curl memory tracker memdebug, so they must not use - * `CURLDEBUG` macro replacements in memdebug.h for free, malloc, etc. To avoid - * these macro replacements, wrap the names in parentheses to call the original - * versions: `ptr = (malloc)(123)`, `(free)(ptr)`, etc. + * Use system allocators to avoid infinite recursion when called by curl's + * memory tracker memdebug functions. */ #include "../curl_setup.h" @@ -103,7 +100,8 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) goto cleanup; if(!needed || needed >= max_path_len) goto cleanup; - ibuf = (malloc)(needed * sizeof(wchar_t)); + /* !checksrc! disable BANNEDFUNC 1 */ + ibuf = malloc(needed * sizeof(wchar_t)); if(!ibuf) goto cleanup; if(mbstowcs_s(&count, ibuf, needed, in, needed - 1)) @@ -124,7 +122,8 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) /* skip paths that are not excessive and do not need modification */ if(needed <= MAX_PATH) goto cleanup; - fbuf = (malloc)(needed * sizeof(wchar_t)); + /* !checksrc! disable BANNEDFUNC 1 */ + fbuf = malloc(needed * sizeof(wchar_t)); if(!fbuf) goto cleanup; count = (size_t)GetFullPathNameW(in_w, (DWORD)needed, fbuf, NULL); @@ -157,16 +156,19 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) if(needed > max_path_len) goto cleanup; - temp = (malloc)(needed * sizeof(wchar_t)); + /* !checksrc! disable BANNEDFUNC 1 */ + temp = malloc(needed * sizeof(wchar_t)); if(!temp) goto cleanup; if(wcsncpy_s(temp, needed, L"\\\\?\\UNC\\", 8)) { - (free)(temp); + /* !checksrc! disable BANNEDFUNC 1 */ + free(temp); goto cleanup; } if(wcscpy_s(temp + 8, needed, fbuf + 2)) { - (free)(temp); + /* !checksrc! disable BANNEDFUNC 1 */ + free(temp); goto cleanup; } } @@ -176,21 +178,25 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) if(needed > max_path_len) goto cleanup; - temp = (malloc)(needed * sizeof(wchar_t)); + /* !checksrc! disable BANNEDFUNC 1 */ + temp = malloc(needed * sizeof(wchar_t)); if(!temp) goto cleanup; if(wcsncpy_s(temp, needed, L"\\\\?\\", 4)) { - (free)(temp); + /* !checksrc! disable BANNEDFUNC 1 */ + free(temp); goto cleanup; } if(wcscpy_s(temp + 4, needed, fbuf)) { - (free)(temp); + /* !checksrc! disable BANNEDFUNC 1 */ + free(temp); goto cleanup; } } - (free)(fbuf); + /* !checksrc! disable BANNEDFUNC 1 */ + free(fbuf); fbuf = temp; } @@ -200,7 +206,8 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) goto cleanup; if(!needed || needed >= max_path_len) goto cleanup; - obuf = (malloc)(needed); + /* !checksrc! disable BANNEDFUNC 1 */ + obuf = malloc(needed); if(!obuf) goto cleanup; if(wcstombs_s(&count, obuf, needed, fbuf, needed - 1)) @@ -215,10 +222,12 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) #endif cleanup: - (free)(fbuf); + /* !checksrc! disable BANNEDFUNC 1 */ + free(fbuf); #ifndef _UNICODE - (free)(ibuf); - (free)(obuf); + /* !checksrc! disable BANNEDFUNC 2 */ + free(ibuf); + free(obuf); #endif return *out ? true : false; } @@ -260,7 +269,8 @@ int curlx_win32_open(const char *filename, int oflag, ...) errno = _sopen_s(&result, target, oflag, _SH_DENYNO, pmode); #endif - (free)(fixed); + /* !checksrc! disable BANNEDFUNC 1 */ + free(fixed); return result; } @@ -293,7 +303,8 @@ FILE *curlx_win32_fopen(const char *filename, const char *mode) errno = fopen_s(&result, target, mode); #endif - (free)(fixed); + /* !checksrc! disable BANNEDFUNC 1 */ + free(fixed); return result; } @@ -331,7 +342,8 @@ FILE *curlx_win32_freopen(const char *filename, const char *mode, FILE *fp) errno = freopen_s(&result, target, mode, fp); #endif - (free)(fixed); + /* !checksrc! disable BANNEDFUNC 1 */ + free(fixed); return result; } @@ -370,7 +382,8 @@ int curlx_win32_stat(const char *path, struct_stat *buffer) #endif #endif - (free)(fixed); + /* !checksrc! disable BANNEDFUNC 1 */ + free(fixed); return result; } diff --git a/lib/curlx/multibyte.c b/lib/curlx/multibyte.c index 9e60edf7e3e2..2583f3087031 100644 --- a/lib/curlx/multibyte.c +++ b/lib/curlx/multibyte.c @@ -23,11 +23,8 @@ ***************************************************************************/ /* - * This file is 'mem-include-scan' clean, which means its memory allocations - * are not tracked by the curl memory tracker memdebug, so they must not use - * `CURLDEBUG` macro replacements in memdebug.h for free, malloc, etc. To avoid - * these macro replacements, wrap the names in parentheses to call the original - * versions: `ptr = (malloc)(123)`, `(free)(ptr)`, etc. + * Use system allocators to avoid infinite recursion when called by curl's + * memory tracker memdebug functions. */ #include "../curl_setup.h" @@ -48,11 +45,13 @@ wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8) int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str_utf8, -1, NULL, 0); if(str_w_len > 0) { - str_w = (malloc)(str_w_len * sizeof(wchar_t)); + /* !checksrc! disable BANNEDFUNC 1 */ + str_w = malloc(str_w_len * sizeof(wchar_t)); if(str_w) { if(MultiByteToWideChar(CP_UTF8, 0, str_utf8, -1, str_w, str_w_len) == 0) { - (free)(str_w); + /* !checksrc! disable BANNEDFUNC 1 */ + free(str_w); return NULL; } } @@ -70,11 +69,13 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w) int bytes = WideCharToMultiByte(CP_UTF8, 0, str_w, -1, NULL, 0, NULL, NULL); if(bytes > 0) { - str_utf8 = (malloc)(bytes); + /* !checksrc! disable BANNEDFUNC 1 */ + str_utf8 = malloc(bytes); if(str_utf8) { if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, bytes, NULL, NULL) == 0) { - (free)(str_utf8); + /* !checksrc! disable BANNEDFUNC 1 */ + free(str_utf8); return NULL; } } diff --git a/lib/curlx/multibyte.h b/lib/curlx/multibyte.h index 8b698c1b7357..c992214a9575 100644 --- a/lib/curlx/multibyte.h +++ b/lib/curlx/multibyte.h @@ -44,11 +44,8 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w); * * Allocated memory should be free'd with curlx_unicodefree(). * - * Note: Because these are curlx functions their memory usage is not tracked - * by the curl memory tracker memdebug. you will notice that curlx - * function-like macros call free and strdup in parentheses, eg (strdup)(ptr), - * and that is to ensure that the curl memdebug override macros do not replace - * them. + * Use system allocators to avoid infinite recursion when called by curl's + * memory tracker memdebug functions. */ #if defined(UNICODE) && defined(_WIN32) @@ -65,8 +62,13 @@ typedef union { #else -#define curlx_convert_UTF8_to_tchar(ptr) (strdup)(ptr) -#define curlx_convert_tchar_to_UTF8(ptr) (strdup)(ptr) +#ifdef _WIN32 +#define curlx_convert_UTF8_to_tchar(ptr) _strdup(ptr) +#define curlx_convert_tchar_to_UTF8(ptr) _strdup(ptr) +#else +#define curlx_convert_UTF8_to_tchar(ptr) strdup(ptr) +#define curlx_convert_tchar_to_UTF8(ptr) strdup(ptr) +#endif typedef union { char *tchar_ptr; @@ -78,6 +80,6 @@ typedef union { #endif /* UNICODE && _WIN32 */ /* the purpose of this macro is to free() without being traced by memdebug */ -#define curlx_unicodefree(ptr) (free)(ptr) +#define curlx_unicodefree(ptr) free(ptr) #endif /* HEADER_CURL_MULTIBYTE_H */ diff --git a/lib/curlx/strerr.c b/lib/curlx/strerr.c index c33d10701125..3dbeab82ee57 100644 --- a/lib/curlx/strerr.c +++ b/lib/curlx/strerr.c @@ -37,9 +37,6 @@ #include "winapi.h" #include "snprintf.h" #include "strerr.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" #ifdef USE_WINSOCK /* This is a helper function for curlx_strerror that converts Winsock error diff --git a/lib/curlx/version_win32.c b/lib/curlx/version_win32.c index cc86b71d3e3d..9ab72c2fd5b9 100644 --- a/lib/curlx/version_win32.c +++ b/lib/curlx/version_win32.c @@ -30,10 +30,6 @@ #include "version_win32.h" #include "warnless.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* This Unicode version struct works for VerifyVersionInfoW (OSVERSIONINFOEXW) and RtlVerifyVersionInfo (RTLOSVERSIONINFOEXW) */ struct OUR_OSVERSIONINFOEXW { diff --git a/lib/cw-out.c b/lib/cw-out.c index 36cfc36aca04..4561546d197d 100644 --- a/lib/cw-out.c +++ b/lib/cw-out.c @@ -35,10 +35,6 @@ #include "cw-out.h" #include "cw-pause.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /** * OVERALL DESIGN of this client writer @@ -85,7 +81,7 @@ struct cw_out_buf { static struct cw_out_buf *cw_out_buf_create(cw_out_type otype) { - struct cw_out_buf *cwbuf = calloc(1, sizeof(*cwbuf)); + struct cw_out_buf *cwbuf = curlx_calloc(1, sizeof(*cwbuf)); if(cwbuf) { cwbuf->type = otype; curlx_dyn_init(&cwbuf->b, DYN_PAUSE_BUFFER); @@ -97,7 +93,7 @@ static void cw_out_buf_free(struct cw_out_buf *cwbuf) { if(cwbuf) { curlx_dyn_free(&cwbuf->b); - free(cwbuf); + curlx_free(cwbuf); } } diff --git a/lib/cw-pause.c b/lib/cw-pause.c index 1af4e8fa4192..2a98667ae4ff 100644 --- a/lib/cw-pause.c +++ b/lib/cw-pause.c @@ -34,10 +34,6 @@ #include "sendf.h" #include "cw-pause.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* body dynbuf sizes */ #define CW_PAUSE_BUF_CHUNK (16 * 1024) @@ -52,7 +48,7 @@ struct cw_pause_buf { static struct cw_pause_buf *cw_pause_buf_create(int type, size_t buflen) { - struct cw_pause_buf *cwbuf = calloc(1, sizeof(*cwbuf)); + struct cw_pause_buf *cwbuf = curlx_calloc(1, sizeof(*cwbuf)); if(cwbuf) { cwbuf->type = type; if(type & CLIENTWRITE_BODY) @@ -68,7 +64,7 @@ static void cw_pause_buf_free(struct cw_pause_buf *cwbuf) { if(cwbuf) { Curl_bufq_free(&cwbuf->b); - free(cwbuf); + curlx_free(cwbuf); } } diff --git a/lib/dict.c b/lib/dict.c index 5c7ba7f6229f..f208892f7302 100644 --- a/lib/dict.c +++ b/lib/dict.c @@ -60,11 +60,6 @@ #include "progress.h" #include "dict.h" -/* The last 2 #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - - #define DICT_MATCH "/MATCH:" #define DICT_MATCH2 "/M:" #define DICT_MATCH3 "/FIND:" @@ -172,7 +167,7 @@ static CURLcode sendf(struct Curl_easy *data, const char *fmt, ...) break; } - free(s); /* free the output string */ + curlx_free(s); /* free the output string */ return result; } @@ -310,8 +305,8 @@ static CURLcode dict_do(struct Curl_easy *data, bool *done) } error: - free(eword); - free(path); + curlx_free(eword); + curlx_free(path); return result; } #endif /* CURL_DISABLE_DICT */ diff --git a/lib/dllmain.c b/lib/dllmain.c index 011090589bb0..7b7d3c7e2e10 100644 --- a/lib/dllmain.c +++ b/lib/dllmain.c @@ -28,10 +28,6 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* DllMain() must only be defined for Windows DLL builds. */ #if defined(_WIN32) && !defined(CURL_STATICLIB) diff --git a/lib/doh.c b/lib/doh.c index 0712981a97ec..d7b1d54c25e8 100644 --- a/lib/doh.c +++ b/lib/doh.c @@ -41,10 +41,6 @@ #include "escape.h" #include "urlapi-int.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define DNS_CLASS_IN 0x01 #ifndef CURL_DISABLE_VERBOSE_STRINGS @@ -269,7 +265,7 @@ static void doh_probe_dtor(void *key, size_t klen, void *e) struct doh_request *doh_req = e; curl_slist_free_all(doh_req->req_hds); curlx_dyn_free(&doh_req->resp_body); - free(e); + curlx_free(e); } } @@ -296,7 +292,7 @@ static CURLcode doh_probe_run(struct Curl_easy *data, *pmid = UINT32_MAX; - doh_req = calloc(1, sizeof(*doh_req)); + doh_req = curlx_calloc(1, sizeof(*doh_req)); if(!doh_req) return CURLE_OUT_OF_MEMORY; doh_req->dnstype = dnstype; @@ -462,12 +458,12 @@ CURLcode Curl_doh(struct Curl_easy *data, const char *hostname, data->state.async.done = FALSE; data->state.async.port = port; data->state.async.ip_version = ip_version; - data->state.async.hostname = strdup(hostname); + data->state.async.hostname = curlx_strdup(hostname); if(!data->state.async.hostname) return CURLE_OUT_OF_MEMORY; /* start clean, consider allocating this struct on demand */ - data->state.async.doh = dohp = calloc(1, sizeof(struct doh_probes)); + data->state.async.doh = dohp = curlx_calloc(1, sizeof(struct doh_probes)); if(!dohp) return CURLE_OUT_OF_MEMORY; @@ -518,7 +514,7 @@ CURLcode Curl_doh(struct Curl_easy *data, const char *hostname, qname ? qname : hostname, data->set.str[STRING_DOH], data->multi, &dohp->probe_resp[DOH_SLOT_HTTPS_RR].probe_mid); - free(qname); + curlx_free(qname); if(result) goto error; dohp->pending++; @@ -963,7 +959,7 @@ static CURLcode doh2ai(const struct dohentry *de, const char *hostname, addrtype = AF_INET; } - ai = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen); + ai = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen); if(!ai) { result = CURLE_OUT_OF_MEMORY; break; @@ -1130,7 +1126,7 @@ UNITTEST CURLcode doh_resp_decode_httpsrr(struct Curl_easy *data, *hrr = NULL; if(len <= 2) return CURLE_BAD_FUNCTION_ARGUMENT; - lhrr = calloc(1, sizeof(struct Curl_https_rrinfo)); + lhrr = curlx_calloc(1, sizeof(struct Curl_https_rrinfo)); if(!lhrr) return CURLE_OUT_OF_MEMORY; lhrr->priority = doh_get16bit(cp, 0); diff --git a/lib/dynhds.c b/lib/dynhds.c index 95d415bf0b49..ebe1beae5856 100644 --- a/lib/dynhds.c +++ b/lib/dynhds.c @@ -31,10 +31,6 @@ #include #endif /* USE_NGHTTP2 */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static struct dynhds_entry * entry_new(const char *name, size_t namelen, @@ -45,7 +41,7 @@ entry_new(const char *name, size_t namelen, DEBUGASSERT(name); DEBUGASSERT(value); - e = calloc(1, sizeof(*e) + namelen + valuelen + 2); + e = curlx_calloc(1, sizeof(*e) + namelen + valuelen + 2); if(!e) return NULL; e->name = p = ((char *)e) + sizeof(*e); @@ -68,7 +64,7 @@ entry_append(struct dynhds_entry *e, char *p; DEBUGASSERT(value); - e2 = calloc(1, sizeof(*e) + e->namelen + valuelen2 + 2); + e2 = curlx_calloc(1, sizeof(*e) + e->namelen + valuelen2 + 2); if(!e2) return NULL; e2->name = p = ((char *)e2) + sizeof(*e2); @@ -85,7 +81,7 @@ entry_append(struct dynhds_entry *e, static void entry_free(struct dynhds_entry *e) { - free(e); + curlx_free(e); } void Curl_dynhds_init(struct dynhds *dynhds, size_t max_entries, @@ -186,7 +182,7 @@ entry = entry_new(name, namelen, value, valuelen, dynhds->opts); if(dynhds->max_entries && nallc > dynhds->max_entries) nallc = dynhds->max_entries; - nhds = calloc(nallc, sizeof(struct dynhds_entry *)); + nhds = curlx_calloc(nallc, sizeof(struct dynhds_entry *)); if(!nhds) goto out; if(dynhds->hds) { @@ -374,7 +370,7 @@ CURLcode Curl_dynhds_h1_dprint(struct dynhds *dynhds, struct dynbuf *dbuf) nghttp2_nv *Curl_dynhds_to_nva(struct dynhds *dynhds, size_t *pcount) { - nghttp2_nv *nva = calloc(1, sizeof(nghttp2_nv) * dynhds->hds_len); + nghttp2_nv *nva = curlx_calloc(1, sizeof(nghttp2_nv) * dynhds->hds_len); size_t i; *pcount = 0; diff --git a/lib/easy.c b/lib/easy.c index db6c419c5771..476f63c74dff 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -80,10 +80,6 @@ #include "easy_lock.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* true globals -- for curl_global_init() and curl_global_cleanup() */ static unsigned int initialized; static long easy_init_flags; @@ -198,7 +194,7 @@ static CURLcode global_init(long flags, bool memoryfuncs) #ifdef DEBUGBUILD if(getenv("CURL_GLOBAL_INIT")) /* alloc data that will leak if *cleanup() is not called! */ - leakpointer = malloc(1); + leakpointer = curlx_malloc(1); #endif return CURLE_OK; @@ -297,7 +293,7 @@ void curl_global_cleanup(void) Curl_ssh_cleanup(); #ifdef DEBUGBUILD - free(leakpointer); + curlx_free(leakpointer); #endif easy_init_flags = 0; @@ -478,7 +474,7 @@ static int events_socket(CURL *easy, /* easy handle */ prev->next = nxt; else ev->list = nxt; - free(m); + curlx_free(m); infof(data, "socket cb: socket %" FMT_SOCKET_T " REMOVED", s); } else { @@ -504,7 +500,7 @@ static int events_socket(CURL *easy, /* easy handle */ DEBUGASSERT(0); } else { - m = malloc(sizeof(struct socketmonitor)); + m = curlx_malloc(sizeof(struct socketmonitor)); if(m) { m->next = ev->list; m->socket.fd = s; @@ -927,7 +923,7 @@ static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src) i = STRING_COPYPOSTFIELDS; if(src->set.str[i]) { if(src->set.postfieldsize == -1) - dst->set.str[i] = strdup(src->set.str[i]); + dst->set.str[i] = curlx_strdup(src->set.str[i]); else /* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */ dst->set.str[i] = Curl_memdup(src->set.str[i], @@ -968,7 +964,7 @@ CURL *curl_easy_duphandle(CURL *d) if(!GOOD_EASY_HANDLE(data)) goto fail; - outcurl = calloc(1, sizeof(struct Curl_easy)); + outcurl = curlx_calloc(1, sizeof(struct Curl_easy)); if(!outcurl) goto fail; @@ -1022,14 +1018,14 @@ CURL *curl_easy_duphandle(CURL *d) #endif if(data->state.url) { - outcurl->state.url = strdup(data->state.url); + outcurl->state.url = curlx_strdup(data->state.url); if(!outcurl->state.url) goto fail; outcurl->state.url_alloc = TRUE; } if(data->state.referer) { - outcurl->state.referer = strdup(data->state.referer); + outcurl->state.referer = curlx_strdup(data->state.referer); if(!outcurl->state.referer) goto fail; outcurl->state.referer_alloc = TRUE; @@ -1073,13 +1069,13 @@ CURL *curl_easy_duphandle(CURL *d) if(outcurl) { #ifndef CURL_DISABLE_COOKIES - free(outcurl->cookies); + curlx_free(outcurl->cookies); #endif curlx_dyn_free(&outcurl->state.headerb); Curl_altsvc_cleanup(&outcurl->asi); Curl_hsts_cleanup(&outcurl->hsts); Curl_freeset(outcurl); - free(outcurl); + curlx_free(outcurl); } return NULL; diff --git a/lib/escape.c b/lib/escape.c index fdc6e438ab3e..04b46f7a9e26 100644 --- a/lib/escape.c +++ b/lib/escape.c @@ -37,10 +37,6 @@ struct Curl_easy; #include "curlx/strparse.h" #include "curl_printf.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* for ABI-compatibility with previous versions */ char *curl_escape(const char *string, int inlength) { @@ -68,7 +64,7 @@ char *curl_easy_escape(CURL *data, const char *string, length = (inlength ? (size_t)inlength : strlen(string)); if(!length) - return strdup(""); + return curlx_strdup(""); curlx_dyn_init(&d, length * 3 + 1); @@ -120,7 +116,7 @@ CURLcode Curl_urldecode(const char *string, size_t length, DEBUGASSERT(ctrl >= REJECT_NADA); /* crash on TRUE/FALSE */ alloc = (length ? length : strlen(string)); - ns = malloc(alloc + 1); + ns = curlx_malloc(alloc + 1); if(!ns) return CURLE_OUT_OF_MEMORY; @@ -196,7 +192,7 @@ char *curl_easy_unescape(CURL *data, const char *string, the library's memory system */ void curl_free(void *p) { - free(p); + curlx_free(p); } /* diff --git a/lib/fake_addrinfo.c b/lib/fake_addrinfo.c index 9789d1ef62bd..7d5da09ead53 100644 --- a/lib/fake_addrinfo.c +++ b/lib/fake_addrinfo.c @@ -31,10 +31,6 @@ #include #include -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - void r_freeaddrinfo(struct addrinfo *cahead) { struct addrinfo *canext; @@ -42,7 +38,7 @@ void r_freeaddrinfo(struct addrinfo *cahead) for(ca = cahead; ca; ca = canext) { canext = ca->ai_next; - free(ca); + curlx_free(ca); } } @@ -90,7 +86,7 @@ static struct addrinfo *mk_getaddrinfo(const struct ares_addrinfo *aihead) if((size_t)ai->ai_addrlen < ss_size) continue; - ca = malloc(sizeof(struct addrinfo) + ss_size + namelen); + ca = curlx_malloc(sizeof(struct addrinfo) + ss_size + namelen); if(!ca) { r_freeaddrinfo(cafirst); return NULL; diff --git a/lib/file.c b/lib/file.c index 3de92408c490..2f30a0297ca6 100644 --- a/lib/file.c +++ b/lib/file.c @@ -68,10 +68,6 @@ #include "curlx/warnless.h" #include "curl_range.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(_WIN32) || defined(MSDOS) #define DOS_FILESYSTEM 1 #elif defined(__amigaos4__) @@ -148,7 +144,7 @@ static void file_easy_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; file_cleanup(file); - free(file); + curlx_free(file); } static CURLcode file_setup_connection(struct Curl_easy *data, @@ -157,7 +153,7 @@ static CURLcode file_setup_connection(struct Curl_easy *data, struct FILEPROTO *filep; (void)conn; /* allocate the FILE specific struct */ - filep = calloc(1, sizeof(*filep)); + filep = curlx_calloc(1, sizeof(*filep)); if(!filep || Curl_meta_set(data, CURL_META_FILE_EASY, filep, file_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -269,7 +265,7 @@ static CURLcode file_connect(struct Curl_easy *data, bool *done) file->path = real_path; #endif #endif - free(file->freepath); + curlx_free(file->freepath); file->freepath = real_path; /* free this when done */ file->fd = fd; diff --git a/lib/fileinfo.c b/lib/fileinfo.c index bddd3fe6fbb1..83d2ef0d005f 100644 --- a/lib/fileinfo.c +++ b/lib/fileinfo.c @@ -27,13 +27,10 @@ #ifndef CURL_DISABLE_FTP #include "fileinfo.h" -#include "curl_memory.h" -/* The last #include file should be: */ -#include "memdebug.h" struct fileinfo *Curl_fileinfo_alloc(void) { - return calloc(1, sizeof(struct fileinfo)); + return curlx_calloc(1, sizeof(struct fileinfo)); } void Curl_fileinfo_cleanup(struct fileinfo *finfo) @@ -42,7 +39,7 @@ void Curl_fileinfo_cleanup(struct fileinfo *finfo) return; curlx_dyn_free(&finfo->buf); - free(finfo); + curlx_free(finfo); } #endif diff --git a/lib/formdata.c b/lib/formdata.c index 416bcad4f57d..d4bfed89beaa 100644 --- a/lib/formdata.c +++ b/lib/formdata.c @@ -40,10 +40,6 @@ struct Curl_easy; #include "curlx/fopen.h" #include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define HTTPPOST_PTRNAME CURL_HTTPPOST_PTRNAME #define HTTPPOST_FILENAME CURL_HTTPPOST_FILENAME @@ -76,7 +72,7 @@ AddHttpPost(struct FormInfo *src, if((src->bufferlength > LONG_MAX) || (namelength > LONG_MAX)) /* avoid overflow in typecasts below */ return NULL; - post = calloc(1, sizeof(struct curl_httppost)); + post = curlx_calloc(1, sizeof(struct curl_httppost)); if(post) { post->name = src->name; post->namelength = (long)namelength; @@ -127,7 +123,7 @@ static struct FormInfo *AddFormInfo(char *value, struct FormInfo *parent_form_info) { struct FormInfo *form_info; - form_info = calloc(1, sizeof(struct FormInfo)); + form_info = curlx_calloc(1, sizeof(struct FormInfo)); if(!form_info) return NULL; if(value) @@ -262,7 +258,7 @@ static CURLFORMcode FormAddCheck(struct FormInfo *first_form, type = FILE_CONTENTTYPE_DEFAULT; /* our contenttype is missing */ - form->contenttype = strdup(type); + form->contenttype = curlx_strdup(type); if(!form->contenttype) return CURL_FORMADD_MEMORY; @@ -320,7 +316,7 @@ static void free_chain(struct curl_httppost *c) struct curl_httppost *next = c->next; if(c->more) free_chain(c->more); - free(c); + curlx_free(c); c = next; } } @@ -346,7 +342,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, /* * We need to allocate the first struct to fill in. */ - first_form = calloc(1, sizeof(struct FormInfo)); + first_form = curlx_calloc(1, sizeof(struct FormInfo)); if(!first_form) return CURL_FORMADD_MEMORY; @@ -458,7 +454,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, if(!array_state) avalue = va_arg(params, char *); if(avalue) { - curr->value = strdup(avalue); + curr->value = curlx_strdup(avalue); if(!curr->value) retval = CURL_FORMADD_MEMORY; else { @@ -479,13 +475,13 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, if(curr->value) { if(curr->flags & HTTPPOST_FILENAME) { if(avalue) { - char *fname = strdup(avalue); + char *fname = curlx_strdup(avalue); if(!fname) retval = CURL_FORMADD_MEMORY; else { form = AddFormInfo(fname, NULL, curr); if(!form) { - free(fname); + curlx_free(fname); retval = CURL_FORMADD_MEMORY; } else { @@ -503,7 +499,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, } else { if(avalue) { - curr->value = strdup(avalue); + curr->value = curlx_strdup(avalue); if(!curr->value) retval = CURL_FORMADD_MEMORY; else { @@ -566,13 +562,13 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, if(curr->contenttype) { if(curr->flags & HTTPPOST_FILENAME) { if(avalue) { - char *type = strdup(avalue); + char *type = curlx_strdup(avalue); if(!type) retval = CURL_FORMADD_MEMORY; else { form = AddFormInfo(NULL, type, curr); if(!form) { - free(type); + curlx_free(type); retval = CURL_FORMADD_MEMORY; } else { @@ -590,7 +586,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, } else { if(avalue) { - curr->contenttype = strdup(avalue); + curr->contenttype = curlx_strdup(avalue); if(!curr->contenttype) retval = CURL_FORMADD_MEMORY; else @@ -623,7 +619,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, if(curr->showfilename) retval = CURL_FORMADD_OPTION_TWICE; else { - curr->showfilename = strdup(avalue); + curr->showfilename = curlx_strdup(avalue); if(!curr->showfilename) retval = CURL_FORMADD_MEMORY; else @@ -650,7 +646,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, now by the httppost linked list */ while(first_form) { struct FormInfo *ptr = first_form->more; - free(first_form); + curlx_free(first_form); first_form = ptr; } @@ -743,14 +739,14 @@ void curl_formfree(struct curl_httppost *form) curl_formfree(form->more); if(!(form->flags & HTTPPOST_PTRNAME)) - free(form->name); /* free the name */ + curlx_free(form->name); /* free the name */ if(!(form->flags & (HTTPPOST_PTRCONTENTS|HTTPPOST_BUFFER|HTTPPOST_CALLBACK)) ) - free(form->contents); /* free the contents */ - free(form->contenttype); /* free the content type */ - free(form->showfilename); /* free the faked filename */ - free(form); /* free the struct */ + curlx_free(form->contents); /* free the contents */ + curlx_free(form->contenttype); /* free the content type */ + curlx_free(form->showfilename); /* free the faked filename */ + curlx_free(form); /* free the struct */ form = next; } while(form); /* continue */ } @@ -768,7 +764,7 @@ static CURLcode setname(curl_mimepart *part, const char *name, size_t len) if(!zname) return CURLE_OUT_OF_MEMORY; res = curl_mime_name(part, zname); - free(zname); + curlx_free(zname); return res; } diff --git a/lib/ftp.c b/lib/ftp.c index ce4001226823..b2b15a89dcd3 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -72,10 +72,6 @@ #include "curlx/strerr.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifndef NI_MAXHOST #define NI_MAXHOST 1025 #endif @@ -1419,7 +1415,7 @@ static CURLcode ftp_state_list(struct Curl_easy *data, return CURLE_OUT_OF_MEMORY; result = Curl_pp_sendf(data, &ftpc->pp, "%s", cmd); - free(cmd); + curlx_free(cmd); if(!result) ftp_state(data, ftpc, FTP_LIST); @@ -1770,12 +1766,12 @@ static CURLcode ftp_control_addr_dup(struct Curl_easy *data, not the ftp host. */ #ifndef CURL_DISABLE_PROXY if(conn->bits.tunnel_proxy || conn->bits.socksproxy) - *newhostp = strdup(conn->host.name); + *newhostp = curlx_strdup(conn->host.name); else #endif if(!Curl_conn_get_ip_info(data, conn, FIRSTSOCKET, &is_ipv6, &ipquad) && *ipquad.remote_ip) - *newhostp = strdup(ipquad.remote_ip); + *newhostp = curlx_strdup(ipquad.remote_ip); else { /* failed to get the remote_ip of the DATA connection */ failf(data, "unable to get peername of DATA connection"); @@ -1934,7 +1930,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, /* postponed address resolution in case of tcp fastopen */ if(conn->bits.tcp_fastopen && !conn->bits.reuse && !newhost[0]) { - free(newhost); + curlx_free(newhost); result = ftp_control_addr_dup(data, &newhost); if(result) goto error; @@ -1956,7 +1952,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, if(result) { if(ftpc->count1 == 0 && ftpcode == 229) { - free(newhost); + curlx_free(newhost); return ftp_epsv_disable(data, ftpc, conn); } @@ -1973,9 +1969,9 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, /* this just dumps information about this second connection */ ftp_pasv_verbose(data, dns->addr, newhost, connectport); - free(conn->secondaryhostname); + curlx_free(conn->secondaryhostname); conn->secondary_port = newport; - conn->secondaryhostname = strdup(newhost); + conn->secondaryhostname = curlx_strdup(newhost); if(!conn->secondaryhostname) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -1985,7 +1981,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, ftp_state(data, ftpc, FTP_STOP); /* this phase is completed */ error: - free(newhost); + curlx_free(newhost); return result; } @@ -2723,17 +2719,17 @@ static CURLcode ftp_pwd_resp(struct Curl_easy *data, if(!ftpc->server_os && dir[0] != '/') { result = Curl_pp_sendf(data, &ftpc->pp, "%s", "SYST"); if(result) { - free(dir); + curlx_free(dir); return result; } } - free(ftpc->entrypath); + curlx_free(ftpc->entrypath); ftpc->entrypath = dir; /* remember this */ infof(data, "Entry path is '%s'", ftpc->entrypath); /* also save it where getinfo can access it: */ - free(data->state.most_recent_ftp_entrypath); - data->state.most_recent_ftp_entrypath = strdup(ftpc->entrypath); + curlx_free(data->state.most_recent_ftp_entrypath); + data->state.most_recent_ftp_entrypath = curlx_strdup(ftpc->entrypath); if(!data->state.most_recent_ftp_entrypath) return CURLE_OUT_OF_MEMORY; @@ -2961,18 +2957,18 @@ static CURLcode ftp_pp_statemachine(struct Curl_easy *data, /* Force OS400 name format 1. */ result = Curl_pp_sendf(data, &ftpc->pp, "%s", "SITE NAMEFMT 1"); if(result) { - free(os); + curlx_free(os); return result; } /* remember target server OS */ - free(ftpc->server_os); + curlx_free(ftpc->server_os); ftpc->server_os = os; ftp_state(data, ftpc, FTP_NAMEFMT); break; } /* Nothing special for the target server. */ /* remember target server OS */ - free(ftpc->server_os); + curlx_free(ftpc->server_os); ftpc->server_os = os; } else { @@ -3277,7 +3273,7 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status, * the error path) */ ftpc->ctl_valid = FALSE; /* mark control connection as bad */ connclose(conn, "FTP: out of memory!"); /* mark for connection closure */ - free(ftpc->prevpath); + curlx_free(ftpc->prevpath); ftpc->prevpath = NULL; /* no path remembering */ } else { /* remember working directory for connection reuse */ @@ -3288,7 +3284,7 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status, else { size_t pathLen = strlen(ftpc->rawpath); - free(ftpc->prevpath); + curlx_free(ftpc->prevpath); if(!ftpc->cwdfail) { if(data->set.ftp_filemethod == FTPFILE_NOCWD) @@ -3757,7 +3753,7 @@ static void wc_data_dtor(void *ptr) struct ftp_wc *ftpwc = ptr; if(ftpwc && ftpwc->parser) Curl_ftp_parselist_data_free(&ftpwc->parser); - free(ftpwc); + curlx_free(ftpwc); } static CURLcode init_wc_data(struct Curl_easy *data, @@ -3777,14 +3773,14 @@ static CURLcode init_wc_data(struct Curl_easy *data, wildcard->state = CURLWC_CLEAN; return ftp_parse_url_path(data, ftpc, ftp); } - wildcard->pattern = strdup(last_slash); + wildcard->pattern = curlx_strdup(last_slash); if(!wildcard->pattern) return CURLE_OUT_OF_MEMORY; last_slash[0] = '\0'; /* cut file from path */ } else { /* there is only 'wildcard pattern' or nothing */ if(path[0]) { - wildcard->pattern = strdup(path); + wildcard->pattern = curlx_strdup(path); if(!wildcard->pattern) return CURLE_OUT_OF_MEMORY; path[0] = '\0'; @@ -3799,7 +3795,7 @@ static CURLcode init_wc_data(struct Curl_easy *data, resources for wildcard transfer */ /* allocate ftp protocol specific wildcard data */ - ftpwc = calloc(1, sizeof(struct ftp_wc)); + ftpwc = curlx_calloc(1, sizeof(struct ftp_wc)); if(!ftpwc) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -3825,7 +3821,7 @@ static CURLcode init_wc_data(struct Curl_easy *data, goto fail; } - wildcard->path = strdup(ftp->path); + wildcard->path = curlx_strdup(ftp->path); if(!wildcard->path) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -3846,7 +3842,7 @@ static CURLcode init_wc_data(struct Curl_easy *data, fail: if(ftpwc) { Curl_ftp_parselist_data_free(&ftpwc->parser); - free(ftpwc); + curlx_free(ftpwc); } Curl_safefree(wildcard->pattern); wildcard->dtor = ZERO_NULL; @@ -3904,7 +3900,7 @@ static CURLcode wc_statemach(struct Curl_easy *data, return CURLE_OUT_OF_MEMORY; /* switch default ftp->path and tmp_path */ - free(ftp->pathalloc); + curlx_free(ftp->pathalloc); ftp->pathalloc = ftp->path = tmp_path; infof(data, "Wildcard - START of \"%s\"", finfo->filename); @@ -4179,7 +4175,7 @@ CURLcode ftp_parse_url_path(struct Curl_easy *data, if(dirlen == 0) dirlen = 1; - ftpc->dirs = calloc(1, sizeof(ftpc->dirs[0])); + ftpc->dirs = curlx_calloc(1, sizeof(ftpc->dirs[0])); if(!ftpc->dirs) return CURLE_OUT_OF_MEMORY; @@ -4205,7 +4201,7 @@ CURLcode ftp_parse_url_path(struct Curl_easy *data, return CURLE_URL_MALFORMAT; if(dirAlloc) { - ftpc->dirs = calloc(dirAlloc, sizeof(ftpc->dirs[0])); + ftpc->dirs = curlx_calloc(dirAlloc, sizeof(ftpc->dirs[0])); if(!ftpc->dirs) return CURLE_OUT_OF_MEMORY; @@ -4372,7 +4368,7 @@ static void ftp_easy_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; Curl_safefree(ftp->pathalloc); - free(ftp); + curlx_free(ftp); } static void ftp_conn_dtor(void *key, size_t klen, void *entry) @@ -4387,7 +4383,7 @@ static void ftp_conn_dtor(void *key, size_t klen, void *entry) Curl_safefree(ftpc->prevpath); Curl_safefree(ftpc->server_os); Curl_pp_disconnect(&ftpc->pp); - free(ftpc); + curlx_free(ftpc); } static void type_url_check(struct Curl_easy *data, struct FTP *ftp) @@ -4426,19 +4422,19 @@ static CURLcode ftp_setup_connection(struct Curl_easy *data, CURLcode result = CURLE_OK; struct ftp_conn *ftpc; - ftp = calloc(1, sizeof(*ftp)); + ftp = curlx_calloc(1, sizeof(*ftp)); if(!ftp || Curl_meta_set(data, CURL_META_FTP_EASY, ftp, ftp_easy_dtor)) return CURLE_OUT_OF_MEMORY; - ftpc = calloc(1, sizeof(*ftpc)); + ftpc = curlx_calloc(1, sizeof(*ftpc)); if(!ftpc || Curl_conn_meta_set(conn, CURL_META_FTP_CONN, ftpc, ftp_conn_dtor)) return CURLE_OUT_OF_MEMORY; /* clone connection related data that is FTP specific */ if(data->set.str[STRING_FTP_ACCOUNT]) { - ftpc->account = strdup(data->set.str[STRING_FTP_ACCOUNT]); + ftpc->account = curlx_strdup(data->set.str[STRING_FTP_ACCOUNT]); if(!ftpc->account) { Curl_conn_meta_remove(conn, CURL_META_FTP_CONN); return CURLE_OUT_OF_MEMORY; @@ -4446,7 +4442,7 @@ static CURLcode ftp_setup_connection(struct Curl_easy *data, } if(data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]) { ftpc->alternative_to_user = - strdup(data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]); + curlx_strdup(data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]); if(!ftpc->alternative_to_user) { Curl_safefree(ftpc->account); Curl_conn_meta_remove(conn, CURL_META_FTP_CONN); diff --git a/lib/ftplistparser.c b/lib/ftplistparser.c index d8d155d5c2eb..b62fa47f6542 100644 --- a/lib/ftplistparser.c +++ b/lib/ftplistparser.c @@ -52,10 +52,6 @@ #include "multiif.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - typedef enum { PL_UNIX_TOTALSIZE = 0, PL_UNIX_FILETYPE, @@ -205,18 +201,18 @@ void Curl_wildcard_dtor(struct WildcardData **wcp) DEBUGASSERT(wc->ftpwc == NULL); Curl_llist_destroy(&wc->filelist, NULL); - free(wc->path); + curlx_free(wc->path); wc->path = NULL; - free(wc->pattern); + curlx_free(wc->pattern); wc->pattern = NULL; wc->state = CURLWC_INIT; - free(wc); + curlx_free(wc); *wcp = NULL; } struct ftp_parselist_data *Curl_ftp_parselist_data_alloc(void) { - return calloc(1, sizeof(struct ftp_parselist_data)); + return curlx_calloc(1, sizeof(struct ftp_parselist_data)); } @@ -225,7 +221,7 @@ void Curl_ftp_parselist_data_free(struct ftp_parselist_data **parserp) struct ftp_parselist_data *parser = *parserp; if(parser) Curl_fileinfo_cleanup(parser->file_data); - free(parser); + curlx_free(parser); *parserp = NULL; } diff --git a/lib/getenv.c b/lib/getenv.c index a2d8056fcc72..73c62d99cd23 100644 --- a/lib/getenv.c +++ b/lib/getenv.c @@ -25,9 +25,6 @@ #include "curl_setup.h" #include -#include "curl_memory.h" - -#include "memdebug.h" static char *GetEnv(const char *variable) { @@ -45,9 +42,9 @@ static char *GetEnv(const char *variable) const DWORD max = 32768; /* max env var size from MSCRT source */ for(;;) { - tmp = realloc(buf, rc); + tmp = curlx_realloc(buf, rc); if(!tmp) { - free(buf); + curlx_free(buf); return NULL; } @@ -58,7 +55,7 @@ static char *GetEnv(const char *variable) Since getenv does not make that distinction we ignore it as well. */ rc = GetEnvironmentVariableA(variable, buf, bufsize); if(!rc || rc == bufsize || rc > max) { - free(buf); + curlx_free(buf); return NULL; } @@ -70,7 +67,7 @@ static char *GetEnv(const char *variable) } #else char *env = getenv(variable); - return (env && env[0]) ? strdup(env) : NULL; + return (env && env[0]) ? curlx_strdup(env) : NULL; #endif } diff --git a/lib/getinfo.c b/lib/getinfo.c index 01c727935620..14244d087b06 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -34,10 +34,6 @@ #include "progress.h" #include "curlx/strparse.h" -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Initialize statistical and informational data. * @@ -74,10 +70,10 @@ void Curl_initinfo(struct Curl_easy *data) info->httpauthpicked = 0; info->numconnects = 0; - free(info->contenttype); + curlx_free(info->contenttype); info->contenttype = NULL; - free(info->wouldredirect); + curlx_free(info->wouldredirect); info->wouldredirect = NULL; memset(&info->primary, 0, sizeof(info->primary)); @@ -137,7 +133,7 @@ static CURLcode getinfo_char(struct Curl_easy *data, CURLINFO info, case CURLINFO_FTP_ENTRY_PATH: /* Return the entrypath string from the most recent connection. This pointer was copied from the connectdata structure by FTP. - The actual string may be free()ed by subsequent libcurl calls so + The actual string may be freed by subsequent libcurl calls so it must be copied to a safer area before the next libcurl call. Callers must never free it themselves. */ *param_charp = data->state.most_recent_ftp_entrypath; diff --git a/lib/gopher.c b/lib/gopher.c index 45d43f6ebdb1..93e9287c99b9 100644 --- a/lib/gopher.c +++ b/lib/gopher.c @@ -40,10 +40,6 @@ #include "escape.h" #include "curlx/warnless.h" -/* The last 2 #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Forward declarations. */ @@ -153,7 +149,7 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) if(query) gopherpath = curl_maprintf("%s?%s", path, query); else - gopherpath = strdup(path); + gopherpath = curlx_strdup(path); if(!gopherpath) return CURLE_OUT_OF_MEMORY; @@ -162,7 +158,7 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) if(strlen(gopherpath) <= 2) { buf = ""; buf_len = 0; - free(gopherpath); + curlx_free(gopherpath); } else { char *newp; @@ -173,7 +169,7 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) /* ... and finally unescape */ result = Curl_urldecode(newp, 0, &buf_alloc, &buf_len, REJECT_ZERO); - free(gopherpath); + curlx_free(gopherpath); if(result) return result; buf = buf_alloc; @@ -224,7 +220,7 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) } } - free(buf_alloc); + curlx_free(buf_alloc); if(!result) result = Curl_xfer_send(data, "\r\n", 2, FALSE, &nwritten); diff --git a/lib/hash.c b/lib/hash.c index 8312fbf050fd..2d91c855e614 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -28,10 +28,6 @@ #include "hash.h" #include "llist.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" /* random patterns for API verification */ #ifdef DEBUGBUILD @@ -115,7 +111,7 @@ hash_elem_create(const void *key, size_t key_len, const void *p, struct Curl_hash_element *he; /* allocate the struct plus memory after it to store the key */ - he = malloc(sizeof(struct Curl_hash_element) + key_len); + he = curlx_malloc(sizeof(struct Curl_hash_element) + key_len); if(he) { he->next = NULL; /* copy the key */ @@ -145,7 +141,7 @@ static void hash_elem_destroy(struct Curl_hash *h, struct Curl_hash_element *he) { hash_elem_clear_ptr(h, he); - free(he); + curlx_free(he); } static void hash_elem_unlink(struct Curl_hash *h, @@ -177,7 +173,7 @@ void *Curl_hash_add2(struct Curl_hash *h, void *key, size_t key_len, void *p, DEBUGASSERT(h->slots); DEBUGASSERT(h->init == HASHINIT); if(!h->table) { - h->table = calloc(h->slots, sizeof(struct Curl_hash_element *)); + h->table = curlx_calloc(h->slots, sizeof(struct Curl_hash_element *)); if(!h->table) return NULL; /* OOM */ } diff --git a/lib/headers.c b/lib/headers.c index feb52e087de8..91715fd51d3a 100644 --- a/lib/headers.c +++ b/lib/headers.c @@ -30,10 +30,6 @@ #include "headers.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_HEADERS_API) /* Generate the curl_header struct for the user. This function MUST assign all @@ -317,7 +313,7 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header, return CURLE_TOO_LARGE; } - hs = calloc(1, sizeof(*hs) + hlen); + hs = curlx_calloc(1, sizeof(*hs) + hlen); if(!hs) return CURLE_OUT_OF_MEMORY; memcpy(hs->buffer, header, hlen); @@ -336,7 +332,7 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header, } else { failf(data, "Invalid response header"); - free(hs); + curlx_free(hs); } return result; } @@ -417,7 +413,7 @@ CURLcode Curl_headers_cleanup(struct Curl_easy *data) for(e = Curl_llist_head(&data->state.httphdrs); e; e = n) { struct Curl_header_store *hs = Curl_node_elem(e); n = Curl_node_next(e); - free(hs); + curlx_free(hs); } headers_reset(data); return CURLE_OK; diff --git a/lib/hmac.c b/lib/hmac.c index 7842f0601b06..4f226e6434f8 100644 --- a/lib/hmac.c +++ b/lib/hmac.c @@ -33,12 +33,8 @@ #include #include "curl_hmac.h" -#include "curl_memory.h" #include "curlx/warnless.h" -/* The last #include file should be: */ -#include "memdebug.h" - /* * Generic HMAC algorithm. * @@ -62,7 +58,7 @@ Curl_HMAC_init(const struct HMAC_params *hashparams, /* Create HMAC context. */ i = sizeof(*ctxt) + 2 * hashparams->ctxtsize + hashparams->resultlen; - ctxt = malloc(i); + ctxt = curlx_malloc(i); if(!ctxt) return ctxt; @@ -103,7 +99,7 @@ Curl_HMAC_init(const struct HMAC_params *hashparams, return ctxt; fail: - free(ctxt); + curlx_free(ctxt); return NULL; } @@ -130,7 +126,7 @@ int Curl_HMAC_final(struct HMAC_context *ctxt, unsigned char *output) hashparams->hfinal(output, ctxt->hashctxt1); hashparams->hupdate(ctxt->hashctxt2, output, hashparams->resultlen); hashparams->hfinal(output, ctxt->hashctxt2); - free(ctxt); + curlx_free(ctxt); return 0; } diff --git a/lib/hostip.c b/lib/hostip.c index 58a7712cf485..e81886995eda 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -62,10 +62,6 @@ #include "easy_lock.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(CURLRES_SYNCH) && \ defined(HAVE_ALARM) && \ defined(SIGALRM) && \ @@ -451,7 +447,7 @@ UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data, struct Curl_addrinfo **nodes; infof(data, "Shuffling %i addresses", num_addrs); - nodes = malloc(num_addrs*sizeof(*nodes)); + nodes = curlx_malloc(num_addrs*sizeof(*nodes)); if(nodes) { int i; unsigned int *rnd; @@ -463,7 +459,7 @@ UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data, nodes[i] = nodes[i-1]->ai_next; } - rnd = malloc(rnd_size); + rnd = curlx_malloc(rnd_size); if(rnd) { /* Fisher-Yates shuffle */ if(Curl_rand(data, (unsigned char *)rnd, rnd_size) == CURLE_OK) { @@ -482,11 +478,11 @@ UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data, nodes[num_addrs-1]->ai_next = NULL; *addr = nodes[0]; } - free(rnd); + curlx_free(rnd); } else result = CURLE_OUT_OF_MEMORY; - free(nodes); + curlx_free(nodes); } else result = CURLE_OUT_OF_MEMORY; @@ -519,7 +515,7 @@ Curl_dnscache_mk_entry(struct Curl_easy *data, hostlen = strlen(hostname); /* Create a new cache entry */ - dns = calloc(1, sizeof(struct Curl_dns_entry) + hostlen); + dns = curlx_calloc(1, sizeof(struct Curl_dns_entry) + hostlen); if(!dns) return NULL; @@ -609,7 +605,7 @@ static struct Curl_addrinfo *get_localhost6(int port, const char *name) struct sockaddr_in6 sa6; unsigned char ipv6[16]; unsigned short port16 = (unsigned short)(port & 0xffff); - ca = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1); + ca = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1); if(!ca) return NULL; @@ -658,7 +654,7 @@ static struct Curl_addrinfo *get_localhost(int port, const char *name) return NULL; memcpy(&sa.sin_addr, &ipv4, sizeof(ipv4)); - ca = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1); + ca = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1); if(!ca) return NULL; ca->ai_flags = 0; @@ -1178,10 +1174,10 @@ static void dnscache_entry_free(struct Curl_dns_entry *dns) #ifdef USE_HTTPSRR if(dns->hinfo) { Curl_httpsrr_cleanup(dns->hinfo); - free(dns->hinfo); + curlx_free(dns->hinfo); } #endif - free(dns); + curlx_free(dns); } /* diff --git a/lib/hostip4.c b/lib/hostip4.c index d543c1e14b19..f01e902fd684 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -50,10 +50,6 @@ #include "curl_share.h" #include "url.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef CURLRES_SYNCH @@ -139,7 +135,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, */ int h_errnop; - buf = calloc(1, CURL_HOSTENT_SIZE); + buf = curlx_calloc(1, CURL_HOSTENT_SIZE); if(!buf) return NULL; /* major failure */ /* @@ -253,8 +249,8 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, * Since we do not know how big buffer this particular lookup required, * we cannot realloc down the huge alloc without doing closer analysis of * the returned data. Thus, we always use CURL_HOSTENT_SIZE for every - * name lookup. Fixing this would require an extra malloc() and then - * calling Curl_addrinfo_copy() that subsequent realloc()s down the new + * name lookup. Fixing this would require an extra allocation and then + * calling Curl_addrinfo_copy() that subsequent reallocation down the new * memory area to the actually used amount. */ } @@ -262,7 +258,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, #endif /* HAVE_...BYNAME_R_5 || HAVE_...BYNAME_R_6 || HAVE_...BYNAME_R_3 */ { h = NULL; /* set return code to NULL */ - free(buf); + curlx_free(buf); } #else /* (HAVE_GETADDRINFO && HAVE_GETADDRINFO_THREADSAFE) || HAVE_GETHOSTBYNAME_R */ @@ -280,7 +276,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, ai = Curl_he2ai(h, port); if(buf) /* used a *_r() function */ - free(buf); + curlx_free(buf); } #endif diff --git a/lib/hostip6.c b/lib/hostip6.c index 0f628b3fb5ca..cfba2a5cbf27 100644 --- a/lib/hostip6.c +++ b/lib/hostip6.c @@ -53,10 +53,6 @@ #include "curlx/inet_pton.h" #include "connect.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef CURLRES_SYNCH #ifdef DEBUG_ADDRINFO diff --git a/lib/hsts.c b/lib/hsts.c index 836481cd4c36..22add0395732 100644 --- a/lib/hsts.c +++ b/lib/hsts.c @@ -41,10 +41,6 @@ #include "strdup.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define MAX_HSTS_LINE 4095 #define MAX_HSTS_HOSTLEN 2048 #define MAX_HSTS_DATELEN 256 @@ -72,7 +68,7 @@ static time_t hsts_debugtime(void *unused) struct hsts *Curl_hsts_init(void) { - struct hsts *h = calloc(1, sizeof(struct hsts)); + struct hsts *h = curlx_calloc(1, sizeof(struct hsts)); if(h) { Curl_llist_init(&h->list, NULL); } @@ -81,8 +77,8 @@ struct hsts *Curl_hsts_init(void) static void hsts_free(struct stsentry *e) { - free(CURL_UNCONST(e->host)); - free(e); + curlx_free(CURL_UNCONST(e->host)); + curlx_free(e); } void Curl_hsts_cleanup(struct hsts **hp) @@ -96,8 +92,8 @@ void Curl_hsts_cleanup(struct hsts **hp) n = Curl_node_next(e); hsts_free(sts); } - free(h->filename); - free(h); + curlx_free(h->filename); + curlx_free(h); *hp = NULL; } } @@ -116,13 +112,13 @@ static CURLcode hsts_create(struct hsts *h, --hlen; if(hlen) { char *duphost; - struct stsentry *sts = calloc(1, sizeof(struct stsentry)); + struct stsentry *sts = curlx_calloc(1, sizeof(struct stsentry)); if(!sts) return CURLE_OUT_OF_MEMORY; duphost = Curl_memdup0(hostname, hlen); if(!duphost) { - free(sts); + curlx_free(sts); return CURLE_OUT_OF_MEMORY; } @@ -385,7 +381,7 @@ CURLcode Curl_hsts_save(struct Curl_easy *data, struct hsts *h, if(result && tempstore) unlink(tempstore); } - free(tempstore); + curlx_free(tempstore); skipsave: if(data->set.hsts_write) { /* if there is a write callback */ @@ -518,8 +514,8 @@ static CURLcode hsts_load(struct hsts *h, const char *file) /* we need a private copy of the filename so that the hsts cache file name survives an easy handle reset */ - free(h->filename); - h->filename = strdup(file); + curlx_free(h->filename); + h->filename = curlx_strdup(file); if(!h->filename) return CURLE_OUT_OF_MEMORY; diff --git a/lib/http.c b/lib/http.c index 8223c6f0e213..f09d96ee0607 100644 --- a/lib/http.c +++ b/lib/http.c @@ -87,10 +87,6 @@ #include "curl_ctype.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Forward declarations. */ @@ -277,7 +273,7 @@ static bool http_header_is_empty(const char *header) /* * Strip off leading and trailing whitespace from the value in the given HTTP - * header line and return a strdup()ed copy in 'valp' - returns an empty + * header line and return a strdup-ed copy in 'valp' - returns an empty * string if the header value consists entirely of whitespace. * * If the header is provided as "name;", ending with a semicolon, it returns a @@ -305,7 +301,7 @@ static CURLcode copy_custom_value(const char *header, char **valp) /* * Strip off leading and trailing whitespace from the value in the given HTTP - * header line and return a strdup()ed copy in 'valp' - returns an empty + * header line and return a strdup-ed copy in 'valp' - returns an empty * string if the header value consists entirely of whitespace. * * This function MUST be used after the header has already been confirmed to @@ -377,18 +373,18 @@ static CURLcode http_output_basic(struct Curl_easy *data, bool proxy) goto fail; } - free(*userp); + curlx_free(*userp); *userp = curl_maprintf("%sAuthorization: Basic %s\r\n", proxy ? "Proxy-" : "", authorization); - free(authorization); + curlx_free(authorization); if(!*userp) { result = CURLE_OUT_OF_MEMORY; goto fail; } fail: - free(out); + curlx_free(out); return result; } @@ -407,7 +403,7 @@ static CURLcode http_output_bearer(struct Curl_easy *data) CURLcode result = CURLE_OK; userp = &data->state.aptr.userpwd; - free(*userp); + curlx_free(*userp); *userp = curl_maprintf("Authorization: Bearer %s\r\n", data->set.str[STRING_BEARER]); @@ -615,8 +611,8 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data) /* In case this is GSS auth, the newurl field is already allocated so we must make sure to free it before allocating a new one. As figured out in bug #2284386 */ - free(data->req.newurl); - data->req.newurl = strdup(data->state.url); /* clone URL */ + curlx_free(data->req.newurl); + data->req.newurl = curlx_strdup(data->state.url); /* clone URL */ if(!data->req.newurl) return CURLE_OUT_OF_MEMORY; } @@ -629,7 +625,7 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data) we did not try HEAD or GET */ if((data->state.httpreq != HTTPREQ_GET) && (data->state.httpreq != HTTPREQ_HEAD)) { - data->req.newurl = strdup(data->state.url); /* clone URL */ + data->req.newurl = curlx_strdup(data->state.url); /* clone URL */ if(!data->req.newurl) return CURLE_OUT_OF_MEMORY; data->state.authhost.done = TRUE; @@ -916,8 +912,8 @@ static CURLcode auth_spnego(struct Curl_easy *data, curlnegotiate *negstate = proxy ? &conn->proxy_negotiate_state : &conn->http_negotiate_state; if(!result) { - free(data->req.newurl); - data->req.newurl = strdup(data->state.url); + curlx_free(data->req.newurl); + data->req.newurl = curlx_strdup(data->state.url); if(!data->req.newurl) return CURLE_OUT_OF_MEMORY; data->state.authproblem = FALSE; @@ -1291,7 +1287,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, /* the URL could not be parsed for some reason, but since this is FAKE mode, just duplicate the field as-is */ - follow_url = strdup(newurl); + follow_url = curlx_strdup(newurl); if(!follow_url) return CURLE_OUT_OF_MEMORY; } @@ -1316,13 +1312,13 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, uc = curl_url_get(data->state.uh, CURLUPART_PORT, &portnum, CURLU_DEFAULT_PORT); if(uc) { - free(follow_url); + curlx_free(follow_url); return Curl_uc_to_curlcode(uc); } p = portnum; curlx_str_number(&p, &value, 0xffff); port = (int)value; - free(portnum); + curlx_free(portnum); } if(port != data->info.conn_remote_port) { infof(data, "Clear auth, redirects to port from %u to %u", @@ -1334,7 +1330,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, const struct Curl_handler *p; uc = curl_url_get(data->state.uh, CURLUPART_SCHEME, &scheme, 0); if(uc) { - free(follow_url); + curlx_free(follow_url); return Curl_uc_to_curlcode(uc); } @@ -1344,7 +1340,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, data->info.conn_scheme, scheme); clear = TRUE; } - free(scheme); + curlx_free(scheme); } if(clear) { Curl_safefree(data->state.aptr.user); @@ -1917,7 +1913,7 @@ static CURLcode http_useragent(struct Curl_easy *data) with the user-agent string specified, we erase the previously made string here. */ if(Curl_checkheaders(data, STRCONST("User-Agent"))) { - free(data->state.aptr.uagent); + curlx_free(data->state.aptr.uagent); data->state.aptr.uagent = NULL; } return CURLE_OK; @@ -1932,9 +1928,9 @@ static CURLcode http_set_aptr_host(struct Curl_easy *data) if(!data->state.this_is_a_follow) { /* Free to avoid leaking memory on multiple requests */ - free(data->state.first_host); + curlx_free(data->state.first_host); - data->state.first_host = strdup(conn->host.name); + data->state.first_host = curlx_strdup(conn->host.name); if(!data->state.first_host) return CURLE_OUT_OF_MEMORY; @@ -1958,7 +1954,7 @@ static CURLcode http_set_aptr_host(struct Curl_easy *data) return result; if(!*cookiehost) /* ignore empty data */ - free(cookiehost); + curlx_free(cookiehost); else { /* If the host begins with '[', we start searching for the port after the bracket has been closed */ @@ -1977,7 +1973,7 @@ static CURLcode http_set_aptr_host(struct Curl_easy *data) if(colon) *colon = 0; /* The host must not include an embedded port number */ } - free(aptr->cookiehost); + curlx_free(aptr->cookiehost); aptr->cookiehost = cookiehost; } #endif @@ -2086,7 +2082,7 @@ static CURLcode http_target(struct Curl_easy *data, /* target or URL */ result = curlx_dyn_add(r, data->set.str[STRING_TARGET] ? data->set.str[STRING_TARGET] : url); - free(url); + curlx_free(url); if(result) return result; @@ -2142,7 +2138,7 @@ static CURLcode set_post_reader(struct Curl_easy *data, Curl_HttpReq httpreq) /* Convert the form structure into a mime structure, then keep the conversion */ if(!data->state.formp) { - data->state.formp = calloc(1, sizeof(curl_mimepart)); + data->state.formp = curlx_calloc(1, sizeof(curl_mimepart)); if(!data->state.formp) return CURLE_OUT_OF_MEMORY; Curl_mime_cleanpart(data->state.formp); @@ -2547,7 +2543,7 @@ static CURLcode http_range(struct Curl_easy *data, if(((httpreq == HTTPREQ_GET) || (httpreq == HTTPREQ_HEAD)) && !Curl_checkheaders(data, STRCONST("Range"))) { /* if a line like this was already allocated, free the previous one */ - free(data->state.aptr.rangeline); + curlx_free(data->state.aptr.rangeline); data->state.aptr.rangeline = curl_maprintf("Range: bytes=%s\r\n", data->state.range); if(!data->state.aptr.rangeline) @@ -2557,7 +2553,7 @@ static CURLcode http_range(struct Curl_easy *data, !Curl_checkheaders(data, STRCONST("Content-Range"))) { curl_off_t req_clen = Curl_creader_total_length(data); /* if a line like this was already allocated, free the previous one */ - free(data->state.aptr.rangeline); + curlx_free(data->state.aptr.rangeline); if(data->set.set_resume_from < 0) { /* Upload resume was asked for, but we do not know the size of the @@ -2723,7 +2719,7 @@ static CURLcode http_add_connection_hd(struct Curl_easy *data, return result; result = curlx_dyn_addf(req, "%s%s", sep, value); sep = ", "; - free(value); + curlx_free(value); break; /* leave, having added 1st one */ } } @@ -3000,7 +2996,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done) } result = Curl_http_output_auth(data, data->conn, method, httpreq, (pq ? pq : data->state.up.path), FALSE); - free(pq); + curlx_free(pq); } if(result) goto out; @@ -3245,9 +3241,9 @@ static CURLcode http_header_c(struct Curl_easy *data, return CURLE_OUT_OF_MEMORY; if(!*contenttype) /* ignore empty data */ - free(contenttype); + curlx_free(contenttype); else { - free(data->info.contenttype); + curlx_free(data->info.contenttype); data->info.contenttype = contenttype; } return CURLE_OK; @@ -3333,14 +3329,14 @@ static CURLcode http_header_l(struct Curl_easy *data, if(!*location || (data->req.location && !strcmp(data->req.location, location))) { /* ignore empty header, or exact repeat of a previous one */ - free(location); + curlx_free(location); return CURLE_OK; } else { /* has value and is not an exact repeat */ if(data->req.location) { failf(data, "Multiple Location headers"); - free(location); + curlx_free(location); return CURLE_WEIRD_SERVER_REPLY; } data->req.location = location; @@ -3349,7 +3345,7 @@ static CURLcode http_header_l(struct Curl_easy *data, data->set.http_follow_mode) { CURLcode result; DEBUGASSERT(!data->req.newurl); - data->req.newurl = strdup(data->req.location); /* clone */ + data->req.newurl = curlx_strdup(data->req.location); /* clone */ if(!data->req.newurl) return CURLE_OUT_OF_MEMORY; @@ -3407,7 +3403,7 @@ static CURLcode http_header_p(struct Curl_easy *data, CURLcode result = auth ? CURLE_OK : CURLE_OUT_OF_MEMORY; if(!result) { result = Curl_http_input_auth(data, TRUE, auth); - free(auth); + curlx_free(auth); } return result; } @@ -3426,7 +3422,7 @@ static CURLcode http_header_p(struct Curl_easy *data, negdata->havenoauthpersist = TRUE; infof(data, "Negotiate: noauthpersist -> %d, header part: %s", negdata->noauthpersist, persistentauth); - free(persistentauth); + curlx_free(persistentauth); } } #endif @@ -3587,7 +3583,7 @@ static CURLcode http_header_w(struct Curl_easy *data, result = CURLE_OUT_OF_MEMORY; else { result = Curl_http_input_auth(data, FALSE, auth); - free(auth); + curlx_free(auth); } } return result; @@ -4065,7 +4061,7 @@ static CURLcode http_on_response(struct Curl_easy *data, data->state.disableexpect = TRUE; Curl_req_abort_sending(data); DEBUGASSERT(!data->req.newurl); - data->req.newurl = strdup(data->state.url); + data->req.newurl = curlx_strdup(data->state.url); if(!data->req.newurl) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -4533,7 +4529,7 @@ CURLcode Curl_http_req_make(struct httpreq **preq, DEBUGASSERT(method && m_len); - req = calloc(1, sizeof(*req) + m_len); + req = curlx_calloc(1, sizeof(*req) + m_len); if(!req) goto out; #if defined(__GNUC__) && __GNUC__ >= 13 @@ -4606,8 +4602,8 @@ static CURLcode req_assign_url_authority(struct httpreq *req, CURLU *url) } req->authority = curlx_dyn_ptr(&buf); out: - free(host); - free(port); + curlx_free(host); + curlx_free(port); if(result) curlx_dyn_free(&buf); return result; @@ -4645,8 +4641,8 @@ static CURLcode req_assign_url_path(struct httpreq *req, CURLU *url) result = CURLE_OK; out: - free(path); - free(query); + curlx_free(path); + curlx_free(query); if(result) curlx_dyn_free(&buf); return result; @@ -4662,7 +4658,7 @@ CURLcode Curl_http_req_make2(struct httpreq **preq, DEBUGASSERT(method && m_len); - req = calloc(1, sizeof(*req) + m_len); + req = curlx_calloc(1, sizeof(*req) + m_len); if(!req) goto out; memcpy(req->method, method, m_len); @@ -4671,7 +4667,7 @@ CURLcode Curl_http_req_make2(struct httpreq **preq, if(uc && uc != CURLUE_NO_SCHEME) goto out; if(!req->scheme && scheme_default) { - req->scheme = strdup(scheme_default); + req->scheme = curlx_strdup(scheme_default); if(!req->scheme) goto out; } @@ -4697,12 +4693,12 @@ CURLcode Curl_http_req_make2(struct httpreq **preq, void Curl_http_req_free(struct httpreq *req) { if(req) { - free(req->scheme); - free(req->authority); - free(req->path); + curlx_free(req->scheme); + curlx_free(req->authority); + curlx_free(req->path); Curl_dynhds_free(&req->headers); Curl_dynhds_free(&req->trailers); - free(req); + curlx_free(req); } } @@ -4840,13 +4836,13 @@ CURLcode Curl_http_resp_make(struct http_resp **presp, struct http_resp *resp; CURLcode result = CURLE_OUT_OF_MEMORY; - resp = calloc(1, sizeof(*resp)); + resp = curlx_calloc(1, sizeof(*resp)); if(!resp) goto out; resp->status = status; if(description) { - resp->description = strdup(description); + resp->description = curlx_strdup(description); if(!resp->description) goto out; } @@ -4864,12 +4860,12 @@ CURLcode Curl_http_resp_make(struct http_resp **presp, void Curl_http_resp_free(struct http_resp *resp) { if(resp) { - free(resp->description); + curlx_free(resp->description); Curl_dynhds_free(&resp->headers); Curl_dynhds_free(&resp->trailers); if(resp->prev) Curl_http_resp_free(resp->prev); - free(resp); + curlx_free(resp); } } diff --git a/lib/http1.c b/lib/http1.c index b1d80976360a..0a80fedfc722 100644 --- a/lib/http1.c +++ b/lib/http1.c @@ -32,10 +32,6 @@ #include "http1.h" #include "urlapi-int.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define H1_MAX_URL_LEN (8*1024) diff --git a/lib/http2.c b/lib/http2.c index 2e8649c10502..baaefd439d4f 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -48,10 +48,6 @@ #include "curlx/warnless.h" #include "headers.h" -/* The last 3 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if (NGHTTP2_VERSION_NUM < 0x010c00) #error too old nghttp2 version, upgrade! #endif @@ -168,7 +164,7 @@ static void cf_h2_ctx_free(struct cf_h2_ctx *ctx) Curl_uint32_hash_destroy(&ctx->streams); memset(ctx, 0, sizeof(*ctx)); } - free(ctx); + curlx_free(ctx); } static void cf_h2_ctx_close(struct cf_h2_ctx *ctx) @@ -276,7 +272,7 @@ static struct h2_stream_ctx *h2_stream_ctx_create(struct cf_h2_ctx *ctx) struct h2_stream_ctx *stream; (void)ctx; - stream = calloc(1, sizeof(*stream)); + stream = curlx_calloc(1, sizeof(*stream)); if(!stream) return NULL; @@ -299,7 +295,7 @@ static void free_push_headers(struct h2_stream_ctx *stream) { size_t i; for(i = 0; i < stream->push_headers_used; i++) - free(stream->push_headers[i]); + curlx_free(stream->push_headers[i]); Curl_safefree(stream->push_headers); stream->push_headers_used = 0; } @@ -310,7 +306,7 @@ static void h2_stream_ctx_free(struct h2_stream_ctx *stream) Curl_h1_req_parse_free(&stream->h1); Curl_dynhds_free(&stream->resp_trailers); free_push_headers(stream); - free(stream); + curlx_free(stream); } static void h2_stream_hash_free(unsigned int id, void *stream) @@ -952,7 +948,7 @@ static int set_transfer_url(struct Curl_easy *data, return rc; if(data->state.url_alloc) - free(data->state.url); + curlx_free(data->state.url); data->state.url_alloc = TRUE; data->state.url = url; return 0; @@ -1642,15 +1638,15 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame, stream_id, NGHTTP2_PROTOCOL_ERROR); rc = NGHTTP2_ERR_CALLBACK_FAILURE; } - free(check); + curlx_free(check); if(rc) return rc; } if(!stream->push_headers) { stream->push_headers_alloc = 10; - stream->push_headers = malloc(stream->push_headers_alloc * - sizeof(char *)); + stream->push_headers = curlx_malloc(stream->push_headers_alloc * + sizeof(char *)); if(!stream->push_headers) return NGHTTP2_ERR_CALLBACK_FAILURE; stream->push_headers_used = 0; @@ -1665,8 +1661,8 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame, return NGHTTP2_ERR_CALLBACK_FAILURE; } stream->push_headers_alloc *= 2; - headp = realloc(stream->push_headers, - stream->push_headers_alloc * sizeof(char *)); + headp = curlx_realloc(stream->push_headers, + stream->push_headers_alloc * sizeof(char *)); if(!headp) { free_push_headers(stream); return NGHTTP2_ERR_CALLBACK_FAILURE; @@ -1859,7 +1855,7 @@ CURLcode Curl_http2_request_upgrade(struct dynbuf *req, "Upgrade: %s\r\n" "HTTP2-Settings: %s\r\n", NGHTTP2_CLEARTEXT_PROTO_VERSION_ID, base64); - free(base64); + curlx_free(base64); k->upgr101 = UPGR101_H2; data->conn->bits.upgrade_in_progress = TRUE; @@ -2881,7 +2877,7 @@ static CURLcode http2_cfilter_add(struct Curl_cfilter **pcf, CURLcode result = CURLE_OUT_OF_MEMORY; DEBUGASSERT(data->conn); - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) goto out; cf_h2_ctx_init(ctx, via_h1_upgrade); @@ -2909,7 +2905,7 @@ static CURLcode http2_cfilter_insert_after(struct Curl_cfilter *cf, CURLcode result = CURLE_OUT_OF_MEMORY; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) goto out; cf_h2_ctx_init(ctx, via_h1_upgrade); diff --git a/lib/http_aws_sigv4.c b/lib/http_aws_sigv4.c index d3d4760be780..0ef18b6feabe 100644 --- a/lib/http_aws_sigv4.c +++ b/lib/http_aws_sigv4.c @@ -39,10 +39,6 @@ #include -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #include "slist.h" #define HMAC_SHA256(k, kl, d, dl, o) \ @@ -210,12 +206,12 @@ static CURLcode merge_duplicate_headers(struct curl_slist *head) if(result) return result; - free(curr->data); + curlx_free(curr->data); curr->data = curlx_dyn_ptr(&buf); curr->next = next->next; - free(next->data); - free(next); + curlx_free(next->data); + curlx_free(next); } else { curr = curr->next; @@ -269,7 +265,7 @@ static CURLcode make_headers(struct Curl_easy *data, if(fullhost) head = Curl_slist_append_nodup(NULL, fullhost); if(!head) { - free(fullhost); + curlx_free(fullhost); goto fail; } } @@ -307,13 +303,13 @@ static CURLcode make_headers(struct Curl_easy *data, ; if(!*ptr && ptr != sep + 1) /* a value of whitespace only */ continue; - dupdata = strdup(l->data); + dupdata = curlx_strdup(l->data); if(!dupdata) goto fail; dupdata[sep - l->data] = ':'; tmp_head = Curl_slist_append_nodup(head, dupdata); if(!tmp_head) { - free(dupdata); + curlx_free(dupdata); goto fail; } head = tmp_head; @@ -964,7 +960,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data) Curl_strntoupper(&auth_headers[sizeof("Authorization: ") - 1], curlx_str(&provider0), curlx_strlen(&provider0)); - free(data->state.aptr.userpwd); + curlx_free(data->state.aptr.userpwd); data->state.aptr.userpwd = auth_headers; data->state.authhost.done = TRUE; result = CURLE_OK; @@ -974,12 +970,12 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data) curlx_dyn_free(&canonical_path); curlx_dyn_free(&canonical_headers); curlx_dyn_free(&signed_headers); - free(canonical_request); - free(request_type); - free(credential_scope); - free(str_to_sign); - free(secret); - free(date_header); + curlx_free(canonical_request); + curlx_free(request_type); + curlx_free(credential_scope); + curlx_free(str_to_sign); + curlx_free(secret); + curlx_free(date_header); return result; } diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 005d34e7b905..9d0a0b324cdd 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -36,10 +36,6 @@ #include "curlx/strparse.h" #include "curlx/warnless.h" -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Chunk format (simplified): * diff --git a/lib/http_digest.c b/lib/http_digest.c index 097c81fd716a..2ca1a12d5daf 100644 --- a/lib/http_digest.c +++ b/lib/http_digest.c @@ -32,10 +32,6 @@ #include "http_digest.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Test example headers: WWW-Authenticate: Digest realm="testrealm", nonce="1053604598" @@ -152,20 +148,20 @@ CURLcode Curl_output_digest(struct Curl_easy *data, } } if(!tmp) - path = (unsigned char *)strdup((const char *) uripath); + path = (unsigned char *)curlx_strdup((const char *) uripath); if(!path) return CURLE_OUT_OF_MEMORY; result = Curl_auth_create_digest_http_message(data, userp, passwdp, request, path, digest, &response, &len); - free(path); + curlx_free(path); if(result) return result; *allocuserpwd = curl_maprintf("%sAuthorization: Digest %s\r\n", proxy ? "Proxy-" : "", response); - free(response); + curlx_free(response); if(!*allocuserpwd) return CURLE_OUT_OF_MEMORY; diff --git a/lib/http_negotiate.c b/lib/http_negotiate.c index 136cb07641c4..fc80f80fa350 100644 --- a/lib/http_negotiate.c +++ b/lib/http_negotiate.c @@ -34,10 +34,6 @@ #include "vtls/vtls.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void http_auth_nego_reset(struct connectdata *conn, struct negotiatedata *neg_ctx, @@ -223,16 +219,16 @@ CURLcode Curl_output_negotiate(struct Curl_easy *data, if(proxy) { #ifndef CURL_DISABLE_PROXY - free(data->state.aptr.proxyuserpwd); + curlx_free(data->state.aptr.proxyuserpwd); data->state.aptr.proxyuserpwd = userp; #endif } else { - free(data->state.aptr.userpwd); + curlx_free(data->state.aptr.userpwd); data->state.aptr.userpwd = userp; } - free(base64); + curlx_free(base64); if(!userp) { return CURLE_OUT_OF_MEMORY; diff --git a/lib/http_ntlm.c b/lib/http_ntlm.c index 8cb6403fdb8b..2856745c34c4 100644 --- a/lib/http_ntlm.c +++ b/lib/http_ntlm.c @@ -49,10 +49,6 @@ #include "curl_sspi.h" #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - CURLcode Curl_input_ntlm(struct Curl_easy *data, bool proxy, /* if proxy or not */ const char *header) /* rest of the www-authenticate: @@ -208,11 +204,11 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy) result = curlx_base64_encode(Curl_bufref_ptr(&ntlmmsg), Curl_bufref_len(&ntlmmsg), &base64, &len); if(!result) { - free(*allocuserpwd); + curlx_free(*allocuserpwd); *allocuserpwd = curl_maprintf("%sAuthorization: NTLM %s\r\n", proxy ? "Proxy-" : "", base64); - free(base64); + curlx_free(base64); if(!*allocuserpwd) result = CURLE_OUT_OF_MEMORY; } @@ -227,11 +223,11 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy) result = curlx_base64_encode(Curl_bufref_ptr(&ntlmmsg), Curl_bufref_len(&ntlmmsg), &base64, &len); if(!result) { - free(*allocuserpwd); + curlx_free(*allocuserpwd); *allocuserpwd = curl_maprintf("%sAuthorization: NTLM %s\r\n", proxy ? "Proxy-" : "", base64); - free(base64); + curlx_free(base64); if(!*allocuserpwd) result = CURLE_OUT_OF_MEMORY; else { diff --git a/lib/http_proxy.c b/lib/http_proxy.c index 9bde118baff2..21f0cc6211c1 100644 --- a/lib/http_proxy.c +++ b/lib/http_proxy.c @@ -44,10 +44,6 @@ #include "vauth/vauth.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static CURLcode dynhds_add_custom(struct Curl_easy *data, bool is_connect, int httpversion, struct dynhds *hds) @@ -270,7 +266,7 @@ CURLcode Curl_http_proxy_create_CONNECT(struct httpreq **preq, Curl_http_req_free(req); req = NULL; } - free(authority); + curlx_free(authority); *preq = req; return result; } @@ -386,7 +382,7 @@ static void http_proxy_cf_destroy(struct Curl_cfilter *cf, (void)data; CURL_TRC_CF(data, cf, "destroy"); - free(ctx); + curlx_free(ctx); } static void http_proxy_cf_close(struct Curl_cfilter *cf, @@ -425,7 +421,7 @@ CURLcode Curl_cf_http_proxy_insert_after(struct Curl_cfilter *cf_at, CURLcode result; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -437,7 +433,7 @@ CURLcode Curl_cf_http_proxy_insert_after(struct Curl_cfilter *cf_at, Curl_conn_cf_insert_after(cf_at, cf); out: - free(ctx); + curlx_free(ctx); return result; } diff --git a/lib/httpsrr.c b/lib/httpsrr.c index 0cf5b131bd31..34d081b50264 100644 --- a/lib/httpsrr.c +++ b/lib/httpsrr.c @@ -33,10 +33,6 @@ #include "sendf.h" #include "strdup.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static CURLcode httpsrr_decode_alpn(const uint8_t *cp, size_t len, unsigned char *alpns) { @@ -97,7 +93,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, case HTTPS_RR_CODE_IPV4: /* addr4 list */ if(!vlen || (vlen & 3)) /* the size must be 4-byte aligned */ return CURLE_BAD_FUNCTION_ARGUMENT; - free(hi->ipv4hints); + curlx_free(hi->ipv4hints); hi->ipv4hints = Curl_memdup(val, vlen); if(!hi->ipv4hints) return CURLE_OUT_OF_MEMORY; @@ -107,7 +103,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, case HTTPS_RR_CODE_ECH: if(!vlen) return CURLE_BAD_FUNCTION_ARGUMENT; - free(hi->echconfiglist); + curlx_free(hi->echconfiglist); hi->echconfiglist = Curl_memdup(val, vlen); if(!hi->echconfiglist) return CURLE_OUT_OF_MEMORY; @@ -117,7 +113,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, case HTTPS_RR_CODE_IPV6: /* addr6 list */ if(!vlen || (vlen & 15)) /* the size must be 16-byte aligned */ return CURLE_BAD_FUNCTION_ARGUMENT; - free(hi->ipv6hints); + curlx_free(hi->ipv6hints); hi->ipv6hints = Curl_memdup(val, vlen); if(!hi->ipv6hints) return CURLE_OUT_OF_MEMORY; @@ -189,8 +185,8 @@ CURLcode Curl_httpsrr_from_ares(struct Curl_easy *data, is in ServiceMode */ target = ares_dns_rr_get_str(rr, ARES_RR_HTTPS_TARGET); if(target && target[0]) { - free(hinfo->target); - hinfo->target = strdup(target); + curlx_free(hinfo->target); + hinfo->target = curlx_strdup(target); if(!hinfo->target) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/idn.c b/lib/idn.c index 7e324db6c4b0..1c404f6543f3 100644 --- a/lib/idn.c +++ b/lib/idn.c @@ -45,10 +45,6 @@ #endif #endif /* USE_LIBIDN2 */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* for macOS and iOS targets */ #ifdef USE_APPLE_IDN #include @@ -108,7 +104,7 @@ static CURLcode mac_idn_to_ascii(const char *in, char **out) buffer, sizeof(buffer) - 1, &info, &err); uidna_close(idna); if(!U_FAILURE(err) && !info.errors) { - *out = strdup(buffer); + *out = curlx_strdup(buffer); if(*out) return CURLE_OK; else @@ -136,7 +132,7 @@ static CURLcode mac_ascii_to_idn(const char *in, char **out) sizeof(buffer) - 1, &info, &err); uidna_close(idna); if(!U_FAILURE(err)) { - *out = strdup(buffer); + *out = curlx_strdup(buffer); if(*out) return CURLE_OK; else @@ -179,7 +175,7 @@ static CURLcode win32_idn_to_ascii(const char *in, char **out) if(chars) { char *mstr = curlx_convert_wchar_to_UTF8(punycode); if(mstr) { - *out = strdup(mstr); + *out = curlx_strdup(mstr); curlx_unicodefree(mstr); if(!*out) return CURLE_OUT_OF_MEMORY; @@ -209,7 +205,7 @@ static CURLcode win32_ascii_to_idn(const char *in, char **output) /* 'chars' is "the number of characters retrieved" */ char *mstr = curlx_convert_wchar_to_UTF8(idn); if(mstr) { - out = strdup(mstr); + out = curlx_strdup(mstr); curlx_unicodefree(mstr); if(!out) return CURLE_OUT_OF_MEMORY; @@ -314,7 +310,7 @@ CURLcode Curl_idn_decode(const char *input, char **output) CURLcode result = idn_decode(input, &d); #ifdef USE_LIBIDN2 if(!result) { - char *c = strdup(d); + char *c = curlx_strdup(d); idn2_free(d); if(c) d = c; @@ -325,7 +321,7 @@ CURLcode Curl_idn_decode(const char *input, char **output) if(!result) { if(!d[0]) { /* ended up zero length, not acceptable */ result = CURLE_URL_MALFORMAT; - free(d); + curlx_free(d); } else *output = d; @@ -339,7 +335,7 @@ CURLcode Curl_idn_encode(const char *puny, char **output) CURLcode result = idn_encode(puny, &d); #ifdef USE_LIBIDN2 if(!result) { - char *c = strdup(d); + char *c = curlx_strdup(d); idn2_free(d); if(c) d = c; diff --git a/lib/if2ip.c b/lib/if2ip.c index 79b0599106de..c2b8aafc4d7e 100644 --- a/lib/if2ip.c +++ b/lib/if2ip.c @@ -55,10 +55,6 @@ #include "curlx/inet_ntop.h" #include "if2ip.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* ------------------------------------------------------------------ */ #ifdef USE_IPV6 diff --git a/lib/imap.c b/lib/imap.c index af9b124d1e72..d093e46d33ab 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -78,10 +78,6 @@ #include "curlx/warnless.h" #include "curl_ctype.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* meta key for storing protocol meta at easy handle */ #define CURL_META_IMAP_EASY "meta:proto:imap:easy" @@ -617,8 +613,8 @@ static CURLcode imap_perform_login(struct Curl_easy *data, result = imap_sendf(data, imapc, "LOGIN %s %s", user ? user : "", passwd ? passwd : ""); - free(user); - free(passwd); + curlx_free(user); + curlx_free(passwd); if(!result) imap_state(data, imapc, IMAP_LOGIN); @@ -751,14 +747,14 @@ static CURLcode imap_perform_list(struct Curl_easy *data, else { /* Make sure the mailbox is in the correct atom format if necessary */ char *mailbox = imap->mailbox ? imap_atom(imap->mailbox, TRUE) - : strdup(""); + : curlx_strdup(""); if(!mailbox) return CURLE_OUT_OF_MEMORY; /* Send the LIST command */ result = imap_sendf(data, imapc, "LIST \"%s\" *", mailbox); - free(mailbox); + curlx_free(mailbox); } if(!result) @@ -797,7 +793,7 @@ static CURLcode imap_perform_select(struct Curl_easy *data, /* Send the SELECT command */ result = imap_sendf(data, imapc, "SELECT %s", mailbox); - free(mailbox); + curlx_free(mailbox); if(!result) imap_state(data, imapc, IMAP_SELECT); @@ -947,7 +943,7 @@ static CURLcode imap_perform_append(struct Curl_easy *data, cleanup: curlx_dyn_free(&flags); - free(mailbox); + curlx_free(mailbox); if(!result) imap_state(data, imapc, IMAP_APPEND); @@ -1338,7 +1334,7 @@ static CURLcode imap_state_select_resp(struct Curl_easy *data, else { /* Note the currently opened mailbox on this connection */ DEBUGASSERT(!imapc->mailbox); - imapc->mailbox = strdup(imap->mailbox); + imapc->mailbox = curlx_strdup(imap->mailbox); if(!imapc->mailbox) return CURLE_OUT_OF_MEMORY; @@ -1967,7 +1963,7 @@ static void imap_easy_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; imap_easy_reset(imap); - free(imap); + curlx_free(imap); } static void imap_conn_dtor(void *key, size_t klen, void *entry) @@ -1978,7 +1974,7 @@ static void imap_conn_dtor(void *key, size_t klen, void *entry) Curl_pp_disconnect(&imapc->pp); curlx_dyn_free(&imapc->dyn); Curl_safefree(imapc->mailbox); - free(imapc); + curlx_free(imapc); } static CURLcode imap_setup_connection(struct Curl_easy *data, @@ -1988,7 +1984,7 @@ static CURLcode imap_setup_connection(struct Curl_easy *data, struct pingpong *pp; struct IMAP *imap; - imapc = calloc(1, sizeof(*imapc)); + imapc = curlx_calloc(1, sizeof(*imapc)); if(!imapc) return CURLE_OUT_OF_MEMORY; @@ -2005,7 +2001,7 @@ static CURLcode imap_setup_connection(struct Curl_easy *data, if(Curl_conn_meta_set(conn, CURL_META_IMAP_CONN, imapc, imap_conn_dtor)) return CURLE_OUT_OF_MEMORY; - imap = calloc(1, sizeof(struct IMAP)); + imap = curlx_calloc(1, sizeof(struct IMAP)); if(!imap || Curl_meta_set(data, CURL_META_IMAP_EASY, imap, imap_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -2078,7 +2074,7 @@ static char *imap_atom(const char *str, bool escape_only) nclean = strcspn(str, "() {%*]\\\""); if(len == nclean) /* nothing to escape, return a strdup */ - return strdup(str); + return curlx_strdup(str); curlx_dyn_init(&line, 2000); @@ -2258,7 +2254,7 @@ static CURLcode imap_parse_url_path(struct Curl_easy *data, result = Curl_urldecode(begin, ptr - begin, &value, &valuelen, REJECT_CTRL); if(result) { - free(name); + curlx_free(name); return result; } @@ -2279,7 +2275,7 @@ static CURLcode imap_parse_url_path(struct Curl_easy *data, imap->uidvalidity = (unsigned int)num; imap->uidvalidity_set = TRUE; } - free(value); + curlx_free(value); } else if(curl_strequal(name, "UID") && !imap->uid) { imap->uid = value; @@ -2294,15 +2290,15 @@ static CURLcode imap_parse_url_path(struct Curl_easy *data, imap->partial = value; } else { - free(name); - free(value); + curlx_free(name); + curlx_free(value); return CURLE_URL_MALFORMAT; } } else /* blank? */ - free(value); - free(name); + curlx_free(value); + curlx_free(name); } /* Does the URL contain a query parameter? Only valid when we have a mailbox @@ -2346,7 +2342,7 @@ static CURLcode imap_parse_custom_request(struct Curl_easy *data, params++; if(*params) { - imap->custom_params = strdup(params); + imap->custom_params = curlx_strdup(params); imap->custom[params - imap->custom] = '\0'; if(!imap->custom_params) diff --git a/lib/ldap.c b/lib/ldap.c index 7f2af3664325..6c6207038571 100644 --- a/lib/ldap.c +++ b/lib/ldap.c @@ -94,10 +94,6 @@ #include "curlx/base64.h" #include "connect.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef USE_WIN32_LDAP #define FREE_ON_WINLDAP(x) curlx_unicodefree(x) #define curl_ldap_num_t ULONG @@ -642,7 +638,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) if(val_b64_sz > 0) { result = Curl_client_write(data, CLIENTWRITE_BODY, val_b64, val_b64_sz); - free(val_b64); + curlx_free(val_b64); if(result) { ldap_value_free_len(vals); FREE_ON_WINLDAP(attr); @@ -809,15 +805,15 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, ludp->lud_host = conn->host.name; /* Duplicate the path */ - p = path = strdup(data->state.up.path + 1); + p = path = curlx_strdup(data->state.up.path + 1); if(!path) return LDAP_NO_MEMORY; /* Duplicate the query if present */ if(data->state.up.query) { - q = query = strdup(data->state.up.query); + q = query = curlx_strdup(data->state.up.query); if(!query) { - free(path); + curlx_free(path); return LDAP_NO_MEMORY; } } @@ -843,7 +839,7 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, ludp->lud_dn = curlx_convert_UTF8_to_tchar(unescaped); /* Free the unescaped string as we are done with it */ - free(unescaped); + curlx_free(unescaped); if(!ludp->lud_dn) { rc = LDAP_NO_MEMORY; @@ -870,9 +866,9 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, /* Allocate our array (+1 for the NULL entry) */ #ifdef USE_WIN32_LDAP - ludp->lud_attrs = calloc(count + 1, sizeof(TCHAR *)); + ludp->lud_attrs = curlx_calloc(count + 1, sizeof(TCHAR *)); #else - ludp->lud_attrs = calloc(count + 1, sizeof(char *)); + ludp->lud_attrs = curlx_calloc(count + 1, sizeof(char *)); #endif if(!ludp->lud_attrs) { rc = LDAP_NO_MEMORY; @@ -902,7 +898,7 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, ludp->lud_attrs[i] = curlx_convert_UTF8_to_tchar(unescaped); /* Free the unescaped string as we are done with it */ - free(unescaped); + curlx_free(unescaped); if(!ludp->lud_attrs[i]) { rc = LDAP_NO_MEMORY; @@ -966,7 +962,7 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, ludp->lud_filter = curlx_convert_UTF8_to_tchar(unescaped); /* Free the unescaped string as we are done with it */ - free(unescaped); + curlx_free(unescaped); if(!ludp->lud_filter) { rc = LDAP_NO_MEMORY; @@ -986,8 +982,8 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, } quit: - free(path); - free(query); + curlx_free(path); + curlx_free(query); return rc; } @@ -996,7 +992,7 @@ static curl_ldap_num_t ldap_url_parse_low(struct Curl_easy *data, const struct connectdata *conn, LDAPURLDesc **ludpp) { - LDAPURLDesc *ludp = calloc(1, sizeof(*ludp)); + LDAPURLDesc *ludp = curlx_calloc(1, sizeof(*ludp)); curl_ldap_num_t rc; *ludpp = NULL; @@ -1021,8 +1017,8 @@ static void ldap_free_urldesc_low(LDAPURLDesc *ludp) curlx_unicodefree(ludp->lud_dn); curlx_unicodefree(ludp->lud_filter); #else - free(ludp->lud_dn); - free(ludp->lud_filter); + curlx_free(ludp->lud_dn); + curlx_free(ludp->lud_filter); #endif if(ludp->lud_attrs) { @@ -1031,13 +1027,13 @@ static void ldap_free_urldesc_low(LDAPURLDesc *ludp) #ifdef USE_WIN32_LDAP curlx_unicodefree(ludp->lud_attrs[i]); #else - free(ludp->lud_attrs[i]); + curlx_free(ludp->lud_attrs[i]); #endif } - free(ludp->lud_attrs); + curlx_free(ludp->lud_attrs); } - free(ludp); + curlx_free(ludp); } #endif /* !HAVE_LDAP_URL_PARSE */ diff --git a/lib/llist.c b/lib/llist.c index c9a7d4a8a789..ebcda82a04ed 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -27,10 +27,6 @@ #include #include "llist.h" -#include "curl_memory.h" - -/* this must be the last include file */ -#include "memdebug.h" #ifdef DEBUGBUILD #define LLISTINIT 0x100cc001 /* random pattern */ diff --git a/lib/md4.c b/lib/md4.c index 0cc62f815233..7929e57f65c0 100644 --- a/lib/md4.c +++ b/lib/md4.c @@ -71,10 +71,6 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(USE_WOLFSSL) && !defined(WOLFSSL_NO_MD4) diff --git a/lib/md5.c b/lib/md5.c index 4b38bb070b32..a579b02c63ae 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -81,10 +81,6 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef USE_GNUTLS typedef struct md5_ctx my_md5_ctx; @@ -604,23 +600,23 @@ struct MD5_context *Curl_MD5_init(const struct MD5_params *md5params) struct MD5_context *ctxt; /* Create MD5 context */ - ctxt = malloc(sizeof(*ctxt)); + ctxt = curlx_malloc(sizeof(*ctxt)); if(!ctxt) return ctxt; - ctxt->md5_hashctx = malloc(md5params->md5_ctxtsize); + ctxt->md5_hashctx = curlx_malloc(md5params->md5_ctxtsize); if(!ctxt->md5_hashctx) { - free(ctxt); + curlx_free(ctxt); return NULL; } ctxt->md5_hash = md5params; if((*md5params->md5_init_func)(ctxt->md5_hashctx)) { - free(ctxt->md5_hashctx); - free(ctxt); + curlx_free(ctxt->md5_hashctx); + curlx_free(ctxt); return NULL; } @@ -640,8 +636,8 @@ CURLcode Curl_MD5_final(struct MD5_context *context, unsigned char *result) { (*context->md5_hash->md5_final_func)(result, context->md5_hashctx); - free(context->md5_hashctx); - free(context); + curlx_free(context->md5_hashctx); + curlx_free(context); return CURLE_OK; } diff --git a/lib/memdebug.c b/lib/memdebug.c index 1121dc26f550..f5b88731ee35 100644 --- a/lib/memdebug.c +++ b/lib/memdebug.c @@ -35,10 +35,6 @@ #include "backtrace.h" #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - struct memdebug { size_t size; union { diff --git a/lib/memdebug.h b/lib/memdebug.h deleted file mode 100644 index c2b7fad9528b..000000000000 --- a/lib/memdebug.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef HEADER_CURL_MEMDEBUG_H -#define HEADER_CURL_MEMDEBUG_H -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ - -/* - * CAUTION: this header is designed to work when included by the app-side - * as well as the library. Do not mix with library internals! - */ - -#ifdef CURLDEBUG - -/* Set this symbol on the command-line, recompile all lib-sources */ -#undef strdup -#define strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__) -#undef malloc -#define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) -#undef calloc -#define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__) -#undef realloc -#define realloc(ptr,size) curl_dbg_realloc(ptr, size, __LINE__, __FILE__) -#undef free -#define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__) - -#ifdef _WIN32 -#undef Curl_tcsdup -#ifdef UNICODE -#define Curl_tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__) -#else -#define Curl_tcsdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__) -#endif -#endif /* _WIN32 */ - -#endif /* CURLDEBUG */ -#endif /* HEADER_CURL_MEMDEBUG_H */ diff --git a/lib/mime.c b/lib/mime.c index b1f432c0b044..7ebe47315de9 100644 --- a/lib/mime.c +++ b/lib/mime.c @@ -50,10 +50,6 @@ struct Curl_easy; #include "slist.h" #include "curlx/dynbuf.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef _WIN32 # ifndef R_OK # define R_OK 4 @@ -357,13 +353,13 @@ static char *strippath(const char *fullfile) { char *filename; char *base; - filename = strdup(fullfile); /* duplicate since basename() may ruin the - buffer it works on */ + filename = curlx_strdup(fullfile); /* duplicate since basename() may ruin + the buffer it works on */ if(!filename) return NULL; - base = strdup(basename(filename)); + base = curlx_strdup(basename(filename)); - free(filename); /* free temporary buffer */ + curlx_free(filename); /* free temporary buffer */ return base; /* returns an allocated string or NULL ! */ } @@ -1190,9 +1186,9 @@ void curl_mime_free(curl_mime *mime) part = mime->firstpart; mime->firstpart = part->nextpart; Curl_mime_cleanpart(part); - free(part); + curlx_free(part); } - free(mime); + curlx_free(mime); } } @@ -1282,7 +1278,7 @@ curl_mime *curl_mime_init(void *easy) { curl_mime *mime; - mime = (curl_mime *) malloc(sizeof(*mime)); + mime = (curl_mime *)curlx_malloc(sizeof(*mime)); if(mime) { mime->parent = NULL; @@ -1294,7 +1290,7 @@ curl_mime *curl_mime_init(void *easy) (unsigned char *) &mime->boundary[MIME_BOUNDARY_DASHES], MIME_RAND_BOUNDARY_CHARS + 1)) { /* failed to get random separator, bail out */ - free(mime); + curlx_free(mime); return NULL; } mimesetstate(&mime->state, MIMESTATE_BEGIN, NULL); @@ -1319,7 +1315,7 @@ curl_mimepart *curl_mime_addpart(curl_mime *mime) if(!mime) return NULL; - part = (curl_mimepart *) malloc(sizeof(*part)); + part = (curl_mimepart *)curlx_malloc(sizeof(*part)); if(part) { Curl_mime_initpart(part); @@ -1345,7 +1341,7 @@ CURLcode curl_mime_name(curl_mimepart *part, const char *name) Curl_safefree(part->name); if(name) { - part->name = strdup(name); + part->name = curlx_strdup(name); if(!part->name) return CURLE_OUT_OF_MEMORY; } @@ -1362,7 +1358,7 @@ CURLcode curl_mime_filename(curl_mimepart *part, const char *filename) Curl_safefree(part->filename); if(filename) { - part->filename = strdup(filename); + part->filename = curlx_strdup(filename); if(!part->filename) return CURLE_OUT_OF_MEMORY; } @@ -1415,7 +1411,7 @@ CURLcode curl_mime_filedata(curl_mimepart *part, const char *filename) if(curlx_stat(filename, &sbuf)) result = CURLE_READ_ERROR; else { - part->data = strdup(filename); + part->data = curlx_strdup(filename); if(!part->data) result = CURLE_OUT_OF_MEMORY; else { @@ -1438,7 +1434,7 @@ CURLcode curl_mime_filedata(curl_mimepart *part, const char *filename) result = CURLE_OUT_OF_MEMORY; else { result = curl_mime_filename(part, base); - free(base); + curlx_free(base); } } } @@ -1455,7 +1451,7 @@ CURLcode curl_mime_type(curl_mimepart *part, const char *mimetype) Curl_safefree(part->mimetype); if(mimetype) { - part->mimetype = strdup(mimetype); + part->mimetype = curlx_strdup(mimetype); if(!part->mimetype) return CURLE_OUT_OF_MEMORY; } @@ -1696,7 +1692,7 @@ CURLcode Curl_mime_add_header(struct curl_slist **slp, const char *fmt, ...) if(hdr) *slp = hdr; else - free(s); + curlx_free(s); } return hdr ? CURLE_OK : CURLE_OUT_OF_MEMORY; diff --git a/lib/mprintf.c b/lib/mprintf.c index 176f8a3e4b78..046917aeb5f0 100644 --- a/lib/mprintf.c +++ b/lib/mprintf.c @@ -27,10 +27,6 @@ #include "curl_printf.h" #include "curlx/strparse.h" -#include "curl_memory.h" -/* The last #include file should be: */ -#include "memdebug.h" - #ifdef HAVE_LONGLONG # define LONG_LONG_TYPE long long # define HAVE_LONG_LONG_TYPE @@ -1177,7 +1173,7 @@ char *curl_mvaprintf(const char *format, va_list ap_save) } if(curlx_dyn_len(info.b)) return curlx_dyn_ptr(info.b); - return strdup(""); + return curlx_strdup(""); } char *curl_maprintf(const char *format, ...) diff --git a/lib/mqtt.c b/lib/mqtt.c index 9cbe800ded8e..a8975d53919b 100644 --- a/lib/mqtt.c +++ b/lib/mqtt.c @@ -40,10 +40,6 @@ #include "multiif.h" #include "rand.h" -/* The last 2 #includes file should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* first byte is command. second byte is for flags. */ #define MQTT_MSG_CONNECT 0x10 @@ -146,14 +142,14 @@ static void mqtt_easy_dtor(void *key, size_t klen, void *entry) (void)klen; curlx_dyn_free(&mq->sendbuf); curlx_dyn_free(&mq->recvbuf); - free(mq); + curlx_free(mq); } static void mqtt_conn_dtor(void *key, size_t klen, void *entry) { (void)key; (void)klen; - free(entry); + curlx_free(entry); } static CURLcode mqtt_setup_conn(struct Curl_easy *data, @@ -163,12 +159,12 @@ static CURLcode mqtt_setup_conn(struct Curl_easy *data, struct mqtt_conn *mqtt; struct MQTT *mq; - mqtt = calloc(1, sizeof(*mqtt)); + mqtt = curlx_calloc(1, sizeof(*mqtt)); if(!mqtt || Curl_conn_meta_set(conn, CURL_META_MQTT_CONN, mqtt, mqtt_conn_dtor)) return CURLE_OUT_OF_MEMORY; - mq = calloc(1, sizeof(struct MQTT)); + mq = curlx_calloc(1, sizeof(struct MQTT)); if(!mq) return CURLE_OUT_OF_MEMORY; curlx_dyn_init(&mq->recvbuf, DYN_MQTT_RECV); @@ -350,7 +346,7 @@ static CURLcode mqtt_connect(struct Curl_easy *data) /* allocating packet */ if(packetlen > 0xFFFFFFF) return CURLE_WEIRD_SERVER_REPLY; - packet = calloc(1, packetlen); + packet = curlx_calloc(1, packetlen); if(!packet) return CURLE_OUT_OF_MEMORY; @@ -400,7 +396,7 @@ static CURLcode mqtt_connect(struct Curl_easy *data) end: if(packet) - free(packet); + curlx_free(packet); Curl_safefree(data->state.aptr.user); Curl_safefree(data->state.aptr.passwd); return result; @@ -524,7 +520,7 @@ static CURLcode mqtt_subscribe(struct Curl_easy *data) n = mqtt_encode_len((char *)encodedsize, packetlen); packetlen += n + 1; /* add one for the control packet type byte */ - packet = malloc(packetlen); + packet = curlx_malloc(packetlen); if(!packet) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -542,8 +538,8 @@ static CURLcode mqtt_subscribe(struct Curl_easy *data) result = mqtt_send(data, (const char *)packet, packetlen); fail: - free(topic); - free(packet); + curlx_free(topic); + curlx_free(packet); return result; } @@ -620,7 +616,7 @@ static CURLcode mqtt_publish(struct Curl_easy *data) } /* add the control byte and the encoded remaining length */ - pkt = malloc(remaininglength + 1 + encodelen); + pkt = curlx_malloc(remaininglength + 1 + encodelen); if(!pkt) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -639,8 +635,8 @@ static CURLcode mqtt_publish(struct Curl_easy *data) result = mqtt_send(data, (const char *)pkt, i); fail: - free(pkt); - free(topic); + curlx_free(pkt); + curlx_free(topic); return result; } diff --git a/lib/multi.c b/lib/multi.c index f7265a94a9ec..c5b78f53e446 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -54,10 +54,6 @@ #include "socks.h" #include "urlapi-int.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* initial multi->xfers table size for a full multi */ #define CURL_XFER_TABLE_SIZE 512 @@ -235,7 +231,7 @@ struct Curl_multi *Curl_multi_handle(uint32_t xfer_table_size, size_t dnssize, /* dns hash */ size_t sesssize) /* TLS session cache */ { - struct Curl_multi *multi = calloc(1, sizeof(struct Curl_multi)); + struct Curl_multi *multi = curlx_calloc(1, sizeof(struct Curl_multi)); if(!multi) return NULL; @@ -328,7 +324,7 @@ struct Curl_multi *Curl_multi_handle(uint32_t xfer_table_size, Curl_uint32_bset_destroy(&multi->msgsent); Curl_uint32_tbl_destroy(&multi->xfers); - free(multi); + curlx_free(multi); return NULL; } @@ -2022,7 +2018,7 @@ static CURLMcode state_performing(struct Curl_easy *data, data->state.errorbuf = FALSE; if(!newurl) /* typically for HTTP_1_1_REQUIRED error on first flight */ - newurl = strdup(data->state.url); + newurl = curlx_strdup(data->state.url); if(!newurl) { result = CURLE_OUT_OF_MEMORY; } @@ -2068,7 +2064,7 @@ static CURLMcode state_performing(struct Curl_easy *data, if(!retry) { /* if the URL is a follow-location and not just a retried request then figure out the URL here */ - free(newurl); + curlx_free(newurl); newurl = data->req.newurl; data->req.newurl = NULL; follow = FOLLOW_REDIR; @@ -2089,7 +2085,7 @@ static CURLMcode state_performing(struct Curl_easy *data, /* but first check to see if we got a location info even though we are not following redirects */ if(data->req.location) { - free(newurl); + curlx_free(newurl); newurl = data->req.location; data->req.location = NULL; result = multi_follow(data, handler, newurl, FOLLOW_FAKE); @@ -2109,7 +2105,7 @@ static CURLMcode state_performing(struct Curl_easy *data, *nowp = curlx_now(); mspeed_check(data, *nowp); } - free(newurl); + curlx_free(newurl); *resultp = result; return rc; } @@ -2237,7 +2233,7 @@ static CURLMcode state_do(struct Curl_easy *data, /* Have error handler disconnect conn if we cannot retry */ *stream_errorp = TRUE; } - free(newurl); + curlx_free(newurl); } else { /* failure detected */ @@ -2976,7 +2972,7 @@ CURLMcode curl_multi_cleanup(CURLM *m) Curl_uint32_bset_destroy(&multi->pending); Curl_uint32_bset_destroy(&multi->msgsent); Curl_uint32_tbl_destroy(&multi->xfers); - free(multi); + curlx_free(multi); return CURLM_OK; } @@ -3814,7 +3810,7 @@ CURL **curl_multi_get_handles(CURLM *m) struct Curl_multi *multi = m; void *entry; unsigned int count = Curl_uint32_tbl_count(&multi->xfers); - CURL **a = malloc(sizeof(struct Curl_easy *) * (count + 1)); + CURL **a = curlx_malloc(sizeof(struct Curl_easy *) * (count + 1)); if(a) { unsigned int i = 0, mid; @@ -3895,13 +3891,13 @@ CURLcode Curl_multi_xfer_buf_borrow(struct Curl_easy *data, if(data->multi->xfer_buf && data->set.buffer_size > data->multi->xfer_buf_len) { /* not large enough, get a new one */ - free(data->multi->xfer_buf); + curlx_free(data->multi->xfer_buf); data->multi->xfer_buf = NULL; data->multi->xfer_buf_len = 0; } if(!data->multi->xfer_buf) { - data->multi->xfer_buf = malloc(curlx_uitouz(data->set.buffer_size)); + data->multi->xfer_buf = curlx_malloc(curlx_uitouz(data->set.buffer_size)); if(!data->multi->xfer_buf) { failf(data, "could not allocate xfer_buf of %u bytes", data->set.buffer_size); @@ -3948,14 +3944,14 @@ CURLcode Curl_multi_xfer_ulbuf_borrow(struct Curl_easy *data, if(data->multi->xfer_ulbuf && data->set.upload_buffer_size > data->multi->xfer_ulbuf_len) { /* not large enough, get a new one */ - free(data->multi->xfer_ulbuf); + curlx_free(data->multi->xfer_ulbuf); data->multi->xfer_ulbuf = NULL; data->multi->xfer_ulbuf_len = 0; } if(!data->multi->xfer_ulbuf) { data->multi->xfer_ulbuf = - malloc(curlx_uitouz(data->set.upload_buffer_size)); + curlx_malloc(curlx_uitouz(data->set.upload_buffer_size)); if(!data->multi->xfer_ulbuf) { failf(data, "could not allocate xfer_ulbuf of %u bytes", data->set.upload_buffer_size); @@ -3996,13 +3992,13 @@ CURLcode Curl_multi_xfer_sockbuf_borrow(struct Curl_easy *data, if(data->multi->xfer_sockbuf && blen > data->multi->xfer_sockbuf_len) { /* not large enough, get a new one */ - free(data->multi->xfer_sockbuf); + curlx_free(data->multi->xfer_sockbuf); data->multi->xfer_sockbuf = NULL; data->multi->xfer_sockbuf_len = 0; } if(!data->multi->xfer_sockbuf) { - data->multi->xfer_sockbuf = malloc(blen); + data->multi->xfer_sockbuf = curlx_malloc(blen); if(!data->multi->xfer_sockbuf) { failf(data, "could not allocate xfer_sockbuf of %zu bytes", blen); return CURLE_OUT_OF_MEMORY; diff --git a/lib/multi_ev.c b/lib/multi_ev.c index d5db331cf1f1..026cbd29968e 100644 --- a/lib/multi_ev.c +++ b/lib/multi_ev.c @@ -41,10 +41,6 @@ #include "multihandle.h" #include "socks.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void mev_in_callback(struct Curl_multi *multi, bool value) { @@ -85,7 +81,7 @@ static void mev_sh_entry_dtor(void *freethis) { struct mev_sh_entry *entry = (struct mev_sh_entry *)freethis; Curl_uint32_spbset_destroy(&entry->xfers); - free(entry); + curlx_free(entry); } /* look up a given socket in the socket hash, skip invalid sockets */ @@ -112,7 +108,7 @@ mev_sh_entry_add(struct Curl_hash *sh, curl_socket_t s) } /* not present, add it */ - check = calloc(1, sizeof(struct mev_sh_entry)); + check = curlx_calloc(1, sizeof(struct mev_sh_entry)); if(!check) return NULL; /* major failure */ @@ -446,7 +442,7 @@ static void mev_pollset_dtor(void *key, size_t klen, void *entry) (void)klen; if(ps) { Curl_pollset_cleanup(ps); - free(ps); + curlx_free(ps); } } diff --git a/lib/multi_ntfy.c b/lib/multi_ntfy.c index d7913bbbfc97..43e4db9e8270 100644 --- a/lib/multi_ntfy.c +++ b/lib/multi_ntfy.c @@ -32,11 +32,6 @@ #include "multiif.h" #include "multi_ntfy.h" -/* The last 3 #include files should be in this order */ -#include "curl_printf.h" -#include "curl_memory.h" -#include "memdebug.h" - struct mntfy_entry { uint32_t mid; @@ -54,12 +49,12 @@ struct mntfy_chunk { static struct mntfy_chunk *mnfty_chunk_create(void) { - return calloc(1, sizeof(struct mntfy_chunk)); + return curlx_calloc(1, sizeof(struct mntfy_chunk)); } static void mnfty_chunk_destroy(struct mntfy_chunk *chunk) { - free(chunk); + curlx_free(chunk); } static void mnfty_chunk_reset(struct mntfy_chunk *chunk) diff --git a/lib/netrc.c b/lib/netrc.c index 9c5c6c7f20c8..f8de4082972c 100644 --- a/lib/netrc.c +++ b/lib/netrc.c @@ -42,10 +42,6 @@ #include "curlx/fopen.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Get user and password from .netrc when given a machine name */ enum host_lookup_state { @@ -277,8 +273,8 @@ static NETRCcode parsenetrc(struct store_netrc *store, our_login = !Curl_timestrcmp(login, tok); else { our_login = TRUE; - free(login); - login = strdup(tok); + curlx_free(login); + login = curlx_strdup(tok); if(!login) { retcode = NETRC_OUT_OF_MEMORY; /* allocation failed */ goto out; @@ -288,8 +284,8 @@ static NETRCcode parsenetrc(struct store_netrc *store, keyword = NONE; } else if(keyword == PASSWORD) { - free(password); - password = strdup(tok); + curlx_free(password); + password = curlx_strdup(tok); if(!password) { retcode = NETRC_OUT_OF_MEMORY; /* allocation failed */ goto out; @@ -346,7 +342,7 @@ static NETRCcode parsenetrc(struct store_netrc *store, if(!retcode) { if(!password && our_login) { /* success without a password, set a blank one */ - password = strdup(""); + password = curlx_strdup(""); if(!password) retcode = NETRC_OUT_OF_MEMORY; /* out of memory */ } @@ -364,8 +360,8 @@ static NETRCcode parsenetrc(struct store_netrc *store, curlx_dyn_free(filebuf); store->loaded = FALSE; if(!specific_login) - free(login); - free(password); + curlx_free(login); + curlx_free(password); } return retcode; @@ -444,25 +440,25 @@ NETRCcode Curl_parsenetrc(struct store_netrc *store, const char *host, filealloc = curl_maprintf("%s%s.netrc", home, DIR_CHAR); if(!filealloc) { - free(homea); + curlx_free(homea); return NETRC_OUT_OF_MEMORY; } } retcode = parsenetrc(store, host, loginp, passwordp, filealloc); - free(filealloc); + curlx_free(filealloc); #ifdef _WIN32 if(retcode == NETRC_FILE_MISSING) { /* fallback to the old-style "_netrc" file */ filealloc = curl_maprintf("%s%s_netrc", home, DIR_CHAR); if(!filealloc) { - free(homea); + curlx_free(homea); return NETRC_OUT_OF_MEMORY; } retcode = parsenetrc(store, host, loginp, passwordp, filealloc); - free(filealloc); + curlx_free(filealloc); } #endif - free(homea); + curlx_free(homea); } else retcode = parsenetrc(store, host, loginp, passwordp, netrcfile); diff --git a/lib/openldap.c b/lib/openldap.c index 806ccb33ccd1..107f6da832a5 100644 --- a/lib/openldap.c +++ b/lib/openldap.c @@ -53,10 +53,6 @@ #include "curl_sasl.h" #include "strcase.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Uncommenting this will enable the built-in debug logging of the openldap * library. The debug log level can be set using the CURL_OPENLDAP_TRACE @@ -577,7 +573,7 @@ static void oldap_easy_dtor(void *key, size_t klen, void *entry) struct ldapreqinfo *lr = entry; (void)key; (void)klen; - free(lr); + curlx_free(lr); } static void oldap_conn_dtor(void *key, size_t klen, void *entry) @@ -589,7 +585,7 @@ static void oldap_conn_dtor(void *key, size_t klen, void *entry) ldap_unbind_ext(li->ld, NULL, NULL); li->ld = NULL; } - free(li); + curlx_free(li); } static CURLcode oldap_connect(struct Curl_easy *data, bool *done) @@ -606,7 +602,7 @@ static CURLcode oldap_connect(struct Curl_easy *data, bool *done) (void)done; - li = calloc(1, sizeof(struct ldapconninfo)); + li = curlx_calloc(1, sizeof(struct ldapconninfo)); if(!li) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -697,7 +693,7 @@ static CURLcode oldap_connect(struct Curl_easy *data, bool *done) result = oldap_perform_bind(data, OLDAP_BIND); out: - free(hosturl); + curlx_free(hosturl); return result; } @@ -1023,7 +1019,7 @@ static CURLcode oldap_do(struct Curl_easy *data, bool *done) goto out; } - lr = calloc(1, sizeof(struct ldapreqinfo)); + lr = curlx_calloc(1, sizeof(struct ldapreqinfo)); if(!lr || Curl_meta_set(data, CURL_META_LDAP_EASY, lr, oldap_easy_dtor)) { ldap_abandon_ext(li->ld, msgid, NULL, NULL); @@ -1219,7 +1215,7 @@ static CURLcode oldap_recv(struct Curl_easy *data, int sockindex, char *buf, if(!result) result = client_write(data, STRCONST(": "), val_b64, val_b64_sz, STRCONST("\n")); - free(val_b64); + curlx_free(val_b64); } else result = client_write(data, STRCONST(" "), diff --git a/lib/pingpong.c b/lib/pingpong.c index 297389043f0e..7ac321af7244 100644 --- a/lib/pingpong.c +++ b/lib/pingpong.c @@ -37,10 +37,6 @@ #include "multiif.h" #include "vtls/vtls.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef USE_PINGPONG /* Returns timeout in ms. 0 or negative number means the timeout has already diff --git a/lib/pop3.c b/lib/pop3.c index 503f4ecb2bd5..f10108229b6a 100644 --- a/lib/pop3.c +++ b/lib/pop3.c @@ -78,10 +78,6 @@ #include "curlx/warnless.h" #include "strdup.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Authentication type flags */ #define POP3_TYPE_CLEARTEXT (1 << 0) #define POP3_TYPE_APOP (1 << 1) @@ -1523,7 +1519,7 @@ static void pop3_easy_dtor(void *key, size_t klen, void *entry) /* Cleanup our per-request based variables */ Curl_safefree(pop3->id); Curl_safefree(pop3->custom); - free(pop3); + curlx_free(pop3); } static void pop3_conn_dtor(void *key, size_t klen, void *entry) @@ -1534,19 +1530,19 @@ static void pop3_conn_dtor(void *key, size_t klen, void *entry) DEBUGASSERT(pop3c); Curl_pp_disconnect(&pop3c->pp); Curl_safefree(pop3c->apoptimestamp); - free(pop3c); + curlx_free(pop3c); } static CURLcode pop3_setup_connection(struct Curl_easy *data, struct connectdata *conn) { struct pop3_conn *pop3c; - struct POP3 *pop3 = calloc(1, sizeof(*pop3)); + struct POP3 *pop3 = curlx_calloc(1, sizeof(*pop3)); if(!pop3 || Curl_meta_set(data, CURL_META_POP3_EASY, pop3, pop3_easy_dtor)) return CURLE_OUT_OF_MEMORY; - pop3c = calloc(1, sizeof(*pop3c)); + pop3c = curlx_calloc(1, sizeof(*pop3c)); if(!pop3c || Curl_conn_meta_set(conn, CURL_META_POP3_CONN, pop3c, pop3_conn_dtor)) return CURLE_OUT_OF_MEMORY; diff --git a/lib/psl.c b/lib/psl.c index f645763d063b..5bf96d09bd88 100644 --- a/lib/psl.c +++ b/lib/psl.c @@ -31,10 +31,6 @@ #include "psl.h" #include "curl_share.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - void Curl_psl_destroy(struct PslCache *pslcache) { if(pslcache->psl) { diff --git a/lib/rand.c b/lib/rand.c index 5eace0283349..8c5a2cf71e44 100644 --- a/lib/rand.c +++ b/lib/rand.c @@ -38,10 +38,6 @@ #include "rand.h" #include "escape.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef _WIN32 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA && \ diff --git a/lib/rename.c b/lib/rename.c index 911afca57563..d3f80422e641 100644 --- a/lib/rename.c +++ b/lib/rename.c @@ -32,10 +32,6 @@ #include "curlx/multibyte.h" #include "curlx/timeval.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* return 0 on success, 1 on error */ int Curl_rename(const char *oldpath, const char *newpath) { diff --git a/lib/request.c b/lib/request.c index 324c4c48f96d..581d7d14537a 100644 --- a/lib/request.c +++ b/lib/request.c @@ -36,10 +36,6 @@ #include "url.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - void Curl_req_init(struct SingleRequest *req) { memset(req, 0, sizeof(*req)); diff --git a/lib/rtsp.c b/lib/rtsp.c index dd49ebc42b4d..5a46dc62c407 100644 --- a/lib/rtsp.c +++ b/lib/rtsp.c @@ -42,10 +42,6 @@ #include "strdup.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* meta key for storing protocol meta at easy handle */ #define CURL_META_RTSP_EASY "meta:proto:rtsp:easy" @@ -162,7 +158,7 @@ static void rtsp_easy_dtor(void *key, size_t klen, void *entry) struct RTSP *rtsp = entry; (void)key; (void)klen; - free(rtsp); + curlx_free(rtsp); } static void rtsp_conn_dtor(void *key, size_t klen, void *entry) @@ -171,7 +167,7 @@ static void rtsp_conn_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; curlx_dyn_free(&rtspc->buf); - free(rtspc); + curlx_free(rtspc); } static CURLcode rtsp_setup_connection(struct Curl_easy *data, @@ -180,14 +176,14 @@ static CURLcode rtsp_setup_connection(struct Curl_easy *data, struct rtsp_conn *rtspc; struct RTSP *rtsp; - rtspc = calloc(1, sizeof(*rtspc)); + rtspc = curlx_calloc(1, sizeof(*rtspc)); if(!rtspc) return CURLE_OUT_OF_MEMORY; curlx_dyn_init(&rtspc->buf, MAX_RTP_BUFFERSIZE); if(Curl_conn_meta_set(conn, CURL_META_RTSP_CONN, rtspc, rtsp_conn_dtor)) return CURLE_OUT_OF_MEMORY; - rtsp = calloc(1, sizeof(struct RTSP)); + rtsp = curlx_calloc(1, sizeof(struct RTSP)); if(!rtsp || Curl_meta_set(data, CURL_META_RTSP_EASY, rtsp, rtsp_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -392,7 +388,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) to this origin */ if(!data->state.first_host) { - data->state.first_host = strdup(conn->host.name); + data->state.first_host = curlx_strdup(conn->host.name); if(!data->state.first_host) return CURLE_OUT_OF_MEMORY; @@ -481,7 +477,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) if(rtspreq == RTSPREQ_SETUP && !p_transport) { /* New Transport: setting? */ if(data->set.str[STRING_RTSP_TRANSPORT]) { - free(data->state.aptr.rtsp_transport); + curlx_free(data->state.aptr.rtsp_transport); data->state.aptr.rtsp_transport = curl_maprintf("Transport: %s\r\n", data->set.str[STRING_RTSP_TRANSPORT]); @@ -507,7 +503,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) /* Accept-Encoding header */ if(!Curl_checkheaders(data, STRCONST("Accept-Encoding")) && data->set.str[STRING_ENCODING]) { - free(data->state.aptr.accept_encoding); + curlx_free(data->state.aptr.accept_encoding); data->state.aptr.accept_encoding = curl_maprintf("Accept-Encoding: %s\r\n", data->set.str[STRING_ENCODING]); @@ -563,7 +559,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) /* Check to see if there is a range set in the custom headers */ if(!Curl_checkheaders(data, STRCONST("Range")) && data->state.range) { - free(data->state.aptr.rangeline); + curlx_free(data->state.aptr.rangeline); data->state.aptr.rangeline = curl_maprintf("Range: %s\r\n", data->state.range); p_range = data->state.aptr.rangeline; diff --git a/lib/select.c b/lib/select.c index 041733973e9e..5692fc020d1f 100644 --- a/lib/select.c +++ b/lib/select.c @@ -46,10 +46,6 @@ #include "curlx/wait.h" #include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifndef HAVE_POLL /* * This is a wrapper around select() to aid in Windows compatibility. A @@ -364,7 +360,7 @@ void Curl_pollfds_cleanup(struct curl_pollfds *cpfds) { DEBUGASSERT(cpfds); if(cpfds->allocated_pfds) { - free(cpfds->pfds); + curlx_free(cpfds->pfds); } memset(cpfds, 0, sizeof(*cpfds)); } @@ -374,13 +370,13 @@ static CURLcode cpfds_increase(struct curl_pollfds *cpfds, unsigned int inc) struct pollfd *new_fds; unsigned int new_count = cpfds->count + inc; - new_fds = calloc(new_count, sizeof(struct pollfd)); + new_fds = curlx_calloc(new_count, sizeof(struct pollfd)); if(!new_fds) return CURLE_OUT_OF_MEMORY; memcpy(new_fds, cpfds->pfds, cpfds->count * sizeof(struct pollfd)); if(cpfds->allocated_pfds) - free(cpfds->pfds); + curlx_free(cpfds->pfds); cpfds->pfds = new_fds; cpfds->count = new_count; cpfds->allocated_pfds = TRUE; @@ -521,7 +517,7 @@ void Curl_pollset_init(struct easy_pollset *ps) struct easy_pollset *Curl_pollset_create(void) { - struct easy_pollset *ps = calloc(1, sizeof(*ps)); + struct easy_pollset *ps = curlx_calloc(1, sizeof(*ps)); if(ps) Curl_pollset_init(ps); return ps; @@ -533,11 +529,11 @@ void Curl_pollset_cleanup(struct easy_pollset *ps) DEBUGASSERT(ps->init == CURL_EASY_POLLSET_MAGIC); #endif if(ps->sockets != ps->def_sockets) { - free(ps->sockets); + curlx_free(ps->sockets); ps->sockets = ps->def_sockets; } if(ps->actions != ps->def_actions) { - free(ps->actions); + curlx_free(ps->actions); ps->actions = ps->def_actions; } ps->count = CURL_ARRAYSIZE(ps->def_sockets); @@ -614,21 +610,21 @@ CURLcode Curl_pollset_change(struct Curl_easy *data, ps->count, new_count); if(new_count <= ps->count) return CURLE_OUT_OF_MEMORY; - nsockets = calloc(new_count, sizeof(nsockets[0])); + nsockets = curlx_calloc(new_count, sizeof(nsockets[0])); if(!nsockets) return CURLE_OUT_OF_MEMORY; - nactions = calloc(new_count, sizeof(nactions[0])); + nactions = curlx_calloc(new_count, sizeof(nactions[0])); if(!nactions) { - free(nsockets); + curlx_free(nsockets); return CURLE_OUT_OF_MEMORY; } memcpy(nsockets, ps->sockets, ps->count * sizeof(ps->sockets[0])); memcpy(nactions, ps->actions, ps->count * sizeof(ps->actions[0])); if(ps->sockets != ps->def_sockets) - free(ps->sockets); + curlx_free(ps->sockets); ps->sockets = nsockets; if(ps->actions != ps->def_actions) - free(ps->actions); + curlx_free(ps->actions); ps->actions = nactions; ps->count = new_count; } @@ -668,7 +664,7 @@ int Curl_pollset_poll(struct Curl_easy *data, if(!ps->n) return curlx_wait_ms(timeout_ms); - pfds = calloc(ps->n, sizeof(*pfds)); + pfds = curlx_calloc(ps->n, sizeof(*pfds)); if(!pfds) return -1; @@ -689,7 +685,7 @@ int Curl_pollset_poll(struct Curl_easy *data, } result = Curl_poll(pfds, npfds, timeout_ms); - free(pfds); + curlx_free(pfds); return result; } diff --git a/lib/sendf.c b/lib/sendf.c index 6731cd874b6b..1d73291c92d2 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -55,10 +55,6 @@ #include "curlx/warnless.h" #include "ws.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static CURLcode do_init_writer_stack(struct Curl_easy *data); @@ -100,7 +96,7 @@ static void cl_reset_writer(struct Curl_easy *data) while(writer) { data->req.writer_stack = writer->next; writer->cwt->do_close(data, writer); - free(writer); + curlx_free(writer); writer = data->req.writer_stack; } } @@ -112,7 +108,7 @@ static void cl_reset_reader(struct Curl_easy *data) while(reader) { data->req.reader_stack = reader->next; reader->crt->do_close(data, reader); - free(reader); + curlx_free(reader); reader = data->req.reader_stack; } } @@ -374,7 +370,7 @@ CURLcode Curl_cwriter_create(struct Curl_cwriter **pwriter, void *p; DEBUGASSERT(cwt->cwriter_size >= sizeof(struct Curl_cwriter)); - p = calloc(1, cwt->cwriter_size); + p = curlx_calloc(1, cwt->cwriter_size); if(!p) goto out; @@ -387,7 +383,7 @@ CURLcode Curl_cwriter_create(struct Curl_cwriter **pwriter, out: *pwriter = result ? NULL : writer; if(result) - free(writer); + curlx_free(writer); return result; } @@ -396,7 +392,7 @@ void Curl_cwriter_free(struct Curl_easy *data, { if(writer) { writer->cwt->do_close(data, writer); - free(writer); + curlx_free(writer); } } @@ -938,7 +934,7 @@ CURLcode Curl_creader_create(struct Curl_creader **preader, void *p; DEBUGASSERT(crt->creader_size >= sizeof(struct Curl_creader)); - p = calloc(1, crt->creader_size); + p = curlx_calloc(1, crt->creader_size); if(!p) goto out; @@ -951,7 +947,7 @@ CURLcode Curl_creader_create(struct Curl_creader **preader, out: *preader = result ? NULL : reader; if(result) - free(reader); + curlx_free(reader); return result; } @@ -959,7 +955,7 @@ void Curl_creader_free(struct Curl_easy *data, struct Curl_creader *reader) { if(reader) { reader->crt->do_close(data, reader); - free(reader); + curlx_free(reader); } } diff --git a/lib/setopt.c b/lib/setopt.c index 36f447cdc5bb..b4ca361ce35f 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -55,10 +55,6 @@ #include "strdup.h" #include "escape.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static CURLcode setopt_set_timeout_sec(timediff_t *ptimeout_ms, long secs) { if(secs < 0) @@ -98,7 +94,7 @@ CURLcode Curl_setstropt(char **charp, const char *s) if(strlen(s) > CURL_MAX_INPUT_LENGTH) return CURLE_BAD_FUNCTION_ARGUMENT; - *charp = strdup(s); + *charp = curlx_strdup(s); if(!*charp) return CURLE_OUT_OF_MEMORY; } @@ -119,8 +115,8 @@ CURLcode Curl_setblobopt(struct curl_blob **blobp, if(blob->len > CURL_MAX_INPUT_LENGTH) return CURLE_BAD_FUNCTION_ARGUMENT; nblob = (struct curl_blob *) - malloc(sizeof(struct curl_blob) + - ((blob->flags & CURL_BLOB_COPY) ? blob->len : 0)); + curlx_malloc(sizeof(struct curl_blob) + + ((blob->flags & CURL_BLOB_COPY) ? blob->len : 0)); if(!nblob) return CURLE_OUT_OF_MEMORY; *nblob = *blob; @@ -158,10 +154,10 @@ static CURLcode setstropt_userpwd(char *option, char **userp, char **passwdp) return result; } - free(*userp); + curlx_free(*userp); *userp = user; - free(*passwdp); + curlx_free(*passwdp); *passwdp = passwd; return CURLE_OK; @@ -185,13 +181,13 @@ static CURLcode setstropt_interface(char *option, char **devp, if(result) return result; } - free(*devp); + curlx_free(*devp); *devp = dev; - free(*ifacep); + curlx_free(*ifacep); *ifacep = iface; - free(*hostp); + curlx_free(*hostp); *hostp = host; return CURLE_OK; @@ -1706,7 +1702,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, if(!p) return CURLE_OUT_OF_MEMORY; else { - free(s->str[STRING_COPYPOSTFIELDS]); + curlx_free(s->str[STRING_COPYPOSTFIELDS]); s->str[STRING_COPYPOSTFIELDS] = p; } } @@ -2040,8 +2036,8 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, result = Curl_urldecode(p, 0, &s->str[STRING_PROXYPASSWORD], NULL, REJECT_ZERO); } - free(u); - free(p); + curlx_free(u); + curlx_free(p); } break; case CURLOPT_PROXYUSERNAME: diff --git a/lib/sha256.c b/lib/sha256.c index 3e3205e36bf3..977ad3edc402 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -59,10 +59,6 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Please keep the SSL backend-specific #if branches in this order: * * 1. USE_OPENSSL diff --git a/lib/slist.c b/lib/slist.c index 88fdd8a2bae2..469ee0ef3b5b 100644 --- a/lib/slist.c +++ b/lib/slist.c @@ -28,10 +28,6 @@ #include "slist.h" -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* returns last node in linked list */ static struct curl_slist *slist_get_last(struct curl_slist *list) { @@ -66,7 +62,7 @@ struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list, DEBUGASSERT(data); - new_item = malloc(sizeof(struct curl_slist)); + new_item = curlx_malloc(sizeof(struct curl_slist)); if(!new_item) return NULL; @@ -92,14 +88,14 @@ struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list, struct curl_slist *curl_slist_append(struct curl_slist *list, const char *data) { - char *dupdata = strdup(data); + char *dupdata = curlx_strdup(data); if(!dupdata) return NULL; list = Curl_slist_append_nodup(list, dupdata); if(!list) - free(dupdata); + curlx_free(dupdata); return list; } @@ -141,7 +137,7 @@ void curl_slist_free_all(struct curl_slist *list) do { next = item->next; Curl_safefree(item->data); - free(item); + curlx_free(item); item = next; } while(next); } diff --git a/lib/smb.c b/lib/smb.c index e5fca3ec0bef..338464961b21 100644 --- a/lib/smb.c +++ b/lib/smb.c @@ -42,10 +42,6 @@ #include "escape.h" #include "curl_endian.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* meta key for storing protocol meta at easy handle */ #define CURL_META_SMB_EASY "meta:proto:smb:easy" @@ -451,7 +447,7 @@ static void smb_easy_dtor(void *key, size_t klen, void *entry) /* `req->path` points to somewhere in `struct smb_conn` which is * kept at the connection meta. If the connection is destroyed first, * req->path points to free'd memory. */ - free(req); + curlx_free(req); } static void smb_conn_dtor(void *key, size_t klen, void *entry) @@ -463,7 +459,7 @@ static void smb_conn_dtor(void *key, size_t klen, void *entry) Curl_safefree(smbc->domain); Curl_safefree(smbc->recv_buf); Curl_safefree(smbc->send_buf); - free(smbc); + curlx_free(smbc); } /* this should setup things in the connection, not in the easy @@ -475,13 +471,13 @@ static CURLcode smb_setup_connection(struct Curl_easy *data, struct smb_request *req; /* Initialize the connection state */ - smbc = calloc(1, sizeof(*smbc)); + smbc = curlx_calloc(1, sizeof(*smbc)); if(!smbc || Curl_conn_meta_set(conn, CURL_META_SMB_CONN, smbc, smb_conn_dtor)) return CURLE_OUT_OF_MEMORY; /* Initialize the request state */ - req = calloc(1, sizeof(*req)); + req = curlx_calloc(1, sizeof(*req)); if(!req || Curl_meta_set(data, CURL_META_SMB_EASY, req, smb_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -506,10 +502,10 @@ static CURLcode smb_connect(struct Curl_easy *data, bool *done) /* Initialize the connection state */ smbc->state = SMB_CONNECTING; - smbc->recv_buf = malloc(MAX_MESSAGE_SIZE); + smbc->recv_buf = curlx_malloc(MAX_MESSAGE_SIZE); if(!smbc->recv_buf) return CURLE_OUT_OF_MEMORY; - smbc->send_buf = malloc(MAX_MESSAGE_SIZE); + smbc->send_buf = curlx_malloc(MAX_MESSAGE_SIZE); if(!smbc->send_buf) return CURLE_OUT_OF_MEMORY; @@ -520,14 +516,14 @@ static CURLcode smb_connect(struct Curl_easy *data, bool *done) if(slash) { smbc->user = slash + 1; - smbc->domain = strdup(conn->user); + smbc->domain = curlx_strdup(conn->user); if(!smbc->domain) return CURLE_OUT_OF_MEMORY; smbc->domain[slash - conn->user] = 0; } else { smbc->user = conn->user; - smbc->domain = strdup(conn->host.name); + smbc->domain = curlx_strdup(conn->host.name); if(!smbc->domain) return CURLE_OUT_OF_MEMORY; } @@ -1246,8 +1242,9 @@ static CURLcode smb_parse_url_path(struct Curl_easy *data, return result; /* Parse the path for the share */ - smbc->share = strdup((*path == '/' || *path == '\\') ? path + 1 : path); - free(path); + smbc->share = curlx_strdup((*path == '/' || *path == '\\') + ? path + 1 : path); + curlx_free(path); if(!smbc->share) return CURLE_OUT_OF_MEMORY; diff --git a/lib/smtp.c b/lib/smtp.c index eca27f146525..55a15b36c08d 100644 --- a/lib/smtp.c +++ b/lib/smtp.c @@ -81,10 +81,6 @@ #include "idn.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* meta key for storing protocol meta at easy handle */ #define CURL_META_SMTP_EASY "meta:proto:smtp:easy" /* meta key for storing protocol meta at connection */ @@ -646,7 +642,7 @@ static CURLcode smtp_perform_command(struct Curl_easy *data, utf8 ? " SMTPUTF8" : ""); Curl_free_idnconverted_hostname(&host); - free(address); + curlx_free(address); } else { /* Establish whether we should report that we support SMTPUTF8 for EXPN @@ -722,11 +718,11 @@ static CURLcode smtp_perform_mail(struct Curl_easy *data, worry about that and reply with a 501 error */ from = curl_maprintf("<%s>%s", address, suffix); - free(address); + curlx_free(address); } else /* Null reverse-path, RFC-5321, sect. 3.6.3 */ - from = strdup("<>"); + from = curlx_strdup("<>"); if(!from) { result = CURLE_OUT_OF_MEMORY; @@ -763,11 +759,11 @@ static CURLcode smtp_perform_mail(struct Curl_easy *data, /* An invalid mailbox was provided but we will simply let the server worry about it */ auth = curl_maprintf("<%s>%s", address, suffix); - free(address); + curlx_free(address); } else /* Empty AUTH, RFC-2554, sect. 5 */ - auth = strdup("<>"); + auth = curlx_strdup("<>"); if(!auth) { result = CURLE_OUT_OF_MEMORY; @@ -848,9 +844,9 @@ static CURLcode smtp_perform_mail(struct Curl_easy *data, : ""); /* included in our envelope */ out: - free(from); - free(auth); - free(size); + curlx_free(from); + curlx_free(auth); + curlx_free(size); if(!result) smtp_state(data, smtpc, SMTP_MAIL); @@ -892,7 +888,7 @@ static CURLcode smtp_perform_rcpt_to(struct Curl_easy *data, address, suffix); Curl_free_idnconverted_hostname(&host); - free(address); + curlx_free(address); if(!result) smtp_state(data, smtpc, SMTP_RCPT); @@ -1716,7 +1712,7 @@ static void smtp_easy_dtor(void *key, size_t klen, void *entry) struct SMTP *smtp = entry; (void)key; (void)klen; - free(smtp); + curlx_free(smtp); } static void smtp_conn_dtor(void *key, size_t klen, void *entry) @@ -1726,7 +1722,7 @@ static void smtp_conn_dtor(void *key, size_t klen, void *entry) (void)klen; Curl_pp_disconnect(&smtpc->pp); Curl_safefree(smtpc->domain); - free(smtpc); + curlx_free(smtpc); } static CURLcode smtp_setup_connection(struct Curl_easy *data, @@ -1736,14 +1732,14 @@ static CURLcode smtp_setup_connection(struct Curl_easy *data, struct SMTP *smtp; CURLcode result = CURLE_OK; - smtpc = calloc(1, sizeof(*smtpc)); + smtpc = curlx_calloc(1, sizeof(*smtpc)); if(!smtpc || Curl_conn_meta_set(conn, CURL_META_SMTP_CONN, smtpc, smtp_conn_dtor)) { result = CURLE_OUT_OF_MEMORY; goto out; } - smtp = calloc(1, sizeof(*smtp)); + smtp = curlx_calloc(1, sizeof(*smtp)); if(!smtp || Curl_meta_set(data, CURL_META_SMTP_EASY, smtp, smtp_easy_dtor)) result = CURLE_OUT_OF_MEMORY; @@ -1877,7 +1873,7 @@ static CURLcode smtp_parse_address(const char *fqma, char **address, /* Duplicate the fully qualified email address so we can manipulate it, ensuring it does not contain the delimiters if specified */ - char *dup = strdup(fqma[0] == '<' ? fqma + 1 : fqma); + char *dup = curlx_strdup(fqma[0] == '<' ? fqma + 1 : fqma); if(!dup) return CURLE_OUT_OF_MEMORY; diff --git a/lib/socketpair.c b/lib/socketpair.c index 08753c8a8c21..0b6111204446 100644 --- a/lib/socketpair.c +++ b/lib/socketpair.c @@ -134,10 +134,6 @@ int Curl_socketpair(int domain, int type, int protocol, #include "curlx/timeval.h" /* needed before select.h */ #include "select.h" /* for Curl_poll */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - int Curl_socketpair(int domain, int type, int protocol, curl_socket_t socks[2], bool nonblocking) { diff --git a/lib/socks.c b/lib/socks.c index 3434030c839f..7160dd150698 100644 --- a/lib/socks.c +++ b/lib/socks.c @@ -45,10 +45,6 @@ #include "curlx/inet_pton.h" #include "url.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) #define DEBUG_AND_VERBOSE #endif @@ -1215,7 +1211,7 @@ static void socks_proxy_cf_free(struct Curl_cfilter *cf) struct socks_state *sxstate = cf->ctx; if(sxstate) { Curl_bufq_free(&sxstate->iobuf); - free(sxstate); + curlx_free(sxstate); cf->ctx = NULL; } } @@ -1247,7 +1243,7 @@ static CURLcode socks_proxy_cf_connect(struct Curl_cfilter *cf, return result; if(!sx) { - cf->ctx = sx = calloc(1, sizeof(*sx)); + cf->ctx = sx = curlx_calloc(1, sizeof(*sx)); if(!sx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/socks_gssapi.c b/lib/socks_gssapi.c index 61c88be60528..6f8a90139ded 100644 --- a/lib/socks_gssapi.c +++ b/lib/socks_gssapi.c @@ -37,10 +37,6 @@ #include "curlx/warnless.h" #include "strdup.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(__GNUC__) && defined(__APPLE__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -151,8 +147,8 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, (gss_OID) GSS_C_NULL_OID, &server); } else { - service.value = malloc(serviceptr_length + - strlen(conn->socks_proxy.host.name) + 2); + service.value = curlx_malloc(serviceptr_length + + strlen(conn->socks_proxy.host.name) + 2); if(!service.value) return CURLE_OUT_OF_MEMORY; service.length = serviceptr_length + @@ -277,7 +273,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = ntohs(us_length); gss_recv_token.length = us_length; - gss_recv_token.value = malloc(gss_recv_token.length); + gss_recv_token.value = curlx_malloc(gss_recv_token.length); if(!gss_recv_token.value) { failf(data, "Could not allocate memory for GSS-API authentication " @@ -464,7 +460,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = ntohs(us_length); gss_recv_token.length = us_length; - gss_recv_token.value = malloc(gss_recv_token.length); + gss_recv_token.value = curlx_malloc(gss_recv_token.length); if(!gss_recv_token.value) { Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL); return CURLE_OUT_OF_MEMORY; diff --git a/lib/socks_sspi.c b/lib/socks_sspi.c index 14025371ce37..92592c5ce007 100644 --- a/lib/socks_sspi.c +++ b/lib/socks_sspi.c @@ -38,10 +38,6 @@ #include "curlx/multibyte.h" #include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Helper sspi error functions. */ @@ -101,7 +97,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, /* prepare service name */ if(strchr(service, '/')) - service_name = strdup(service); + service_name = curlx_strdup(service); else service_name = curl_maprintf("%s/%s", service, conn->socks_proxy.host.name); @@ -267,7 +263,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = ntohs(us_length); sspi_recv_token.cbBuffer = us_length; - sspi_recv_token.pvBuffer = malloc(us_length); + sspi_recv_token.pvBuffer = curlx_malloc(us_length); if(!sspi_recv_token.pvBuffer) { result = CURLE_OUT_OF_MEMORY; @@ -371,7 +367,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, sspi_w_token[0].cbBuffer = sspi_sizes.cbSecurityTrailer; sspi_w_token[0].BufferType = SECBUFFER_TOKEN; - sspi_w_token[0].pvBuffer = malloc(sspi_sizes.cbSecurityTrailer); + sspi_w_token[0].pvBuffer = curlx_malloc(sspi_sizes.cbSecurityTrailer); if(!sspi_w_token[0].pvBuffer) { result = CURLE_OUT_OF_MEMORY; @@ -379,7 +375,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, } sspi_w_token[1].cbBuffer = 1; - sspi_w_token[1].pvBuffer = malloc(1); + sspi_w_token[1].pvBuffer = curlx_malloc(1); if(!sspi_w_token[1].pvBuffer) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -388,7 +384,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, memcpy(sspi_w_token[1].pvBuffer, &gss_enc, 1); sspi_w_token[2].BufferType = SECBUFFER_PADDING; sspi_w_token[2].cbBuffer = sspi_sizes.cbBlockSize; - sspi_w_token[2].pvBuffer = malloc(sspi_sizes.cbBlockSize); + sspi_w_token[2].pvBuffer = curlx_malloc(sspi_sizes.cbBlockSize); if(!sspi_w_token[2].pvBuffer) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -409,7 +405,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, result = CURLE_COULDNT_CONNECT; goto error; } - etbuf = malloc(etbuf_size); + etbuf = curlx_malloc(etbuf_size); if(!etbuf) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -486,7 +482,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = ntohs(us_length); sspi_w_token[0].cbBuffer = us_length; - sspi_w_token[0].pvBuffer = malloc(us_length); + sspi_w_token[0].pvBuffer = curlx_malloc(us_length); if(!sspi_w_token[0].pvBuffer) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -514,7 +510,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, /* since sspi_w_token[1].pvBuffer is allocated by the SSPI in this case, it must be freed in this block using FreeContextBuffer() instead of - potentially in error cleanup using free(). */ + potentially in error cleanup using curlx_free(). */ if(check_sspi_err(data, status, "DecryptMessage")) { failf(data, "Failed to query security context attributes."); @@ -577,18 +573,18 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, return CURLE_OK; error: (void)curlx_nonblock(sock, TRUE); - free(service_name); + curlx_free(service_name); Curl_pSecFn->DeleteSecurityContext(&sspi_context); Curl_pSecFn->FreeCredentialsHandle(&cred_handle); - free(sspi_recv_token.pvBuffer); + curlx_free(sspi_recv_token.pvBuffer); if(sspi_send_token.pvBuffer) Curl_pSecFn->FreeContextBuffer(sspi_send_token.pvBuffer); if(names.sUserName) Curl_pSecFn->FreeContextBuffer(names.sUserName); - free(sspi_w_token[0].pvBuffer); - free(sspi_w_token[1].pvBuffer); - free(sspi_w_token[2].pvBuffer); - free(etbuf); + curlx_free(sspi_w_token[0].pvBuffer); + curlx_free(sspi_w_token[1].pvBuffer); + curlx_free(sspi_w_token[2].pvBuffer); + curlx_free(etbuf); return result; } #endif diff --git a/lib/strdup.c b/lib/strdup.c index 3339e909ee79..375f0f50442a 100644 --- a/lib/strdup.c +++ b/lib/strdup.c @@ -31,10 +31,6 @@ #endif #include "strdup.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" #ifndef HAVE_STRDUP char *Curl_strdup(const char *str) @@ -47,7 +43,7 @@ char *Curl_strdup(const char *str) len = strlen(str) + 1; - newstr = malloc(len); + newstr = curlx_malloc(len); if(!newstr) return (char *)NULL; @@ -90,7 +86,7 @@ wchar_t *Curl_wcsdup(const wchar_t *src) ***************************************************************************/ void *Curl_memdup(const void *src, size_t length) { - void *buffer = malloc(length); + void *buffer = curlx_malloc(length); if(!buffer) return NULL; /* fail */ @@ -111,7 +107,7 @@ void *Curl_memdup(const void *src, size_t length) ***************************************************************************/ void *Curl_memdup0(const char *src, size_t length) { - char *buf = (length < SIZE_MAX) ? malloc(length + 1) : NULL; + char *buf = (length < SIZE_MAX) ? curlx_malloc(length + 1) : NULL; if(!buf) return NULL; if(length) { @@ -126,7 +122,7 @@ void *Curl_memdup0(const char *src, size_t length) * * Curl_saferealloc(ptr, size) * - * Does a normal realloc(), but will free the data pointer if the realloc + * Does a normal curlx_realloc(), but will free the data pointer if the realloc * fails. If 'size' is non-zero, it will free the data and return a failure. * * This convenience function is provided and used to help us avoid a common @@ -138,9 +134,9 @@ void *Curl_memdup0(const char *src, size_t length) ***************************************************************************/ void *Curl_saferealloc(void *ptr, size_t size) { - void *datap = realloc(ptr, size); + void *datap = curlx_realloc(ptr, size); if(size && !datap) /* only free 'ptr' if size was non-zero */ - free(ptr); + curlx_free(ptr); return datap; } diff --git a/lib/strerror.c b/lib/strerror.c index afe69756bcbc..4b957bef2312 100644 --- a/lib/strerror.c +++ b/lib/strerror.c @@ -34,10 +34,6 @@ #include "curlx/winapi.h" #include "strerror.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - const char * curl_easy_strerror(CURLcode error) { diff --git a/lib/system_win32.c b/lib/system_win32.c index bdbed66162eb..f8a6cbfcccd6 100644 --- a/lib/system_win32.c +++ b/lib/system_win32.c @@ -32,10 +32,6 @@ #include "curl_sspi.h" #include "curlx/warnless.h" -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - #ifndef HAVE_IF_NAMETOINDEX /* Handle of iphlpapp.dll */ static HMODULE s_hIpHlpApiDll = NULL; @@ -218,7 +214,8 @@ static HMODULE curl_load_library(LPCTSTR filename) /* Allocate space for the full DLL path (Room for the null-terminator is included in systemdirlen) */ size_t filenamelen = _tcslen(filename); - TCHAR *path = malloc(sizeof(TCHAR) * (systemdirlen + 1 + filenamelen)); + TCHAR *path = curlx_malloc(sizeof(TCHAR) * + (systemdirlen + 1 + filenamelen)); if(path && GetSystemDirectory(path, systemdirlen)) { /* Calculate the full DLL path */ _tcscpy(path + _tcslen(path), TEXT("\\")); @@ -230,7 +227,7 @@ static HMODULE curl_load_library(LPCTSTR filename) pLoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) : LoadLibrary(path); } - free(path); + curlx_free(path); } } return hModule; diff --git a/lib/telnet.c b/lib/telnet.c index d0ca5a66ce11..5319130b90f3 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -60,10 +60,6 @@ #include "curlx/warnless.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define SUBBUFSIZE 512 #define CURL_SB_CLEAR(x) x->subpointer = x->subbuffer @@ -211,7 +207,7 @@ static void telnet_easy_dtor(void *key, size_t klen, void *entry) (void)klen; curl_slist_free_all(tn->telnet_vars); curlx_dyn_free(&tn->out); - free(tn); + curlx_free(tn); } static @@ -219,7 +215,7 @@ CURLcode init_telnet(struct Curl_easy *data) { struct TELNET *tn; - tn = calloc(1, sizeof(struct TELNET)); + tn = curlx_calloc(1, sizeof(struct TELNET)); if(!tn) return CURLE_OUT_OF_MEMORY; diff --git a/lib/tftp.c b/lib/tftp.c index ce9d200f05e3..5311a4c683a2 100644 --- a/lib/tftp.c +++ b/lib/tftp.c @@ -64,10 +64,6 @@ #include "curlx/strerr.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* RFC2348 allows the block size to be negotiated */ #define TFTP_BLKSIZE_DEFAULT 512 #define TFTP_OPTION_BLKSIZE "blksize" @@ -470,7 +466,7 @@ static CURLcode tftp_send_first(struct tftp_conn *state, if(strlen(filename) > (state->blksize - strlen(mode) - 4)) { failf(data, "TFTP filename too long"); - free(filename); + curlx_free(filename); return CURLE_TFTP_ILLEGAL; /* too long filename field */ } @@ -478,7 +474,7 @@ static CURLcode tftp_send_first(struct tftp_conn *state, state->blksize, "%s%c%s%c", filename, '\0', mode, '\0'); sbytes = 4 + strlen(filename) + strlen(mode); - free(filename); + curlx_free(filename); /* optional addition of TFTP options */ if(!data->set.tftp_no_options) { @@ -946,7 +942,7 @@ static void tftp_conn_dtor(void *key, size_t klen, void *entry) (void)klen; Curl_safefree(state->rpacket.data); Curl_safefree(state->spacket.data); - free(state); + curlx_free(state); } /********************************************************** @@ -967,7 +963,7 @@ static CURLcode tftp_connect(struct Curl_easy *data, bool *done) blksize = TFTP_BLKSIZE_DEFAULT; - state = calloc(1, sizeof(*state)); + state = curlx_calloc(1, sizeof(*state)); if(!state || Curl_conn_meta_set(conn, CURL_META_TFTP_CONN, state, tftp_conn_dtor)) return CURLE_OUT_OF_MEMORY; @@ -983,14 +979,14 @@ static CURLcode tftp_connect(struct Curl_easy *data, bool *done) need_blksize = TFTP_BLKSIZE_DEFAULT; if(!state->rpacket.data) { - state->rpacket.data = calloc(1, need_blksize + 2 + 2); + state->rpacket.data = curlx_calloc(1, need_blksize + 2 + 2); if(!state->rpacket.data) return CURLE_OUT_OF_MEMORY; } if(!state->spacket.data) { - state->spacket.data = calloc(1, need_blksize + 2 + 2); + state->spacket.data = curlx_calloc(1, need_blksize + 2 + 2); if(!state->spacket.data) return CURLE_OUT_OF_MEMORY; diff --git a/lib/transfer.c b/lib/transfer.c index f0ce3c501271..d8a0d6c0ba2e 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -81,10 +81,6 @@ #include "headers.h" #include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) || \ !defined(CURL_DISABLE_IMAP) /* @@ -479,7 +475,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) is allowed to be changed by the user between transfers */ if(data->set.uh) { CURLUcode uc; - free(data->set.str[STRING_SET_URL]); + curlx_free(data->set.str[STRING_SET_URL]); uc = curl_url_get(data->set.uh, CURLUPART_URL, &data->set.str[STRING_SET_URL], 0); if(uc) { @@ -574,7 +570,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) if(data->state.wildcardmatch) { struct WildcardData *wc; if(!data->wildcard) { - data->wildcard = calloc(1, sizeof(struct WildcardData)); + data->wildcard = curlx_calloc(1, sizeof(struct WildcardData)); if(!data->wildcard) return CURLE_OUT_OF_MEMORY; } @@ -597,7 +593,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) * protocol. */ if(!result && data->set.str[STRING_USERAGENT]) { - free(data->state.aptr.uagent); + curlx_free(data->state.aptr.uagent); data->state.aptr.uagent = curl_maprintf("User-Agent: %s\r\n", data->set.str[STRING_USERAGENT]); if(!data->state.aptr.uagent) @@ -629,7 +625,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) /* Returns CURLE_OK *and* sets '*url' if a request retry is wanted. - NOTE: that the *url is malloc()ed. */ + NOTE: that the *url is curlx_malloc()ed. */ CURLcode Curl_retry_request(struct Curl_easy *data, char **url) { struct connectdata *conn = data->conn; @@ -680,7 +676,7 @@ CURLcode Curl_retry_request(struct Curl_easy *data, char **url) } infof(data, "Connection died, retrying a fresh connect (retry count: %d)", data->state.retrycount); - *url = strdup(data->state.url); + *url = curlx_strdup(data->state.url); if(!*url) return CURLE_OUT_OF_MEMORY; diff --git a/lib/uint-bset.c b/lib/uint-bset.c index 82440c56378a..dcad94e42a6e 100644 --- a/lib/uint-bset.c +++ b/lib/uint-bset.c @@ -25,10 +25,6 @@ #include "curl_setup.h" #include "uint-bset.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef DEBUGBUILD #define CURL_UINT32_BSET_MAGIC 0x62757473 #endif @@ -49,14 +45,14 @@ CURLcode Curl_uint32_bset_resize(struct uint32_bset *bset, uint32_t nmax) DEBUGASSERT(bset->init == CURL_UINT32_BSET_MAGIC); if(nslots != bset->nslots) { - uint64_t *slots = calloc(nslots, sizeof(uint64_t)); + uint64_t *slots = curlx_calloc(nslots, sizeof(uint64_t)); if(!slots) return CURLE_OUT_OF_MEMORY; if(bset->slots) { memcpy(slots, bset->slots, (CURLMIN(nslots, bset->nslots) * sizeof(uint64_t))); - free(bset->slots); + curlx_free(bset->slots); } bset->slots = slots; bset->nslots = nslots; @@ -69,7 +65,7 @@ CURLcode Curl_uint32_bset_resize(struct uint32_bset *bset, uint32_t nmax) void Curl_uint32_bset_destroy(struct uint32_bset *bset) { DEBUGASSERT(bset->init == CURL_UINT32_BSET_MAGIC); - free(bset->slots); + curlx_free(bset->slots); memset(bset, 0, sizeof(*bset)); } diff --git a/lib/uint-hash.c b/lib/uint-hash.c index 4677c6ac9128..166a9ab99ba5 100644 --- a/lib/uint-hash.c +++ b/lib/uint-hash.c @@ -27,10 +27,6 @@ #include #include "uint-hash.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" /* random patterns for API verification */ #ifdef DEBUGBUILD @@ -70,7 +66,7 @@ static struct uint_hash_entry *uint32_hash_mk_entry(uint32_t id, void *value) struct uint_hash_entry *e; /* allocate the struct for the hash entry */ - e = malloc(sizeof(*e)); + e = curlx_malloc(sizeof(*e)); if(e) { e->id = id; e->next = NULL; @@ -95,7 +91,7 @@ static void uint32_hash_entry_destroy(struct uint_hash *h, struct uint_hash_entry *e) { uint32_hash_entry_clear(h, e); - free(e); + curlx_free(e); } static void uint32_hash_entry_unlink(struct uint_hash *h, @@ -126,7 +122,7 @@ bool Curl_uint32_hash_set(struct uint_hash *h, uint32_t id, void *value) DEBUGASSERT(h->slots); DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); if(!h->table) { - h->table = calloc(h->slots, sizeof(*he)); + h->table = curlx_calloc(h->slots, sizeof(*he)); if(!h->table) return FALSE; /* OOM */ } diff --git a/lib/uint-spbset.c b/lib/uint-spbset.c index f250bcb1b43f..c726bfb900c1 100644 --- a/lib/uint-spbset.c +++ b/lib/uint-spbset.c @@ -26,10 +26,6 @@ #include "uint-bset.h" #include "uint-spbset.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef DEBUGBUILD #define CURL_UINT32_SPBSET_MAGIC 0x70737362 #endif @@ -85,7 +81,7 @@ UNITTEST void Curl_uint32_spbset_clear(struct uint32_spbset *bset) for(chunk = bset->head.next; chunk; chunk = next) { next = chunk->next; - free(chunk); + curlx_free(chunk); } memset(&bset->head, 0, sizeof(bset->head)); } @@ -116,7 +112,7 @@ uint32_spbset_get_chunk(struct uint32_spbset *bset, uint32_t i, bool grow) return NULL; /* need a new one */ - chunk = calloc(1, sizeof(*chunk)); + chunk = curlx_calloc(1, sizeof(*chunk)); if(!chunk) return NULL; diff --git a/lib/uint-table.c b/lib/uint-table.c index 5516ab634bf1..05b53766f30a 100644 --- a/lib/uint-table.c +++ b/lib/uint-table.c @@ -25,10 +25,6 @@ #include "curl_setup.h" #include "uint-table.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef DEBUGBUILD #define CURL_UINT32_TBL_MAGIC 0x62757473 #endif @@ -73,14 +69,14 @@ CURLcode Curl_uint32_tbl_resize(struct uint32_tbl *tbl, uint32_t nrows) if(!nrows) return CURLE_BAD_FUNCTION_ARGUMENT; if(nrows != tbl->nrows) { - void **rows = calloc(nrows, sizeof(void *)); + void **rows = curlx_calloc(nrows, sizeof(void *)); if(!rows) return CURLE_OUT_OF_MEMORY; if(tbl->rows) { memcpy(rows, tbl->rows, (CURLMIN(nrows, tbl->nrows) * sizeof(void *))); if(nrows < tbl->nrows) uint32_tbl_clear_rows(tbl, nrows, tbl->nrows); - free(tbl->rows); + curlx_free(tbl->rows); } tbl->rows = rows; tbl->nrows = nrows; @@ -93,7 +89,7 @@ void Curl_uint32_tbl_destroy(struct uint32_tbl *tbl) { DEBUGASSERT(tbl->init == CURL_UINT32_TBL_MAGIC); Curl_uint32_tbl_clear(tbl); - free(tbl->rows); + curlx_free(tbl->rows); memset(tbl, 0, sizeof(*tbl)); } diff --git a/lib/url.c b/lib/url.c index e7f39d5471d1..b4c33236cd67 100644 --- a/lib/url.c +++ b/lib/url.c @@ -126,10 +126,6 @@ #include "curlx/strerr.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef USE_NGHTTP2 static void data_priority_cleanup(struct Curl_easy *data); #else @@ -257,7 +253,7 @@ CURLcode Curl_close(struct Curl_easy **datap) Curl_expire_clear(data); /* shut off any timers left */ if(data->state.rangestringalloc) - free(data->state.range); + curlx_free(data->state.range); /* release any resolve information this transfer kept */ Curl_async_destroy(data); @@ -346,7 +342,7 @@ CURLcode Curl_close(struct Curl_easy **datap) Curl_freeset(data); Curl_headers_cleanup(data); Curl_netrc_cleanup(&data->state.netrc); - free(data); + curlx_free(data); return CURLE_OK; } @@ -500,7 +496,7 @@ CURLcode Curl_open(struct Curl_easy **curl) struct Curl_easy *data; /* simple start-up: alloc the struct, init it with zeroes and return */ - data = calloc(1, sizeof(struct Curl_easy)); + data = curlx_calloc(1, sizeof(struct Curl_easy)); if(!data) { /* this is a serious error */ DEBUGF(curl_mfprintf(stderr, "Error: calloc of Curl_easy failed\n")); @@ -578,7 +574,7 @@ void Curl_conn_free(struct Curl_easy *data, struct connectdata *conn) Curl_uint32_spbset_destroy(&conn->xfers_attached); Curl_hash_destroy(&conn->meta_hash); - free(conn); /* free all the connection oriented data */ + curlx_free(conn); /* free all the connection oriented data */ } /* @@ -1351,7 +1347,7 @@ ConnectionExists(struct Curl_easy *data, */ static struct connectdata *allocate_conn(struct Curl_easy *data) { - struct connectdata *conn = calloc(1, sizeof(struct connectdata)); + struct connectdata *conn = curlx_calloc(1, sizeof(struct connectdata)); if(!conn) return NULL; @@ -1406,7 +1402,7 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) /* Store the local bind parameters that will be used for this connection */ if(data->set.str[STRING_DEVICE]) { - conn->localdev = strdup(data->set.str[STRING_DEVICE]); + conn->localdev = curlx_strdup(data->set.str[STRING_DEVICE]); if(!conn->localdev) goto error; } @@ -1427,8 +1423,8 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) return conn; error: - free(conn->localdev); - free(conn); + curlx_free(conn->localdev); + curlx_free(conn); return NULL; } @@ -1747,7 +1743,7 @@ static void zonefrom_url(CURLU *uh, struct Curl_easy *data, } #endif /* HAVE_IF_NAMETOINDEX || _WIN32 */ - free(zoneid); + curlx_free(zoneid); } } #else @@ -1787,7 +1783,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, if(!url) return CURLE_OUT_OF_MEMORY; if(data->state.url_alloc) - free(data->state.url); + curlx_free(data->state.url); data->state.url = url; data->state.url_alloc = TRUE; } @@ -1810,7 +1806,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, if(uc) return Curl_uc_to_curlcode(uc); if(data->state.url_alloc) - free(data->state.url); + curlx_free(data->state.url); data->state.url = newurl; data->state.url_alloc = TRUE; } @@ -1844,7 +1840,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, } /* make sure the connect struct gets its own copy of the hostname */ - conn->host.rawalloc = strdup(hostname ? hostname : ""); + conn->host.rawalloc = curlx_strdup(hostname ? hostname : ""); if(!conn->host.rawalloc) return CURLE_OUT_OF_MEMORY; conn->host.name = conn->host.rawalloc; @@ -1874,7 +1870,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, return Curl_uc_to_curlcode(uc); uc = curl_url_get(uh, CURLUPART_SCHEME, &data->state.up.scheme, 0); if(uc) { - free(url); + curlx_free(url); return Curl_uc_to_curlcode(uc); } data->state.url = url; @@ -1937,7 +1933,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, uc = curl_url_get(uh, CURLUPART_OPTIONS, &data->state.up.options, CURLU_URLDECODE); if(!uc) { - conn->options = strdup(data->state.up.options); + conn->options = curlx_strdup(data->state.up.options); if(!conn->options) return CURLE_OUT_OF_MEMORY; } @@ -1993,12 +1989,12 @@ static CURLcode setup_range(struct Curl_easy *data) s->resume_from = data->set.set_resume_from; if(s->resume_from || data->set.str[STRING_SET_RANGE]) { if(s->rangestringalloc) - free(s->range); + curlx_free(s->range); if(s->resume_from) s->range = curl_maprintf("%" FMT_OFF_T "-", s->resume_from); else - s->range = strdup(data->set.str[STRING_SET_RANGE]); + s->range = curlx_strdup(data->set.str[STRING_SET_RANGE]); if(!s->range) return CURLE_OUT_OF_MEMORY; @@ -2261,7 +2257,7 @@ static CURLcode parse_proxy(struct Curl_easy *data, goto error; if(proxyuser || proxypasswd) { - free(proxyinfo->user); + curlx_free(proxyinfo->user); proxyinfo->user = proxyuser; result = Curl_setstropt(&data->state.aptr.proxyuser, proxyuser); proxyuser = NULL; @@ -2269,7 +2265,7 @@ static CURLcode parse_proxy(struct Curl_easy *data, goto error; Curl_safefree(proxyinfo->passwd); if(!proxypasswd) { - proxypasswd = strdup(""); + proxypasswd = curlx_strdup(""); if(!proxypasswd) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -2295,7 +2291,7 @@ static CURLcode parse_proxy(struct Curl_easy *data, if(!curlx_str_number(&p, &num, UINT16_MAX)) proxyinfo->port = (uint16_t)num; /* Should we not error out when the port number is invalid? */ - free(portptr); + curlx_free(portptr); } else { if(data->set.proxyport) @@ -2326,13 +2322,13 @@ static CURLcode parse_proxy(struct Curl_easy *data, /* path will be "/", if no path was found */ if(strcmp("/", path)) { is_unix_proxy = TRUE; - free(host); + curlx_free(host); host = curl_maprintf(UNIX_SOCKET_PREFIX"%s", path); if(!host) { result = CURLE_OUT_OF_MEMORY; goto error; } - free(proxyinfo->host.rawalloc); + curlx_free(proxyinfo->host.rawalloc); proxyinfo->host.rawalloc = host; proxyinfo->host.name = host; host = NULL; @@ -2341,7 +2337,7 @@ static CURLcode parse_proxy(struct Curl_easy *data, if(!is_unix_proxy) { #endif - free(proxyinfo->host.rawalloc); + curlx_free(proxyinfo->host.rawalloc); proxyinfo->host.rawalloc = host; if(host[0] == '[') { /* this is a numerical IPv6, strip off the brackets */ @@ -2357,12 +2353,12 @@ static CURLcode parse_proxy(struct Curl_easy *data, #endif error: - free(proxyuser); - free(proxypasswd); - free(host); - free(scheme); + curlx_free(proxyuser); + curlx_free(proxypasswd); + curlx_free(host); + curlx_free(scheme); #ifdef USE_UNIX_SOCKETS - free(path); + curlx_free(path); #endif curl_url_cleanup(uhp); return result; @@ -2380,9 +2376,9 @@ static CURLcode parse_proxy_auth(struct Curl_easy *data, data->state.aptr.proxypasswd : ""; CURLcode result = CURLE_OUT_OF_MEMORY; - conn->http_proxy.user = strdup(proxyuser); + conn->http_proxy.user = curlx_strdup(proxyuser); if(conn->http_proxy.user) { - conn->http_proxy.passwd = strdup(proxypasswd); + conn->http_proxy.passwd = curlx_strdup(proxypasswd); if(conn->http_proxy.passwd) result = CURLE_OK; else @@ -2414,7 +2410,7 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, * Detect what (if any) proxy to use *************************************************************/ if(data->set.str[STRING_PROXY]) { - proxy = strdup(data->set.str[STRING_PROXY]); + proxy = curlx_strdup(data->set.str[STRING_PROXY]); /* if global proxy is set, this is it */ if(!proxy) { failf(data, "memory shortage"); @@ -2424,7 +2420,7 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, } if(data->set.str[STRING_PRE_PROXY]) { - socksproxy = strdup(data->set.str[STRING_PRE_PROXY]); + socksproxy = curlx_strdup(data->set.str[STRING_PRE_PROXY]); /* if global socks proxy is set, this is it */ if(!socksproxy) { failf(data, "memory shortage"); @@ -2460,20 +2456,21 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, #ifdef USE_UNIX_SOCKETS /* For the time being do not mix proxy and Unix domain sockets. See #1274 */ if(proxy && conn->unix_domain_socket) { - free(proxy); + curlx_free(proxy); proxy = NULL; } #endif if(proxy && (!*proxy || (conn->handler->flags & PROTOPT_NONETWORK))) { - free(proxy); /* Do not bother with an empty proxy string or if the - protocol does not work with network */ + curlx_free(proxy); /* Do not bother with an empty proxy string + or if the protocol does not work with network */ proxy = NULL; } if(socksproxy && (!*socksproxy || (conn->handler->flags & PROTOPT_NONETWORK))) { - free(socksproxy); /* Do not bother with an empty socks proxy string or if - the protocol does not work with network */ + curlx_free(socksproxy); /* Do not bother with an empty socks proxy string + or if the protocol does not work with + network */ socksproxy = NULL; } @@ -2528,7 +2525,7 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, if(!conn->socks_proxy.user) { conn->socks_proxy.user = conn->http_proxy.user; conn->http_proxy.user = NULL; - free(conn->socks_proxy.passwd); + curlx_free(conn->socks_proxy.passwd); conn->socks_proxy.passwd = conn->http_proxy.passwd; conn->http_proxy.passwd = NULL; } @@ -2558,8 +2555,8 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, out: - free(socksproxy); - free(proxy); + curlx_free(socksproxy); + curlx_free(proxy); return result; } #endif /* CURL_DISABLE_PROXY */ @@ -2653,8 +2650,8 @@ CURLcode Curl_parse_login_details(const char *login, const size_t len, *passwdp = pbuf; return CURLE_OK; error: - free(ubuf); - free(pbuf); + curlx_free(ubuf); + curlx_free(pbuf); return CURLE_OUT_OF_MEMORY; } @@ -2712,8 +2709,8 @@ static CURLcode override_login(struct Curl_easy *data, char **optionsp = &conn->options; if(data->set.str[STRING_OPTIONS]) { - free(*optionsp); - *optionsp = strdup(data->set.str[STRING_OPTIONS]); + curlx_free(*optionsp); + *optionsp = curlx_strdup(data->set.str[STRING_OPTIONS]); if(!*optionsp) return CURLE_OUT_OF_MEMORY; } @@ -2767,14 +2764,14 @@ static CURLcode override_login(struct Curl_easy *data, } } if(url_provided) { - free(conn->user); - conn->user = strdup(*userp); + curlx_free(conn->user); + conn->user = curlx_strdup(*userp); if(!conn->user) return CURLE_OUT_OF_MEMORY; } /* no user was set but a password, set a blank user */ if(!*userp && *passwdp) { - *userp = strdup(""); + *userp = curlx_strdup(""); if(!*userp) return CURLE_OUT_OF_MEMORY; } @@ -2798,7 +2795,7 @@ static CURLcode override_login(struct Curl_easy *data, if(uc) return Curl_uc_to_curlcode(uc); if(!*userp) { - *userp = strdup(data->state.aptr.user); + *userp = curlx_strdup(data->state.aptr.user); if(!*userp) return CURLE_OUT_OF_MEMORY; } @@ -2815,7 +2812,7 @@ static CURLcode override_login(struct Curl_easy *data, if(uc) return Curl_uc_to_curlcode(uc); if(!*passwdp) { - *passwdp = strdup(data->state.aptr.passwd); + *passwdp = curlx_strdup(data->state.aptr.passwd); if(!*passwdp) return CURLE_OUT_OF_MEMORY; } @@ -2843,14 +2840,14 @@ static CURLcode set_login(struct Curl_easy *data, } /* Store the default user */ if(!conn->user) { - conn->user = strdup(setuser); + conn->user = curlx_strdup(setuser); if(!conn->user) return CURLE_OUT_OF_MEMORY; } /* Store the default password */ if(!conn->passwd) { - conn->passwd = strdup(setpasswd); + conn->passwd = curlx_strdup(setpasswd); if(!conn->passwd) result = CURLE_OUT_OF_MEMORY; } @@ -2885,7 +2882,7 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data, if(!host || !*host) return CURLE_OK; - host_dup = strdup(host); + host_dup = curlx_strdup(host); if(!host_dup) return CURLE_OUT_OF_MEMORY; @@ -2947,7 +2944,7 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data, /* now, clone the cleaned hostname */ DEBUGASSERT(hostptr); - *hostname_result = strdup(hostptr); + *hostname_result = curlx_strdup(hostptr); if(!*hostname_result) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -2956,7 +2953,7 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data, *port_result = port; error: - free(host_dup); + curlx_free(host_dup); return result; } @@ -2995,7 +2992,7 @@ static CURLcode parse_connect_to_string(struct Curl_easy *data, hostname_to_match_len = strlen(hostname_to_match); host_match = curl_strnequal(ptr, hostname_to_match, hostname_to_match_len); - free(hostname_to_match); + curlx_free(hostname_to_match); ptr += hostname_to_match_len; host_match = host_match && *ptr == ':'; @@ -3136,7 +3133,7 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data, } if(hit) { - char *hostd = strdup((char *)as->dst.host); + char *hostd = curlx_strdup((char *)as->dst.host); if(!hostd) return CURLE_OUT_OF_MEMORY; conn->conn_to_host.rawalloc = hostd; @@ -3188,7 +3185,7 @@ static CURLcode resolve_unix(struct Curl_easy *data, /* Unix domain sockets are local. The host gets ignored, just use the * specified domain socket address. Do not cache "DNS entries". There is * no DNS involved and we already have the file system path available. */ - hostaddr = calloc(1, sizeof(struct Curl_dns_entry)); + hostaddr = curlx_calloc(1, sizeof(struct Curl_dns_entry)); if(!hostaddr) return CURLE_OUT_OF_MEMORY; @@ -3198,7 +3195,7 @@ static CURLcode resolve_unix(struct Curl_easy *data, if(longpath) /* Long paths are not supported for now */ failf(data, "Unix socket path too long: '%s'", unix_path); - free(hostaddr); + curlx_free(hostaddr); return longpath ? CURLE_COULDNT_RESOLVE_HOST : CURLE_OUT_OF_MEMORY; } @@ -3261,7 +3258,7 @@ static CURLcode resolve_server(struct Curl_easy *data, } /* Resolve target host right on */ - conn->hostname_resolve = strdup(ehost->name); + conn->hostname_resolve = curlx_strdup(ehost->name); if(!conn->hostname_resolve) return CURLE_OUT_OF_MEMORY; @@ -3308,8 +3305,8 @@ static void reuse_conn(struct Curl_easy *data, * be new for this request even when we reuse an existing connection */ if(temp->user) { /* use the new username and password though */ - free(existing->user); - free(existing->passwd); + curlx_free(existing->user); + curlx_free(existing->passwd); existing->user = temp->user; existing->passwd = temp->passwd; temp->user = NULL; @@ -3320,10 +3317,10 @@ static void reuse_conn(struct Curl_easy *data, existing->bits.proxy_user_passwd = temp->bits.proxy_user_passwd; if(existing->bits.proxy_user_passwd) { /* use the new proxy username and proxy password though */ - free(existing->http_proxy.user); - free(existing->socks_proxy.user); - free(existing->http_proxy.passwd); - free(existing->socks_proxy.passwd); + curlx_free(existing->http_proxy.user); + curlx_free(existing->socks_proxy.user); + curlx_free(existing->http_proxy.passwd); + curlx_free(existing->socks_proxy.passwd); existing->http_proxy.user = temp->http_proxy.user; existing->socks_proxy.user = temp->socks_proxy.user; existing->http_proxy.passwd = temp->http_proxy.passwd; @@ -3354,7 +3351,7 @@ static void reuse_conn(struct Curl_easy *data, existing->conn_to_port = temp->conn_to_port; existing->remote_port = temp->remote_port; - free(existing->hostname_resolve); + curlx_free(existing->hostname_resolve); existing->hostname_resolve = temp->hostname_resolve; temp->hostname_resolve = NULL; @@ -3436,7 +3433,7 @@ static CURLcode create_conn(struct Curl_easy *data, goto out; if(data->set.str[STRING_SASL_AUTHZID]) { - conn->sasl_authzid = strdup(data->set.str[STRING_SASL_AUTHZID]); + conn->sasl_authzid = curlx_strdup(data->set.str[STRING_SASL_AUTHZID]); if(!conn->sasl_authzid) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -3444,7 +3441,7 @@ static CURLcode create_conn(struct Curl_easy *data, } if(data->set.str[STRING_BEARER]) { - conn->oauth_bearer = strdup(data->set.str[STRING_BEARER]); + conn->oauth_bearer = curlx_strdup(data->set.str[STRING_BEARER]); if(!conn->oauth_bearer) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -3453,7 +3450,8 @@ static CURLcode create_conn(struct Curl_easy *data, #ifdef USE_UNIX_SOCKETS if(data->set.str[STRING_UNIX_SOCKET_PATH]) { - conn->unix_domain_socket = strdup(data->set.str[STRING_UNIX_SOCKET_PATH]); + conn->unix_domain_socket = + curlx_strdup(data->set.str[STRING_UNIX_SOCKET_PATH]); if(!conn->unix_domain_socket) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -3924,7 +3922,7 @@ static void priority_remove_child(struct Curl_easy *parent, DEBUGASSERT(pnode); if(pnode) { *pnext = pnode->next; - free(pnode); + curlx_free(pnode); } child->set.priority.parent = 0; @@ -3943,7 +3941,7 @@ CURLcode Curl_data_priority_add_child(struct Curl_easy *parent, struct Curl_data_prio_node **tail; struct Curl_data_prio_node *pnode; - pnode = calloc(1, sizeof(*pnode)); + pnode = curlx_calloc(1, sizeof(*pnode)); if(!pnode) return CURLE_OUT_OF_MEMORY; pnode->data = child; diff --git a/lib/urlapi.c b/lib/urlapi.c index 9d3eb0f8cf0f..ad4d367dc34c 100644 --- a/lib/urlapi.c +++ b/lib/urlapi.c @@ -37,10 +37,6 @@ #include "curlx/strparse.h" #include "curl_memrchr.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef _WIN32 /* MS-DOS/Windows style drive prefix, eg c: in c:foo */ #define STARTS_WITH_DRIVE_PREFIX(str) \ @@ -94,16 +90,16 @@ static CURLUcode parseurl_and_replace(const char *url, CURLU *u, static void free_urlhandle(struct Curl_URL *u) { - free(u->scheme); - free(u->user); - free(u->password); - free(u->options); - free(u->host); - free(u->zoneid); - free(u->port); - free(u->path); - free(u->query); - free(u->fragment); + curlx_free(u->scheme); + curlx_free(u->user); + curlx_free(u->password); + curlx_free(u->options); + curlx_free(u->host); + curlx_free(u->zoneid); + curlx_free(u->port); + curlx_free(u->path); + curlx_free(u->query); + curlx_free(u->fragment); } /* @@ -384,17 +380,17 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u, result = CURLUE_USER_NOT_ALLOWED; goto out; } - free(u->user); + curlx_free(u->user); u->user = userp; } if(passwdp) { - free(u->password); + curlx_free(u->password); u->password = passwdp; } if(optionsp) { - free(u->options); + curlx_free(u->options); u->options = optionsp; } @@ -404,9 +400,9 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u, out: - free(userp); - free(passwdp); - free(optionsp); + curlx_free(userp); + curlx_free(passwdp); + curlx_free(optionsp); u->user = NULL; u->password = NULL; u->options = NULL; @@ -459,7 +455,7 @@ UNITTEST CURLUcode Curl_parse_port(struct Curl_URL *u, struct dynbuf *host, u->portnum = (unsigned short) port; /* generate a new port number string to get rid of leading zeroes etc */ - free(u->port); + curlx_free(u->port); u->port = curl_maprintf("%" CURL_FORMAT_CURL_OFF_T, port); if(!u->port) return CURLUE_OUT_OF_MEMORY; @@ -497,7 +493,7 @@ static CURLUcode ipv6_parse(struct Curl_URL *u, char *hostname, if(!i || (']' != *h)) return CURLUE_BAD_IPV6; zoneid[i] = 0; - u->zoneid = strdup(zoneid); + u->zoneid = curlx_strdup(zoneid); if(!u->zoneid) return CURLUE_OUT_OF_MEMORY; hostname[len] = ']'; /* insert end bracket */ @@ -675,7 +671,7 @@ static CURLUcode urldecode_host(struct dynbuf *host) return CURLUE_BAD_HOSTNAME; curlx_dyn_reset(host); result = curlx_dyn_addn(host, decoded, dlen); - free(decoded); + curlx_free(decoded); if(result) return cc2cu(result); } @@ -750,7 +746,7 @@ CURLUcode Curl_url_set_authority(CURLU *u, const char *authority) if(result) curlx_dyn_free(&host); else { - free(u->host); + curlx_free(u->host); u->host = curlx_dyn_ptr(&host); } return result; @@ -894,7 +890,7 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp) if(curlx_dyn_len(&out)) *outp = curlx_dyn_ptr(&out); else { - *outp = strdup(""); + *outp = curlx_strdup(""); if(!*outp) return 1; } @@ -940,7 +936,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) path = &url[5]; pathlen = urllen - 5; - u->scheme = strdup("file"); + u->scheme = curlx_strdup("file"); if(!u->scheme) { result = CURLUE_OUT_OF_MEMORY; goto fail; @@ -1087,7 +1083,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) } if(schemep) { - u->scheme = strdup(schemep); + u->scheme = curlx_strdup(schemep); if(!u->scheme) { result = CURLUE_OUT_OF_MEMORY; goto fail; @@ -1124,7 +1120,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) else schemep = "http"; - u->scheme = strdup(schemep); + u->scheme = curlx_strdup(schemep); if(!u->scheme) { result = CURLUE_OUT_OF_MEMORY; goto fail; @@ -1197,7 +1193,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) } else { /* single byte query */ - u->query = strdup(""); + u->query = curlx_strdup(""); if(!u->query) { result = CURLUE_OUT_OF_MEMORY; goto fail; @@ -1241,7 +1237,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) goto fail; } if(dedot) { - free(u->path); + curlx_free(u->path); u->path = dedot; } } @@ -1277,21 +1273,21 @@ static CURLUcode parseurl_and_replace(const char *url, CURLU *u, */ CURLU *curl_url(void) { - return calloc(1, sizeof(struct Curl_URL)); + return curlx_calloc(1, sizeof(struct Curl_URL)); } void curl_url_cleanup(CURLU *u) { if(u) { free_urlhandle(u); - free(u); + curlx_free(u); } } #define DUP(dest, src, name) \ do { \ if(src->name) { \ - dest->name = strdup(src->name); \ + dest->name = curlx_strdup(src->name); \ if(!dest->name) \ goto fail; \ } \ @@ -1299,7 +1295,7 @@ void curl_url_cleanup(CURLU *u) CURLU *curl_url_dup(const CURLU *in) { - struct Curl_URL *u = calloc(1, sizeof(struct Curl_URL)); + struct Curl_URL *u = curlx_calloc(1, sizeof(struct Curl_URL)); if(u) { DUP(u, in, scheme); DUP(u, in, user); @@ -1373,7 +1369,7 @@ static CURLUcode urlget_format(const CURLU *u, CURLUPart what, /* this unconditional rejection of control bytes is documented API behavior */ CURLcode res = Curl_urldecode(part, partlen, &decoded, &dlen, REJECT_CTRL); - free(part); + curlx_free(part); if(res) return CURLUE_URLDECODE; part = decoded; @@ -1383,7 +1379,7 @@ static CURLUcode urlget_format(const CURLU *u, CURLUPart what, struct dynbuf enc; curlx_dyn_init(&enc, CURL_MAX_INPUT_LENGTH); uc = urlencode_str(&enc, part, partlen, TRUE, what == CURLUPART_QUERY); - free(part); + curlx_free(part); if(uc) return uc; part = curlx_dyn_ptr(&enc); @@ -1392,7 +1388,7 @@ static CURLUcode urlget_format(const CURLU *u, CURLUPart what, if(!Curl_is_ASCII_name(u->host)) { char *punyversion = NULL; uc = host_decode(part, &punyversion); - free(part); + curlx_free(part); if(uc) return uc; part = punyversion; @@ -1402,7 +1398,7 @@ static CURLUcode urlget_format(const CURLU *u, CURLUPart what, if(Curl_is_ASCII_name(u->host)) { char *unpunified = NULL; uc = host_encode(part, &unpunified); - free(part); + curlx_free(part); if(uc) return uc; part = unpunified; @@ -1520,7 +1516,7 @@ static CURLUcode urlget_url(const CURLU *u, char **part, unsigned int flags) u->query ? u->query : "", show_fragment ? "#": "", u->fragment ? u->fragment : ""); - free(allochost); + curlx_free(allochost); } if(!url) return CURLUE_OUT_OF_MEMORY; @@ -1666,7 +1662,7 @@ static CURLUcode set_url_port(CURLU *u, const char *provided_port) tmp = curl_maprintf("%" CURL_FORMAT_CURL_OFF_T, port); if(!tmp) return CURLUE_OUT_OF_MEMORY; - free(u->port); + curlx_free(u->port); u->port = tmp; u->portnum = (unsigned short)port; return CURLUE_OK; @@ -1691,7 +1687,7 @@ static CURLUcode set_url(CURLU *u, const char *url, size_t part_size, if(!uc) { /* success, meaning the "" is a fine relative URL, but nothing changes */ - free(oldurl); + curlx_free(oldurl); return CURLUE_OK; } if(uc == CURLUE_OUT_OF_MEMORY) @@ -1715,7 +1711,7 @@ static CURLUcode set_url(CURLU *u, const char *url, size_t part_size, DEBUGASSERT(oldurl); /* it is set here */ /* apply the relative part to create a new URL */ uc = redirect_url(oldurl, url, u, flags); - free(oldurl); + curlx_free(oldurl); return uc; } @@ -1930,7 +1926,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what, if(curlx_dyn_add(&qbuf, newp)) goto nomem; curlx_dyn_free(&enc); - free(*storep); + curlx_free(*storep); *storep = curlx_dyn_ptr(&qbuf); return CURLUE_OK; nomem: @@ -1957,7 +1953,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what, Curl_urldecode(newp, n, &decoded, &dlen, REJECT_CTRL); if(result || hostname_check(u, decoded, dlen)) bad = TRUE; - free(decoded); + curlx_free(decoded); } else if(hostname_check(u, (char *)CURL_UNCONST(newp), n)) bad = TRUE; @@ -1968,7 +1964,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what, } } - free(*storep); + curlx_free(*storep); *storep = (char *)CURL_UNCONST(newp); } return CURLUE_OK; diff --git a/lib/vauth/cleartext.c b/lib/vauth/cleartext.c index 884ebce0f268..d259bc42b5b2 100644 --- a/lib/vauth/cleartext.c +++ b/lib/vauth/cleartext.c @@ -38,10 +38,6 @@ #include "../curlx/warnless.h" #include "../sendf.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Curl_auth_create_plain_message() * diff --git a/lib/vauth/cram.c b/lib/vauth/cram.c index 2754ddc4a29f..3b02e5751fcc 100644 --- a/lib/vauth/cram.c +++ b/lib/vauth/cram.c @@ -36,10 +36,6 @@ #include "../curl_md5.h" #include "../curlx/warnless.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Curl_auth_create_cram_md5_message() diff --git a/lib/vauth/digest.c b/lib/vauth/digest.c index 16045707fd1e..850891f17535 100644 --- a/lib/vauth/digest.c +++ b/lib/vauth/digest.c @@ -44,10 +44,6 @@ #include "../curlx/strparse.h" #include "../rand.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #ifndef USE_WINDOWS_SSPI #define SESSION_ALGO 1 /* for algos with this bit set */ @@ -174,7 +170,7 @@ static char *auth_digest_string_quoted(const char *source) ++s; } - dest = malloc(n); + dest = curlx_malloc(n); if(dest) { char *d = dest; s = source; @@ -426,7 +422,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, /* Calculate H(A2) */ ctxt = Curl_MD5_init(&Curl_DIGEST_MD5); if(!ctxt) { - free(spn); + curlx_free(spn); return CURLE_OUT_OF_MEMORY; } @@ -444,7 +440,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, /* Now calculate the response hash */ ctxt = Curl_MD5_init(&Curl_DIGEST_MD5); if(!ctxt) { - free(spn); + curlx_free(spn); return CURLE_OUT_OF_MEMORY; } @@ -477,7 +473,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, "response=%s,qop=%s", userp, realm, nonce, cnonce, nonceCount, spn, resp_hash_hex, qop); - free(spn); + curlx_free(spn); if(!response) return CURLE_OUT_OF_MEMORY; @@ -522,8 +518,8 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg, /* Extract a value=content pair */ if(Curl_auth_digest_get_pair(chlg, value, content, &chlg)) { if(curl_strequal(value, "nonce")) { - free(digest->nonce); - digest->nonce = strdup(content); + curlx_free(digest->nonce); + digest->nonce = curlx_strdup(content); if(!digest->nonce) return CURLE_OUT_OF_MEMORY; } @@ -534,14 +530,14 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg, } } else if(curl_strequal(value, "realm")) { - free(digest->realm); - digest->realm = strdup(content); + curlx_free(digest->realm); + digest->realm = curlx_strdup(content); if(!digest->realm) return CURLE_OUT_OF_MEMORY; } else if(curl_strequal(value, "opaque")) { - free(digest->opaque); - digest->opaque = strdup(content); + curlx_free(digest->opaque); + digest->opaque = curlx_strdup(content); if(!digest->opaque) return CURLE_OUT_OF_MEMORY; } @@ -567,21 +563,21 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg, /* Select only auth or auth-int. Otherwise, ignore */ if(foundAuth) { - free(digest->qop); - digest->qop = strdup(DIGEST_QOP_VALUE_STRING_AUTH); + curlx_free(digest->qop); + digest->qop = curlx_strdup(DIGEST_QOP_VALUE_STRING_AUTH); if(!digest->qop) return CURLE_OUT_OF_MEMORY; } else if(foundAuthInt) { - free(digest->qop); - digest->qop = strdup(DIGEST_QOP_VALUE_STRING_AUTH_INT); + curlx_free(digest->qop); + digest->qop = curlx_strdup(DIGEST_QOP_VALUE_STRING_AUTH_INT); if(!digest->qop) return CURLE_OUT_OF_MEMORY; } } else if(curl_strequal(value, "algorithm")) { - free(digest->algorithm); - digest->algorithm = strdup(content); + curlx_free(digest->algorithm); + digest->algorithm = curlx_strdup(content); if(!digest->algorithm) return CURLE_OUT_OF_MEMORY; @@ -725,7 +721,7 @@ static CURLcode auth_create_digest_http_message( return CURLE_OUT_OF_MEMORY; result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis)); - free(hashthis); + curlx_free(hashthis); if(result) return result; convert_to_ascii(hashbuf, (unsigned char *)userh); @@ -748,7 +744,7 @@ static CURLcode auth_create_digest_http_message( return CURLE_OUT_OF_MEMORY; result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis)); - free(hashthis); + curlx_free(hashthis); if(result) return result; convert_to_ascii(hashbuf, ha1); @@ -760,7 +756,7 @@ static CURLcode auth_create_digest_http_message( return CURLE_OUT_OF_MEMORY; result = hash(hashbuf, (unsigned char *) tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); if(result) return result; convert_to_ascii(hashbuf, ha1); @@ -790,13 +786,13 @@ static CURLcode auth_create_digest_http_message( result = hash(hashbuf, (const unsigned char *)"", 0); if(result) { - free(hashthis); + curlx_free(hashthis); return result; } convert_to_ascii(hashbuf, (unsigned char *)hashed); hashthis2 = curl_maprintf("%s:%s", hashthis, hashed); - free(hashthis); + curlx_free(hashthis); hashthis = hashthis2; } @@ -804,7 +800,7 @@ static CURLcode auth_create_digest_http_message( return CURLE_OUT_OF_MEMORY; result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis)); - free(hashthis); + curlx_free(hashthis); if(result) return result; convert_to_ascii(hashbuf, ha2); @@ -821,7 +817,7 @@ static CURLcode auth_create_digest_http_message( return CURLE_OUT_OF_MEMORY; result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis)); - free(hashthis); + curlx_free(hashthis); if(result) return result; convert_to_ascii(hashbuf, request_digest); @@ -845,18 +841,18 @@ static CURLcode auth_create_digest_http_message( if(digest->realm) realm_quoted = auth_digest_string_quoted(digest->realm); else { - realm_quoted = malloc(1); + realm_quoted = curlx_malloc(1); if(realm_quoted) realm_quoted[0] = 0; } if(!realm_quoted) { - free(userp_quoted); + curlx_free(userp_quoted); return CURLE_OUT_OF_MEMORY; } nonce_quoted = auth_digest_string_quoted(digest->nonce); if(!nonce_quoted) { - free(realm_quoted); - free(userp_quoted); + curlx_free(realm_quoted); + curlx_free(userp_quoted); return CURLE_OUT_OF_MEMORY; } @@ -893,9 +889,9 @@ static CURLcode auth_create_digest_http_message( uripath, request_digest); } - free(nonce_quoted); - free(realm_quoted); - free(userp_quoted); + curlx_free(nonce_quoted); + curlx_free(realm_quoted); + curlx_free(userp_quoted); if(!response) return CURLE_OUT_OF_MEMORY; @@ -905,12 +901,12 @@ static CURLcode auth_create_digest_http_message( /* Append the opaque */ opaque_quoted = auth_digest_string_quoted(digest->opaque); if(!opaque_quoted) { - free(response); + curlx_free(response); return CURLE_OUT_OF_MEMORY; } tmp = curl_maprintf("%s, opaque=\"%s\"", response, opaque_quoted); - free(response); - free(opaque_quoted); + curlx_free(response); + curlx_free(opaque_quoted); if(!tmp) return CURLE_OUT_OF_MEMORY; @@ -920,7 +916,7 @@ static CURLcode auth_create_digest_http_message( if(digest->algorithm) { /* Append the algorithm */ tmp = curl_maprintf("%s, algorithm=%s", response, digest->algorithm); - free(response); + curlx_free(response); if(!tmp) return CURLE_OUT_OF_MEMORY; @@ -930,7 +926,7 @@ static CURLcode auth_create_digest_http_message( if(digest->userhash) { /* Append the userhash */ tmp = curl_maprintf("%s, userhash=true", response); - free(response); + curlx_free(response); if(!tmp) return CURLE_OUT_OF_MEMORY; diff --git a/lib/vauth/digest_sspi.c b/lib/vauth/digest_sspi.c index f730c52987a3..ea6a66af9fac 100644 --- a/lib/vauth/digest_sspi.c +++ b/lib/vauth/digest_sspi.c @@ -41,10 +41,6 @@ #include "../strcase.h" #include "../strerror.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Curl_auth_is_digest_supported() * @@ -135,14 +131,14 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, Curl_pSecFn->FreeContextBuffer(SecurityPackage); /* Allocate our response buffer */ - output_token = malloc(token_max); + output_token = curlx_malloc(token_max); if(!output_token) return CURLE_OUT_OF_MEMORY; /* Generate our SPN */ spn = Curl_auth_build_spn(service, data->conn->host.name, NULL); if(!spn) { - free(output_token); + curlx_free(output_token); return CURLE_OUT_OF_MEMORY; } @@ -150,8 +146,8 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, /* Populate our identity structure */ result = Curl_create_sspi_identity(userp, passwdp, &identity); if(result) { - free(spn); - free(output_token); + curlx_free(spn); + curlx_free(output_token); return result; } @@ -171,8 +167,8 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, if(status != SEC_E_OK) { Curl_sspi_free_identity(p_identity); - free(spn); - free(output_token); + curlx_free(spn); + curlx_free(output_token); return CURLE_LOGIN_DENIED; } @@ -208,8 +204,8 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, Curl_pSecFn->FreeCredentialsHandle(&credentials); Curl_sspi_free_identity(p_identity); - free(spn); - free(output_token); + curlx_free(spn); + curlx_free(output_token); if(status == SEC_E_INSUFFICIENT_MEMORY) return CURLE_OUT_OF_MEMORY; @@ -233,7 +229,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, Curl_sspi_free_identity(p_identity); /* Free the SPN */ - free(spn); + curlx_free(spn); return result; } @@ -276,13 +272,13 @@ CURLcode Curl_override_sspi_http_realm(const char *chlg, if(!domain.tchar_ptr) return CURLE_OUT_OF_MEMORY; - dup_domain.tchar_ptr = Curl_tcsdup(domain.tchar_ptr); + dup_domain.tchar_ptr = curlx_tcsdup(domain.tchar_ptr); if(!dup_domain.tchar_ptr) { curlx_unicodefree(domain.tchar_ptr); return CURLE_OUT_OF_MEMORY; } - free(identity->Domain); + curlx_free(identity->Domain); identity->Domain = dup_domain.tbyte_ptr; identity->DomainLength = curlx_uztoul(_tcslen(dup_domain.tchar_ptr)); dup_domain.tchar_ptr = NULL; @@ -429,7 +425,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, /* Allocate the output buffer according to the max token size as indicated by the security package */ - output_token = malloc(token_max); + output_token = curlx_malloc(token_max); if(!output_token) { return CURLE_OUT_OF_MEMORY; } @@ -495,7 +491,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, if(userp && *userp) { /* Populate our identity structure */ if(Curl_create_sspi_identity(userp, passwdp, &identity)) { - free(output_token); + curlx_free(output_token); return CURLE_OUT_OF_MEMORY; } @@ -503,7 +499,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, if(Curl_override_sspi_http_realm((const char *) digest->input_token, &identity)) { Curl_sspi_free_identity(&identity); - free(output_token); + curlx_free(output_token); return CURLE_OUT_OF_MEMORY; } @@ -515,20 +511,20 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, p_identity = NULL; if(userp) { - digest->user = strdup(userp); + digest->user = curlx_strdup(userp); if(!digest->user) { - free(output_token); + curlx_free(output_token); Curl_sspi_free_identity(p_identity); return CURLE_OUT_OF_MEMORY; } } if(passwdp) { - digest->passwd = strdup(passwdp); + digest->passwd = curlx_strdup(passwdp); if(!digest->passwd) { - free(output_token); + curlx_free(output_token); Curl_sspi_free_identity(p_identity); Curl_safefree(digest->user); return CURLE_OUT_OF_MEMORY; @@ -543,7 +539,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, &credentials, NULL); if(status != SEC_E_OK) { Curl_sspi_free_identity(p_identity); - free(output_token); + curlx_free(output_token); return CURLE_LOGIN_DENIED; } @@ -575,18 +571,18 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, Curl_pSecFn->FreeCredentialsHandle(&credentials); Curl_sspi_free_identity(p_identity); - free(output_token); + curlx_free(output_token); return CURLE_OUT_OF_MEMORY; } /* Allocate our new context handle */ - digest->http_context = calloc(1, sizeof(CtxtHandle)); + digest->http_context = curlx_calloc(1, sizeof(CtxtHandle)); if(!digest->http_context) { Curl_pSecFn->FreeCredentialsHandle(&credentials); curlx_unicodefree(spn); Curl_sspi_free_identity(p_identity); - free(output_token); + curlx_free(output_token); return CURLE_OUT_OF_MEMORY; } @@ -610,7 +606,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, Curl_pSecFn->FreeCredentialsHandle(&credentials); Curl_sspi_free_identity(p_identity); - free(output_token); + curlx_free(output_token); Curl_safefree(digest->http_context); @@ -632,7 +628,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, } resp = Curl_memdup0((const char *)output_token, output_token_len); - free(output_token); + curlx_free(output_token); if(!resp) { return CURLE_OUT_OF_MEMORY; } diff --git a/lib/vauth/gsasl.c b/lib/vauth/gsasl.c index 119c392cda13..debeda0604e2 100644 --- a/lib/vauth/gsasl.c +++ b/lib/vauth/gsasl.c @@ -36,10 +36,6 @@ #include -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - bool Curl_auth_gsasl_is_supported(struct Curl_easy *data, const char *mech, struct gsasldata *gsasl) diff --git a/lib/vauth/krb5_gssapi.c b/lib/vauth/krb5_gssapi.c index a414d0a35961..9ea36171faec 100644 --- a/lib/vauth/krb5_gssapi.c +++ b/lib/vauth/krb5_gssapi.c @@ -37,10 +37,6 @@ #include "../curl_gssapi.h" #include "../sendf.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #if defined(__GNUC__) && defined(__APPLE__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -120,12 +116,12 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data, Curl_gss_log_error(data, "gss_import_name() failed: ", major_status, minor_status); - free(spn); + curlx_free(spn); return CURLE_AUTH_ERROR; } - free(spn); + curlx_free(spn); } if(chlg) { @@ -258,7 +254,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, messagelen = 4; if(authzid) messagelen += strlen(authzid); - message = malloc(messagelen); + message = curlx_malloc(messagelen); if(!message) return CURLE_OUT_OF_MEMORY; @@ -285,7 +281,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, if(GSS_ERROR(major_status)) { Curl_gss_log_error(data, "gss_wrap() failed: ", major_status, minor_status); - free(message); + curlx_free(message); return CURLE_AUTH_ERROR; } @@ -295,7 +291,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, gss_release_buffer(&unused_status, &output_token); /* Free the message buffer */ - free(message); + curlx_free(message); return result; } diff --git a/lib/vauth/krb5_sspi.c b/lib/vauth/krb5_sspi.c index cad2412d1794..10fbac7644db 100644 --- a/lib/vauth/krb5_sspi.c +++ b/lib/vauth/krb5_sspi.c @@ -36,10 +36,6 @@ #include "../curlx/multibyte.h" #include "../sendf.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Curl_auth_is_gssapi_supported() * @@ -131,7 +127,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data, Curl_pSecFn->FreeContextBuffer(SecurityPackage); /* Allocate our response buffer */ - krb5->output_token = malloc(krb5->token_max); + krb5->output_token = curlx_malloc(krb5->token_max); if(!krb5->output_token) return CURLE_OUT_OF_MEMORY; } @@ -152,7 +148,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data, krb5->p_identity = NULL; /* Allocate our credentials handle */ - krb5->credentials = calloc(1, sizeof(CredHandle)); + krb5->credentials = curlx_calloc(1, sizeof(CredHandle)); if(!krb5->credentials) return CURLE_OUT_OF_MEMORY; @@ -166,7 +162,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data, return CURLE_LOGIN_DENIED; /* Allocate our new context handle */ - krb5->context = calloc(1, sizeof(CtxtHandle)); + krb5->context = curlx_calloc(1, sizeof(CtxtHandle)); if(!krb5->context) return CURLE_OUT_OF_MEMORY; } @@ -340,7 +336,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, } /* Allocate the trailer */ - trailer = malloc(sizes.cbSecurityTrailer); + trailer = curlx_malloc(sizes.cbSecurityTrailer); if(!trailer) return CURLE_OUT_OF_MEMORY; @@ -348,7 +344,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, messagelen = 4; if(authzid) messagelen += strlen(authzid); - message = malloc(messagelen); + message = curlx_malloc(messagelen); if(!message) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -367,7 +363,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, memcpy(message + 4, authzid, messagelen - 4); /* Allocate the padding */ - padding = malloc(sizes.cbBlockSize); + padding = curlx_malloc(sizes.cbBlockSize); if(!padding) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -401,7 +397,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, /* Allocate the encryption (wrap) buffer */ appdatalen = wrap_buf[0].cbBuffer + wrap_buf[1].cbBuffer + wrap_buf[2].cbBuffer; - appdata = malloc(appdatalen); + appdata = curlx_malloc(appdatalen); if(!appdata) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -416,9 +412,9 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, out: /* Free all of our local buffers */ - free(padding); - free(message); - free(trailer); + curlx_free(padding); + curlx_free(message); + curlx_free(trailer); if(result) return result; @@ -443,14 +439,14 @@ void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5) /* Free our security context */ if(krb5->context) { Curl_pSecFn->DeleteSecurityContext(krb5->context); - free(krb5->context); + curlx_free(krb5->context); krb5->context = NULL; } /* Free our credentials handle */ if(krb5->credentials) { Curl_pSecFn->FreeCredentialsHandle(krb5->credentials); - free(krb5->credentials); + curlx_free(krb5->credentials); krb5->credentials = NULL; } diff --git a/lib/vauth/ntlm.c b/lib/vauth/ntlm.c index 1e9b629d8f49..a757d1c8f9fd 100644 --- a/lib/vauth/ntlm.c +++ b/lib/vauth/ntlm.c @@ -48,10 +48,6 @@ #include "vauth.h" #include "../curl_endian.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* NTLM buffer fixed size, large enough for long user + host + domain */ #define NTLM_BUFSIZE 1024 @@ -282,7 +278,7 @@ static CURLcode ntlm_decode_type2_target(struct Curl_easy *data, return CURLE_BAD_CONTENT_ENCODING; } - free(ntlm->target_info); /* replace any previous data */ + curlx_free(ntlm->target_info); /* replace any previous data */ ntlm->target_info = Curl_memdup(&type2[target_info_offset], target_info_len); if(!ntlm->target_info) @@ -842,7 +838,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data, result = Curl_bufref_memdup(out, ntlmbuf, size); error: - free(ntlmv2resp); /* Free the dynamic buffer allocated for NTLMv2 */ + curlx_free(ntlmv2resp); /* Free the dynamic buffer allocated for NTLMv2 */ Curl_auth_cleanup_ntlm(ntlm); diff --git a/lib/vauth/ntlm_sspi.c b/lib/vauth/ntlm_sspi.c index 071617182e7e..d976bc5d2131 100644 --- a/lib/vauth/ntlm_sspi.c +++ b/lib/vauth/ntlm_sspi.c @@ -36,10 +36,6 @@ #include "../sendf.h" #include "../strdup.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Curl_auth_is_ntlm_supported() * @@ -117,7 +113,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data, Curl_pSecFn->FreeContextBuffer(SecurityPackage); /* Allocate our output buffer */ - ntlm->output_token = malloc(ntlm->token_max); + ntlm->output_token = curlx_malloc(ntlm->token_max); if(!ntlm->output_token) return CURLE_OUT_OF_MEMORY; @@ -137,7 +133,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data, ntlm->p_identity = NULL; /* Allocate our credentials handle */ - ntlm->credentials = calloc(1, sizeof(CredHandle)); + ntlm->credentials = curlx_calloc(1, sizeof(CredHandle)); if(!ntlm->credentials) return CURLE_OUT_OF_MEMORY; @@ -151,7 +147,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data, return CURLE_LOGIN_DENIED; /* Allocate our new context handle */ - ntlm->context = calloc(1, sizeof(CtxtHandle)); + ntlm->context = curlx_calloc(1, sizeof(CtxtHandle)); if(!ntlm->context) return CURLE_OUT_OF_MEMORY; @@ -343,14 +339,14 @@ void Curl_auth_cleanup_ntlm(struct ntlmdata *ntlm) /* Free our security context */ if(ntlm->context) { Curl_pSecFn->DeleteSecurityContext(ntlm->context); - free(ntlm->context); + curlx_free(ntlm->context); ntlm->context = NULL; } /* Free our credentials handle */ if(ntlm->credentials) { Curl_pSecFn->FreeCredentialsHandle(ntlm->credentials); - free(ntlm->credentials); + curlx_free(ntlm->credentials); ntlm->credentials = NULL; } diff --git a/lib/vauth/oauth2.c b/lib/vauth/oauth2.c index cf7addf53597..0bb7a9d6bdab 100644 --- a/lib/vauth/oauth2.c +++ b/lib/vauth/oauth2.c @@ -36,10 +36,6 @@ #include "vauth.h" #include "../curlx/warnless.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Curl_auth_create_oauth_bearer_message() * diff --git a/lib/vauth/spnego_gssapi.c b/lib/vauth/spnego_gssapi.c index 4e9125ba4400..f956f2c03e81 100644 --- a/lib/vauth/spnego_gssapi.c +++ b/lib/vauth/spnego_gssapi.c @@ -38,10 +38,6 @@ #include "../curlx/multibyte.h" #include "../sendf.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #if defined(__GNUC__) && defined(__APPLE__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -131,12 +127,12 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, Curl_gss_log_error(data, "gss_import_name() failed: ", major_status, minor_status); - free(spn); + curlx_free(spn); return CURLE_AUTH_ERROR; } - free(spn); + curlx_free(spn); } if(chlg64 && *chlg64) { diff --git a/lib/vauth/spnego_sspi.c b/lib/vauth/spnego_sspi.c index b36535557bd9..90e622da3d4e 100644 --- a/lib/vauth/spnego_sspi.c +++ b/lib/vauth/spnego_sspi.c @@ -38,10 +38,6 @@ #include "../sendf.h" #include "../strerror.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Curl_auth_is_spnego_supported() * @@ -140,7 +136,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, Curl_pSecFn->FreeContextBuffer(SecurityPackage); /* Allocate our output buffer */ - nego->output_token = malloc(nego->token_max); + nego->output_token = curlx_malloc(nego->token_max); if(!nego->output_token) return CURLE_OUT_OF_MEMORY; } @@ -161,7 +157,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, nego->p_identity = NULL; /* Allocate our credentials handle */ - nego->credentials = calloc(1, sizeof(CredHandle)); + nego->credentials = curlx_calloc(1, sizeof(CredHandle)); if(!nego->credentials) return CURLE_OUT_OF_MEMORY; @@ -175,7 +171,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, return CURLE_AUTH_ERROR; /* Allocate our new context handle */ - nego->context = calloc(1, sizeof(CtxtHandle)); + nego->context = curlx_calloc(1, sizeof(CtxtHandle)); if(!nego->context) return CURLE_OUT_OF_MEMORY; } @@ -248,7 +244,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, &resp_desc, &attrs, NULL); /* Free the decoded challenge as it is not required anymore */ - free(chlg); + curlx_free(chlg); if(GSS_ERROR(nego->status)) { char buffer[STRERROR_LEN]; @@ -305,7 +301,7 @@ CURLcode Curl_auth_create_spnego_message(struct negotiatedata *nego, nego->output_token_length, outptr, outlen); if(!result && (!*outptr || !*outlen)) { - free(*outptr); + curlx_free(*outptr); result = CURLE_REMOTE_ACCESS_DENIED; } @@ -327,14 +323,14 @@ void Curl_auth_cleanup_spnego(struct negotiatedata *nego) /* Free our security context */ if(nego->context) { Curl_pSecFn->DeleteSecurityContext(nego->context); - free(nego->context); + curlx_free(nego->context); nego->context = NULL; } /* Free our credentials handle */ if(nego->credentials) { Curl_pSecFn->FreeCredentialsHandle(nego->credentials); - free(nego->credentials); + curlx_free(nego->credentials); nego->credentials = NULL; } diff --git a/lib/vauth/vauth.c b/lib/vauth/vauth.c index 6ee687dcab22..6626ace8bc6a 100644 --- a/lib/vauth/vauth.c +++ b/lib/vauth/vauth.c @@ -32,10 +32,6 @@ #include "../curlx/multibyte.h" #include "../url.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Curl_auth_build_spn() * @@ -96,10 +92,10 @@ TCHAR *Curl_auth_build_spn(const char *service, const char *host, must be freed by curlx_unicodefree we will dupe the result so that the pointer this function returns can be normally free'd. */ tchar_spn = curlx_convert_UTF8_to_tchar(utf8_spn); - free(utf8_spn); + curlx_free(utf8_spn); if(!tchar_spn) return NULL; - dupe_tchar_spn = Curl_tcsdup(tchar_spn); + dupe_tchar_spn = curlx_tcsdup(tchar_spn); curlx_unicodefree(tchar_spn); return dupe_tchar_spn; } @@ -170,7 +166,7 @@ static void ntlm_conn_dtor(void *key, size_t klen, void *entry) (void)klen; DEBUGASSERT(ntlm); Curl_auth_cleanup_ntlm(ntlm); - free(ntlm); + curlx_free(ntlm); } struct ntlmdata *Curl_auth_ntlm_get(struct connectdata *conn, bool proxy) @@ -179,7 +175,7 @@ struct ntlmdata *Curl_auth_ntlm_get(struct connectdata *conn, bool proxy) CURL_META_NTLM_CONN; struct ntlmdata *ntlm = Curl_conn_meta_get(conn, key); if(!ntlm) { - ntlm = calloc(1, sizeof(*ntlm)); + ntlm = curlx_calloc(1, sizeof(*ntlm)); if(!ntlm || Curl_conn_meta_set(conn, key, ntlm, ntlm_conn_dtor)) return NULL; @@ -204,14 +200,14 @@ static void krb5_conn_dtor(void *key, size_t klen, void *entry) (void)klen; DEBUGASSERT(krb5); Curl_auth_cleanup_gssapi(krb5); - free(krb5); + curlx_free(krb5); } struct kerberos5data *Curl_auth_krb5_get(struct connectdata *conn) { struct kerberos5data *krb5 = Curl_conn_meta_get(conn, CURL_META_KRB5_CONN); if(!krb5) { - krb5 = calloc(1, sizeof(*krb5)); + krb5 = curlx_calloc(1, sizeof(*krb5)); if(!krb5 || Curl_conn_meta_set(conn, CURL_META_KRB5_CONN, krb5, krb5_conn_dtor)) return NULL; @@ -230,14 +226,14 @@ static void gsasl_conn_dtor(void *key, size_t klen, void *entry) (void)klen; DEBUGASSERT(gsasl); Curl_auth_gsasl_cleanup(gsasl); - free(gsasl); + curlx_free(gsasl); } struct gsasldata *Curl_auth_gsasl_get(struct connectdata *conn) { struct gsasldata *gsasl = Curl_conn_meta_get(conn, CURL_META_GSASL_CONN); if(!gsasl) { - gsasl = calloc(1, sizeof(*gsasl)); + gsasl = curlx_calloc(1, sizeof(*gsasl)); if(!gsasl || Curl_conn_meta_set(conn, CURL_META_GSASL_CONN, gsasl, gsasl_conn_dtor)) return NULL; @@ -256,7 +252,7 @@ static void nego_conn_dtor(void *key, size_t klen, void *entry) (void)klen; DEBUGASSERT(nego); Curl_auth_cleanup_spnego(nego); - free(nego); + curlx_free(nego); } struct negotiatedata *Curl_auth_nego_get(struct connectdata *conn, bool proxy) @@ -265,7 +261,7 @@ struct negotiatedata *Curl_auth_nego_get(struct connectdata *conn, bool proxy) CURL_META_NEGO_CONN; struct negotiatedata *nego = Curl_conn_meta_get(conn, key); if(!nego) { - nego = calloc(1, sizeof(*nego)); + nego = curlx_calloc(1, sizeof(*nego)); if(!nego || Curl_conn_meta_set(conn, key, nego, nego_conn_dtor)) return NULL; diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index 86f7428048e1..4767780a922d 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -71,10 +71,6 @@ #include "../curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - #define QUIC_MAX_STREAMS (256*1024) #define QUIC_HANDSHAKE_TIMEOUT (10*NGTCP2_SECONDS) @@ -182,7 +178,7 @@ static void cf_ngtcp2_ctx_free(struct cf_ngtcp2_ctx *ctx) Curl_uint32_hash_destroy(&ctx->streams); Curl_ssl_peer_cleanup(&ctx->peer); } - free(ctx); + curlx_free(ctx); } static void cf_ngtcp2_setup_keep_alive(struct Curl_cfilter *cf, @@ -255,7 +251,7 @@ static void h3_stream_ctx_free(struct h3_stream_ctx *stream) { Curl_bufq_free(&stream->sendbuf); Curl_h1_req_parse_free(&stream->h1); - free(stream); + curlx_free(stream); } static void h3_stream_hash_free(unsigned int id, void *stream) @@ -277,7 +273,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, if(stream) return CURLE_OK; - stream = calloc(1, sizeof(*stream)); + stream = curlx_calloc(1, sizeof(*stream)); if(!stream) return CURLE_OUT_OF_MEMORY; @@ -1573,7 +1569,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, Curl_h1_req_parse_free(&stream->h1); nheader = Curl_dynhds_count(&h2_headers); - nva = malloc(sizeof(nghttp3_nv) * nheader); + nva = curlx_malloc(sizeof(nghttp3_nv) * nheader); if(!nva) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1650,7 +1646,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, } out: - free(nva); + curlx_free(nva); Curl_dynhds_free(&h2_headers); return result; } @@ -2851,7 +2847,7 @@ CURLcode Curl_cf_ngtcp2_create(struct Curl_cfilter **pcf, CURLcode result; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/vquic/curl_osslq.c b/lib/vquic/curl_osslq.c index d6672ce13252..1c3f0c55b66e 100644 --- a/lib/vquic/curl_osslq.c +++ b/lib/vquic/curl_osslq.c @@ -57,10 +57,6 @@ #include "../curlx/warnless.h" #include "../curlx/strerr.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* A stream window is the maximum amount we need to buffer for * each active transfer. We use HTTP/3 flow control and only ACK * when we take things out of the buffer. @@ -318,10 +314,10 @@ static void cf_osslq_ctx_free(struct cf_osslq_ctx *ctx) Curl_bufcp_free(&ctx->stream_bufcp); Curl_uint32_hash_destroy(&ctx->streams); Curl_ssl_peer_cleanup(&ctx->peer); - free(ctx->poll_items); - free(ctx->curl_items); + curlx_free(ctx->poll_items); + curlx_free(ctx->curl_items); } - free(ctx); + curlx_free(ctx); } static void cf_osslq_ctx_close(struct cf_osslq_ctx *ctx) @@ -596,7 +592,7 @@ static void h3_stream_ctx_free(struct h3_stream_ctx *stream) Curl_bufq_free(&stream->sendbuf); Curl_bufq_free(&stream->recvbuf); Curl_h1_req_parse_free(&stream->h1); - free(stream); + curlx_free(stream); } static void h3_stream_hash_free(unsigned int id, void *stream) @@ -618,7 +614,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, if(stream) return CURLE_OK; - stream = calloc(1, sizeof(*stream)); + stream = curlx_calloc(1, sizeof(*stream)); if(!stream) return CURLE_OUT_OF_MEMORY; @@ -1511,18 +1507,19 @@ static CURLcode cf_osslq_check_and_unblock(struct Curl_cfilter *cf, if(ctx->items_max < Curl_uint32_hash_count(&ctx->streams)) { size_t nmax = Curl_uint32_hash_count(&ctx->streams); ctx->items_max = 0; - tmpptr = realloc(ctx->poll_items, nmax * sizeof(SSL_POLL_ITEM)); + tmpptr = curlx_realloc(ctx->poll_items, nmax * sizeof(SSL_POLL_ITEM)); if(!tmpptr) { - free(ctx->poll_items); + curlx_free(ctx->poll_items); ctx->poll_items = NULL; res = CURLE_OUT_OF_MEMORY; goto out; } ctx->poll_items = tmpptr; - tmpptr = realloc(ctx->curl_items, nmax * sizeof(struct Curl_easy *)); + tmpptr = curlx_realloc(ctx->curl_items, + nmax * sizeof(struct Curl_easy *)); if(!tmpptr) { - free(ctx->curl_items); + curlx_free(ctx->curl_items); ctx->curl_items = NULL; res = CURLE_OUT_OF_MEMORY; goto out; @@ -1922,7 +1919,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, Curl_h1_req_parse_free(&stream->h1); nheader = Curl_dynhds_count(&h2_headers); - nva = malloc(sizeof(nghttp3_nv) * nheader); + nva = curlx_malloc(sizeof(nghttp3_nv) * nheader); if(!nva) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1999,7 +1996,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, } out: - free(nva); + curlx_free(nva); Curl_dynhds_free(&h2_headers); return result; } @@ -2407,7 +2404,7 @@ CURLcode Curl_cf_osslq_create(struct Curl_cfilter **pcf, CURLcode result; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/vquic/curl_quiche.c b/lib/vquic/curl_quiche.c index f8fbadeebb1f..c182e1490d23 100644 --- a/lib/vquic/curl_quiche.c +++ b/lib/vquic/curl_quiche.c @@ -52,10 +52,6 @@ #include "../vtls/keylog.h" #include "../vtls/vtls.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* HTTP/3 error values defined in RFC 9114, ch. 8.1 */ #define CURL_H3_NO_ERROR (0x0100) @@ -141,7 +137,7 @@ static void cf_quiche_ctx_free(struct cf_quiche_ctx *ctx) Curl_bufcp_free(&ctx->stream_bufcp); Curl_uint32_hash_destroy(&ctx->streams); } - free(ctx); + curlx_free(ctx); } static void cf_quiche_ctx_close(struct cf_quiche_ctx *ctx) @@ -188,7 +184,7 @@ static void h3_stream_ctx_free(struct h3_stream_ctx *stream) { Curl_bufq_free(&stream->recvbuf); Curl_h1_req_parse_free(&stream->h1); - free(stream); + curlx_free(stream); } static void h3_stream_hash_free(unsigned int id, void *stream) @@ -269,7 +265,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, if(stream) return CURLE_OK; - stream = calloc(1, sizeof(*stream)); + stream = curlx_calloc(1, sizeof(*stream)); if(!stream) return CURLE_OUT_OF_MEMORY; @@ -1000,7 +996,7 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, Curl_h1_req_parse_free(&stream->h1); nheader = Curl_dynhds_count(&h2_headers); - nva = malloc(sizeof(quiche_h3_header) * nheader); + nva = curlx_malloc(sizeof(quiche_h3_header) * nheader); if(!nva) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1070,7 +1066,7 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, } out: - free(nva); + curlx_free(nva); Curl_dynhds_free(&h2_headers); return result; } @@ -1633,7 +1629,7 @@ CURLcode Curl_cf_quiche_create(struct Curl_cfilter **pcf, (void)data; (void)conn; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/vquic/vquic-tls.c b/lib/vquic/vquic-tls.c index 46bb4c7d4c25..7a3c99b58441 100644 --- a/lib/vquic/vquic-tls.c +++ b/lib/vquic/vquic-tls.c @@ -53,10 +53,6 @@ #include "../vtls/vtls_scache.h" #include "vquic-tls.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - CURLcode Curl_vquic_tls_init(struct curl_tls_ctx *ctx, struct Curl_cfilter *cf, struct Curl_easy *data, diff --git a/lib/vquic/vquic.c b/lib/vquic/vquic.c index 8b4d678d8118..c1267cef9ed0 100644 --- a/lib/vquic/vquic.c +++ b/lib/vquic/vquic.c @@ -47,10 +47,6 @@ #include "../curlx/strerr.h" #include "../curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - #if !defined(CURL_DISABLE_HTTP) && defined(USE_HTTP3) @@ -675,7 +671,7 @@ CURLcode Curl_qlogdir(struct Curl_easy *data, *qlogfdp = qlogfd; } curlx_dyn_free(&fname); - free(qlog_dir); + curlx_free(qlog_dir); if(result) return result; } diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index 4b003bd71ca9..a5997a6f6cf9 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -72,10 +72,6 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* A recent macro provided by libssh. Or make our own. */ #ifndef SSH_STRING_FREE_CHAR #define SSH_STRING_FREE_CHAR(x) \ @@ -491,10 +487,12 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc) cleanup: if(found_base64) { - (free)(found_base64); + /* !checksrc! disable BANNEDFUNC 1 */ + free(found_base64); /* allocated by libssh, deallocate with system free */ } if(known_base64) { - (free)(known_base64); + /* !checksrc! disable BANNEDFUNC 1 */ + free(known_base64); /* allocated by libssh, deallocate with system free */ } if(hash) ssh_clean_pubkey_hash(&hash); @@ -605,7 +603,7 @@ static int myssh_in_SFTP_READDIR(struct Curl_easy *data, } result = Curl_client_write(data, CLIENTWRITE_BODY, tmpLine, sshc->readdir_len + 1); - free(tmpLine); + curlx_free(tmpLine); if(result) { myssh_to(data, sshc, SSH_STOP); @@ -787,7 +785,7 @@ static int myssh_in_SFTP_QUOTE_STATVFS(struct Curl_easy *data, if(!result) { result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); } if(result) { myssh_to(data, sshc, SSH_SFTP_CLOSE); @@ -1478,8 +1476,8 @@ static int myssh_in_SFTP_REALPATH(struct Curl_easy *data, if(!sshc->homedir) return myssh_to_ERROR(data, sshc, CURLE_COULDNT_CONNECT); - free(data->state.most_recent_ftp_entrypath); - data->state.most_recent_ftp_entrypath = strdup(sshc->homedir); + curlx_free(data->state.most_recent_ftp_entrypath); + data->state.most_recent_ftp_entrypath = curlx_strdup(sshc->homedir); if(!data->state.most_recent_ftp_entrypath) return myssh_to_ERROR(data, sshc, CURLE_OUT_OF_MEMORY); @@ -1577,7 +1575,7 @@ static int myssh_in_SFTP_QUOTE(struct Curl_easy *data, the current directory can be read similar to how it is read when using ordinary FTP. */ result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); if(result) { myssh_to(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; @@ -2529,7 +2527,7 @@ static void myssh_easy_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; Curl_safefree(sshp->path); - free(sshp); + curlx_free(sshp); } static void myssh_conn_dtor(void *key, size_t klen, void *entry) @@ -2538,7 +2536,7 @@ static void myssh_conn_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; sshc_cleanup(sshc); - free(sshc); + curlx_free(sshc); } /* @@ -2550,7 +2548,7 @@ static CURLcode myssh_setup_connection(struct Curl_easy *data, struct SSHPROTO *sshp; struct ssh_conn *sshc; - sshc = calloc(1, sizeof(*sshc)); + sshc = curlx_calloc(1, sizeof(*sshc)); if(!sshc) return CURLE_OUT_OF_MEMORY; @@ -2559,7 +2557,7 @@ static CURLcode myssh_setup_connection(struct Curl_easy *data, if(Curl_conn_meta_set(conn, CURL_META_SSH_CONN, sshc, myssh_conn_dtor)) return CURLE_OUT_OF_MEMORY; - sshp = calloc(1, sizeof(*sshp)); + sshp = curlx_calloc(1, sizeof(*sshp)); if(!sshp || Curl_meta_set(data, CURL_META_SSH_EASY, sshp, myssh_easy_dtor)) return CURLE_OUT_OF_MEMORY; diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index e4ceda8c3494..4ac9d89f1ad5 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -66,10 +66,6 @@ #include "../curlx/strparse.h" #include "../curlx/base64.h" /* for base64 encoding/decoding */ -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* Local functions: */ static const char *sftp_libssh2_strerror(unsigned long err); static LIBSSH2_ALLOC_FUNC(my_libssh2_malloc); @@ -181,7 +177,7 @@ kbd_callback(const char *name, int name_len, const char *instruction, #endif /* CURL_LIBSSH2_DEBUG */ if(num_prompts == 1) { struct connectdata *conn = data->conn; - responses[0].text = strdup(conn->passwd); + responses[0].text = curlx_strdup(conn->passwd); responses[0].length = responses[0].text == NULL ? 0 : curlx_uztoui(strlen(conn->passwd)); } @@ -635,12 +631,12 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data, failf(data, "Denied establishing ssh session: mismatch sha256 fingerprint. " "Remote %s is not equal to %s", fingerprint_b64, pubkey_sha256); - free(fingerprint_b64); + curlx_free(fingerprint_b64); myssh_state(data, sshc, SSH_SESSION_FREE); return CURLE_PEER_FAILED_VERIFICATION; } - free(fingerprint_b64); + curlx_free(fingerprint_b64); infof(data, "SHA256 checksum match"); } @@ -881,7 +877,7 @@ static CURLcode sftp_quote(struct Curl_easy *data, the current directory can be read similar to how it is read when using ordinary FTP. */ result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); if(!result) myssh_state(data, sshc, SSH_SFTP_NEXT_QUOTE); return result; @@ -1204,7 +1200,7 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, sshc->rsa_pub = sshc->rsa = NULL; if(data->set.str[STRING_SSH_PRIVATE_KEY]) - sshc->rsa = strdup(data->set.str[STRING_SSH_PRIVATE_KEY]); + sshc->rsa = curlx_strdup(data->set.str[STRING_SSH_PRIVATE_KEY]); else { /* To ponder about: should really the lib be messing about with the HOME environment variable etc? */ @@ -1218,7 +1214,7 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, if(!sshc->rsa) out_of_memory = TRUE; else if(curlx_stat(sshc->rsa, &sbuf)) { - free(sshc->rsa); + curlx_free(sshc->rsa); sshc->rsa = curl_maprintf("%s/.ssh/id_dsa", home); if(!sshc->rsa) out_of_memory = TRUE; @@ -1226,19 +1222,19 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, Curl_safefree(sshc->rsa); } } - free(home); + curlx_free(home); } if(!out_of_memory && !sshc->rsa) { /* Nothing found; try the current dir. */ - sshc->rsa = strdup("id_rsa"); + sshc->rsa = curlx_strdup("id_rsa"); if(sshc->rsa && curlx_stat(sshc->rsa, &sbuf)) { - free(sshc->rsa); - sshc->rsa = strdup("id_dsa"); + curlx_free(sshc->rsa); + sshc->rsa = curlx_strdup("id_dsa"); if(sshc->rsa && curlx_stat(sshc->rsa, &sbuf)) { - free(sshc->rsa); + curlx_free(sshc->rsa); /* Out of guesses. Set to the empty string to avoid * surprising info messages. */ - sshc->rsa = strdup(""); + sshc->rsa = curlx_strdup(""); } } } @@ -1252,7 +1248,7 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, if(data->set.str[STRING_SSH_PUBLIC_KEY] /* treat empty string the same way as NULL */ && data->set.str[STRING_SSH_PUBLIC_KEY][0]) { - sshc->rsa_pub = strdup(data->set.str[STRING_SSH_PUBLIC_KEY]); + sshc->rsa_pub = curlx_strdup(data->set.str[STRING_SSH_PUBLIC_KEY]); if(!sshc->rsa_pub) out_of_memory = TRUE; } @@ -1936,12 +1932,12 @@ static CURLcode ssh_state_sftp_realpath(struct Curl_easy *data, myssh_state(data, sshc, SSH_STOP); if(rc > 0) { - free(sshc->homedir); - sshc->homedir = strdup(sshp->readdir_filename); + curlx_free(sshc->homedir); + sshc->homedir = curlx_strdup(sshp->readdir_filename); if(!sshc->homedir) return CURLE_OUT_OF_MEMORY; - free(data->state.most_recent_ftp_entrypath); - data->state.most_recent_ftp_entrypath = strdup(sshc->homedir); + curlx_free(data->state.most_recent_ftp_entrypath); + data->state.most_recent_ftp_entrypath = curlx_strdup(sshc->homedir); if(!data->state.most_recent_ftp_entrypath) return CURLE_OUT_OF_MEMORY; } @@ -2251,7 +2247,7 @@ static CURLcode ssh_state_sftp_quote_statvfs(struct Curl_easy *data, } result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); if(result) { myssh_state(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; @@ -3177,7 +3173,7 @@ static void myssh_easy_dtor(void *key, size_t klen, void *entry) Curl_safefree(sshp->path); curlx_dyn_free(&sshp->readdir); curlx_dyn_free(&sshp->readdir_link); - free(sshp); + curlx_free(sshp); } static void myssh_conn_dtor(void *key, size_t klen, void *entry) @@ -3186,7 +3182,7 @@ static void myssh_conn_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; sshc_cleanup(sshc, NULL, TRUE); - free(sshc); + curlx_free(sshc); } /* @@ -3199,14 +3195,14 @@ static CURLcode ssh_setup_connection(struct Curl_easy *data, struct SSHPROTO *sshp; (void)conn; - sshc = calloc(1, sizeof(*sshc)); + sshc = curlx_calloc(1, sizeof(*sshc)); if(!sshc) return CURLE_OUT_OF_MEMORY; if(Curl_conn_meta_set(conn, CURL_META_SSH_CONN, sshc, myssh_conn_dtor)) return CURLE_OUT_OF_MEMORY; - sshp = calloc(1, sizeof(*sshp)); + sshp = curlx_calloc(1, sizeof(*sshp)); if(!sshp) return CURLE_OUT_OF_MEMORY; diff --git a/lib/vssh/vssh.c b/lib/vssh/vssh.c index e33386a16aa5..a23f9e8e981f 100644 --- a/lib/vssh/vssh.c +++ b/lib/vssh/vssh.c @@ -30,9 +30,7 @@ #include #include "../curlx/strparse.h" #include "../curl_trc.h" -#include "../curl_memory.h" #include "../escape.h" -#include "../memdebug.h" #define MAX_SSHPATH_LEN 100000 /* arbitrary */ @@ -59,7 +57,7 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data, (working_path_len > 3) && (!memcmp(working_path, "/~/", 3))) { /* It is referenced to the home directory, so strip the leading '/~/' */ if(curlx_dyn_addn(&npath, &working_path[3], working_path_len - 3)) { - free(working_path); + curlx_free(working_path); return CURLE_OUT_OF_MEMORY; } } @@ -67,7 +65,7 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data, (!strcmp("/~", working_path) || ((working_path_len > 2) && !memcmp(working_path, "/~/", 3)))) { if(curlx_dyn_add(&npath, homedir)) { - free(working_path); + curlx_free(working_path); return CURLE_OUT_OF_MEMORY; } if(working_path_len > 2) { @@ -82,20 +80,20 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data, if(curlx_dyn_addn(&npath, &working_path[copyfrom], working_path_len - copyfrom)) { - free(working_path); + curlx_free(working_path); return CURLE_OUT_OF_MEMORY; } } else { if(curlx_dyn_add(&npath, "/")) { - free(working_path); + curlx_free(working_path); return CURLE_OUT_OF_MEMORY; } } } if(curlx_dyn_len(&npath)) { - free(working_path); + curlx_free(working_path); /* store the pointer for the caller to receive */ *path = curlx_dyn_ptr(&npath); diff --git a/lib/vtls/apple.c b/lib/vtls/apple.c index 297ebc39f393..62bb9e3bd194 100644 --- a/lib/vtls/apple.c +++ b/lib/vtls/apple.c @@ -50,10 +50,6 @@ #include #endif -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #ifdef USE_APPLE_SECTRUST #define SSL_SYSTEM_VERIFIER @@ -244,11 +240,11 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf, if(error_ref) { CFIndex size = CFStringGetMaximumSizeForEncoding( CFStringGetLength(error_ref), kCFStringEncodingUTF8); - err_desc = malloc(size + 1); + err_desc = curlx_malloc(size + 1); if(err_desc) { if(!CFStringGetCString(error_ref, err_desc, size, kCFStringEncodingUTF8)) { - free(err_desc); + curlx_free(err_desc); err_desc = NULL; } } @@ -276,7 +272,7 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf, } out: - free(err_desc); + curlx_free(err_desc); if(error_ref) CFRelease(error_ref); if(error) diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c index 55a75fa72150..c05ab8427b89 100644 --- a/lib/vtls/gtls.c +++ b/lib/vtls/gtls.c @@ -59,9 +59,6 @@ #include "../curlx/warnless.h" #include "x509asn1.h" #include "../multiif.h" -#include "../curl_memory.h" -/* The last #include file should be: */ -#include "../memdebug.h" /* Enable GnuTLS debugging by defining GTLSDEBUG */ /*#define GTLSDEBUG */ @@ -215,10 +212,10 @@ static gnutls_datum_t load_file(const char *file) if(fseek(f, 0, SEEK_END) != 0 || (filelen = ftell(f)) < 0 || fseek(f, 0, SEEK_SET) != 0 - || !(ptr = malloc((size_t)filelen))) + || !(ptr = curlx_malloc((size_t)filelen))) goto out; if(fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) { - free(ptr); + curlx_free(ptr); goto out; } @@ -231,7 +228,7 @@ static gnutls_datum_t load_file(const char *file) static void unload_file(gnutls_datum_t data) { - free(data.data); + curlx_free(data.data); } @@ -404,14 +401,14 @@ CURLcode Curl_gtls_shared_creds_create(struct Curl_easy *data, int rc; *pcreds = NULL; - shared = calloc(1, sizeof(*shared)); + shared = curlx_calloc(1, sizeof(*shared)); if(!shared) return CURLE_OUT_OF_MEMORY; rc = gnutls_certificate_allocate_credentials(&shared->creds); if(rc != GNUTLS_E_SUCCESS) { failf(data, "gnutls_cert_all_cred() failed: %s", gnutls_strerror(rc)); - free(shared); + curlx_free(shared); return CURLE_SSL_CONNECT_ERROR; } @@ -439,8 +436,8 @@ void Curl_gtls_shared_creds_free(struct gtls_shared_creds **pcreds) --shared->refcount; if(!shared->refcount) { gnutls_certificate_free_credentials(shared->creds); - free(shared->CAfile); - free(shared); + curlx_free(shared->CAfile); + curlx_free(shared); } } } @@ -629,7 +626,7 @@ static void gtls_set_cached_creds(struct Curl_cfilter *cf, return; if(conn_config->CAfile) { - sc->CAfile = strdup(conn_config->CAfile); + sc->CAfile = curlx_strdup(conn_config->CAfile); if(!sc->CAfile) return; } @@ -723,7 +720,7 @@ CURLcode Curl_gtls_cache_session(struct Curl_cfilter *cf, if(!sdata_len) /* gnutls does this for some version combinations */ return CURLE_OK; - sdata = malloc(sdata_len); /* get a buffer for it */ + sdata = curlx_malloc(sdata_len); /* get a buffer for it */ if(!sdata) return CURLE_OUT_OF_MEMORY; @@ -737,7 +734,7 @@ CURLcode Curl_gtls_cache_session(struct Curl_cfilter *cf, if(quic_tp && quic_tp_len) { qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len); if(!qtp_clone) { - free(sdata); + curlx_free(sdata); return CURLE_OUT_OF_MEMORY; } } @@ -1312,7 +1309,7 @@ static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data, if(ret != GNUTLS_E_SHORT_MEMORY_BUFFER || len1 == 0) break; /* failed */ - buff1 = malloc(len1); + buff1 = curlx_malloc(len1); if(!buff1) break; /* failed */ diff --git a/lib/vtls/hostcheck.c b/lib/vtls/hostcheck.c index 23ba33951f17..672f473db42a 100644 --- a/lib/vtls/hostcheck.c +++ b/lib/vtls/hostcheck.c @@ -37,10 +37,6 @@ #include "hostcheck.h" #include "../hostip.h" -#include "../curl_memory.h" -/* The last #include file should be: */ -#include "../memdebug.h" - /* check the two input strings with given length, but do not assume they end in nul-bytes */ static bool pmatch(const char *hostname, size_t hostlen, diff --git a/lib/vtls/keylog.c b/lib/vtls/keylog.c index 9179d38fe76f..397bac1a366a 100644 --- a/lib/vtls/keylog.c +++ b/lib/vtls/keylog.c @@ -35,10 +35,6 @@ #include "../escape.h" #include "../curlx/fopen.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* The fp for the open SSLKEYLOGFILE, or NULL if not open */ static FILE *keylog_file_fp; diff --git a/lib/vtls/mbedtls.c b/lib/vtls/mbedtls.c index 2ea3670c1bf2..9e13ed4641d9 100644 --- a/lib/vtls/mbedtls.c +++ b/lib/vtls/mbedtls.c @@ -75,10 +75,6 @@ #include "../strdup.h" #include "../curl_sha256.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* ALPN for http2 */ #if defined(USE_HTTP2) && defined(MBEDTLS_SSL_ALPN) # define HAS_ALPN_MBEDTLS @@ -355,7 +351,7 @@ mbed_set_selected_ciphers(struct Curl_easy *data, for(i = 0; supported[i] != 0; i++); supported_len = i; - selected = malloc(sizeof(int) * (supported_len + 1)); + selected = curlx_malloc(sizeof(int) * (supported_len + 1)); if(!selected) return CURLE_OUT_OF_MEMORY; @@ -433,7 +429,7 @@ mbed_set_selected_ciphers(struct Curl_easy *data, selected[count] = 0; if(count == 0) { - free(selected); + curlx_free(selected); failf(data, "mbedTLS: no supported cipher in list"); return CURLE_SSL_CIPHER; } @@ -452,7 +448,7 @@ mbed_dump_cert_info(struct Curl_easy *data, const mbedtls_x509_crt *crt) (void)data, (void)crt; #else const size_t bufsize = 16384; - char *p, *buffer = malloc(bufsize); + char *p, *buffer = curlx_malloc(bufsize); if(buffer && mbedtls_x509_crt_info(buffer, bufsize, " ", crt) > 0) { infof(data, "Server certificate:"); @@ -465,7 +461,7 @@ mbed_dump_cert_info(struct Curl_easy *data, const mbedtls_x509_crt *crt) else infof(data, "Unable to dump certificate information"); - free(buffer); + curlx_free(buffer); #endif } @@ -597,7 +593,7 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_OUT_OF_MEMORY; ret = mbedtls_x509_crt_parse(&backend->cacert, newblob, ca_info_blob->len + 1); - free(newblob); + curlx_free(newblob); if(ret < 0) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); failf(data, "Error importing ca cert blob - mbedTLS: (-0x%04X) %s", @@ -670,7 +666,7 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_OUT_OF_MEMORY; ret = mbedtls_x509_crt_parse(&backend->clicert, newblob, ssl_cert_blob->len + 1); - free(newblob); + curlx_free(newblob); if(ret) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); @@ -1027,12 +1023,12 @@ mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_SSL_PINNEDPUBKEYNOTMATCH; } - p = calloc(1, sizeof(*p)); + p = curlx_calloc(1, sizeof(*p)); if(!p) return CURLE_OUT_OF_MEMORY; - pubkey = malloc(PUB_DER_MAX_BYTES); + pubkey = curlx_malloc(PUB_DER_MAX_BYTES); if(!pubkey) { result = CURLE_OUT_OF_MEMORY; @@ -1064,8 +1060,8 @@ mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) &pubkey[PUB_DER_MAX_BYTES - size], size); pinnedpubkey_error: mbedtls_x509_crt_free(p); - free(p); - free(pubkey); + curlx_free(p); + curlx_free(pubkey); if(result) return result; } @@ -1122,7 +1118,7 @@ mbed_new_session(struct Curl_cfilter *cf, struct Curl_easy *data) goto out; } - sdata = malloc(slen); + sdata = curlx_malloc(slen); if(!sdata) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1147,7 +1143,7 @@ mbed_new_session(struct Curl_cfilter *cf, struct Curl_easy *data) out: if(msession_alloced) mbedtls_ssl_session_free(&session); - free(sdata); + curlx_free(sdata); return result; } diff --git a/lib/vtls/mbedtls_threadlock.c b/lib/vtls/mbedtls_threadlock.c index 82590929cd78..91de9eceb59b 100644 --- a/lib/vtls/mbedtls_threadlock.c +++ b/lib/vtls/mbedtls_threadlock.c @@ -37,10 +37,6 @@ #include "mbedtls_threadlock.h" -/* The last 2 #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* number of thread locks */ #define NUMT 2 diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index d8f99b21c371..bdfe527acd83 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -132,10 +132,6 @@ static void ossl_provider_cleanup(struct Curl_easy *data); #include "../curlx/warnless.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #if defined(USE_OPENSSL_ENGINE) || defined(OPENSSL_HAS_PROVIDERS) #include #endif @@ -1831,7 +1827,7 @@ static CURLcode ossl_set_provider(struct Curl_easy *data, const char *iname) if(!libctx) return CURLE_OUT_OF_MEMORY; if(propq) { - data->state.propq = strdup(propq); + data->state.propq = curlx_strdup(propq); if(!data->state.propq) { OSSL_LIB_CTX_free(libctx); return CURLE_OUT_OF_MEMORY; @@ -2738,7 +2734,7 @@ CURLcode Curl_ossl_add_session(struct Curl_cfilter *cf, goto out; } - der_session_buf = der_session_ptr = malloc(der_session_size); + der_session_buf = der_session_ptr = curlx_malloc(der_session_size); if(!der_session_buf) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -2775,7 +2771,7 @@ CURLcode Curl_ossl_add_session(struct Curl_cfilter *cf, } out: - free(der_session_buf); + curlx_free(der_session_buf); return result; } @@ -2932,7 +2928,7 @@ static CURLcode ossl_win_load_store(struct Curl_easy *data, */ if(CertGetEnhancedKeyUsage(pContext, 0, NULL, &req_size)) { if(req_size && req_size > enhkey_usage_size) { - void *tmp = realloc(enhkey_usage, req_size); + void *tmp = curlx_realloc(enhkey_usage, req_size); if(!tmp) { failf(data, "SSL: Out of memory allocating for OID list"); @@ -2990,7 +2986,7 @@ static CURLcode ossl_win_load_store(struct Curl_easy *data, X509_free(x509); } - free(enhkey_usage); + curlx_free(enhkey_usage); CertFreeCertificateContext(pContext); CertCloseStore(hStore, 0); @@ -3233,8 +3229,8 @@ static void oss_x509_share_free(void *key, size_t key_len, void *p) if(share->store) { X509_STORE_free(share->store); } - free(share->CAfile); - free(share); + curlx_free(share->CAfile); + curlx_free(share); } static bool @@ -3304,14 +3300,14 @@ static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, sizeof(MPROTO_OSSL_X509_KEY)-1); if(!share) { - share = calloc(1, sizeof(*share)); + share = curlx_calloc(1, sizeof(*share)); if(!share) return; if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_OSSL_X509_KEY), sizeof(MPROTO_OSSL_X509_KEY)-1, share, oss_x509_share_free)) { - free(share); + curlx_free(share); return; } } @@ -3320,7 +3316,7 @@ static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, char *CAfile = NULL; if(conn_config->CAfile) { - CAfile = strdup(conn_config->CAfile); + CAfile = curlx_strdup(conn_config->CAfile); if(!CAfile) { X509_STORE_free(store); return; @@ -3329,7 +3325,7 @@ static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, if(share->store) { X509_STORE_free(share->store); - free(share->CAfile); + curlx_free(share->CAfile); } share->time = curlx_now(); @@ -3516,11 +3512,11 @@ static CURLcode ossl_init_ech(struct ossl_ctx *octx, ech_config_len) != 1) { infof(data, "ECH: SSL_ECH_set1_ech_config_list failed"); if(data->set.tls_ech & CURLECH_HARD) { - free(ech_config); + curlx_free(ech_config); return CURLE_SSL_CONNECT_ERROR; } } - free(ech_config); + curlx_free(ech_config); trying_ech_now = 1; # else ech_config = (unsigned char *) data->set.str[STRING_ECH_CONFIG]; @@ -4160,7 +4156,7 @@ static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL* ssl, result = curlx_base64_encode(rcs, rcl, &b64str, &blen); if(!result && b64str) { infof(data, "ECH: retry_configs %s", b64str); - free(b64str); + curlx_free(b64str); #ifndef HAVE_BORINGSSL_LIKE rv = SSL_ech_get1_status(ssl, &inner, &outer); infof(data, "ECH: retry_configs for %s from %s, %d %d", @@ -4446,7 +4442,7 @@ static CURLcode ossl_pkp_pin_peer_pubkey(struct Curl_easy *data, X509* cert, if(len1 < 1) break; /* failed */ - buff1 = temp = malloc(len1); + buff1 = temp = curlx_malloc(len1); if(!buff1) break; /* failed */ @@ -4468,7 +4464,7 @@ static CURLcode ossl_pkp_pin_peer_pubkey(struct Curl_easy *data, X509* cert, } while(0); if(buff1) - free(buff1); + curlx_free(buff1); return result; } diff --git a/lib/vtls/rustls.c b/lib/vtls/rustls.c index cc19a328eda1..e4251a915198 100644 --- a/lib/vtls/rustls.c +++ b/lib/vtls/rustls.c @@ -42,10 +42,6 @@ #include "cipher_suite.h" #include "x509asn1.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - struct rustls_ssl_backend_data { const struct rustls_client_config *config; @@ -586,7 +582,7 @@ init_config_builder(struct Curl_easy *data, } #endif /* USE_ECH */ - cipher_suites = malloc(sizeof(*cipher_suites) * (cipher_suites_len)); + cipher_suites = curlx_malloc(sizeof(*cipher_suites) * (cipher_suites_len)); if(!cipher_suites) { result = CURLE_OUT_OF_MEMORY; goto cleanup; @@ -643,7 +639,7 @@ init_config_builder(struct Curl_easy *data, cleanup: if(cipher_suites) { - free(cipher_suites); + curlx_free(cipher_suites); } if(custom_provider_builder) { rustls_crypto_provider_builder_free(custom_provider_builder); @@ -1004,7 +1000,7 @@ init_config_builder_ech(struct Curl_easy *data, cleanup: /* if we base64 decoded, we can free now */ if(data->set.tls_ech & CURLECH_CLA_CFG && data->set.str[STRING_ECH_CONFIG]) { - free(ech_config); + curlx_free(ech_config); } if(dns) { Curl_resolv_unlink(data, &dns); diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c index e5fbe40a8c1a..49a4516cdfc8 100644 --- a/lib/vtls/schannel.c +++ b/lib/vtls/schannel.c @@ -60,10 +60,6 @@ #include "../progress.h" #include "../curl_sha256.h" -/* The last #include file should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* Some verbose debug messages are wrapped by SCH_DEV() instead of DEBUGF() * and only shown if CURL_SCHANNEL_DEV_DEBUG was defined at build time. These * messages are extra verbose and intended for curl developers debugging @@ -427,7 +423,7 @@ get_cert_location(TCHAR *path, DWORD *store_name, TCHAR **store_path, return CURLE_SSL_CERTPROBLEM; *sep = TEXT('\0'); - *store_path = Curl_tcsdup(store_path_start); + *store_path = curlx_tcsdup(store_path_start); *sep = TEXT('\\'); if(!*store_path) return CURLE_OUT_OF_MEMORY; @@ -571,7 +567,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, failf(data, "schannel: certificate format compatibility error " " for %s", blob ? "(memory blob)" : data->set.ssl.primary.clientcert); - free(cert_store_path); + curlx_free(cert_store_path); curlx_unicodefree(cert_path); if(fInCert) curlx_fclose(fInCert); @@ -589,7 +585,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, int cert_find_flags; const char *cert_showfilename_error = blob ? "(memory blob)" : data->set.ssl.primary.clientcert; - free(cert_store_path); + curlx_free(cert_store_path); curlx_unicodefree(cert_path); if(fInCert) { long cert_tell = 0; @@ -603,7 +599,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, if(continue_reading) continue_reading = fseek(fInCert, 0, SEEK_SET) == 0; if(continue_reading) - certdata = malloc(certsize + 1); + certdata = curlx_malloc(certsize + 1); if((!certdata) || ((int) fread(certdata, certsize, 1, fInCert) != 1)) continue_reading = FALSE; @@ -611,7 +607,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, if(!continue_reading) { failf(data, "schannel: Failed to read cert file %s", data->set.ssl.primary.clientcert); - free(certdata); + curlx_free(certdata); return CURLE_SSL_CERTPROBLEM; } } @@ -622,7 +618,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, if(data->set.ssl.key_passwd) pwd_len = strlen(data->set.ssl.key_passwd); - pszPassword = (WCHAR*)malloc(sizeof(WCHAR)*(pwd_len + 1)); + pszPassword = (WCHAR*)curlx_malloc(sizeof(WCHAR)*(pwd_len + 1)); if(pszPassword) { if(pwd_len > 0) str_w_len = MultiByteToWideChar(CP_UTF8, @@ -642,10 +638,10 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, else cert_store = PFXImportCertStore(&datablob, pszPassword, 0); - free(pszPassword); + curlx_free(pszPassword); } if(!blob) - free(certdata); + curlx_free(certdata); if(!cert_store) { DWORD errorcode = GetLastError(); if(errorcode == ERROR_INVALID_PASSWORD) @@ -699,12 +695,12 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, cert_store_name, (path_utf8 ? path_utf8 : "(unknown)"), GetLastError()); - free(cert_store_path); + curlx_free(cert_store_path); curlx_unicodefree(path_utf8); curlx_unicodefree(cert_path); return CURLE_SSL_CERTPROBLEM; } - free(cert_store_path); + curlx_free(cert_store_path); cert_thumbprint.pbData = cert_thumbprint_data; cert_thumbprint.cbData = CERT_THUMBPRINT_DATA_LEN; @@ -738,7 +734,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, /* allocate memory for the reusable credential handle */ backend->cred = (struct Curl_schannel_cred *) - calloc(1, sizeof(struct Curl_schannel_cred)); + curlx_calloc(1, sizeof(struct Curl_schannel_cred)); if(!backend->cred) { failf(data, "schannel: unable to allocate memory"); @@ -1019,7 +1015,7 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) /* allocate memory for the security context handle */ backend->ctxt = (struct Curl_schannel_ctxt *) - calloc(1, sizeof(struct Curl_schannel_ctxt)); + curlx_calloc(1, sizeof(struct Curl_schannel_ctxt)); if(!backend->ctxt) { failf(data, "schannel: unable to allocate memory"); return CURLE_OUT_OF_MEMORY; @@ -1170,7 +1166,7 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) if(!backend->decdata_buffer) { backend->decdata_offset = 0; backend->decdata_length = CURL_SCHANNEL_BUFFER_INIT_SIZE; - backend->decdata_buffer = malloc(backend->decdata_length); + backend->decdata_buffer = curlx_malloc(backend->decdata_length); if(!backend->decdata_buffer) { failf(data, "schannel: unable to allocate memory"); return CURLE_OUT_OF_MEMORY; @@ -1182,7 +1178,7 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) backend->encdata_is_incomplete = FALSE; backend->encdata_offset = 0; backend->encdata_length = CURL_SCHANNEL_BUFFER_INIT_SIZE; - backend->encdata_buffer = malloc(backend->encdata_length); + backend->encdata_buffer = curlx_malloc(backend->encdata_length); if(!backend->encdata_buffer) { failf(data, "schannel: unable to allocate memory"); return CURLE_OUT_OF_MEMORY; @@ -1195,8 +1191,8 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) /* increase internal encrypted data buffer */ size_t reallocated_length = backend->encdata_offset + CURL_SCHANNEL_BUFFER_FREE_SIZE; - reallocated_buffer = realloc(backend->encdata_buffer, - reallocated_length); + reallocated_buffer = curlx_realloc(backend->encdata_buffer, + reallocated_length); if(!reallocated_buffer) { failf(data, "schannel: unable to re-allocate memory"); @@ -1247,7 +1243,8 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) backend->encdata_offset, backend->encdata_length)); /* setup input buffers */ - InitSecBuffer(&inbuf[0], SECBUFFER_TOKEN, malloc(backend->encdata_offset), + InitSecBuffer(&inbuf[0], SECBUFFER_TOKEN, + curlx_malloc(backend->encdata_offset), curlx_uztoul(backend->encdata_offset)); InitSecBuffer(&inbuf[1], SECBUFFER_EMPTY, NULL, 0); InitSecBufferDesc(&inbuf_desc, inbuf, 2); @@ -1274,7 +1271,7 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) if(!SOCKET_WRITABLE(Curl_conn_cf_get_socket(cf, data), 0)) { SCH_DEV(infof(data, "schannel: handshake waiting for writeable socket")); connssl->io_need = CURL_SSL_IO_NEED_SEND; - free(inbuf[0].pvBuffer); + curlx_free(inbuf[0].pvBuffer); return CURLE_OK; } @@ -1931,7 +1928,7 @@ schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, /* calculate the complete message length and allocate a buffer for it */ data_len = backend->stream_sizes.cbHeader + len + backend->stream_sizes.cbTrailer; - ptr = (unsigned char *)malloc(data_len); + ptr = (unsigned char *)curlx_malloc(data_len); if(!ptr) { return CURLE_OUT_OF_MEMORY; } @@ -2110,8 +2107,8 @@ schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(reallocated_length < min_encdata_length) { reallocated_length = min_encdata_length; } - reallocated_buffer = realloc(backend->encdata_buffer, - reallocated_length); + reallocated_buffer = curlx_realloc(backend->encdata_buffer, + reallocated_length); if(!reallocated_buffer) { result = CURLE_OUT_OF_MEMORY; failf(data, "schannel: unable to re-allocate memory"); @@ -2196,8 +2193,8 @@ schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(reallocated_length < len) { reallocated_length = len; } - reallocated_buffer = realloc(backend->decdata_buffer, - reallocated_length); + reallocated_buffer = curlx_realloc(backend->decdata_buffer, + reallocated_length); if(!reallocated_buffer) { result = CURLE_OUT_OF_MEMORY; failf(data, "schannel: unable to re-allocate memory"); @@ -2819,8 +2816,8 @@ static void schannel_cert_share_free(void *key, size_t key_len, void *p) if(share->cert_store) { CertCloseStore(share->cert_store, 0); } - free(share->CAfile); - free(share); + curlx_free(share->CAfile); + curlx_free(share); } bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, @@ -2844,7 +2841,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY)-1); if(!share) { - share = calloc(1, sizeof(*share)); + share = curlx_calloc(1, sizeof(*share)); if(!share) { return FALSE; } @@ -2852,7 +2849,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY)-1, share, schannel_cert_share_free)) { - free(share); + curlx_free(share); return FALSE; } } @@ -2866,7 +2863,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, } else { if(conn_config->CAfile) { - CAfile = strdup(conn_config->CAfile); + CAfile = curlx_strdup(conn_config->CAfile); if(!CAfile) { return FALSE; } @@ -2877,7 +2874,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, if(share->cert_store) { CertCloseStore(share->cert_store, 0); } - free(share->CAfile); + curlx_free(share->CAfile); share->time = curlx_now(); share->cert_store = cert_store; diff --git a/lib/vtls/schannel_verify.c b/lib/vtls/schannel_verify.c index 72c42ed35341..4ff7b5d536a1 100644 --- a/lib/vtls/schannel_verify.c +++ b/lib/vtls/schannel_verify.c @@ -49,10 +49,6 @@ #include "hostcheck.h" #include "../curlx/version_win32.h" -/* The last #include file should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #define BACKEND ((struct schannel_ssl_backend_data *)connssl->backend) #define MAX_CAFILE_SIZE 1048576 /* 1 MiB */ @@ -319,7 +315,7 @@ static CURLcode add_certs_file_to_store(HCERTSTORE trust_store, } ca_file_bufsize = (size_t)file_size.QuadPart; - ca_file_buffer = (char *)malloc(ca_file_bufsize + 1); + ca_file_buffer = (char *)curlx_malloc(ca_file_bufsize + 1); if(!ca_file_buffer) { result = CURLE_OUT_OF_MEMORY; goto cleanup; @@ -606,7 +602,7 @@ CURLcode Curl_verify_host(struct Curl_cfilter *cf, /* CertGetNameString guarantees that the returned name will not contain * embedded null bytes. This appears to be undocumented behavior. */ - cert_hostname_buff = (LPTSTR)malloc(len * sizeof(TCHAR)); + cert_hostname_buff = (LPTSTR)curlx_malloc(len * sizeof(TCHAR)); if(!cert_hostname_buff) { result = CURLE_OUT_OF_MEMORY; goto cleanup; diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c index 3b242fd485d2..6eb60e41cf99 100644 --- a/lib/vtls/vtls.c +++ b/lib/vtls/vtls.c @@ -81,15 +81,11 @@ #include #endif -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #define CLONE_STRING(var) \ do { \ if(source->var) { \ - dest->var = strdup(source->var); \ + dest->var = curlx_strdup(source->var); \ if(!dest->var) \ return FALSE; \ } \ @@ -111,7 +107,7 @@ static CURLcode blobdup(struct curl_blob **dest, if(src) { /* only if there is data to dupe! */ struct curl_blob *d; - d = malloc(sizeof(struct curl_blob) + src->len); + d = curlx_malloc(sizeof(struct curl_blob) + src->len); if(!d) return CURLE_OUT_OF_MEMORY; d->len = src->len; @@ -503,16 +499,16 @@ static struct ssl_connect_data *cf_ctx_new(struct Curl_easy *data, struct ssl_connect_data *ctx; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) return NULL; ctx->ssl_impl = Curl_ssl; ctx->alpn = alpn; Curl_bufq_init2(&ctx->earlydata, CURL_SSL_EARLY_MAX, 1, BUFQ_OPT_NO_SPARES); - ctx->backend = calloc(1, ctx->ssl_impl->sizeof_ssl_backend_data); + ctx->backend = curlx_calloc(1, ctx->ssl_impl->sizeof_ssl_backend_data); if(!ctx->backend) { - free(ctx); + curlx_free(ctx); return NULL; } return ctx; @@ -523,8 +519,8 @@ static void cf_ctx_free(struct ssl_connect_data *ctx) if(ctx) { Curl_safefree(ctx->negotiated.alpn); Curl_bufq_free(&ctx->earlydata); - free(ctx->backend); - free(ctx); + curlx_free(ctx->backend); + curlx_free(ctx); } } @@ -617,7 +613,7 @@ void Curl_ssl_free_certinfo(struct Curl_easy *data) ci->certinfo[i] = NULL; } - free(ci->certinfo); /* free the actual array too */ + curlx_free(ci->certinfo); /* free the actual array too */ ci->certinfo = NULL; ci->num_of_certs = 0; } @@ -632,7 +628,7 @@ CURLcode Curl_ssl_init_certinfo(struct Curl_easy *data, int num) Curl_ssl_free_certinfo(data); /* Allocate the required certificate information structures */ - table = calloc((size_t) num, sizeof(struct curl_slist *)); + table = curlx_calloc((size_t) num, sizeof(struct curl_slist *)); if(!table) return CURLE_OUT_OF_MEMORY; @@ -783,7 +779,7 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data, } /* compute sha256sum of public key */ - sha256sumdigest = malloc(CURL_SHA256_DIGEST_LENGTH); + sha256sumdigest = curlx_malloc(CURL_SHA256_DIGEST_LENGTH); if(!sha256sumdigest) return CURLE_OUT_OF_MEMORY; encode = Curl_ssl->sha256sum(pubkey, pubkeylen, @@ -1118,7 +1114,7 @@ static int multissl_setup(const struct Curl_ssl *backend) for(i = 0; available_backends[i]; i++) { if(curl_strequal(env, available_backends[i]->info.name)) { Curl_ssl = available_backends[i]; - free(env); + curlx_free(env); return 0; } } @@ -1129,7 +1125,7 @@ static int multissl_setup(const struct Curl_ssl *backend) if(curl_strequal(CURL_DEFAULT_SSL_BACKEND, available_backends[i]->info.name)) { Curl_ssl = available_backends[i]; - free(env); + curlx_free(env); return 0; } } @@ -1137,7 +1133,7 @@ static int multissl_setup(const struct Curl_ssl *backend) /* Fall back to first available backend */ Curl_ssl = available_backends[0]; - free(env); + curlx_free(env); return 0; } @@ -1190,7 +1186,7 @@ void Curl_ssl_peer_cleanup(struct ssl_peer *peer) { Curl_safefree(peer->sni); if(peer->dispname != peer->hostname) - free(peer->dispname); + curlx_free(peer->dispname); peer->dispname = NULL; Curl_safefree(peer->hostname); Curl_safefree(peer->scache_key); @@ -1266,13 +1262,13 @@ CURLcode Curl_ssl_peer_init(struct ssl_peer *peer, goto out; } - peer->hostname = strdup(ehostname); + peer->hostname = curlx_strdup(ehostname); if(!peer->hostname) goto out; if(!edispname || !strcmp(ehostname, edispname)) peer->dispname = peer->hostname; else { - peer->dispname = strdup(edispname); + peer->dispname = curlx_strdup(edispname); if(!peer->dispname) goto out; } @@ -1284,7 +1280,7 @@ CURLcode Curl_ssl_peer_init(struct ssl_peer *peer, if(len && (peer->hostname[len-1] == '.')) len--; if(len < USHRT_MAX) { - peer->sni = calloc(1, len + 1); + peer->sni = curlx_calloc(1, len + 1); if(!peer->sni) goto out; Curl_strntolower(peer->sni, peer->hostname, len); diff --git a/lib/vtls/vtls_scache.c b/lib/vtls/vtls_scache.c index 3524a25a4417..21dfe2eaa032 100644 --- a/lib/vtls/vtls_scache.c +++ b/lib/vtls/vtls_scache.c @@ -47,10 +47,6 @@ #include "../rand.h" #include "../curlx/warnless.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - static bool cf_ssl_peer_key_is_global(const char *peer_key); @@ -104,10 +100,10 @@ static void cf_ssl_scache_session_ldestroy(void *udata, void *obj) { struct Curl_ssl_session *s = obj; (void)udata; - free(CURL_UNCONST(s->sdata)); - free(CURL_UNCONST(s->quic_tp)); - free((void *)s->alpn); - free(s); + curlx_free(CURL_UNCONST(s->sdata)); + curlx_free(CURL_UNCONST(s->quic_tp)); + curlx_free((void *)s->alpn); + curlx_free(s); } CURLcode @@ -131,15 +127,15 @@ Curl_ssl_session_create2(void *sdata, size_t sdata_len, struct Curl_ssl_session *s; if(!sdata || !sdata_len) { - free(sdata); + curlx_free(sdata); return CURLE_BAD_FUNCTION_ARGUMENT; } *psession = NULL; - s = calloc(1, sizeof(*s)); + s = curlx_calloc(1, sizeof(*s)); if(!s) { - free(sdata); - free(quic_tp); + curlx_free(sdata); + curlx_free(quic_tp); return CURLE_OUT_OF_MEMORY; } @@ -151,7 +147,7 @@ Curl_ssl_session_create2(void *sdata, size_t sdata_len, s->quic_tp = quic_tp; s->quic_tp_len = quic_tp_len; if(alpn) { - s->alpn = strdup(alpn); + s->alpn = curlx_strdup(alpn); if(!s->alpn) { cf_ssl_scache_session_ldestroy(NULL, s); return CURLE_OUT_OF_MEMORY; @@ -231,7 +227,7 @@ cf_ssl_scache_peer_init(struct Curl_ssl_scache_peer *peer, DEBUGASSERT(!peer->ssl_peer_key); if(ssl_peer_key) { - peer->ssl_peer_key = strdup(ssl_peer_key); + peer->ssl_peer_key = curlx_strdup(ssl_peer_key); if(!peer->ssl_peer_key) goto out; peer->hmac_set = FALSE; @@ -246,17 +242,17 @@ cf_ssl_scache_peer_init(struct Curl_ssl_scache_peer *peer, goto out; } if(clientcert) { - peer->clientcert = strdup(clientcert); + peer->clientcert = curlx_strdup(clientcert); if(!peer->clientcert) goto out; } if(srp_username) { - peer->srp_username = strdup(srp_username); + peer->srp_username = curlx_strdup(srp_username); if(!peer->srp_username) goto out; } if(srp_password) { - peer->srp_password = strdup(srp_password); + peer->srp_password = curlx_strdup(srp_password); if(!peer->srp_password) goto out; } @@ -315,13 +311,13 @@ CURLcode Curl_ssl_scache_create(size_t max_peers, size_t i; *pscache = NULL; - peers = calloc(max_peers, sizeof(*peers)); + peers = curlx_calloc(max_peers, sizeof(*peers)); if(!peers) return CURLE_OUT_OF_MEMORY; - scache = calloc(1, sizeof(*scache)); + scache = curlx_calloc(1, sizeof(*scache)); if(!scache) { - free(peers); + curlx_free(peers); return CURLE_OUT_OF_MEMORY; } @@ -348,8 +344,8 @@ void Curl_ssl_scache_destroy(struct Curl_ssl_scache *scache) for(i = 0; i < scache->peer_count; ++i) { cf_ssl_scache_clear_peer(&scache->peers[i]); } - free(scache->peers); - free(scache); + curlx_free(scache->peers); + curlx_free(scache); } } @@ -396,7 +392,8 @@ static CURLcode cf_ssl_peer_key_add_path(struct dynbuf *buf, char *abspath = realpath(path, NULL); if(abspath) { CURLcode r = curlx_dyn_addf(buf, ":%s-%s", name, abspath); - (free)(abspath); /* allocated by libc, free without memdebug */ + /* !checksrc! disable BANNEDFUNC 1 */ + free(abspath); /* allocated by libc, free without memdebug */ return r; } *is_local = TRUE; @@ -675,7 +672,7 @@ cf_ssl_find_peer_by_key(struct Curl_easy *data, /* remember peer_key for future lookups */ CURL_TRC_SSLS(data, "peer entry %zu key recovered: %s", i, ssl_peer_key); - scache->peers[i].ssl_peer_key = strdup(ssl_peer_key); + scache->peers[i].ssl_peer_key = curlx_strdup(ssl_peer_key); if(!scache->peers[i].ssl_peer_key) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/vtls/vtls_spack.c b/lib/vtls/vtls_spack.c index d86f31d72721..070bb485a350 100644 --- a/lib/vtls/vtls_spack.c +++ b/lib/vtls/vtls_spack.c @@ -32,10 +32,6 @@ #include "vtls_spack.h" #include "../strdup.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #ifndef UINT16_MAX #define UINT16_MAX 0xffff #endif @@ -267,7 +263,7 @@ CURLcode Curl_ssl_session_unpack(struct Curl_easy *data, goto out; } - s = calloc(1, sizeof(*s)); + s = curlx_calloc(1, sizeof(*s)); if(!s) { r = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c index 2ad033f98899..eae17078fd35 100644 --- a/lib/vtls/wolfssl.c +++ b/lib/vtls/wolfssl.c @@ -75,10 +75,6 @@ #include #include "wolfssl.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #ifdef HAVE_WOLFSSL_CTX_GENERATEECHCONFIG #define USE_ECH_WOLFSSL #endif @@ -447,7 +443,7 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, result = CURLE_FAILED_INIT; goto out; } - sdata = calloc(1, sdata_len); + sdata = curlx_calloc(1, sdata_len); if(!sdata) { failf(data, "unable to allocate session buffer of %u bytes", sdata_len); result = CURLE_OUT_OF_MEMORY; @@ -462,7 +458,7 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, if(quic_tp && quic_tp_len) { qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len); if(!qtp_clone) { - free(sdata); + curlx_free(sdata); return CURLE_OUT_OF_MEMORY; } } @@ -483,7 +479,7 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, } out: - free(sdata); + curlx_free(sdata); return result; } @@ -726,8 +722,8 @@ static void wssl_x509_share_free(void *key, size_t key_len, void *p) if(share->store) { wolfSSL_X509_STORE_free(share->store); } - free(share->CAfile); - free(share); + curlx_free(share->CAfile); + curlx_free(share); } static bool @@ -792,14 +788,14 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, sizeof(MPROTO_WSSL_X509_KEY)-1); if(!share) { - share = calloc(1, sizeof(*share)); + share = curlx_calloc(1, sizeof(*share)); if(!share) return; if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_WSSL_X509_KEY), sizeof(MPROTO_WSSL_X509_KEY)-1, share, wssl_x509_share_free)) { - free(share); + curlx_free(share); return; } } @@ -808,7 +804,7 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, char *CAfile = NULL; if(conn_config->CAfile) { - CAfile = strdup(conn_config->CAfile); + CAfile = curlx_strdup(conn_config->CAfile); if(!CAfile) { wolfSSL_X509_STORE_free(store); return; @@ -817,7 +813,7 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, if(share->store) { wolfSSL_X509_STORE_free(share->store); - free(share->CAfile); + curlx_free(share->CAfile); } share->time = curlx_now(); @@ -1821,7 +1817,7 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, &b64str, &blen); if(!result && b64str) infof(data, "ECH: (not yet) retry_configs %s", b64str); - free(b64str); + curlx_free(b64str); } return CURLE_SSL_CONNECT_ERROR; } diff --git a/lib/vtls/x509asn1.c b/lib/vtls/x509asn1.c index 417a5382d873..fcc0d0e1daf2 100644 --- a/lib/vtls/x509asn1.c +++ b/lib/vtls/x509asn1.c @@ -49,10 +49,6 @@ #include "x509asn1.h" #include "../curlx/dynbuf.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Constants. */ @@ -1260,7 +1256,7 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data, if(!result) result = curlx_dyn_add(&out, "-----END CERTIFICATE-----\n"); } - free(certptr); + curlx_free(certptr); if(!result) if(data->set.ssl.certinfo) result = ssl_push_certinfo_dyn(data, certnum, "Cert", &out); diff --git a/lib/ws.c b/lib/ws.c index 15dc2e9aea7e..93e13e1ac184 100644 --- a/lib/ws.c +++ b/lib/ws.c @@ -43,10 +43,6 @@ #include "curlx/strparse.h" #include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /*** RFC 6455 Section 5.2 @@ -1281,11 +1277,11 @@ CURLcode Curl_ws_request(struct Curl_easy *data, struct dynbuf *req) return result; DEBUGASSERT(randlen < sizeof(keyval)); if(randlen >= sizeof(keyval)) { - free(randstr); + curlx_free(randstr); return CURLE_FAILED_INIT; } strcpy(keyval, randstr); - free(randstr); + curlx_free(randstr); for(i = 0; !result && (i < CURL_ARRAYSIZE(heads)); i++) { if(!Curl_checkheaders(data, heads[i].name, strlen(heads[i].name))) { result = curlx_dyn_addf(req, "%s: %s\r\n", heads[i].name, @@ -1305,7 +1301,7 @@ static void ws_conn_dtor(void *key, size_t klen, void *entry) (void)klen; Curl_bufq_free(&ws->recvbuf); Curl_bufq_free(&ws->sendbuf); - free(ws); + curlx_free(ws); } /* @@ -1325,7 +1321,7 @@ CURLcode Curl_ws_accept(struct Curl_easy *data, ws = Curl_conn_meta_get(data->conn, CURL_META_PROTO_WS_CONN); if(!ws) { size_t chunk_size = WS_CHUNK_SIZE; - ws = calloc(1, sizeof(*ws)); + ws = curlx_calloc(1, sizeof(*ws)); if(!ws) return CURLE_OUT_OF_MEMORY; #ifdef DEBUGBUILD diff --git a/packages/Makefile.am b/packages/Makefile.am index 43e544a0195c..8b6d4dc4b242 100644 --- a/packages/Makefile.am +++ b/packages/Makefile.am @@ -24,6 +24,7 @@ SUBDIRS = vms EXTRA_DIST = README.md \ + OS400/.checksrc \ OS400/README.OS400 \ OS400/rpg-examples \ OS400/ccsidcurl.c \ diff --git a/packages/OS400/.checksrc b/packages/OS400/.checksrc new file mode 100644 index 000000000000..aae405506b9e --- /dev/null +++ b/packages/OS400/.checksrc @@ -0,0 +1,9 @@ +# Copyright (C) Daniel Stenberg, , et al. +# +# SPDX-License-Identifier: curl + +# Possible not what we want, but cannot test, just silence the warnings +allowfunc calloc +allowfunc free +allowfunc malloc +allowfunc realloc diff --git a/scripts/checksrc.pl b/scripts/checksrc.pl index 49290ff137a5..87b72af96326 100755 --- a/scripts/checksrc.pl +++ b/scripts/checksrc.pl @@ -69,10 +69,12 @@ "aprintf" => 1, "atoi" => 1, "atol" => 1, + "calloc" => 1, "fclose" => 1, "fdopen" => 1, "fopen" => 1, "fprintf" => 1, + "free" => 1, "freeaddrinfo" => 1, "freopen" => 1, "getaddrinfo" => 1, @@ -85,11 +87,13 @@ "LoadLibraryExW" => 1, "LoadLibraryW" => 1, "localtime" => 1, + "malloc" => 1, "mbstowcs" => 1, "msnprintf" => 1, "mvsnprintf" => 1, "open" => 1, "printf" => 1, + "realloc" => 1, "recv" => 1, "send" => 1, "snprintf" => 1, @@ -99,6 +103,7 @@ "sscanf" => 1, "stat" => 1, "strcat" => 1, + "strdup" => 1, "strerror" => 1, "strncat" => 1, "strncpy" => 1, diff --git a/src/mkhelp.pl b/src/mkhelp.pl index d1a040c0cc63..b3a6c5abdce7 100755 --- a/src/mkhelp.pl +++ b/src/mkhelp.pl @@ -78,7 +78,6 @@ print < -#include /* keep this as LAST include */ static const unsigned char hugehelpgz[] = { /* This mumbo-jumbo is the huge help text compressed with gzip. Thanks to this operation, the size of this data shrank from $gzip @@ -105,13 +104,13 @@ static voidpf zalloc_func(voidpf opaque, unsigned int items, unsigned int size) { (void)opaque; - /* not a typo, keep it calloc() */ - return (voidpf) calloc(items, size); + /* not a typo, keep it curlx_calloc() */ + return (voidpf)curlx_calloc(items, size); } static void zfree_func(voidpf opaque, voidpf ptr) { (void)opaque; - free(ptr); + curlx_free(ptr); } #define HEADERLEN 10 @@ -136,7 +135,7 @@ if(inflateInit2(&z, -MAX_WBITS) != Z_OK) return; - buf = malloc(BUF_SIZE); + buf = curlx_malloc(BUF_SIZE); if(buf) { while(1) { z.avail_out = BUF_SIZE; @@ -150,7 +149,7 @@ else break; /* error */ } - free(buf); + curlx_free(buf); } inflateEnd(&z); } @@ -176,7 +175,7 @@ if(inflateInit2(&z, -MAX_WBITS) != Z_OK) return; - buf = malloc(BUF_SIZE); + buf = curlx_malloc(BUF_SIZE); if(buf) { while(1) { z.avail_out = BUF_SIZE; @@ -192,7 +191,7 @@ else break; /* error */ } - free(buf); + curlx_free(buf); } inflateEnd(&z); } diff --git a/src/slist_wc.c b/src/slist_wc.c index 7f1e8f19be8d..26a91362b8e3 100644 --- a/src/slist_wc.c +++ b/src/slist_wc.c @@ -28,9 +28,6 @@ #include "slist_wc.h" -/* The last #include files should be: */ -#include "memdebug.h" - /* * slist_wc_append() appends a string to the linked list. This function can be * used as an initialization function as well as an append function. @@ -44,7 +41,7 @@ struct slist_wc *slist_wc_append(struct slist_wc *list, return NULL; if(!list) { - list = malloc(sizeof(struct slist_wc)); + list = curlx_malloc(sizeof(struct slist_wc)); if(!list) { curl_slist_free_all(new_item); @@ -68,7 +65,7 @@ void slist_wc_free_all(struct slist_wc *list) return; curl_slist_free_all(list->first); - free(list); + curlx_free(list); } #endif /* CURL_DISABLE_LIBCURL_OPTION */ diff --git a/src/terminal.c b/src/terminal.c index 867ca6edcf88..bb3e2ac61184 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -28,7 +28,6 @@ #endif #include "terminal.h" -#include "memdebug.h" /* keep this as LAST include */ #ifdef HAVE_TERMIOS_H # include diff --git a/src/tool_bname.c b/src/tool_bname.c index 4ba1a3b8eeac..50d77abb9644 100644 --- a/src/tool_bname.c +++ b/src/tool_bname.c @@ -25,8 +25,6 @@ #include "tool_bname.h" -#include "memdebug.h" /* keep this as LAST include */ - #ifndef HAVE_BASENAME char *tool_basename(char *path) diff --git a/src/tool_cb_dbg.c b/src/tool_cb_dbg.c index 043daef26dd0..b858b6688e6e 100644 --- a/src/tool_cb_dbg.c +++ b/src/tool_cb_dbg.c @@ -28,8 +28,6 @@ #include "tool_cb_dbg.h" #include "tool_util.h" -#include "memdebug.h" /* keep this as LAST include */ - static void dump(const char *timebuf, const char *idsbuf, const char *text, FILE *stream, const unsigned char *ptr, size_t size, trace tracetype, curl_infotype infotype); diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c index d4431a74b951..7a5a475981d5 100644 --- a/src/tool_cb_hdr.c +++ b/src/tool_cb_hdr.c @@ -36,8 +36,6 @@ #include "tool_libinfo.h" #include "tool_strdup.h" -#include "memdebug.h" /* keep this as LAST include */ - static char *parse_filename(const char *ptr, size_t len); #ifdef _WIN32 @@ -212,14 +210,14 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata) if(filename) { if(outs->stream) { /* indication of problem, get out! */ - free(filename); + curlx_free(filename); return CURL_WRITEFUNC_ERROR; } if(per->config->output_dir) { outs->filename = curl_maprintf("%s/%s", per->config->output_dir, filename); - free(filename); + curlx_free(filename); if(!outs->filename) return CURL_WRITEFUNC_ERROR; } @@ -252,7 +250,7 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata) if(clone) { struct curl_slist *old = hdrcbdata->headlist; hdrcbdata->headlist = curl_slist_append(old, clone); - free(clone); + curlx_free(clone); if(!hdrcbdata->headlist) { curl_slist_free_all(old); return CURL_WRITEFUNC_ERROR; @@ -479,7 +477,7 @@ static void write_linked_location(CURL *curl, const char *location, curl_free(finalurl); curl_free(scheme); curl_url_cleanup(u); - free(copyloc); + curlx_free(copyloc); } } #endif diff --git a/src/tool_cb_prg.c b/src/tool_cb_prg.c index 5f33c7c29c05..6ae53b3ba227 100644 --- a/src/tool_cb_prg.c +++ b/src/tool_cb_prg.c @@ -29,8 +29,6 @@ #include "tool_operate.h" #include "terminal.h" -#include "memdebug.h" /* keep this as LAST include */ - #define MAX_BARLENGTH 400 #define MIN_BARLENGTH 20 diff --git a/src/tool_cb_rea.c b/src/tool_cb_rea.c index cc7ef5a55079..0f2bf8177198 100644 --- a/src/tool_cb_rea.c +++ b/src/tool_cb_rea.c @@ -38,8 +38,6 @@ #include "tool_util.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ - #ifndef _WIN32 /* Wait up to a number of milliseconds for socket activity. This function waits on read activity on a file descriptor that is not a socket which diff --git a/src/tool_cb_see.c b/src/tool_cb_see.c index fd1b4c563c80..ea5c8e313b40 100644 --- a/src/tool_cb_see.c +++ b/src/tool_cb_see.c @@ -27,8 +27,6 @@ #include "tool_operate.h" #include "tool_cb_see.h" -#include "memdebug.h" /* keep this as LAST include */ - /* ** callback for CURLOPT_SEEKFUNCTION ** diff --git a/src/tool_cb_wrt.c b/src/tool_cb_wrt.c index 48f5fea3c9b9..5696df2a5935 100644 --- a/src/tool_cb_wrt.c +++ b/src/tool_cb_wrt.c @@ -28,8 +28,6 @@ #include "tool_cb_wrt.h" #include "tool_operate.h" -#include "memdebug.h" /* keep this as LAST include */ - #ifdef _WIN32 #define OPENMODE S_IREAD | S_IWRITE #else @@ -211,8 +209,8 @@ static size_t win_console(intptr_t fhnd, struct OutStruct *outs, /* grow the buffer if needed */ if(len > global->term.len) { - wchar_t *buf = (wchar_t *) realloc(global->term.buf, - len * sizeof(wchar_t)); + wchar_t *buf = (wchar_t *)curlx_realloc(global->term.buf, + len * sizeof(wchar_t)); if(!buf) return CURL_WRITEFUNC_ERROR; global->term.len = len; diff --git a/src/tool_cfgable.c b/src/tool_cfgable.c index 086e4ac21659..ab4892b06578 100644 --- a/src/tool_cfgable.c +++ b/src/tool_cfgable.c @@ -28,7 +28,6 @@ #include "tool_paramhlp.h" #include "tool_main.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ static struct GlobalConfig globalconf; struct GlobalConfig *global; @@ -36,7 +35,7 @@ struct GlobalConfig *global; struct OperationConfig *config_alloc(void) { struct OperationConfig *config = - calloc(1, sizeof(struct OperationConfig)); + curlx_calloc(1, sizeof(struct OperationConfig)); if(!config) return NULL; @@ -199,7 +198,7 @@ void config_free(struct OperationConfig *config) struct OperationConfig *prev = last->prev; free_config_fields(last); - free(last); + curlx_free(last); last = prev; } @@ -236,12 +235,12 @@ CURLcode globalconf_init(void) if(result) { errorf("error retrieving curl library information"); - free(global->first); + curlx_free(global->first); } } else { errorf("error initializing curl library"); - free(global->first); + curlx_free(global->first); } } else { @@ -263,7 +262,7 @@ static void free_globalconfig(void) tool_safefree(global->ssl_sessions); tool_safefree(global->libcurl); #ifdef _WIN32 - free(global->term.buf); + curlx_free(global->term.buf); #endif } diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h index dc78f2db44f6..0eac0185f280 100644 --- a/src/tool_cfgable.h +++ b/src/tool_cfgable.h @@ -42,7 +42,7 @@ #define checkprefix(a,b) curl_strnequal(b, STRCONST(a)) #define tool_safefree(ptr) \ - do { free((ptr)); (ptr) = NULL;} while(0) + do { curlx_free((ptr)); (ptr) = NULL;} while(0) extern struct GlobalConfig *global; diff --git a/src/tool_dirhie.c b/src/tool_dirhie.c index 17b2d01e9bc6..31962bd1c546 100644 --- a/src/tool_dirhie.c +++ b/src/tool_dirhie.c @@ -30,8 +30,6 @@ #include "tool_dirhie.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ - #if defined(_WIN32) || (defined(MSDOS) && !defined(__DJGPP__)) # define mkdir(x,y) (mkdir)((x)) # ifndef F_OK diff --git a/src/tool_doswin.c b/src/tool_doswin.c index cd0ec3b9c1b1..ee236178c276 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -40,8 +40,6 @@ #include "tool_doswin.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ - #ifdef _WIN32 # undef PATH_MAX # define PATH_MAX MAX_PATH @@ -133,7 +131,7 @@ SANITIZEcode sanitize_file_name(char **const sanitized, const char *file_name, if(len > max_sanitized_len) return SANITIZE_ERR_INVALID_PATH; - target = strdup(file_name); + target = curlx_strdup(file_name); if(!target) return SANITIZE_ERR_OUT_OF_MEMORY; @@ -183,28 +181,28 @@ SANITIZEcode sanitize_file_name(char **const sanitized, const char *file_name, #ifdef MSDOS sc = msdosify(&p, target, flags); - free(target); + curlx_free(target); if(sc) return sc; target = p; len = strlen(target); if(len > max_sanitized_len) { - free(target); + curlx_free(target); return SANITIZE_ERR_INVALID_PATH; } #endif if(!(flags & SANITIZE_ALLOW_RESERVED)) { sc = rename_if_reserved_dos(&p, target, flags); - free(target); + curlx_free(target); if(sc) return sc; target = p; len = strlen(target); if(len > max_sanitized_len) { - free(target); + curlx_free(target); return SANITIZE_ERR_INVALID_PATH; } } @@ -415,7 +413,7 @@ static SANITIZEcode msdosify(char **const sanitized, const char *file_name, return SANITIZE_ERR_INVALID_PATH; } - *sanitized = strdup(dos_name); + *sanitized = curlx_strdup(dos_name); return *sanitized ? SANITIZE_ERR_OK : SANITIZE_ERR_OUT_OF_MEMORY; } #endif /* MSDOS */ @@ -457,7 +455,7 @@ static SANITIZEcode rename_if_reserved_dos(char **const sanitized, #ifndef MSDOS if((flags & SANITIZE_ALLOW_PATH) && file_name[0] == '\\' && file_name[1] == '\\') { - *sanitized = strdup(file_name); + *sanitized = curlx_strdup(file_name); if(!*sanitized) return SANITIZE_ERR_OUT_OF_MEMORY; return SANITIZE_ERR_OK; @@ -544,7 +542,7 @@ static SANITIZEcode rename_if_reserved_dos(char **const sanitized, } #endif - *sanitized = strdup(fname); + *sanitized = curlx_strdup(fname); return *sanitized ? SANITIZE_ERR_OK : SANITIZE_ERR_OUT_OF_MEMORY; } @@ -597,7 +595,7 @@ CURLcode FindWin32CACert(struct OperationConfig *config, char *mstr = curlx_convert_tchar_to_UTF8(buf); tool_safefree(config->cacert); if(mstr) - config->cacert = strdup(mstr); + config->cacert = curlx_strdup(mstr); curlx_unicodefree(mstr); if(!config->cacert) result = CURLE_OUT_OF_MEMORY; @@ -801,7 +799,7 @@ static DWORD WINAPI win_stdin_thread_func(void *thread_data) if(socket_w != CURL_SOCKET_BAD) sclose(socket_w); - free(tdata); + curlx_free(tdata); return 0; } @@ -824,9 +822,10 @@ curl_socket_t win32_stdin_read_thread(void) do { /* Prepare handles for thread */ - tdata = (struct win_thread_data*)calloc(1, sizeof(struct win_thread_data)); + tdata = (struct win_thread_data*) + curlx_calloc(1, sizeof(struct win_thread_data)); if(!tdata) { - errorf("calloc() error"); + errorf("curlx_calloc() error"); break; } /* Create the listening socket for the thread. When it starts, it will @@ -937,7 +936,7 @@ curl_socket_t win32_stdin_read_thread(void) if(tdata->socket_l != CURL_SOCKET_BAD) sclose(tdata->socket_l); - free(tdata); + curlx_free(tdata); } return CURL_SOCKET_BAD; diff --git a/src/tool_easysrc.c b/src/tool_easysrc.c index 65d01d5f85a6..4747f6dfe6bb 100644 --- a/src/tool_easysrc.c +++ b/src/tool_easysrc.c @@ -31,8 +31,6 @@ #include "tool_easysrc.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ - /* global variable definitions, for easy-interface source code generation */ struct slist_wc *easysrc_decl; /* Variable declarations */ diff --git a/src/tool_findfile.c b/src/tool_findfile.c index 6e9fbdfd6003..4dbd7bccb470 100644 --- a/src/tool_findfile.c +++ b/src/tool_findfile.c @@ -36,8 +36,6 @@ #include "tool_findfile.h" #include "tool_cfgable.h" -#include "memdebug.h" /* keep this as LAST include */ - struct finder { const char *env; const char *append; @@ -75,7 +73,7 @@ static char *checkhome(const char *home, const char *fname, bool dotscore) if(c) { int fd = curlx_open(c, O_RDONLY); if(fd >= 0) { - char *path = strdup(c); + char *path = curlx_strdup(c); close(fd); curl_free(c); return path; diff --git a/src/tool_formparse.c b/src/tool_formparse.c index c1e9abe9d0b8..181abf7b8627 100644 --- a/src/tool_formparse.c +++ b/src/tool_formparse.c @@ -30,13 +30,11 @@ #include "tool_formparse.h" #include "tool_parsecfg.h" -#include "memdebug.h" /* keep this as LAST include */ - /* tool_mime functions. */ static struct tool_mime *tool_mime_new(struct tool_mime *parent, toolmimekind kind) { - struct tool_mime *m = (struct tool_mime *) calloc(1, sizeof(*m)); + struct tool_mime *m = (struct tool_mime *)curlx_calloc(1, sizeof(*m)); if(m) { m->kind = kind; @@ -60,11 +58,11 @@ static struct tool_mime *tool_mime_new_data(struct tool_mime *parent, char *mime_data_copy; struct tool_mime *m = NULL; - mime_data_copy = strdup(mime_data); + mime_data_copy = curlx_strdup(mime_data); if(mime_data_copy) { m = tool_mime_new(parent, TOOLMIME_DATA); if(!m) - free(mime_data_copy); + curlx_free(mime_data_copy); else m->data = mime_data_copy; } @@ -107,11 +105,11 @@ static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent, *errcode = CURLE_OUT_OF_MEMORY; if(strcmp(filename, "-")) { /* This is a normal file. */ - char *filedup = strdup(filename); + char *filedup = curlx_strdup(filename); if(filedup) { m = tool_mime_new(parent, TOOLMIME_FILE); if(!m) - free(filedup); + curlx_free(filedup); else { m->data = filedup; if(!isremotefile) @@ -152,7 +150,7 @@ static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent, default: if(!stdinsize) { /* Zero-length data has been freed. Re-create it. */ - data = strdup(""); + data = curlx_strdup(""); if(!data) return m; } @@ -190,7 +188,7 @@ void tool_mime_free(struct tool_mime *mime) tool_safefree(mime->encoder); tool_safefree(mime->data); curl_slist_free_all(mime->headers); - free(mime); + curlx_free(mime); } } @@ -711,7 +709,7 @@ static int get_param_part(char endchar, #define SET_TOOL_MIME_PTR(m, field) \ do { \ if(field) { \ - (m)->field = strdup(field); \ + (m)->field = curlx_strdup(field); \ if(!(m)->field) \ goto fail; \ } \ @@ -745,7 +743,7 @@ int formparse(const char *input, } /* Make a copy we can overwrite. */ - contents = strdup(input); + contents = curlx_strdup(input); if(!contents) goto fail; diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 76113e45bd0d..7afb0c5fc051 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -38,22 +38,20 @@ #include "tool_help.h" #include "var.h" -#include "memdebug.h" /* keep this as LAST include */ - #define ALLOW_BLANK TRUE #define DENY_BLANK FALSE static ParameterError getstr(char **str, const char *val, bool allowblank) { if(*str) { - free(*str); + curlx_free(*str); *str = NULL; } DEBUGASSERT(val); if(!allowblank && !val[0]) return PARAM_BLANK_STRING; - *str = strdup(val); + *str = curlx_strdup(val); if(!*str) return PARAM_NO_MEM; @@ -64,14 +62,14 @@ static ParameterError getstrn(char **str, const char *val, size_t len, bool allowblank) { if(*str) { - free(*str); + curlx_free(*str); *str = NULL; } DEBUGASSERT(val); if(!allowblank && !val[0]) return PARAM_BLANK_STRING; - *str = malloc(len + 1); + *str = curlx_malloc(len + 1); if(!*str) return PARAM_NO_MEM; @@ -407,13 +405,13 @@ ParameterError parse_cert_parameter(const char *cert_parameter, * means no passphrase was given and no characters escaped */ if(curl_strnequal(cert_parameter, "pkcs11:", 7) || !strpbrk(cert_parameter, ":\\")) { - *certname = strdup(cert_parameter); + *certname = curlx_strdup(cert_parameter); if(!*certname) return PARAM_NO_MEM; return PARAM_OK; } /* deal with escaped chars; find unescaped colon if it exists */ - certname_place = malloc(param_length + 1); + certname_place = curlx_malloc(param_length + 1); if(!certname_place) { err = PARAM_NO_MEM; goto done; @@ -475,7 +473,7 @@ ParameterError parse_cert_parameter(const char *cert_parameter, * above; if we are still here, this is a separating colon */ param_place++; if(*param_place) { - *passphrase = strdup(param_place); + *passphrase = curlx_strdup(param_place); if(!*passphrase) err = PARAM_NO_MEM; } @@ -527,10 +525,10 @@ GetFileAndPassword(const char *nextarg, char **file, char **password) /* nextarg is never NULL here */ err = parse_cert_parameter(nextarg, &certname, &passphrase); if(!err) { - free(*file); + curlx_free(*file); *file = certname; if(passphrase) { - free(*password); + curlx_free(*password); *password = passphrase; } } @@ -668,7 +666,7 @@ static ParameterError data_urlencode(const char *nextarg, if(!postdata) { /* no data from the file, point to a zero byte string to make this get sent as a POST anyway */ - postdata = strdup(""); + postdata = curlx_strdup(""); if(!postdata) return PARAM_NO_MEM; size = 0; @@ -870,7 +868,7 @@ static ParameterError url_query(const char *nextarg, if(*nextarg == '+') { /* use without encoding */ - query = strdup(&nextarg[1]); + query = curlx_strdup(&nextarg[1]); if(!query) err = PARAM_NO_MEM; } @@ -880,11 +878,11 @@ static ParameterError url_query(const char *nextarg, if(!err) { if(config->query) { CURLcode result = curlx_dyn_addf(&dyn, "%s&%s", config->query, query); - free(query); + curlx_free(query); if(result) err = PARAM_NO_MEM; else { - free(config->query); + curlx_free(config->query); config->query = curlx_dyn_ptr(&dyn); } } @@ -944,7 +942,7 @@ static ParameterError set_data(cmdline_t cmd, if(!postdata) { /* no data from the file, point to a zero byte string to make this get sent as a POST anyway */ - postdata = strdup(""); + postdata = curlx_strdup(""); if(!postdata) return PARAM_NO_MEM; } @@ -1240,7 +1238,7 @@ static ParameterError parse_ech(struct OperationConfig *config, if(err) return err; config->ech_config = curl_maprintf("ecl:%s",tmpcfg); - free(tmpcfg); + curlx_free(tmpcfg); if(!config->ech_config) return PARAM_NO_MEM; } /* file done */ @@ -1424,8 +1422,8 @@ static ParameterError parse_range(struct OperationConfig *config, "Appending one for you"); curl_msnprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", value); - free(config->range); - config->range = strdup(buffer); + curlx_free(config->range); + config->range = curlx_strdup(buffer); if(!config->range) err = PARAM_NO_MEM; } @@ -1509,8 +1507,8 @@ static ParameterError parse_verbose(bool toggle) switch(global->verbosity) { case 0: global->verbosity = 1; - free(global->trace_dump); - global->trace_dump = strdup("%"); + curlx_free(global->trace_dump); + global->trace_dump = curlx_strdup("%"); if(!global->trace_dump) err = PARAM_NO_MEM; else { @@ -3021,7 +3019,7 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ error: if(nextalloc) - free(CURL_UNCONST(nextarg)); + curlx_free(CURL_UNCONST(nextarg)); return err; } diff --git a/src/tool_getpass.c b/src/tool_getpass.c index 014c22813acf..b0316510bc23 100644 --- a/src/tool_getpass.c +++ b/src/tool_getpass.c @@ -51,8 +51,6 @@ #endif #include "tool_getpass.h" -#include "memdebug.h" /* keep this as LAST include */ - #ifdef __VMS /* VMS implementation */ char *getpass_r(const char *prompt, char *buffer, size_t buflen) diff --git a/src/tool_help.c b/src/tool_help.c index 4509fa2b949d..bbe8dc68a4c3 100644 --- a/src/tool_help.c +++ b/src/tool_help.c @@ -33,8 +33,6 @@ #include "tool_cfgable.h" #include "terminal.h" -#include "memdebug.h" /* keep this as LAST include */ - struct category_descriptors { const char *opt; const char *desc; @@ -364,7 +362,7 @@ void tool_version_info(void) #ifdef CURL_CA_EMBED ++feat_ext_count; #endif - feat_ext = malloc(sizeof(*feature_names) * (feat_ext_count + 1)); + feat_ext = curlx_malloc(sizeof(*feature_names) * (feat_ext_count + 1)); if(feat_ext) { memcpy((void *)feat_ext, feature_names, sizeof(*feature_names) * feature_count); @@ -379,7 +377,7 @@ void tool_version_info(void) for(builtin = feat_ext; *builtin; ++builtin) curl_mprintf(" %s", *builtin); puts(""); /* newline */ - free((void *)feat_ext); + curlx_free((void *)feat_ext); } } if(strcmp(CURL_VERSION, curlinfo->version)) { diff --git a/src/tool_helpers.c b/src/tool_helpers.c index b36bd4af1d87..2e308a248f13 100644 --- a/src/tool_helpers.c +++ b/src/tool_helpers.c @@ -27,7 +27,6 @@ #include "tool_msgs.h" #include "tool_getparam.h" #include "tool_helpers.h" -#include "memdebug.h" /* keep this as LAST include */ /* ** Helper functions that are used from more than one source file. diff --git a/src/tool_ipfs.c b/src/tool_ipfs.c index 0214a2004f1e..c1d27fc99b09 100644 --- a/src/tool_ipfs.c +++ b/src/tool_ipfs.c @@ -28,7 +28,6 @@ #include "tool_cfgable.h" #include "tool_msgs.h" #include "tool_ipfs.h" -#include "memdebug.h" /* keep this as LAST include */ /* input string ends in slash? */ static bool has_trailing_slash(const char *input) @@ -45,7 +44,7 @@ static char *ipfs_gateway(void) char *gateway_env = getenv("IPFS_GATEWAY"); if(gateway_env) - return strdup(gateway_env); + return curlx_strdup(gateway_env); /* Try to find the gateway in the IPFS data folder. */ ipfs_path_c = curl_getenv("IPFS_PATH"); @@ -133,7 +132,7 @@ CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url, if(config->ipfs_gateway) { if(!curl_url_set(gatewayurl, CURLUPART_URL, config->ipfs_gateway, CURLU_GUESS_SCHEME)) { - gateway = strdup(config->ipfs_gateway); + gateway = curlx_strdup(config->ipfs_gateway); if(!gateway) { result = CURLE_URL_MALFORMAT; goto clean; @@ -200,8 +199,8 @@ CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url, if(curl_url_get(uh, CURLUPART_URL, &cloneurl, CURLU_URLENCODE)) { goto clean; } - /* we need to strdup the URL so that we can call free() on it later */ - *url = strdup(cloneurl); + /* we need to strdup the URL so that we can call curlx_free() on it later */ + *url = curlx_strdup(cloneurl); curl_free(cloneurl); if(!*url) goto clean; @@ -209,7 +208,7 @@ CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url, result = CURLE_OK; clean: - free(gateway); + curlx_free(gateway); curl_free(gwhost); curl_free(gwpath); curl_free(gwquery); diff --git a/src/tool_libinfo.c b/src/tool_libinfo.c index d755532652c8..1687005481a9 100644 --- a/src/tool_libinfo.c +++ b/src/tool_libinfo.c @@ -24,7 +24,6 @@ #include "tool_setup.h" #include "tool_libinfo.h" -#include "memdebug.h" /* keep this as LAST include */ /* global variable definitions, for libcurl runtime info */ diff --git a/src/tool_libinfo.h b/src/tool_libinfo.h index 5e6e1de24c43..ddc41a133867 100644 --- a/src/tool_libinfo.h +++ b/src/tool_libinfo.h @@ -27,7 +27,6 @@ /* global variable declarations, for libcurl runtime info */ - extern curl_version_info_data *curlinfo; extern const char * const *built_in_protos; diff --git a/src/tool_main.c b/src/tool_main.c index 8047e663c8f7..eb15ae740dd1 100644 --- a/src/tool_main.c +++ b/src/tool_main.c @@ -42,13 +42,6 @@ #include "tool_libinfo.h" #include "tool_stderr.h" -/* - * This is low-level hard-hacking memory leak tracking and similar. Using - * the library level code from this client-side is ugly, but we do this - * anyway for convenience. - */ -#include "memdebug.h" /* keep this as LAST include */ - #ifdef __VMS /* * vms_show is a global variable, used in main() as parameter for @@ -121,7 +114,7 @@ static void memory_tracking_init(void) curl_free(env); curl_dbg_memdebug(fname); /* this weird stuff here is to make curl_free() get called before - curl_dbg_memdebug() as otherwise memory tracking will log a free() + curl_dbg_memdebug() as otherwise memory tracking will log a curlx_free() without an alloc! */ } /* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */ diff --git a/src/tool_msgs.c b/src/tool_msgs.c index ae0b6b983586..b385f75cf8b8 100644 --- a/src/tool_msgs.c +++ b/src/tool_msgs.c @@ -28,8 +28,6 @@ #include "tool_cb_prg.h" #include "terminal.h" -#include "memdebug.h" /* keep this as LAST include */ - #define WARN_PREFIX "Warning: " #define NOTE_PREFIX "Note: " #define ERROR_PREFIX "curl: " diff --git a/src/tool_operate.c b/src/tool_operate.c index eb591935db4f..968dc864f9f6 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -90,8 +90,6 @@ CURL_EXTERN CURLcode curl_easy_perform_ev(CURL *easy); #endif -#include "memdebug.h" /* keep this as LAST include */ - #ifdef CURL_CA_EMBED #ifndef CURL_DECLARED_CURL_CA_EMBED #define CURL_DECLARED_CURL_CA_EMBED @@ -204,7 +202,7 @@ static struct per_transfer *transfersl; /* last node */ static CURLcode add_per_transfer(struct per_transfer **per) { struct per_transfer *p; - p = calloc(1, sizeof(struct per_transfer)); + p = curlx_calloc(1, sizeof(struct per_transfer)); if(!p) return CURLE_OUT_OF_MEMORY; if(!transfers) @@ -246,7 +244,7 @@ static struct per_transfer *del_per_transfer(struct per_transfer *per) else transfersl = p; - free(per); + curlx_free(per); return n; } @@ -770,10 +768,10 @@ static CURLcode post_per_transfer(struct per_transfer *per, curl_easy_cleanup(per->curl); if(outs->alloc_filename) - free(outs->filename); - free(per->url); - free(per->outfile); - free(per->uploadfile); + curlx_free(outs->filename); + curlx_free(per->url); + curlx_free(per->outfile); + curlx_free(per->uploadfile); curl_slist_free_all(per->hdrcbdata.headlist); per->hdrcbdata.headlist = NULL; return result; @@ -785,7 +783,7 @@ static CURLcode set_cert_types(struct OperationConfig *config) /* Check if config->cert is a PKCS#11 URI and set the config->cert_type if * necessary */ if(config->cert && !config->cert_type && is_pkcs11_uri(config->cert)) { - config->cert_type = strdup("ENG"); + config->cert_type = curlx_strdup("ENG"); if(!config->cert_type) return CURLE_OUT_OF_MEMORY; } @@ -793,7 +791,7 @@ static CURLcode set_cert_types(struct OperationConfig *config) /* Check if config->key is a PKCS#11 URI and set the config->key_type if * necessary */ if(config->key && !config->key_type && is_pkcs11_uri(config->key)) { - config->key_type = strdup("ENG"); + config->key_type = curlx_strdup("ENG"); if(!config->key_type) return CURLE_OUT_OF_MEMORY; } @@ -802,7 +800,7 @@ static CURLcode set_cert_types(struct OperationConfig *config) * config->proxy_type if necessary */ if(config->proxy_cert && !config->proxy_cert_type && is_pkcs11_uri(config->proxy_cert)) { - config->proxy_cert_type = strdup("ENG"); + config->proxy_cert_type = curlx_strdup("ENG"); if(!config->proxy_cert_type) return CURLE_OUT_OF_MEMORY; } @@ -811,7 +809,7 @@ static CURLcode set_cert_types(struct OperationConfig *config) * config->proxy_key_type if necessary */ if(config->proxy_key && !config->proxy_key_type && is_pkcs11_uri(config->proxy_key)) { - config->proxy_key_type = strdup("ENG"); + config->proxy_key_type = curlx_strdup("ENG"); if(!config->proxy_key_type) return CURLE_OUT_OF_MEMORY; } @@ -844,7 +842,7 @@ static CURLcode append2query(struct OperationConfig *config, if(uerr) result = urlerr_cvt(uerr); else { - free(per->url); /* free previous URL */ + curlx_free(per->url); /* free previous URL */ per->url = updated; /* use our new URL instead! */ } } @@ -1022,7 +1020,7 @@ static CURLcode setup_outfile(struct OperationConfig *config, char *d = curl_maprintf("%s/%s", config->output_dir, per->outfile); if(!d) return CURLE_WRITE_ERROR; - free(per->outfile); + curlx_free(per->outfile); per->outfile = d; } /* Create the directory hierarchy, if not pre-existent to a multiple @@ -1264,7 +1262,7 @@ static CURLcode single_transfer(struct OperationConfig *config, } per->etag_save = etag_first; /* copy the whole struct */ if(state->uploadfile) { - per->uploadfile = strdup(state->uploadfile); + per->uploadfile = curlx_strdup(state->uploadfile); if(!per->uploadfile || SetHTTPrequest(TOOL_HTTPREQ_PUT, &config->httpreq)) { tool_safefree(per->uploadfile); @@ -1300,7 +1298,7 @@ static CURLcode single_transfer(struct OperationConfig *config, if(glob_inuse(&state->urlglob)) result = glob_next_url(&per->url, &state->urlglob); else if(!state->urlidx) { - per->url = strdup(u->url); + per->url = curlx_strdup(u->url); if(!per->url) result = CURLE_OUT_OF_MEMORY; } @@ -1312,7 +1310,7 @@ static CURLcode single_transfer(struct OperationConfig *config, return result; if(u->outfile) { - per->outfile = strdup(u->outfile); + per->outfile = curlx_strdup(u->outfile); if(!per->outfile) return CURLE_OUT_OF_MEMORY; } @@ -1586,7 +1584,7 @@ static struct contextuv *create_context(curl_socket_t sockfd, { struct contextuv *c; - c = (struct contextuv *) malloc(sizeof(*c)); + c = (struct contextuv *)curlx_malloc(sizeof(*c)); c->sockfd = sockfd; c->uv = uv; @@ -1600,7 +1598,7 @@ static struct contextuv *create_context(curl_socket_t sockfd, static void close_cb(uv_handle_t *handle) { struct contextuv *c = (struct contextuv *) handle->data; - free(c); + curlx_free(c); } static void destroy_context(struct contextuv *c) @@ -2053,7 +2051,7 @@ static CURLcode cacertpaths(struct OperationConfig *config) env = curl_getenv("CURL_CA_BUNDLE"); if(env) { - config->cacert = strdup(env); + config->cacert = curlx_strdup(env); curl_free(env); if(!config->cacert) { result = CURLE_OUT_OF_MEMORY; @@ -2063,7 +2061,7 @@ static CURLcode cacertpaths(struct OperationConfig *config) else { env = curl_getenv("SSL_CERT_DIR"); if(env) { - config->capath = strdup(env); + config->capath = curlx_strdup(env); curl_free(env); if(!config->capath) { result = CURLE_OUT_OF_MEMORY; @@ -2072,7 +2070,7 @@ static CURLcode cacertpaths(struct OperationConfig *config) } env = curl_getenv("SSL_CERT_FILE"); if(env) { - config->cacert = strdup(env); + config->cacert = curlx_strdup(env); curl_free(env); if(!config->cacert) { result = CURLE_OUT_OF_MEMORY; @@ -2088,7 +2086,7 @@ static CURLcode cacertpaths(struct OperationConfig *config) FILE *cafile = tool_execpath("curl-ca-bundle.crt", &cacert); if(cafile) { curlx_fclose(cafile); - config->cacert = strdup(cacert); + config->cacert = curlx_strdup(cacert); if(!config->cacert) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -2260,7 +2258,7 @@ CURLcode operate(int argc, argv_item_t argv[]) if(found_curlrc) { /* After parse_args so notef knows the verbosity */ notef("Read config file from '%s'", curlrc_path); - free(curlrc_path); + curlx_free(curlrc_path); } if(res) { result = CURLE_OK; diff --git a/src/tool_operhlp.c b/src/tool_operhlp.c index 0d6c2cb6e0e5..a8b5e9497570 100644 --- a/src/tool_operhlp.c +++ b/src/tool_operhlp.c @@ -28,7 +28,6 @@ #include "tool_doswin.h" #include "tool_operhlp.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ void clean_getout(struct OperationConfig *config) { @@ -144,7 +143,7 @@ CURLcode add_file_name_to_url(CURL *curl, char **inurlp, const char *filename) if(!newpath) goto fail; uerr = curl_url_set(uh, CURLUPART_PATH, newpath, 0); - free(newpath); + curlx_free(newpath); if(uerr) { result = urlerr_cvt(uerr); goto fail; @@ -154,7 +153,7 @@ CURLcode add_file_name_to_url(CURL *curl, char **inurlp, const char *filename) result = urlerr_cvt(uerr); goto fail; } - free(*inurlp); + curlx_free(*inurlp); *inurlp = newurl; result = CURLE_OK; } @@ -206,11 +205,11 @@ CURLcode get_url_file_name(char **filename, const char *url) if(pc) { /* duplicate the string beyond the slash */ - *filename = strdup(pc + 1); + *filename = curlx_strdup(pc + 1); } else { /* no slash => empty string, use default */ - *filename = strdup("curl_response"); + *filename = curlx_strdup("curl_response"); warnf("No remote filename, uses \"%s\"", *filename); } diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 15293c0cc6ce..b16fc42906d8 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -32,11 +32,9 @@ #include "tool_util.h" #include "tool_version.h" -#include "memdebug.h" /* keep this as LAST include */ - struct getout *new_getout(struct OperationConfig *config) { - struct getout *node = calloc(1, sizeof(struct getout)); + struct getout *node = curlx_calloc(1, sizeof(struct getout)); struct getout *last = config->url_last; if(node) { static int outnum = 0; @@ -401,7 +399,7 @@ ParameterError proto2num(const char * const *val, char **ostr, const char *str) curlx_dyn_init(&obuf, MAX_PROTOSTRING); - protoset = malloc((proto_count + 1) * sizeof(*protoset)); + protoset = curlx_malloc((proto_count + 1) * sizeof(*protoset)); if(!protoset) return PARAM_NO_MEM; @@ -499,14 +497,14 @@ ParameterError proto2num(const char * const *val, char **ostr, const char *str) for(proto = 0; protoset[proto] && !result; proto++) result = curlx_dyn_addf(&obuf, "%s%s", curlx_dyn_len(&obuf) ? "," : "", protoset[proto]); - free((char *) protoset); + curlx_free((char *)protoset); if(result) return PARAM_NO_MEM; if(!curlx_dyn_len(&obuf)) { curlx_dyn_free(&obuf); return PARAM_BAD_USE; } - free(*ostr); + curlx_free(*ostr); *ostr = curlx_dyn_ptr(&obuf); return PARAM_OK; } @@ -592,7 +590,7 @@ static CURLcode checkpasswd(const char *kind, /* for what purpose */ return CURLE_OUT_OF_MEMORY; /* return the new string */ - free(*userpwd); + curlx_free(*userpwd); *userpwd = curlx_dyn_ptr(&dyn); } diff --git a/src/tool_parsecfg.c b/src/tool_parsecfg.c index e7a00cf70883..f901e69e7849 100644 --- a/src/tool_parsecfg.c +++ b/src/tool_parsecfg.c @@ -30,7 +30,6 @@ #include "tool_msgs.h" #include "tool_parsecfg.h" #include "tool_util.h" -#include "memdebug.h" /* keep this as LAST include */ /* only acknowledge colon or equals as separators if the option was not specified with an initial dash! */ @@ -96,7 +95,7 @@ ParameterError parseconfig(const char *filename, int max_recursive, if(curlrc) { file = curlx_fopen(curlrc, FOPEN_READTEXT); if(!file) { - free(curlrc); + curlx_free(curlrc); return PARAM_READ_ERROR; } filename = pathalloc = curlrc; @@ -266,11 +265,11 @@ ParameterError parseconfig(const char *filename, int max_recursive, errorf("cannot read config from '%s'", filename); if(!err && resolved) { - *resolved = strdup(filename); + *resolved = curlx_strdup(filename); if(!*resolved) err = PARAM_NO_MEM; } - free(pathalloc); + curlx_free(pathalloc); return err; } diff --git a/src/tool_setopt.c b/src/tool_setopt.c index b7039fbb4881..97d469d76daa 100644 --- a/src/tool_setopt.c +++ b/src/tool_setopt.c @@ -30,7 +30,6 @@ #ifndef CURL_DISABLE_LIBCURL_OPTION #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ /* Lookup tables for converting setopt values back to symbols */ /* For enums, values may be in any order. */ @@ -385,7 +384,7 @@ static CURLcode libcurl_generate_slist(struct curl_slist *slist, int *slistno) ret = easysrc_addf(&easysrc_data, "slist%d = curl_slist_append(slist%d, \"%s\");", *slistno, *slistno, escaped); - free(escaped); + curlx_free(escaped); } return ret; @@ -439,7 +438,7 @@ static CURLcode libcurl_generate_mime_part(CURL *curl, easysrc_addf(&easysrc_code, "curl_mime_data(part%d, \"%s\", CURL_ZERO_TERMINATED);", mimeno, escaped); - free(escaped); + curlx_free(escaped); } break; @@ -452,7 +451,7 @@ static CURLcode libcurl_generate_mime_part(CURL *curl, ret = easysrc_addf(&easysrc_code, "curl_mime_filename(part%d, NULL);", mimeno); } - free(escaped); + curlx_free(escaped); break; } @@ -477,28 +476,28 @@ static CURLcode libcurl_generate_mime_part(CURL *curl, char *escaped = c_escape(part->encoder, ZERO_TERMINATED); ret = easysrc_addf(&easysrc_code, "curl_mime_encoder(part%d, \"%s\");", mimeno, escaped); - free(escaped); + curlx_free(escaped); } if(!ret && filename) { char *escaped = c_escape(filename, ZERO_TERMINATED); ret = easysrc_addf(&easysrc_code, "curl_mime_filename(part%d, \"%s\");", mimeno, escaped); - free(escaped); + curlx_free(escaped); } if(!ret && part->name) { char *escaped = c_escape(part->name, ZERO_TERMINATED); ret = easysrc_addf(&easysrc_code, "curl_mime_name(part%d, \"%s\");", mimeno, escaped); - free(escaped); + curlx_free(escaped); } if(!ret && part->type) { char *escaped = c_escape(part->type, ZERO_TERMINATED); ret = easysrc_addf(&easysrc_code, "curl_mime_type(part%d, \"%s\");", mimeno, escaped); - free(escaped); + curlx_free(escaped); } if(!ret && part->headers) { @@ -687,7 +686,7 @@ CURLcode tool_setopt_str(CURL *curl, struct OperationConfig *config, result = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, \"%s\");", name, escaped); - free(escaped); + curlx_free(escaped); } else result = CURLE_OUT_OF_MEMORY; diff --git a/src/tool_setup.h b/src/tool_setup.h index 17c2f420b582..f693fc1dae70 100644 --- a/src/tool_setup.h +++ b/src/tool_setup.h @@ -68,6 +68,8 @@ extern FILE *tool_stderr; #ifndef HAVE_STRDUP #include "tool_strdup.h" +#undef Curl_strdup +#define Curl_strdup tool_strdup #endif #ifndef tool_nop_stmt diff --git a/src/tool_ssls.c b/src/tool_ssls.c index 2b67be9baaf8..7ffd6f707420 100644 --- a/src/tool_ssls.c +++ b/src/tool_ssls.c @@ -30,8 +30,6 @@ #include "tool_ssls.h" #include "tool_parsecfg.h" -#include "memdebug.h" /* keep this as LAST include */ - /* The maximum line length for an ecoded session ticket */ #define MAX_SSLS_LINE (64 * 1024) @@ -127,8 +125,8 @@ CURLcode tool_ssls_load(struct OperationConfig *config, if(fp) curlx_fclose(fp); curlx_dyn_free(&buf); - free(shmac); - free(sdata); + curlx_free(shmac); + curlx_free(sdata); return r; } @@ -181,7 +179,7 @@ static CURLcode tool_ssls_exp(CURL *easy, void *userptr, out: if(r) warnf("Warning: error saving SSL session for '%s': %d", session_key, r); - free(enc); + curlx_free(enc); return r; } diff --git a/src/tool_ssls.h b/src/tool_ssls.h index 7a1b95194d35..c06e9427cf4a 100644 --- a/src/tool_ssls.h +++ b/src/tool_ssls.h @@ -26,7 +26,6 @@ #include "tool_setup.h" #include "tool_operate.h" - CURLcode tool_ssls_load(struct OperationConfig *config, CURLSH *share, const char *filename); CURLcode tool_ssls_save(struct OperationConfig *config, diff --git a/src/tool_stderr.c b/src/tool_stderr.c index 8812f8bf8e52..7871ebc0ccb5 100644 --- a/src/tool_stderr.c +++ b/src/tool_stderr.c @@ -26,8 +26,6 @@ #include "tool_stderr.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ - FILE *tool_stderr; void tool_init_stderr(void) diff --git a/src/tool_strdup.c b/src/tool_strdup.c index ff80b56b9263..c799d1acdfde 100644 --- a/src/tool_strdup.c +++ b/src/tool_strdup.c @@ -22,10 +22,9 @@ * ***************************************************************************/ #include "tool_strdup.h" -#include "memdebug.h" /* keep this as LAST include */ #ifndef HAVE_STRDUP -char *strdup(const char *str) +char *tool_strdup(const char *str) { size_t len; char *newstr; @@ -35,7 +34,7 @@ char *strdup(const char *str) len = strlen(str) + 1; - newstr = malloc(len); + newstr = curlx_malloc(len); if(!newstr) return (char *)NULL; @@ -46,7 +45,7 @@ char *strdup(const char *str) char *memdup0(const char *data, size_t len) { - char *p = malloc(len + 1); + char *p = curlx_malloc(len + 1); if(!p) return NULL; if(len) diff --git a/src/tool_strdup.h b/src/tool_strdup.h index 275be7c5d907..0f121e20fdff 100644 --- a/src/tool_strdup.h +++ b/src/tool_strdup.h @@ -26,7 +26,7 @@ #include "tool_setup.h" #ifndef HAVE_STRDUP -extern char *strdup(const char *str); +extern char *tool_strdup(const char *str); #endif char *memdup0(const char *data, size_t len); diff --git a/src/tool_urlglob.c b/src/tool_urlglob.c index 7185e80f66b1..9ea8a274fa0d 100644 --- a/src/tool_urlglob.c +++ b/src/tool_urlglob.c @@ -28,7 +28,6 @@ #include "tool_urlglob.h" #include "tool_vms.h" #include "tool_strdup.h" -#include "memdebug.h" /* keep this as LAST include */ static CURLcode globerror(struct URLGlob *glob, const char *err, size_t pos, CURLcode error) @@ -45,7 +44,7 @@ static CURLcode glob_fixed(struct URLGlob *glob, char *fixed, size_t len) pat->globindex = -1; pat->c.set.size = 0; pat->c.set.idx = 0; - pat->c.set.elem = malloc(sizeof(char *)); + pat->c.set.elem = curlx_malloc(sizeof(char *)); if(!pat->c.set.elem) return globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY); @@ -137,10 +136,10 @@ static CURLcode glob_set(struct URLGlob *glob, const char **patternp, if(!palloc) { palloc = 5; /* a reasonable default */ - elem = malloc(palloc * sizeof(char *)); + elem = curlx_malloc(palloc * sizeof(char *)); } else if(size >= palloc) { - char **arr = realloc(elem, palloc * 2 * sizeof(char *)); + char **arr = curlx_realloc(elem, palloc * 2 * sizeof(char *)); if(!arr) { result = globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY); goto error; @@ -154,8 +153,8 @@ static CURLcode glob_set(struct URLGlob *glob, const char **patternp, goto error; } - elem[size] = - strdup(curlx_dyn_ptr(&glob->buf) ? curlx_dyn_ptr(&glob->buf) : ""); + elem[size] = curlx_strdup(curlx_dyn_ptr(&glob->buf) ? + curlx_dyn_ptr(&glob->buf) : ""); if(!elem[size]) { result = globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY); goto error; @@ -206,7 +205,7 @@ static CURLcode glob_set(struct URLGlob *glob, const char **patternp, for(i = 0; i < size; i++) tool_safefree(elem[i]); } - free(elem); + curlx_free(elem); return result; } @@ -387,7 +386,8 @@ static CURLcode add_glob(struct URLGlob *glob, size_t pos) struct URLPattern *np = NULL; glob->palloc *= 2; if(glob->pnum < 255) { /* avoid ridiculous amounts */ - np = realloc(glob->pattern, glob->palloc * sizeof(struct URLPattern)); + np = curlx_realloc(glob->pattern, + glob->palloc * sizeof(struct URLPattern)); if(!np) return globerror(glob, NULL, pos, CURLE_OUT_OF_MEMORY); } @@ -491,7 +491,7 @@ CURLcode glob_url(struct URLGlob *glob, char *url, curl_off_t *urlnum, memset(glob, 0, sizeof(struct URLGlob)); curlx_dyn_init(&glob->buf, 1024*1024); - glob->pattern = malloc(2 * sizeof(struct URLPattern)); + glob->pattern = curlx_malloc(2 * sizeof(struct URLPattern)); if(!glob->pattern) return CURLE_OUT_OF_MEMORY; glob->palloc = 2; @@ -617,7 +617,7 @@ CURLcode glob_next_url(char **globbed, struct URLGlob *glob) } *globbed = - strdup(curlx_dyn_ptr(&glob->buf) ? curlx_dyn_ptr(&glob->buf) : ""); + curlx_strdup(curlx_dyn_ptr(&glob->buf) ? curlx_dyn_ptr(&glob->buf) : ""); if(!*globbed) return CURLE_OUT_OF_MEMORY; diff --git a/src/tool_util.c b/src/tool_util.c index cb64f9a0b921..43dd096783cc 100644 --- a/src/tool_util.c +++ b/src/tool_util.c @@ -24,7 +24,6 @@ #include "tool_setup.h" #include "tool_util.h" -#include "memdebug.h" /* keep this as LAST include */ #ifdef _WIN32 diff --git a/src/tool_vms.c b/src/tool_vms.c index fac0cfc4dd72..75aa7d5370ee 100644 --- a/src/tool_vms.c +++ b/src/tool_vms.c @@ -32,7 +32,6 @@ #include "curlmsg_vms.h" #include "tool_vms.h" -#include "memdebug.h" /* keep this as LAST include */ void decc$__posix_exit(int __status); void decc$exit(int __status); diff --git a/src/tool_writeout.c b/src/tool_writeout.c index 52b35345f4a9..f846add4e311 100644 --- a/src/tool_writeout.c +++ b/src/tool_writeout.c @@ -26,7 +26,6 @@ #include "tool_cfgable.h" #include "tool_writeout.h" #include "tool_writeout_json.h" -#include "memdebug.h" /* keep this as LAST include */ static int writeTime(FILE *stream, const struct writeoutvar *wovar, struct per_transfer *per, CURLcode per_result, diff --git a/src/tool_xattr.c b/src/tool_xattr.c index fb0669106e4b..b111c7b843e4 100644 --- a/src/tool_xattr.c +++ b/src/tool_xattr.c @@ -24,8 +24,6 @@ #include "tool_setup.h" #include "tool_xattr.h" -#include "memdebug.h" /* keep this as LAST include */ - #ifdef USE_XATTR /* mapping table of curl metadata to extended attribute names */ diff --git a/src/var.c b/src/var.c index 5cedf1d24a2c..08269e1db704 100644 --- a/src/var.c +++ b/src/var.c @@ -33,7 +33,6 @@ #include "tool_writeout_json.h" #include "tool_strdup.h" #include "var.h" -#include "memdebug.h" /* keep this as LAST include */ #define MAX_EXPAND_CONTENT 10000000 #define MAX_VAR_LEN 128 /* max length of a name */ @@ -45,8 +44,8 @@ void varcleanup(void) while(list) { struct tool_var *t = list; list = list->next; - free(CURL_UNCONST(t->content)); - free(t); + curlx_free(CURL_UNCONST(t->content)); + curlx_free(t); } } @@ -192,7 +191,7 @@ static ParameterError varfunc(char *c, /* content */ break; } if(alloc) - free(c); + curlx_free(c); clen = curlx_dyn_len(out); c = memdup0(curlx_dyn_ptr(out), clen); @@ -203,7 +202,7 @@ static ParameterError varfunc(char *c, /* content */ alloc = TRUE; } if(alloc) - free(c); + curlx_free(c); if(err) curlx_dyn_free(out); return err; @@ -359,7 +358,7 @@ static ParameterError addvariable(const char *name, if(check) notef("Overwriting variable '%s'", check->name); - p = calloc(1, sizeof(struct tool_var) + nlen); + p = curlx_calloc(1, sizeof(struct tool_var) + nlen); if(p) { memcpy(p->name, name, nlen); /* the null termination byte is already present from above */ @@ -372,7 +371,7 @@ static ParameterError addvariable(const char *name, global->variables = p; return PARAM_OK; } - free(p); + curlx_free(p); } return PARAM_NO_MEM; } @@ -496,7 +495,7 @@ ParameterError setvariable(const char *input) err = addvariable(name, nlen, content, clen, contalloc); if(err) { if(contalloc) - free(content); + curlx_free(content); } return err; } diff --git a/tests/Makefile.am b/tests/Makefile.am index 677a17cd99fe..0371159d68d8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -25,7 +25,6 @@ # scripts used in test cases TESTSCRIPTS = \ test1119.pl \ - test1132.pl \ test1135.pl \ test1139.pl \ test1140.pl \ diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index bc3abbc7d80c..18c6969391be 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -152,7 +152,7 @@ test1093 test1094 test1095 test1096 test1097 test1098 test1099 test1100 \ test1101 test1102 test1103 test1104 test1105 test1106 test1107 test1108 \ test1109 test1110 test1111 test1112 test1113 test1114 test1115 test1116 \ test1117 test1118 test1119 test1120 test1121 test1122 test1123 test1124 \ -test1125 test1126 test1127 test1128 test1129 test1130 test1131 test1132 \ +test1125 test1126 test1127 test1128 test1129 test1130 test1131 \ test1133 test1134 test1135 test1136 test1137 test1138 test1139 test1140 \ test1141 test1142 test1143 test1144 test1145 test1146 test1147 test1148 \ test1149 test1150 test1151 test1152 test1153 test1154 test1155 test1156 \ diff --git a/tests/data/test1132 b/tests/data/test1132 deleted file mode 100644 index d0ef42a24e6f..000000000000 --- a/tests/data/test1132 +++ /dev/null @@ -1,21 +0,0 @@ - - - -source analysis -memory-includes - - - -# -# Client-side - - -Verify memory #include files in libcurl's C source files - - - -%SRCDIR/test1132.pl %SRCDIR/../lib - - - - diff --git a/tests/libtest/cli_h2_pausing.c b/tests/libtest/cli_h2_pausing.c index 0f06dadd5204..25b798af4b2b 100644 --- a/tests/libtest/cli_h2_pausing.c +++ b/tests/libtest/cli_h2_pausing.c @@ -26,7 +26,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static void usage_h2_pausing(const char *msg) { diff --git a/tests/libtest/cli_h2_serverpush.c b/tests/libtest/cli_h2_serverpush.c index ad3ae4f91406..80d8c031367f 100644 --- a/tests/libtest/cli_h2_serverpush.c +++ b/tests/libtest/cli_h2_serverpush.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static FILE *out_download = NULL; diff --git a/tests/libtest/cli_h2_upgrade_extreme.c b/tests/libtest/cli_h2_upgrade_extreme.c index b5c6c31b1b59..bc28a6f4d05e 100644 --- a/tests/libtest/cli_h2_upgrade_extreme.c +++ b/tests/libtest/cli_h2_upgrade_extreme.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static size_t write_h2_upg_extreme_cb(char *ptr, size_t size, size_t nmemb, void *opaque) diff --git a/tests/libtest/cli_hx_download.c b/tests/libtest/cli_hx_download.c index 82e8c1b70da7..a7f5d200903c 100644 --- a/tests/libtest/cli_hx_download.c +++ b/tests/libtest/cli_hx_download.c @@ -25,8 +25,6 @@ #include "testtrace.h" -#include "curl_mem_undef.h" - #if defined(USE_QUICHE) || defined(USE_OPENSSL) #include #endif @@ -45,8 +43,6 @@ #include #endif -#include "memdebug.h" - static int verbose_d = 1; struct transfer_d { @@ -346,8 +342,8 @@ static CURLcode test_cli_hx_download(const char *URL) pause_offset = (size_t)num; break; case 'r': - free(resolve); - resolve = strdup(coptarg); + curlx_free(resolve); + resolve = curlx_strdup(coptarg); break; case 'T': if(!curlx_str_number(&opt, &num, LONG_MAX)) @@ -407,7 +403,7 @@ static CURLcode test_cli_hx_download(const char *URL) curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_PSL); curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_HSTS); - transfer_d = calloc(transfer_count_d, sizeof(*transfer_d)); + transfer_d = curlx_calloc(transfer_count_d, sizeof(*transfer_d)); if(!transfer_d) { curl_mfprintf(stderr, "error allocating transfer structs\n"); res = (CURLcode)1; @@ -559,7 +555,7 @@ static CURLcode test_cli_hx_download(const char *URL) else /* on success we expect ssl to have been checked */ assert(t->checked_ssl); } - free(transfer_d); + curlx_free(transfer_d); } curl_share_cleanup(share); @@ -569,7 +565,7 @@ static CURLcode test_cli_hx_download(const char *URL) optcleanup: - free(resolve); + curlx_free(resolve); return res; } diff --git a/tests/libtest/cli_hx_upload.c b/tests/libtest/cli_hx_upload.c index f0183f6df2bf..f7036509fea2 100644 --- a/tests/libtest/cli_hx_upload.c +++ b/tests/libtest/cli_hx_upload.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static int verbose_u = 1; @@ -358,7 +357,7 @@ static CURLcode test_cli_hx_upload(const char *URL) curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_PSL); curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_HSTS); - transfer_u = calloc(transfer_count_u, sizeof(*transfer_u)); + transfer_u = curlx_calloc(transfer_count_u, sizeof(*transfer_u)); if(!transfer_u) { curl_mfprintf(stderr, "error allocating transfer structs\n"); res = (CURLcode)1; @@ -539,7 +538,7 @@ static CURLcode test_cli_hx_upload(const char *URL) curl_mime_free(t->mime); } } - free(transfer_u); + curlx_free(transfer_u); } curl_share_cleanup(share); diff --git a/tests/libtest/cli_tls_session_reuse.c b/tests/libtest/cli_tls_session_reuse.c index 2f6bde43e384..aa56a0e28c66 100644 --- a/tests/libtest/cli_tls_session_reuse.c +++ b/tests/libtest/cli_tls_session_reuse.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static int tse_found_tls_session = FALSE; diff --git a/tests/libtest/cli_upload_pausing.c b/tests/libtest/cli_upload_pausing.c index 441ce899a09e..042eddd7d7dc 100644 --- a/tests/libtest/cli_upload_pausing.c +++ b/tests/libtest/cli_upload_pausing.c @@ -26,7 +26,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static size_t total_read = 0; diff --git a/tests/libtest/cli_ws_data.c b/tests/libtest/cli_ws_data.c index aa43bc6058ca..2276f0c92ce1 100644 --- a/tests/libtest/cli_ws_data.c +++ b/tests/libtest/cli_ws_data.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" #ifndef CURL_DISABLE_WEBSOCKETS @@ -83,8 +82,8 @@ static CURLcode test_ws_data_m2_echo(const char *url, size_t i, scount = count, rcount = count; int rblock, sblock; - send_buf = calloc(1, plen_max + 1); - recv_buf = calloc(1, plen_max + 1); + send_buf = curlx_calloc(1, plen_max + 1); + recv_buf = curlx_calloc(1, plen_max + 1); if(!send_buf || !recv_buf) { r = CURLE_OUT_OF_MEMORY; goto out; @@ -184,8 +183,8 @@ static CURLcode test_ws_data_m2_echo(const char *url, ws_close(curl); curl_easy_cleanup(curl); } - free(send_buf); - free(recv_buf); + curlx_free(send_buf); + curlx_free(recv_buf); return r; } @@ -294,8 +293,8 @@ static CURLcode test_ws_data_m1_echo(const char *url, curl_mfprintf(stderr, "test_ws_data_m1_echo(min=%zu, max=%zu)\n", plen_min, plen_max); memset(&m1_ctx, 0, sizeof(m1_ctx)); - m1_ctx.send_buf = calloc(1, plen_max + 1); - m1_ctx.recv_buf = calloc(1, plen_max + 1); + m1_ctx.send_buf = curlx_calloc(1, plen_max + 1); + m1_ctx.recv_buf = curlx_calloc(1, plen_max + 1); if(!m1_ctx.send_buf || !m1_ctx.recv_buf) { r = CURLE_OUT_OF_MEMORY; goto out; @@ -389,8 +388,8 @@ static CURLcode test_ws_data_m1_echo(const char *url, if(m1_ctx.curl) { curl_easy_cleanup(m1_ctx.curl); } - free(m1_ctx.send_buf); - free(m1_ctx.recv_buf); + curlx_free(m1_ctx.send_buf); + curlx_free(m1_ctx.recv_buf); return r; } diff --git a/tests/libtest/cli_ws_pingpong.c b/tests/libtest/cli_ws_pingpong.c index 0a8e957aa411..8449b9d1278f 100644 --- a/tests/libtest/cli_ws_pingpong.c +++ b/tests/libtest/cli_ws_pingpong.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" #ifndef CURL_DISABLE_WEBSOCKETS diff --git a/tests/libtest/first.c b/tests/libtest/first.c index a8e2e91cf0cc..2f6553088211 100644 --- a/tests/libtest/first.c +++ b/tests/libtest/first.c @@ -27,8 +27,6 @@ #include /* for setlocale() */ #endif -#include "memdebug.h" - int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc, struct timeval *tv) { diff --git a/tests/libtest/lib1156.c b/tests/libtest/lib1156.c index 6ceb6894e785..758f6e3f1ae9 100644 --- a/tests/libtest/lib1156.c +++ b/tests/libtest/lib1156.c @@ -34,8 +34,6 @@ */ -#include "memdebug.h" - #define F_RESUME (1 << 0) /* resume/range. */ #define F_HTTP416 (1 << 1) /* Server returns http code 416. */ #define F_FAIL (1 << 2) /* Fail on error. */ diff --git a/tests/libtest/lib1485.c b/tests/libtest/lib1485.c index 7fea83317c06..828e1ede74df 100644 --- a/tests/libtest/lib1485.c +++ b/tests/libtest/lib1485.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t1485_transfer_status { CURL *curl; curl_off_t out_len; diff --git a/tests/libtest/lib1500.c b/tests/libtest/lib1500.c index 5fe8e7ab4faf..921d1ce8b182 100644 --- a/tests/libtest/lib1500.c +++ b/tests/libtest/lib1500.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1500(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib1501.c b/tests/libtest/lib1501.c index 5b5e64c48cca..cd1cd874f777 100644 --- a/tests/libtest/lib1501.c +++ b/tests/libtest/lib1501.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1501(const char *URL) { static const long HANG_TIMEOUT = 30 * 1000; diff --git a/tests/libtest/lib1502.c b/tests/libtest/lib1502.c index 527f969b116f..1546acfaa8ad 100644 --- a/tests/libtest/lib1502.c +++ b/tests/libtest/lib1502.c @@ -31,8 +31,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1502(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib1506.c b/tests/libtest/lib1506.c index 5790f3baebad..8b986c59a029 100644 --- a/tests/libtest/lib1506.c +++ b/tests/libtest/lib1506.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1506(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1507.c b/tests/libtest/lib1507.c index d9f85a3318aa..ffdaa50df6d3 100644 --- a/tests/libtest/lib1507.c +++ b/tests/libtest/lib1507.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t1507_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) { (void)ptr; diff --git a/tests/libtest/lib1508.c b/tests/libtest/lib1508.c index b7b47daa3f9e..446e8231a528 100644 --- a/tests/libtest/lib1508.c +++ b/tests/libtest/lib1508.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1508(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1509.c b/tests/libtest/lib1509.c index 3ab4feea8b8e..16935de7a757 100644 --- a/tests/libtest/lib1509.c +++ b/tests/libtest/lib1509.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t realHeaderSize = 0; static size_t WriteOutput(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib1510.c b/tests/libtest/lib1510.c index e914d48eb78c..7a70763813d8 100644 --- a/tests/libtest/lib1510.c +++ b/tests/libtest/lib1510.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1510(const char *URL) { static const int NUM_URLS = 4; diff --git a/tests/libtest/lib1511.c b/tests/libtest/lib1511.c index de09d2a6fa93..fb65dcae988f 100644 --- a/tests/libtest/lib1511.c +++ b/tests/libtest/lib1511.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1511(const char *URL) { long unmet; diff --git a/tests/libtest/lib1512.c b/tests/libtest/lib1512.c index dd80163d43d4..16648d7e56f4 100644 --- a/tests/libtest/lib1512.c +++ b/tests/libtest/lib1512.c @@ -30,8 +30,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1512(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1513.c b/tests/libtest/lib1513.c index c86c5185e23e..8bf1613fa17b 100644 --- a/tests/libtest/lib1513.c +++ b/tests/libtest/lib1513.c @@ -30,8 +30,6 @@ #include "first.h" -#include "memdebug.h" - static int progressKiller(void *arg, double dltotal, double dlnow, diff --git a/tests/libtest/lib1514.c b/tests/libtest/lib1514.c index fc7e33e3d3b3..fa0aa0742439 100644 --- a/tests/libtest/lib1514.c +++ b/tests/libtest/lib1514.c @@ -28,8 +28,6 @@ #include "first.h" -#include "memdebug.h" - struct t1514_WriteThis { char *readptr; size_t sizeleft; diff --git a/tests/libtest/lib1515.c b/tests/libtest/lib1515.c index 679a413c69a3..7833f06a10f6 100644 --- a/tests/libtest/lib1515.c +++ b/tests/libtest/lib1515.c @@ -31,7 +31,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" #define DNS_TIMEOUT 1L diff --git a/tests/libtest/lib1517.c b/tests/libtest/lib1517.c index d8ad3b753bb2..cebdeab0a1b4 100644 --- a/tests/libtest/lib1517.c +++ b/tests/libtest/lib1517.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t1517_WriteThis { const char *readptr; size_t sizeleft; diff --git a/tests/libtest/lib1518.c b/tests/libtest/lib1518.c index 63e861910dd1..1ebe957af3f7 100644 --- a/tests/libtest/lib1518.c +++ b/tests/libtest/lib1518.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* Test inspired by github issue 3340 */ static size_t t1518_write_cb(char *buffer, size_t size, size_t nitems, diff --git a/tests/libtest/lib1520.c b/tests/libtest/lib1520.c index e61727eadc22..4cf54388eb1a 100644 --- a/tests/libtest/lib1520.c +++ b/tests/libtest/lib1520.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct upload_status { int lines_read; }; diff --git a/tests/libtest/lib1522.c b/tests/libtest/lib1522.c index 3423f4777c95..1ac2332e8121 100644 --- a/tests/libtest/lib1522.c +++ b/tests/libtest/lib1522.c @@ -26,7 +26,6 @@ /* test case and code based on https://github.com/curl/curl/issues/2847 */ #include "testtrace.h" -#include "memdebug.h" static int sockopt_callback(void *clientp, curl_socket_t curlfd, curlsocktype purpose) diff --git a/tests/libtest/lib1523.c b/tests/libtest/lib1523.c index 5c9a01a5eb1b..711aa3f7140f 100644 --- a/tests/libtest/lib1523.c +++ b/tests/libtest/lib1523.c @@ -25,8 +25,6 @@ /* test case and code based on https://github.com/curl/curl/issues/3927 */ -#include "memdebug.h" - static int dload_progress_cb(void *a, curl_off_t b, curl_off_t c, curl_off_t d, curl_off_t e) { diff --git a/tests/libtest/lib1525.c b/tests/libtest/lib1525.c index 7e7d98ef7997..c9a1e1514f80 100644 --- a/tests/libtest/lib1525.c +++ b/tests/libtest/lib1525.c @@ -30,8 +30,6 @@ #include "first.h" -#include "memdebug.h" - static const char t1525_testdata[] = "Hello Cloud!\n"; static size_t t1525_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib1526.c b/tests/libtest/lib1526.c index bf2a07ee9dfe..031f8bfd2746 100644 --- a/tests/libtest/lib1526.c +++ b/tests/libtest/lib1526.c @@ -29,8 +29,6 @@ #include "first.h" -#include "memdebug.h" - static const char t1526_testdata[] = "Hello Cloud!\n"; static size_t t1526_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib1527.c b/tests/libtest/lib1527.c index 362472868799..1d9a5821324b 100644 --- a/tests/libtest/lib1527.c +++ b/tests/libtest/lib1527.c @@ -29,8 +29,6 @@ #include "first.h" -#include "memdebug.h" - static const char t1527_testdata[] = "Hello Cloud!\n"; static size_t t1527_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib1528.c b/tests/libtest/lib1528.c index 98bd2bdaf18a..e1dd3657fe42 100644 --- a/tests/libtest/lib1528.c +++ b/tests/libtest/lib1528.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1528(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib1529.c b/tests/libtest/lib1529.c index ae86b61a5e67..24cdd78b0315 100644 --- a/tests/libtest/lib1529.c +++ b/tests/libtest/lib1529.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1529(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib1530.c b/tests/libtest/lib1530.c index 19b0d9cbde38..6cb6d59e874f 100644 --- a/tests/libtest/lib1530.c +++ b/tests/libtest/lib1530.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static curl_socket_t opensocket(void *clientp, curlsocktype purpose, struct curl_sockaddr *address) diff --git a/tests/libtest/lib1531.c b/tests/libtest/lib1531.c index 65b20c2993b4..a3554434e643 100644 --- a/tests/libtest/lib1531.c +++ b/tests/libtest/lib1531.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1531(const char *URL) { static char const testData[] = ".abc\0xyz"; diff --git a/tests/libtest/lib1532.c b/tests/libtest/lib1532.c index 83a826de32d2..e1c5c0470278 100644 --- a/tests/libtest/lib1532.c +++ b/tests/libtest/lib1532.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* Test CURLINFO_RESPONSE_CODE */ static CURLcode test_lib1532(const char *URL) diff --git a/tests/libtest/lib1533.c b/tests/libtest/lib1533.c index 1c6017273410..a2d541c4124f 100644 --- a/tests/libtest/lib1533.c +++ b/tests/libtest/lib1533.c @@ -31,8 +31,6 @@ #include "first.h" -#include "memdebug.h" - struct cb_data { CURL *curl; int response_received; diff --git a/tests/libtest/lib1534.c b/tests/libtest/lib1534.c index af1c0bd52020..377df3b2fe19 100644 --- a/tests/libtest/lib1534.c +++ b/tests/libtest/lib1534.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* Test CURLINFO_FILETIME */ static CURLcode test_lib1534(const char *URL) diff --git a/tests/libtest/lib1535.c b/tests/libtest/lib1535.c index c0e0689d98ba..c49c3076dfee 100644 --- a/tests/libtest/lib1535.c +++ b/tests/libtest/lib1535.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* Test CURLINFO_PROTOCOL */ static CURLcode test_lib1535(const char *URL) diff --git a/tests/libtest/lib1536.c b/tests/libtest/lib1536.c index 3219724b9aef..f89b50a19583 100644 --- a/tests/libtest/lib1536.c +++ b/tests/libtest/lib1536.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* Test CURLINFO_SCHEME */ static CURLcode test_lib1536(const char *URL) diff --git a/tests/libtest/lib1537.c b/tests/libtest/lib1537.c index cb35fb19087c..f521986ebc54 100644 --- a/tests/libtest/lib1537.c +++ b/tests/libtest/lib1537.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1537(const char *URL) { const unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, diff --git a/tests/libtest/lib1538.c b/tests/libtest/lib1538.c index 9aaec8171a18..2a8830c5cce9 100644 --- a/tests/libtest/lib1538.c +++ b/tests/libtest/lib1538.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1538(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1540.c b/tests/libtest/lib1540.c index 7f9123435632..849431e79633 100644 --- a/tests/libtest/lib1540.c +++ b/tests/libtest/lib1540.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" struct t1540_transfer_status { CURL *curl; diff --git a/tests/libtest/lib1541.c b/tests/libtest/lib1541.c index 150fd2e30bc9..c39bee989cd7 100644 --- a/tests/libtest/lib1541.c +++ b/tests/libtest/lib1541.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t1541_transfer_status { CURL *curl; int hd_count; diff --git a/tests/libtest/lib1542.c b/tests/libtest/lib1542.c index 9fc9f17efb46..9a6ba0b36e0a 100644 --- a/tests/libtest/lib1542.c +++ b/tests/libtest/lib1542.c @@ -33,7 +33,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static CURLcode test_lib1542(const char *URL) { diff --git a/tests/libtest/lib1549.c b/tests/libtest/lib1549.c index 10d318381027..fa9515e4f6cb 100644 --- a/tests/libtest/lib1549.c +++ b/tests/libtest/lib1549.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static CURLcode test_lib1549(const char *URL) { diff --git a/tests/libtest/lib1550.c b/tests/libtest/lib1550.c index 566cbfa1928a..b328dd27bc2a 100644 --- a/tests/libtest/lib1550.c +++ b/tests/libtest/lib1550.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #include static CURLcode test_lib1550(const char *URL) diff --git a/tests/libtest/lib1551.c b/tests/libtest/lib1551.c index 80020f55566d..ce4989a6163d 100644 --- a/tests/libtest/lib1551.c +++ b/tests/libtest/lib1551.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #include static CURLcode test_lib1551(const char *URL) diff --git a/tests/libtest/lib1552.c b/tests/libtest/lib1552.c index d0c3469d4cea..bceacd354cdf 100644 --- a/tests/libtest/lib1552.c +++ b/tests/libtest/lib1552.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1552(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib1553.c b/tests/libtest/lib1553.c index fa753ac23102..d1eaefee4a4e 100644 --- a/tests/libtest/lib1553.c +++ b/tests/libtest/lib1553.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static int t1553_xferinfo(void *p, curl_off_t dltotal, curl_off_t dlnow, diff --git a/tests/libtest/lib1554.c b/tests/libtest/lib1554.c index a23d713e63d7..f330b2df7d90 100644 --- a/tests/libtest/lib1554.c +++ b/tests/libtest/lib1554.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static const char *ldata_names[] = { "NONE", "SHARE", diff --git a/tests/libtest/lib1555.c b/tests/libtest/lib1555.c index 4ebde5c74c6d..001a8f5bae7e 100644 --- a/tests/libtest/lib1555.c +++ b/tests/libtest/lib1555.c @@ -27,8 +27,6 @@ #include "first.h" -#include "memdebug.h" - static CURL *t1555_curl; static int progressCallback(void *arg, diff --git a/tests/libtest/lib1556.c b/tests/libtest/lib1556.c index 4987fc9f0969..e852bb322471 100644 --- a/tests/libtest/lib1556.c +++ b/tests/libtest/lib1556.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct headerinfo { size_t largest; }; diff --git a/tests/libtest/lib1557.c b/tests/libtest/lib1557.c index 1c2785dbe33e..28162a1b0342 100644 --- a/tests/libtest/lib1557.c +++ b/tests/libtest/lib1557.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1557(const char *URL) { CURLM *multi = NULL; diff --git a/tests/libtest/lib1558.c b/tests/libtest/lib1558.c index 1bbc0f77b75f..d299405fe214 100644 --- a/tests/libtest/lib1558.c +++ b/tests/libtest/lib1558.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1558(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1559.c b/tests/libtest/lib1559.c index 1aa0f830c75d..c6851918a685 100644 --- a/tests/libtest/lib1559.c +++ b/tests/libtest/lib1559.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1559(const char *URL) { static const int EXCESSIVE = 10*1000*1000; @@ -38,7 +36,7 @@ static CURLcode test_lib1559(const char *URL) global_init(CURL_GLOBAL_ALL); easy_init(curl); - longurl = malloc(EXCESSIVE); + longurl = curlx_malloc(EXCESSIVE); if(!longurl) { res = TEST_ERR_MAJOR_BAD; goto test_cleanup; @@ -70,7 +68,7 @@ static CURLcode test_lib1559(const char *URL) } test_cleanup: - free(longurl); + curlx_free(longurl); curl_easy_cleanup(curl); curl_global_cleanup(); diff --git a/tests/libtest/lib1560.c b/tests/libtest/lib1560.c index db85fe738239..2f6608108cca 100644 --- a/tests/libtest/lib1560.c +++ b/tests/libtest/lib1560.c @@ -35,8 +35,6 @@ #define USE_IDN #endif -#include "memdebug.h" /* LAST include file */ - static int checkparts(CURLU *u, const char *in, const char *wanted, unsigned int getflags) { diff --git a/tests/libtest/lib1564.c b/tests/libtest/lib1564.c index 42b3a07d1a91..23d0c2cd6f43 100644 --- a/tests/libtest/lib1564.c +++ b/tests/libtest/lib1564.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #define WAKEUP_NUM 10 static CURLcode test_lib1564(const char *URL) diff --git a/tests/libtest/lib1565.c b/tests/libtest/lib1565.c index 7e983978e7bf..506959dd9083 100644 --- a/tests/libtest/lib1565.c +++ b/tests/libtest/lib1565.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #ifdef HAVE_PTHREAD_H #include diff --git a/tests/libtest/lib1567.c b/tests/libtest/lib1567.c index e0016157256e..539da3c34f86 100644 --- a/tests/libtest/lib1567.c +++ b/tests/libtest/lib1567.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #include static CURLcode test_lib1567(const char *URL) diff --git a/tests/libtest/lib1568.c b/tests/libtest/lib1568.c index 89dd83480dad..0db1e49e2f7a 100644 --- a/tests/libtest/lib1568.c +++ b/tests/libtest/lib1568.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1568(const char *URL) { CURLcode res = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib1569.c b/tests/libtest/lib1569.c index c2fd27bfe195..44d77a5d455b 100644 --- a/tests/libtest/lib1569.c +++ b/tests/libtest/lib1569.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1569(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1571.c b/tests/libtest/lib1571.c index 622be2f643d0..8b29a9a1bf17 100644 --- a/tests/libtest/lib1571.c +++ b/tests/libtest/lib1571.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1571(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib1576.c b/tests/libtest/lib1576.c index 203ef2b9891e..9a5d415193e3 100644 --- a/tests/libtest/lib1576.c +++ b/tests/libtest/lib1576.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static char t1576_testdata[] = "request indicates that the client, which made"; static size_t t1576_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib1582.c b/tests/libtest/lib1582.c index 0e209beee450..e1877a99ac5a 100644 --- a/tests/libtest/lib1582.c +++ b/tests/libtest/lib1582.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1582(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib1591.c b/tests/libtest/lib1591.c index 3031ba1bb71c..42761c3065d2 100644 --- a/tests/libtest/lib1591.c +++ b/tests/libtest/lib1591.c @@ -29,8 +29,6 @@ #include "first.h" -#include "memdebug.h" - static size_t consumed = 0; static size_t t1591_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib1593.c b/tests/libtest/lib1593.c index 5b6e57d4f752..f8d7be9d7273 100644 --- a/tests/libtest/lib1593.c +++ b/tests/libtest/lib1593.c @@ -26,8 +26,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1593(const char *URL) { struct curl_slist *header = NULL; diff --git a/tests/libtest/lib1594.c b/tests/libtest/lib1594.c index 5c8db3ae92ae..6cf5cace5335 100644 --- a/tests/libtest/lib1594.c +++ b/tests/libtest/lib1594.c @@ -26,8 +26,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1594(const char *URL) { struct curl_slist *header = NULL; diff --git a/tests/libtest/lib1597.c b/tests/libtest/lib1597.c index 251016641e7a..a338a53944fb 100644 --- a/tests/libtest/lib1597.c +++ b/tests/libtest/lib1597.c @@ -26,8 +26,6 @@ #include "first.h" -#include "memdebug.h" - struct pair { const char *in; CURLcode *exp; diff --git a/tests/libtest/lib1598.c b/tests/libtest/lib1598.c index 4120916ff0ab..8d9ec7eb8e6b 100644 --- a/tests/libtest/lib1598.c +++ b/tests/libtest/lib1598.c @@ -29,8 +29,6 @@ #include "first.h" -#include "memdebug.h" - /* * carefully not leak memory on OOM */ diff --git a/tests/libtest/lib1900.c b/tests/libtest/lib1900.c index 2f0954bb6c52..04ce5aa9f197 100644 --- a/tests/libtest/lib1900.c +++ b/tests/libtest/lib1900.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1900(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1901.c b/tests/libtest/lib1901.c index cb66001f9bb2..4494633b94f3 100644 --- a/tests/libtest/lib1901.c +++ b/tests/libtest/lib1901.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t1901_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) { static const char *chunks[] = { diff --git a/tests/libtest/lib1902.c b/tests/libtest/lib1902.c index 8e5929e33827..e114554ec526 100644 --- a/tests/libtest/lib1902.c +++ b/tests/libtest/lib1902.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1902(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1903.c b/tests/libtest/lib1903.c index fc2858d5eecb..19c2f50e197a 100644 --- a/tests/libtest/lib1903.c +++ b/tests/libtest/lib1903.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1903(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1905.c b/tests/libtest/lib1905.c index 600e6962383e..d1fdba4d2ea5 100644 --- a/tests/libtest/lib1905.c +++ b/tests/libtest/lib1905.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1905(const char *URL) { CURLSH *share = NULL; diff --git a/tests/libtest/lib1906.c b/tests/libtest/lib1906.c index da0f9f56b900..07404f8b9054 100644 --- a/tests/libtest/lib1906.c +++ b/tests/libtest/lib1906.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1906(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1907.c b/tests/libtest/lib1907.c index 0a3556719b61..ebf106d3b1e4 100644 --- a/tests/libtest/lib1907.c +++ b/tests/libtest/lib1907.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1907(const char *URL) { char *url_after; diff --git a/tests/libtest/lib1908.c b/tests/libtest/lib1908.c index ac841ca1a18b..2ceb04d5a243 100644 --- a/tests/libtest/lib1908.c +++ b/tests/libtest/lib1908.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1908(const char *URL) { CURLcode res = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib1910.c b/tests/libtest/lib1910.c index ebe86c12453c..4f2277752692 100644 --- a/tests/libtest/lib1910.c +++ b/tests/libtest/lib1910.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1910(const char *URL) { CURLcode res = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib1911.c b/tests/libtest/lib1911.c index 46c73ffb361d..0f88752b6fbd 100644 --- a/tests/libtest/lib1911.c +++ b/tests/libtest/lib1911.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* The maximum string length limit (CURL_MAX_INPUT_LENGTH) is an internal define not publicly exposed so we set our own */ #define MAX_INPUT_LENGTH 8000000 diff --git a/tests/libtest/lib1912.c b/tests/libtest/lib1912.c index 0dd246e4612b..76ba51c4479f 100644 --- a/tests/libtest/lib1912.c +++ b/tests/libtest/lib1912.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #define print_err(name, exp) \ curl_mfprintf(stderr, "Type mismatch for CURLOPT_%s (expected %s)\n", \ name, exp) diff --git a/tests/libtest/lib1913.c b/tests/libtest/lib1913.c index cea7a6c6ec81..b4b4ab720f83 100644 --- a/tests/libtest/lib1913.c +++ b/tests/libtest/lib1913.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1913(const char *URL) { CURLcode res = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib1915.c b/tests/libtest/lib1915.c index e47ae9ee8028..367533aef64f 100644 --- a/tests/libtest/lib1915.c +++ b/tests/libtest/lib1915.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" struct state { int index; diff --git a/tests/libtest/lib1916.c b/tests/libtest/lib1916.c index 24583ab8a189..4c66b1b97ead 100644 --- a/tests/libtest/lib1916.c +++ b/tests/libtest/lib1916.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1916(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1918.c b/tests/libtest/lib1918.c index de9252107bfb..d99563916416 100644 --- a/tests/libtest/lib1918.c +++ b/tests/libtest/lib1918.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1918(const char *URL) { const struct curl_easyoption *o; diff --git a/tests/libtest/lib1919.c b/tests/libtest/lib1919.c index a619850dc718..79d31810a466 100644 --- a/tests/libtest/lib1919.c +++ b/tests/libtest/lib1919.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1919(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1933.c b/tests/libtest/lib1933.c index bdd914a641ef..8b02f16aa7f8 100644 --- a/tests/libtest/lib1933.c +++ b/tests/libtest/lib1933.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1933(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1934.c b/tests/libtest/lib1934.c index 2cffaa9bc790..465dfeb5dec6 100644 --- a/tests/libtest/lib1934.c +++ b/tests/libtest/lib1934.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1934(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1935.c b/tests/libtest/lib1935.c index 4f6a1ebb731c..61382399a32f 100644 --- a/tests/libtest/lib1935.c +++ b/tests/libtest/lib1935.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1935(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1936.c b/tests/libtest/lib1936.c index 438cf92c58e0..20b170397e3c 100644 --- a/tests/libtest/lib1936.c +++ b/tests/libtest/lib1936.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1936(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1937.c b/tests/libtest/lib1937.c index 4903f7409a5c..c6fb120b6ad6 100644 --- a/tests/libtest/lib1937.c +++ b/tests/libtest/lib1937.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1937(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1938.c b/tests/libtest/lib1938.c index c0bfb6b8ced9..b585c53c0114 100644 --- a/tests/libtest/lib1938.c +++ b/tests/libtest/lib1938.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1938(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1939.c b/tests/libtest/lib1939.c index 9985af5adc28..b3d79fc68dd1 100644 --- a/tests/libtest/lib1939.c +++ b/tests/libtest/lib1939.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1939(const char *URL) { CURLM *multi; diff --git a/tests/libtest/lib1940.c b/tests/libtest/lib1940.c index 283128dc31d6..75b8f7818c02 100644 --- a/tests/libtest/lib1940.c +++ b/tests/libtest/lib1940.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t1940_write_cb(char *data, size_t n, size_t l, void *userp) { /* take care of the data here, ignored in this example */ diff --git a/tests/libtest/lib1945.c b/tests/libtest/lib1945.c index ee8e69f10016..99044880cfe8 100644 --- a/tests/libtest/lib1945.c +++ b/tests/libtest/lib1945.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static void t1945_showem(CURL *curl, unsigned int type) { struct curl_header *header = NULL; diff --git a/tests/libtest/lib1947.c b/tests/libtest/lib1947.c index 19fbcb7af417..acbc260aa1d5 100644 --- a/tests/libtest/lib1947.c +++ b/tests/libtest/lib1947.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t1947_write_cb(char *data, size_t n, size_t l, void *userp) { /* ignore the data */ diff --git a/tests/libtest/lib1955.c b/tests/libtest/lib1955.c index e47a52275e74..3fe118269e82 100644 --- a/tests/libtest/lib1955.c +++ b/tests/libtest/lib1955.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1955(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1956.c b/tests/libtest/lib1956.c index 0f1c72e3d2e2..a86a4c9e4ca3 100644 --- a/tests/libtest/lib1956.c +++ b/tests/libtest/lib1956.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1956(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1957.c b/tests/libtest/lib1957.c index 8eeed09b7c34..c7864a150c47 100644 --- a/tests/libtest/lib1957.c +++ b/tests/libtest/lib1957.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1957(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1958.c b/tests/libtest/lib1958.c index 7a94c76709a3..9a7f12f286ab 100644 --- a/tests/libtest/lib1958.c +++ b/tests/libtest/lib1958.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1958(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1959.c b/tests/libtest/lib1959.c index d718149772e3..6739cfe3ab9e 100644 --- a/tests/libtest/lib1959.c +++ b/tests/libtest/lib1959.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1959(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1960.c b/tests/libtest/lib1960.c index 152b1053f133..2dbdf5995fd3 100644 --- a/tests/libtest/lib1960.c +++ b/tests/libtest/lib1960.c @@ -32,8 +32,6 @@ #include #endif -#include "memdebug.h" - /* to prevent libcurl from closing our socket */ static int closesocket_cb(void *clientp, curl_socket_t item) { diff --git a/tests/libtest/lib1964.c b/tests/libtest/lib1964.c index cbad31dcc00f..9536575ba82d 100644 --- a/tests/libtest/lib1964.c +++ b/tests/libtest/lib1964.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1964(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1970.c b/tests/libtest/lib1970.c index 5ba51f6a58f2..fa110462c2c6 100644 --- a/tests/libtest/lib1970.c +++ b/tests/libtest/lib1970.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1970(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1971.c b/tests/libtest/lib1971.c index bc25226bded6..982f06b28629 100644 --- a/tests/libtest/lib1971.c +++ b/tests/libtest/lib1971.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t1971_read_cb(char *ptr, size_t size, size_t nitems, void *userp) { (void)ptr; diff --git a/tests/libtest/lib1972.c b/tests/libtest/lib1972.c index ec9c9b06988f..7931e866bf70 100644 --- a/tests/libtest/lib1972.c +++ b/tests/libtest/lib1972.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1972(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1973.c b/tests/libtest/lib1973.c index e887e80c2e0b..2cc1c8ebfe0c 100644 --- a/tests/libtest/lib1973.c +++ b/tests/libtest/lib1973.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1973(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1974.c b/tests/libtest/lib1974.c index b2d0b59450ea..1534cfadeeba 100644 --- a/tests/libtest/lib1974.c +++ b/tests/libtest/lib1974.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1974(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1975.c b/tests/libtest/lib1975.c index d6c05a1251f2..c5b6568a07b1 100644 --- a/tests/libtest/lib1975.c +++ b/tests/libtest/lib1975.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t1975_read_cb(char *ptr, size_t size, size_t nitems, void *userp) { (void)ptr; diff --git a/tests/libtest/lib1977.c b/tests/libtest/lib1977.c index dae8bcbae70b..10412f66c0c4 100644 --- a/tests/libtest/lib1977.c +++ b/tests/libtest/lib1977.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1977(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1978.c b/tests/libtest/lib1978.c index 113f06da8f3b..6c06e727dcb1 100644 --- a/tests/libtest/lib1978.c +++ b/tests/libtest/lib1978.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1978(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib2023.c b/tests/libtest/lib2023.c index 8c181fa09338..1475deb2d3f8 100644 --- a/tests/libtest/lib2023.c +++ b/tests/libtest/lib2023.c @@ -28,14 +28,12 @@ #include "first.h" -#include "memdebug.h" - static CURLcode send_request(CURL *curl, const char *url, int seq, long auth_scheme, const char *userpwd) { CURLcode res; size_t len = strlen(url) + 4 + 1; - char *full_url = malloc(len); + char *full_url = curlx_malloc(len); if(!full_url) { curl_mfprintf(stderr, "Not enough memory for full url\n"); return CURLE_OUT_OF_MEMORY; @@ -54,7 +52,7 @@ static CURLcode send_request(CURL *curl, const char *url, int seq, res = curl_easy_perform(curl); test_cleanup: - free(full_url); + curlx_free(full_url); return res; } diff --git a/tests/libtest/lib2032.c b/tests/libtest/lib2032.c index e0f9990f59f4..a733f34e6fc0 100644 --- a/tests/libtest/lib2032.c +++ b/tests/libtest/lib2032.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #define MAX_EASY_HANDLES 3 static int ntlm_counter[MAX_EASY_HANDLES]; @@ -92,7 +90,7 @@ static CURLcode test_lib2032(const char *URL) /* libntlmconnect */ int num_handles = 0; enum HandleState state = ReadyForNewHandle; size_t urllen = strlen(URL) + 4 + 1; - char *full_url = malloc(urllen); + char *full_url = curlx_malloc(urllen); start_test_timing(); @@ -108,7 +106,7 @@ static CURLcode test_lib2032(const char *URL) /* libntlmconnect */ res_global_init(CURL_GLOBAL_ALL); if(res) { - free(full_url); + curlx_free(full_url); return res; } @@ -230,7 +228,7 @@ static CURLcode test_lib2032(const char *URL) /* libntlmconnect */ curl_multi_cleanup(multi); curl_global_cleanup(); - free(full_url); + curlx_free(full_url); return res; } diff --git a/tests/libtest/lib2302.c b/tests/libtest/lib2302.c index 47276197bb08..aa0be3d5140d 100644 --- a/tests/libtest/lib2302.c +++ b/tests/libtest/lib2302.c @@ -102,7 +102,7 @@ static CURLcode test_lib2302(const char *URL) global_init(CURL_GLOBAL_ALL); memset(&ws_data, 0, sizeof(ws_data)); - ws_data.buf = (char *)calloc(LIB2302_BUFSIZE, 1); + ws_data.buf = (char *)curlx_calloc(LIB2302_BUFSIZE, 1); if(ws_data.buf) { curl = curl_easy_init(); if(curl) { @@ -120,7 +120,7 @@ static CURLcode test_lib2302(const char *URL) curl_easy_cleanup(curl); flush_data(&ws_data); } - free(ws_data.buf); + curlx_free(ws_data.buf); } curl_global_cleanup(); return res; diff --git a/tests/libtest/lib2402.c b/tests/libtest/lib2402.c index 1695208716b1..58c1b6c431fe 100644 --- a/tests/libtest/lib2402.c +++ b/tests/libtest/lib2402.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib2402(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib2404.c b/tests/libtest/lib2404.c index 42d81d8d4ae6..93a3ef926f40 100644 --- a/tests/libtest/lib2404.c +++ b/tests/libtest/lib2404.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib2404(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib2405.c b/tests/libtest/lib2405.c index 4f3c8015c64e..97d0d5d231e5 100644 --- a/tests/libtest/lib2405.c +++ b/tests/libtest/lib2405.c @@ -39,8 +39,6 @@ #include "first.h" -#include "memdebug.h" - /* ---------------------------------------------------------------- */ #define test_check(expected_fds) \ diff --git a/tests/libtest/lib2502.c b/tests/libtest/lib2502.c index b9a2cabd798c..4b5e0ef6833e 100644 --- a/tests/libtest/lib2502.c +++ b/tests/libtest/lib2502.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static CURLcode test_lib2502(const char *URL) { diff --git a/tests/libtest/lib2700.c b/tests/libtest/lib2700.c index f50908964543..1760d243ea1a 100644 --- a/tests/libtest/lib2700.c +++ b/tests/libtest/lib2700.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" #ifndef CURL_DISABLE_WEBSOCKETS diff --git a/tests/libtest/lib3010.c b/tests/libtest/lib3010.c index 4595f4de3577..0f805c2d6f7f 100644 --- a/tests/libtest/lib3010.c +++ b/tests/libtest/lib3010.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3010(const char *URL) { CURLcode res = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib3025.c b/tests/libtest/lib3025.c index b0056193b772..7d94c4062684 100644 --- a/tests/libtest/lib3025.c +++ b/tests/libtest/lib3025.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3025(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib3027.c b/tests/libtest/lib3027.c index 5cd2bd757d86..7a25c214bb9b 100644 --- a/tests/libtest/lib3027.c +++ b/tests/libtest/lib3027.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3027(const char *URL) { CURLcode ret = CURLE_OK; diff --git a/tests/libtest/lib3033.c b/tests/libtest/lib3033.c index b00bba9e7466..428de8afc31d 100644 --- a/tests/libtest/lib3033.c +++ b/tests/libtest/lib3033.c @@ -25,8 +25,6 @@ #include "testtrace.h" -#include "memdebug.h" - static CURLcode t3033_req_test(CURLM *multi, CURL *curl, const char *URL, int index) { diff --git a/tests/libtest/lib3100.c b/tests/libtest/lib3100.c index b661aa76ceb1..e9a2b4111c77 100644 --- a/tests/libtest/lib3100.c +++ b/tests/libtest/lib3100.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3100(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib3101.c b/tests/libtest/lib3101.c index 3f5cbce17cbf..d95167f0ce6d 100644 --- a/tests/libtest/lib3101.c +++ b/tests/libtest/lib3101.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3101(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib3102.c b/tests/libtest/lib3102.c index 9cc87543dc87..72da47551e40 100644 --- a/tests/libtest/lib3102.c +++ b/tests/libtest/lib3102.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Verify correct order of certificates in the chain by comparing the * subject and issuer attributes of each certificate. diff --git a/tests/libtest/lib3103.c b/tests/libtest/lib3103.c index 5b25e1cd4175..4e3a0d79fd4d 100644 --- a/tests/libtest/lib3103.c +++ b/tests/libtest/lib3103.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3103(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib3104.c b/tests/libtest/lib3104.c index dd1500ede55c..278aa515b1de 100644 --- a/tests/libtest/lib3104.c +++ b/tests/libtest/lib3104.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3104(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib3105.c b/tests/libtest/lib3105.c index 808fd98ca4de..a3cbf28bb8b5 100644 --- a/tests/libtest/lib3105.c +++ b/tests/libtest/lib3105.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3105(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib3207.c b/tests/libtest/lib3207.c index 8ba88e4a66b6..7757643a269b 100644 --- a/tests/libtest/lib3207.c +++ b/tests/libtest/lib3207.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #ifdef USE_THREADS_POSIX #include #endif @@ -48,7 +46,7 @@ static size_t write_memory_callback(char *contents, size_t size, /* append the data to contents */ size_t realsize = size * nmemb; struct Ctx *mem = (struct Ctx *)userp; - char *data = (char *)malloc(realsize + 1); + char *data = (char *)curlx_malloc(realsize + 1); struct curl_slist *item_append = NULL; if(!data) { curl_mprintf("not enough memory (malloc returned NULL)\n"); @@ -57,7 +55,7 @@ static size_t write_memory_callback(char *contents, size_t size, memcpy(data, contents, realsize); data[realsize] = '\0'; item_append = curl_slist_append(mem->contents, data); - free(data); + curlx_free(data); if(item_append) { mem->contents = item_append; } diff --git a/tests/libtest/lib3208.c b/tests/libtest/lib3208.c index 39585c159775..befa92e6d0ca 100644 --- a/tests/libtest/lib3208.c +++ b/tests/libtest/lib3208.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3208(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib500.c b/tests/libtest/lib500.c index ff886a05ca60..0d01b0102649 100644 --- a/tests/libtest/lib500.c +++ b/tests/libtest/lib500.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static int testcounter; diff --git a/tests/libtest/lib501.c b/tests/libtest/lib501.c index d761c8a63604..3dbed1cd4ff5 100644 --- a/tests/libtest/lib501.c +++ b/tests/libtest/lib501.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib501(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib502.c b/tests/libtest/lib502.c index c33783ea687a..4e1fc14a97a7 100644 --- a/tests/libtest/lib502.c +++ b/tests/libtest/lib502.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Get a single URL without select(). */ diff --git a/tests/libtest/lib503.c b/tests/libtest/lib503.c index 34a6105bf7ae..48f0b671b91a 100644 --- a/tests/libtest/lib503.c +++ b/tests/libtest/lib503.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Source code in here hugely as reported in bug report 651460 by * Christopher R. Palmer. diff --git a/tests/libtest/lib504.c b/tests/libtest/lib504.c index fa9338f262ec..996130c246d4 100644 --- a/tests/libtest/lib504.c +++ b/tests/libtest/lib504.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Source code in here hugely as reported in bug report 651464 by * Christopher R. Palmer. diff --git a/tests/libtest/lib505.c b/tests/libtest/lib505.c index 37cc1e0b3f8c..b28a01a9ce05 100644 --- a/tests/libtest/lib505.c +++ b/tests/libtest/lib505.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * This example shows an FTP upload, with a rename of the file just after * a successful upload. diff --git a/tests/libtest/lib506.c b/tests/libtest/lib506.c index 928c33b13cc3..3d2a3556fdb0 100644 --- a/tests/libtest/lib506.c +++ b/tests/libtest/lib506.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" #define THREADS 2 diff --git a/tests/libtest/lib507.c b/tests/libtest/lib507.c index 9a306d39a656..0496099ce204 100644 --- a/tests/libtest/lib507.c +++ b/tests/libtest/lib507.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib507(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib508.c b/tests/libtest/lib508.c index a4c25b7918f6..697505150056 100644 --- a/tests/libtest/lib508.c +++ b/tests/libtest/lib508.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t508_WriteThis { const char *readptr; size_t sizeleft; diff --git a/tests/libtest/lib509.c b/tests/libtest/lib509.c index a8be3eae5221..b5a0c583e072 100644 --- a/tests/libtest/lib509.c +++ b/tests/libtest/lib509.c @@ -29,9 +29,8 @@ * libcurl and that it works unconditionally no matter how libcurl is built, * nothing more. * - * Do not include memdebug.h in this source file, and do not use directly - * memory related functions in this file except those used inside custom - * memory callbacks which should be calling 'the real thing'. + * Do not use directly memory related functions in this file except those used + * inside custom memory callbacks which should be calling 'the real thing'. */ static int seen; @@ -39,31 +38,40 @@ static int seen; static void *custom_calloc(size_t nmemb, size_t size) { seen++; - return (calloc)(nmemb, size); + /* !checksrc! disable BANNEDFUNC 1 */ + return calloc(nmemb, size); } static void *custom_malloc(size_t size) { seen++; - return (malloc)(size); + /* !checksrc! disable BANNEDFUNC 1 */ + return malloc(size); } static char *custom_strdup(const char *ptr) { seen++; - return (strdup)(ptr); +#ifdef _WIN32 + return _strdup(ptr); +#else + /* !checksrc! disable BANNEDFUNC 1 */ + return strdup(ptr); +#endif } static void *custom_realloc(void *ptr, size_t size) { seen++; - return (realloc)(ptr, size); + /* !checksrc! disable BANNEDFUNC 1 */ + return realloc(ptr, size); } static void custom_free(void *ptr) { seen++; - (free)(ptr); + /* !checksrc! disable BANNEDFUNC 1 */ + free(ptr); } @@ -95,10 +103,11 @@ static CURLcode test_lib509(const char *URL) return TEST_ERR_MAJOR_BAD; } - test_setopt(curl, CURLOPT_USERAGENT, "test509"); /* uses strdup() */ + test_setopt(curl, CURLOPT_USERAGENT, "test509"); /* uses curlx_strdup() */ asize = (int)sizeof(a); - str = curl_easy_escape(curl, (const char *)a, asize); /* uses realloc() */ + /* uses curlx_realloc() */ + str = curl_easy_escape(curl, (const char *)a, asize); if(seen) curl_mprintf("Callbacks were invoked!\n"); diff --git a/tests/libtest/lib510.c b/tests/libtest/lib510.c index da270c1c9213..d2df0eaf203b 100644 --- a/tests/libtest/lib510.c +++ b/tests/libtest/lib510.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t510_WriteThis { int counter; }; diff --git a/tests/libtest/lib511.c b/tests/libtest/lib511.c index 1db409378098..c4e78a1117ec 100644 --- a/tests/libtest/lib511.c +++ b/tests/libtest/lib511.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib511(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib512.c b/tests/libtest/lib512.c index 59a1cd7595d5..be7187542a14 100644 --- a/tests/libtest/lib512.c +++ b/tests/libtest/lib512.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* Test case code based on source in a bug report filed by James Bursa on 28 Apr 2004 */ diff --git a/tests/libtest/lib513.c b/tests/libtest/lib513.c index 3d0afb1191b9..1458971007ec 100644 --- a/tests/libtest/lib513.c +++ b/tests/libtest/lib513.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t513_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) { (void)ptr; diff --git a/tests/libtest/lib514.c b/tests/libtest/lib514.c index f47cdb321d58..0ce96f5be81f 100644 --- a/tests/libtest/lib514.c +++ b/tests/libtest/lib514.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib514(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib515.c b/tests/libtest/lib515.c index d9814525df55..b0d3a65d5073 100644 --- a/tests/libtest/lib515.c +++ b/tests/libtest/lib515.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib515(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib516.c b/tests/libtest/lib516.c index b7778a6a76c8..42b63c9d87d0 100644 --- a/tests/libtest/lib516.c +++ b/tests/libtest/lib516.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib516(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib517.c b/tests/libtest/lib517.c index 01d3ac4bad1a..843c5c03f0ef 100644 --- a/tests/libtest/lib517.c +++ b/tests/libtest/lib517.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib517(const char *URL) { struct dcheck { diff --git a/tests/libtest/lib518.c b/tests/libtest/lib518.c index b8a9ec4a6a84..d785857bb1c0 100644 --- a/tests/libtest/lib518.c +++ b/tests/libtest/lib518.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" #ifndef FD_SETSIZE #error "this test requires FD_SETSIZE" @@ -65,7 +64,7 @@ static void t518_close_file_descriptors(void) t518_num_open.rlim_cur++) if(t518_testfd[t518_num_open.rlim_cur] > 0) close(t518_testfd[t518_num_open.rlim_cur]); - free(t518_testfd); + curlx_free(t518_testfd); t518_testfd = NULL; } @@ -213,8 +212,8 @@ static int t518_test_rlimit(int keep_open) * avoid a low memory condition once the file descriptors are * open. System conditions that could make the test fail should * be addressed in the precheck phase. This chunk of memory shall - * be always free()ed before exiting the t518_test_rlimit() function so - * that it becomes available to the test. + * be always curlx_free()ed before exiting the t518_test_rlimit() + * function so that it becomes available to the test. */ for(nitems = i = 1; nitems <= i; i *= 2) @@ -225,7 +224,7 @@ static int t518_test_rlimit(int keep_open) t518_num_open.rlim_max = sizeof(*memchunk) * nitems; tutil_rlim2str(strbuff, sizeof(strbuff), t518_num_open.rlim_max); curl_mfprintf(stderr, "allocating memchunk %s byte array\n", strbuff); - memchunk = malloc(sizeof(*memchunk) * (size_t)nitems); + memchunk = curlx_malloc(sizeof(*memchunk) * (size_t)nitems); if(!memchunk) { curl_mfprintf(stderr, "memchunk, malloc() failed\n"); nitems /= 2; @@ -248,7 +247,7 @@ static int t518_test_rlimit(int keep_open) t518_num_open.rlim_max = NUM_OPEN; - /* verify that we do not overflow size_t in malloc() */ + /* verify that we do not overflow size_t in curlx_malloc() */ if((size_t)(t518_num_open.rlim_max) > ((size_t)-1) / sizeof(*t518_testfd)) { tutil_rlim2str(strbuff1, sizeof(strbuff1), t518_num_open.rlim_max); @@ -257,7 +256,7 @@ static int t518_test_rlimit(int keep_open) "file descriptors, would overflow size_t", strbuff1); t518_store_errmsg(strbuff, 0); curl_mfprintf(stderr, "%s\n", t518_msgbuff); - free(memchunk); + curlx_free(memchunk); return -6; } @@ -266,12 +265,12 @@ static int t518_test_rlimit(int keep_open) tutil_rlim2str(strbuff, sizeof(strbuff), t518_num_open.rlim_max); curl_mfprintf(stderr, "allocating array for %s file descriptors\n", strbuff); - t518_testfd = malloc(sizeof(*t518_testfd) * - (size_t)(t518_num_open.rlim_max)); + t518_testfd = curlx_malloc(sizeof(*t518_testfd) * + (size_t)(t518_num_open.rlim_max)); if(!t518_testfd) { t518_store_errmsg("testfd, malloc() failed", errno); curl_mfprintf(stderr, "%s\n", t518_msgbuff); - free(memchunk); + curlx_free(memchunk); return -7; } @@ -294,9 +293,9 @@ static int t518_test_rlimit(int keep_open) curl_msnprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL); t518_store_errmsg(strbuff, errno); curl_mfprintf(stderr, "%s\n", t518_msgbuff); - free(t518_testfd); + curlx_free(t518_testfd); t518_testfd = NULL; - free(memchunk); + curlx_free(memchunk); return -8; } @@ -335,9 +334,9 @@ static int t518_test_rlimit(int keep_open) t518_testfd[t518_num_open.rlim_cur] >= 0; t518_num_open.rlim_cur++) close(t518_testfd[t518_num_open.rlim_cur]); - free(t518_testfd); + curlx_free(t518_testfd); t518_testfd = NULL; - free(memchunk); + curlx_free(memchunk); return -9; } } @@ -365,7 +364,7 @@ static int t518_test_rlimit(int keep_open) t518_store_errmsg(strbuff, 0); curl_mfprintf(stderr, "%s\n", t518_msgbuff); t518_close_file_descriptors(); - free(memchunk); + curlx_free(memchunk); return -10; } @@ -380,7 +379,7 @@ static int t518_test_rlimit(int keep_open) t518_store_errmsg(strbuff, 0); curl_mfprintf(stderr, "%s\n", t518_msgbuff); t518_close_file_descriptors(); - free(memchunk); + curlx_free(memchunk); return -11; } } @@ -405,14 +404,14 @@ static int t518_test_rlimit(int keep_open) "fopen fails with lots of fds open"); t518_store_errmsg(strbuff, 0); t518_close_file_descriptors(); - free(memchunk); + curlx_free(memchunk); return -12; } /* free the chunk of memory we were reserving so that it becomes available to the test */ - free(memchunk); + curlx_free(memchunk); /* close file descriptors unless instructed to keep them */ diff --git a/tests/libtest/lib519.c b/tests/libtest/lib519.c index 615e8aac8a52..0d2f23e0d355 100644 --- a/tests/libtest/lib519.c +++ b/tests/libtest/lib519.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib519(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib520.c b/tests/libtest/lib520.c index 34f7c541e222..b3e67864e21e 100644 --- a/tests/libtest/lib520.c +++ b/tests/libtest/lib520.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib520(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib521.c b/tests/libtest/lib521.c index acfec703811f..0d2bacd16de1 100644 --- a/tests/libtest/lib521.c +++ b/tests/libtest/lib521.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib521(const char *URL) { CURLcode res = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib523.c b/tests/libtest/lib523.c index 3b56ada894e8..60648a7da1fc 100644 --- a/tests/libtest/lib523.c +++ b/tests/libtest/lib523.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib523(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib524.c b/tests/libtest/lib524.c index e015e58637eb..5b7e01c087b5 100644 --- a/tests/libtest/lib524.c +++ b/tests/libtest/lib524.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib524(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib525.c b/tests/libtest/lib525.c index 4ca7ab7d6545..abc75644ce5b 100644 --- a/tests/libtest/lib525.c +++ b/tests/libtest/lib525.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib525(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib526.c b/tests/libtest/lib526.c index 6f586c5a3e54..a4d5ab6b1a1e 100644 --- a/tests/libtest/lib526.c +++ b/tests/libtest/lib526.c @@ -42,8 +42,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib526(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib530.c b/tests/libtest/lib530.c index e7e86a32ccbb..429a4869f5c9 100644 --- a/tests/libtest/lib530.c +++ b/tests/libtest/lib530.c @@ -30,9 +30,6 @@ #include "first.h" -#include "memdebug.h" - - static struct t530_ctx { int socket_calls; int max_socket_calls; @@ -106,14 +103,15 @@ static int t530_addFd(struct t530_Sockets *sockets, curl_socket_t fd, * Allocate array storage when required. */ if(!sockets->sockets) { - sockets->sockets = malloc(sizeof(curl_socket_t) * 20U); + sockets->sockets = curlx_malloc(sizeof(curl_socket_t) * 20U); if(!sockets->sockets) return 1; sockets->max_count = 20; } else if(sockets->count + 1 > sockets->max_count) { - curl_socket_t *ptr = realloc(sockets->sockets, sizeof(curl_socket_t) * - (sockets->max_count + 20)); + curl_socket_t *ptr = curlx_realloc(sockets->sockets, + sizeof(curl_socket_t) * + (sockets->max_count + 20)); if(!ptr) /* cleanup in test_cleanup */ return 1; @@ -390,8 +388,8 @@ static CURLcode testone(const char *URL, int timer_fail_at, int socket_fail_at) curl_global_cleanup(); /* free local memory */ - free(sockets.read.sockets); - free(sockets.write.sockets); + curlx_free(sockets.read.sockets); + curlx_free(sockets.write.sockets); t530_msg("done"); return res; diff --git a/tests/libtest/lib533.c b/tests/libtest/lib533.c index 8f3b0f1474c0..b730960695a6 100644 --- a/tests/libtest/lib533.c +++ b/tests/libtest/lib533.c @@ -25,8 +25,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib533(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib536.c b/tests/libtest/lib536.c index c0107ed9cbdc..4810aba83fc3 100644 --- a/tests/libtest/lib536.c +++ b/tests/libtest/lib536.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static void proxystat(CURL *curl) { long wasproxy; diff --git a/tests/libtest/lib537.c b/tests/libtest/lib537.c index 02d4a89b26a6..8027a09c0286 100644 --- a/tests/libtest/lib537.c +++ b/tests/libtest/lib537.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" #if !defined(HAVE_POLL) && !defined(USE_WINSOCK) && !defined(FD_SETSIZE) #error "this test requires FD_SETSIZE" @@ -62,7 +61,7 @@ static void t537_close_file_descriptors(void) t537_num_open.rlim_cur++) if(t537_testfd[t537_num_open.rlim_cur] > 0) close(t537_testfd[t537_num_open.rlim_cur]); - free(t537_testfd); + curlx_free(t537_testfd); t537_testfd = NULL; } @@ -193,8 +192,8 @@ static int t537_test_rlimit(int keep_open) * avoid a low memory condition once the file descriptors are * open. System conditions that could make the test fail should * be addressed in the precheck phase. This chunk of memory shall - * be always free()ed before exiting the t537_test_rlimit() function so - * that it becomes available to the test. + * be always curlx_free()ed before exiting the t537_test_rlimit() + * function so that it becomes available to the test. */ for(nitems = i = 1; nitems <= i; i *= 2) @@ -205,7 +204,7 @@ static int t537_test_rlimit(int keep_open) t537_num_open.rlim_max = sizeof(*memchunk) * nitems; tutil_rlim2str(strbuff, sizeof(strbuff), t537_num_open.rlim_max); curl_mfprintf(stderr, "allocating memchunk %s byte array\n", strbuff); - memchunk = malloc(sizeof(*memchunk) * (size_t)nitems); + memchunk = curlx_malloc(sizeof(*memchunk) * (size_t)nitems); if(!memchunk) { curl_mfprintf(stderr, "memchunk, malloc() failed\n"); nitems /= 2; @@ -243,7 +242,7 @@ static int t537_test_rlimit(int keep_open) t537_num_open.rlim_max = nitems; } - /* verify that we do not overflow size_t in malloc() */ + /* verify that we do not overflow size_t in curlx_malloc() */ if((size_t)(t537_num_open.rlim_max) > ((size_t)-1) / sizeof(*t537_testfd)) { tutil_rlim2str(strbuff1, sizeof(strbuff1), t537_num_open.rlim_max); @@ -252,7 +251,7 @@ static int t537_test_rlimit(int keep_open) "file descriptors, would overflow size_t", strbuff1); t537_store_errmsg(strbuff, 0); curl_mfprintf(stderr, "%s\n", t537_msgbuff); - free(memchunk); + curlx_free(memchunk); return -5; } @@ -263,8 +262,8 @@ static int t537_test_rlimit(int keep_open) curl_mfprintf(stderr, "allocating array for %s file descriptors\n", strbuff); - t537_testfd = malloc(sizeof(*t537_testfd) * - (size_t)(t537_num_open.rlim_max)); + t537_testfd = curlx_malloc(sizeof(*t537_testfd) * + (size_t)(t537_num_open.rlim_max)); if(!t537_testfd) { curl_mfprintf(stderr, "testfd, malloc() failed\n"); t537_num_open.rlim_max /= 2; @@ -273,7 +272,7 @@ static int t537_test_rlimit(int keep_open) if(!t537_testfd) { t537_store_errmsg("testfd, malloc() failed", errno); curl_mfprintf(stderr, "%s\n", t537_msgbuff); - free(memchunk); + curlx_free(memchunk); return -6; } @@ -296,9 +295,9 @@ static int t537_test_rlimit(int keep_open) curl_msnprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL); t537_store_errmsg(strbuff, errno); curl_mfprintf(stderr, "%s\n", t537_msgbuff); - free(t537_testfd); + curlx_free(t537_testfd); t537_testfd = NULL; - free(memchunk); + curlx_free(memchunk); return -7; } @@ -345,8 +344,9 @@ static int t537_test_rlimit(int keep_open) /* we do not care if we cannot shrink it */ - tmpfd = realloc(t537_testfd, - sizeof(*t537_testfd) * (size_t)(t537_num_open.rlim_max)); + tmpfd = curlx_realloc(t537_testfd, + sizeof(*t537_testfd) * + (size_t)(t537_num_open.rlim_max)); if(tmpfd) { t537_testfd = tmpfd; tmpfd = NULL; @@ -379,7 +379,7 @@ static int t537_test_rlimit(int keep_open) t537_store_errmsg(strbuff, 0); curl_mfprintf(stderr, "%s\n", t537_msgbuff); t537_close_file_descriptors(); - free(memchunk); + curlx_free(memchunk); return -8; } @@ -394,7 +394,7 @@ static int t537_test_rlimit(int keep_open) t537_store_errmsg(strbuff, 0); curl_mfprintf(stderr, "%s\n", t537_msgbuff); t537_close_file_descriptors(); - free(memchunk); + curlx_free(memchunk); return -9; } } @@ -419,14 +419,14 @@ static int t537_test_rlimit(int keep_open) "fopen fails with lots of fds open"); t537_store_errmsg(strbuff, 0); t537_close_file_descriptors(); - free(memchunk); + curlx_free(memchunk); return -10; } /* free the chunk of memory we were reserving so that it becomes available to the test */ - free(memchunk); + curlx_free(memchunk); /* close file descriptors unless instructed to keep them */ diff --git a/tests/libtest/lib539.c b/tests/libtest/lib539.c index e4e26c204a13..1e6c0fb0ef2f 100644 --- a/tests/libtest/lib539.c +++ b/tests/libtest/lib539.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib539(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib540.c b/tests/libtest/lib540.c index 55d5adad0742..5e8890d98421 100644 --- a/tests/libtest/lib540.c +++ b/tests/libtest/lib540.c @@ -32,8 +32,6 @@ #include "first.h" -#include "memdebug.h" - static CURL *t540_curl[2]; static CURLcode init(int num, CURLM *multi, const char *url, diff --git a/tests/libtest/lib541.c b/tests/libtest/lib541.c index ebab472456b5..891c2de52585 100644 --- a/tests/libtest/lib541.c +++ b/tests/libtest/lib541.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Two FTP uploads, the second with no content sent. */ diff --git a/tests/libtest/lib542.c b/tests/libtest/lib542.c index b29a2733fffd..d6689517c7d2 100644 --- a/tests/libtest/lib542.c +++ b/tests/libtest/lib542.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * FTP get with NOBODY but no HEADER */ diff --git a/tests/libtest/lib543.c b/tests/libtest/lib543.c index 579a71a6117c..9938d269addc 100644 --- a/tests/libtest/lib543.c +++ b/tests/libtest/lib543.c @@ -25,8 +25,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib543(const char *URL) { static const unsigned char a[] = { diff --git a/tests/libtest/lib544.c b/tests/libtest/lib544.c index d0ed914051ed..0d72af3042d5 100644 --- a/tests/libtest/lib544.c +++ b/tests/libtest/lib544.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib544(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib547.c b/tests/libtest/lib547.c index 9184d933a882..8f51fef088d8 100644 --- a/tests/libtest/lib547.c +++ b/tests/libtest/lib547.c @@ -28,8 +28,6 @@ #include "first.h" -#include "memdebug.h" - static const char t547_uploadthis[] = "this is the blurb we want to upload\n"; #define T547_DATALEN (sizeof(t547_uploadthis)-1) diff --git a/tests/libtest/lib549.c b/tests/libtest/lib549.c index 4eaacf5868a4..2793f92bcb51 100644 --- a/tests/libtest/lib549.c +++ b/tests/libtest/lib549.c @@ -28,8 +28,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib549(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib552.c b/tests/libtest/lib552.c index 3d5b09c1ec3f..403ad6fec196 100644 --- a/tests/libtest/lib552.c +++ b/tests/libtest/lib552.c @@ -28,7 +28,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static size_t current_offset = 0; static char databuf[70000]; /* MUST be more than 64k OR diff --git a/tests/libtest/lib553.c b/tests/libtest/lib553.c index 0d44573131ec..4bc2568a46fd 100644 --- a/tests/libtest/lib553.c +++ b/tests/libtest/lib553.c @@ -28,8 +28,6 @@ #include "first.h" -#include "memdebug.h" - #define POSTLEN 40960 static size_t myreadfunc(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib554.c b/tests/libtest/lib554.c index 230da065a1b4..dd8c690ddbc3 100644 --- a/tests/libtest/lib554.c +++ b/tests/libtest/lib554.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t554_WriteThis { const char *readptr; size_t sizeleft; diff --git a/tests/libtest/lib555.c b/tests/libtest/lib555.c index 19e0480e2a51..005fefe72ff8 100644 --- a/tests/libtest/lib555.c +++ b/tests/libtest/lib555.c @@ -32,8 +32,6 @@ #include "first.h" -#include "memdebug.h" - static const char t555_uploadthis[] = "this is the blurb we want to upload\n"; #define T555_DATALEN (sizeof(t555_uploadthis)-1) diff --git a/tests/libtest/lib556.c b/tests/libtest/lib556.c index daf92fe1e600..cdf9ebe94194 100644 --- a/tests/libtest/lib556.c +++ b/tests/libtest/lib556.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib556(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib557.c b/tests/libtest/lib557.c index 38d93a687e81..fa1ee2fa2fbc 100644 --- a/tests/libtest/lib557.c +++ b/tests/libtest/lib557.c @@ -33,8 +33,6 @@ # include /* for setlocale() */ #endif -#include "memdebug.h" - #if defined(CURL_GNUC_DIAG) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat" diff --git a/tests/libtest/lib558.c b/tests/libtest/lib558.c index c82b6ee969de..94dd7f57b80f 100644 --- a/tests/libtest/lib558.c +++ b/tests/libtest/lib558.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib558(const char *URL) { unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, @@ -40,7 +38,7 @@ static CURLcode test_lib558(const char *URL) return TEST_ERR_MAJOR_BAD; } - ptr = malloc(558); + ptr = curlx_malloc(558); Curl_safefree(ptr); asize = (int)sizeof(a); diff --git a/tests/libtest/lib559.c b/tests/libtest/lib559.c index 36a557512652..bf9cd86e639e 100644 --- a/tests/libtest/lib559.c +++ b/tests/libtest/lib559.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib559(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib560.c b/tests/libtest/lib560.c index 45f137aabeb7..fc156f43d795 100644 --- a/tests/libtest/lib560.c +++ b/tests/libtest/lib560.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Simply download an HTTPS file! * diff --git a/tests/libtest/lib562.c b/tests/libtest/lib562.c index 3f2c912c9173..fbe2560147df 100644 --- a/tests/libtest/lib562.c +++ b/tests/libtest/lib562.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * From "KNOWN_BUGS" April 2009: diff --git a/tests/libtest/lib564.c b/tests/libtest/lib564.c index b105fc710e6b..56acfe40f72a 100644 --- a/tests/libtest/lib564.c +++ b/tests/libtest/lib564.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static CURLcode test_lib564(const char *URL) { diff --git a/tests/libtest/lib566.c b/tests/libtest/lib566.c index 79f48f235b2c..89adbdbd9c75 100644 --- a/tests/libtest/lib566.c +++ b/tests/libtest/lib566.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib566(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib567.c b/tests/libtest/lib567.c index a11a6c31f010..95b66f102c25 100644 --- a/tests/libtest/lib567.c +++ b/tests/libtest/lib567.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Test a simple OPTIONS request with a custom header */ diff --git a/tests/libtest/lib568.c b/tests/libtest/lib568.c index 5465ca0c8be8..260061f5191f 100644 --- a/tests/libtest/lib568.c +++ b/tests/libtest/lib568.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" /* * Test the Client->Server ANNOUNCE functionality (PUT style) diff --git a/tests/libtest/lib569.c b/tests/libtest/lib569.c index 1c44153d009f..77e0471e5f4e 100644 --- a/tests/libtest/lib569.c +++ b/tests/libtest/lib569.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" /* * Test Session ID capture diff --git a/tests/libtest/lib570.c b/tests/libtest/lib570.c index 300881efa7b7..f5ada6770b2e 100644 --- a/tests/libtest/lib570.c +++ b/tests/libtest/lib570.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" static CURLcode test_lib570(const char *URL) { diff --git a/tests/libtest/lib571.c b/tests/libtest/lib571.c index 509557f0f50b..678141b1c545 100644 --- a/tests/libtest/lib571.c +++ b/tests/libtest/lib571.c @@ -34,7 +34,6 @@ #endif #include "testutil.h" -#include "memdebug.h" #define RTP_PKT_CHANNEL(p) ((int)((unsigned char)((p)[1]))) diff --git a/tests/libtest/lib572.c b/tests/libtest/lib572.c index 2865372f5fef..4e20cb3da5b8 100644 --- a/tests/libtest/lib572.c +++ b/tests/libtest/lib572.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" /* * Test GET_PARAMETER: PUT, HEARTBEAT, and POST diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c index 38612df7b58c..ed00bbb04243 100644 --- a/tests/libtest/lib573.c +++ b/tests/libtest/lib573.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" /* * Get a single URL without select(). diff --git a/tests/libtest/lib574.c b/tests/libtest/lib574.c index e82be6c0d663..f74371e97383 100644 --- a/tests/libtest/lib574.c +++ b/tests/libtest/lib574.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static int new_fnmatch(void *ptr, const char *pattern, const char *string) { diff --git a/tests/libtest/lib575.c b/tests/libtest/lib575.c index 36efe6ef5a66..4709708a52bd 100644 --- a/tests/libtest/lib575.c +++ b/tests/libtest/lib575.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* 3x download! * 1. normal * 2. dup handle diff --git a/tests/libtest/lib576.c b/tests/libtest/lib576.c index 11c0f76d1390..7ee7bc9525d4 100644 --- a/tests/libtest/lib576.c +++ b/tests/libtest/lib576.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct chunk_data { int remains; int print_content; diff --git a/tests/libtest/lib578.c b/tests/libtest/lib578.c index b6be1600f4c9..799821123df2 100644 --- a/tests/libtest/lib578.c +++ b/tests/libtest/lib578.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* The size of data should be kept below MAX_INITIAL_POST_SIZE! */ static char t578_testdata[] = "this is a short string.\n"; diff --git a/tests/libtest/lib579.c b/tests/libtest/lib579.c index 9e626c130002..aaa81baedeb1 100644 --- a/tests/libtest/lib579.c +++ b/tests/libtest/lib579.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t579_WriteThis { int counter; }; diff --git a/tests/libtest/lib582.c b/tests/libtest/lib582.c index 4318096e1f79..e99d5febdfab 100644 --- a/tests/libtest/lib582.c +++ b/tests/libtest/lib582.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t582_Sockets { curl_socket_t *sockets; int count; /* number of sockets actually stored in array */ @@ -72,7 +70,7 @@ static void t582_addFd(struct t582_Sockets *sockets, curl_socket_t fd, * Allocate array storage when required. */ if(!sockets->sockets) { - sockets->sockets = malloc(sizeof(curl_socket_t) * 20U); + sockets->sockets = curlx_malloc(sizeof(curl_socket_t) * 20U); if(!sockets->sockets) return; sockets->max_count = 20; @@ -359,8 +357,8 @@ static CURLcode test_lib582(const char *URL) curlx_fclose(hd_src); /* free local memory */ - free(sockets.read.sockets); - free(sockets.write.sockets); + curlx_free(sockets.read.sockets); + curlx_free(sockets.write.sockets); return res; } diff --git a/tests/libtest/lib583.c b/tests/libtest/lib583.c index 510c5a3bdcf6..8f29e310c7ed 100644 --- a/tests/libtest/lib583.c +++ b/tests/libtest/lib583.c @@ -28,8 +28,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib583(const char *URL) { int stillRunning; diff --git a/tests/libtest/lib586.c b/tests/libtest/lib586.c index dac6751b3587..d0671b18fec3 100644 --- a/tests/libtest/lib586.c +++ b/tests/libtest/lib586.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #define THREADS 2 /* struct containing data of a thread */ diff --git a/tests/libtest/lib589.c b/tests/libtest/lib589.c index 9b912ab037d8..46b2a22a05f2 100644 --- a/tests/libtest/lib589.c +++ b/tests/libtest/lib589.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib589(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib590.c b/tests/libtest/lib590.c index c804f995dee9..bba31e9da4e2 100644 --- a/tests/libtest/lib590.c +++ b/tests/libtest/lib590.c @@ -37,8 +37,6 @@ - Start the request */ -#include "memdebug.h" - static CURLcode test_lib590(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib591.c b/tests/libtest/lib591.c index c30bde5e8be4..521cbb7503ab 100644 --- a/tests/libtest/lib591.c +++ b/tests/libtest/lib591.c @@ -25,8 +25,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib591(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib597.c b/tests/libtest/lib597.c index e82d061a222e..38e60c084486 100644 --- a/tests/libtest/lib597.c +++ b/tests/libtest/lib597.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Test case for below scenario: * - Connect to an FTP server using CONNECT_ONLY option diff --git a/tests/libtest/lib598.c b/tests/libtest/lib598.c index 56330c4a2448..b42743845d62 100644 --- a/tests/libtest/lib598.c +++ b/tests/libtest/lib598.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib598(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib599.c b/tests/libtest/lib599.c index 199ef90dbf8c..a216aa13a38e 100644 --- a/tests/libtest/lib599.c +++ b/tests/libtest/lib599.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static int t599_progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) { diff --git a/tests/libtest/lib643.c b/tests/libtest/lib643.c index d74d7ea9ee03..52ea1eb664cc 100644 --- a/tests/libtest/lib643.c +++ b/tests/libtest/lib643.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t643_WriteThis { const char *readptr; curl_off_t sizeleft; diff --git a/tests/libtest/lib650.c b/tests/libtest/lib650.c index 069e94f8e5ce..4aa6ea9d8bb4 100644 --- a/tests/libtest/lib650.c +++ b/tests/libtest/lib650.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* This test attempts to use all form API features that are not * used elsewhere. */ diff --git a/tests/libtest/lib651.c b/tests/libtest/lib651.c index 05e9e381da9c..7d1d28563f15 100644 --- a/tests/libtest/lib651.c +++ b/tests/libtest/lib651.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib651(const char *URL) { static char testbuf[17000]; /* more than 16K */ diff --git a/tests/libtest/lib652.c b/tests/libtest/lib652.c index dcbc5a3ab3f8..4fae340042b0 100644 --- a/tests/libtest/lib652.c +++ b/tests/libtest/lib652.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib652(const char *URL) { static char testbuf[17000]; /* more than 16K */ diff --git a/tests/libtest/lib653.c b/tests/libtest/lib653.c index 21948a5720e6..8447706958e0 100644 --- a/tests/libtest/lib653.c +++ b/tests/libtest/lib653.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib653(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib654.c b/tests/libtest/lib654.c index 5b2236ebb044..1d93798d7c10 100644 --- a/tests/libtest/lib654.c +++ b/tests/libtest/lib654.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t654_WriteThis { const char *readptr; curl_off_t sizeleft; diff --git a/tests/libtest/lib655.c b/tests/libtest/lib655.c index a213a1c493b3..3a8e0df43473 100644 --- a/tests/libtest/lib655.c +++ b/tests/libtest/lib655.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static const char *TEST_DATA_STRING = "Test data"; static int cb_count = 0; diff --git a/tests/libtest/lib658.c b/tests/libtest/lib658.c index 4f0f867d65de..edcb26333822 100644 --- a/tests/libtest/lib658.c +++ b/tests/libtest/lib658.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Get a single URL without select(). */ diff --git a/tests/libtest/lib659.c b/tests/libtest/lib659.c index 84c3ecc8cd46..5071e7fa267d 100644 --- a/tests/libtest/lib659.c +++ b/tests/libtest/lib659.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Get a single URL without select(). */ diff --git a/tests/libtest/lib661.c b/tests/libtest/lib661.c index 10a4ab99cee7..7cf6d091339b 100644 --- a/tests/libtest/lib661.c +++ b/tests/libtest/lib661.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib661(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib666.c b/tests/libtest/lib666.c index cff244dafb1c..f47bacb9a807 100644 --- a/tests/libtest/lib666.c +++ b/tests/libtest/lib666.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib666(const char *URL) { static char testbuf[17000]; /* more than 16K */ diff --git a/tests/libtest/lib667.c b/tests/libtest/lib667.c index 2827d0051194..1bd612f37797 100644 --- a/tests/libtest/lib667.c +++ b/tests/libtest/lib667.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t667_WriteThis { const char *readptr; curl_off_t sizeleft; diff --git a/tests/libtest/lib668.c b/tests/libtest/lib668.c index 488f86215247..5011391736b1 100644 --- a/tests/libtest/lib668.c +++ b/tests/libtest/lib668.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t668_WriteThis { const char *readptr; curl_off_t sizeleft; diff --git a/tests/libtest/lib670.c b/tests/libtest/lib670.c index b30d097f68ff..e97b04319e3c 100644 --- a/tests/libtest/lib670.c +++ b/tests/libtest/lib670.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #define PAUSE_TIME 5 struct t670_ReadThis { diff --git a/tests/libtest/lib674.c b/tests/libtest/lib674.c index 668ecdf32d14..c84d1af05db8 100644 --- a/tests/libtest/lib674.c +++ b/tests/libtest/lib674.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Get a single URL without select(). */ diff --git a/tests/libtest/lib676.c b/tests/libtest/lib676.c index 63437523df88..17494b73e7de 100644 --- a/tests/libtest/lib676.c +++ b/tests/libtest/lib676.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib676(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib677.c b/tests/libtest/lib677.c index 526e1706c376..089202b5c591 100644 --- a/tests/libtest/lib677.c +++ b/tests/libtest/lib677.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib677(const char *URL) { static const char testcmd[] = "A1 IDLE\r\n"; diff --git a/tests/libtest/lib678.c b/tests/libtest/lib678.c index 2a2e21321f79..ed8731d20d5b 100644 --- a/tests/libtest/lib678.c +++ b/tests/libtest/lib678.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static int loadfile(const char *filename, void **filedata, size_t *filesize) { size_t datasize = 0; @@ -44,13 +42,13 @@ static int loadfile(const char *filename, void **filedata, size_t *filesize) if(continue_reading) continue_reading = fseek(fInCert, 0, SEEK_SET) == 0; if(continue_reading) - data = malloc(datasize + 1); + data = curlx_malloc(datasize + 1); if((!data) || ((int)fread(data, datasize, 1, fInCert) != 1)) continue_reading = FALSE; curlx_fclose(fInCert); if(!continue_reading) { - free(data); + curlx_free(data); datasize = 0; data = NULL; } @@ -86,7 +84,7 @@ static CURLcode test_cert_blob(const char *url, const char *cafile) blob.len = certsize; blob.flags = CURL_BLOB_COPY; curl_easy_setopt(curl, CURLOPT_CAINFO_BLOB, &blob); - free(certdata); + curlx_free(certdata); code = curl_easy_perform(curl); } curl_easy_cleanup(curl); diff --git a/tests/libtest/lib694.c b/tests/libtest/lib694.c index 5b477ecebd44..25db2694c6d7 100644 --- a/tests/libtest/lib694.c +++ b/tests/libtest/lib694.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib694(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib695.c b/tests/libtest/lib695.c index 325897c357c9..1177a529fd64 100644 --- a/tests/libtest/lib695.c +++ b/tests/libtest/lib695.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* write callback that does nothing */ static size_t write_it(char *ptr, size_t size, size_t nmemb, void *userdata) { diff --git a/tests/libtest/lib751.c b/tests/libtest/lib751.c index 42c1aeb1176e..898ba8d7efcb 100644 --- a/tests/libtest/lib751.c +++ b/tests/libtest/lib751.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Get a single URL without select(). */ diff --git a/tests/libtest/lib753.c b/tests/libtest/lib753.c index 19194c4646a5..f01fa3f5c806 100644 --- a/tests/libtest/lib753.c +++ b/tests/libtest/lib753.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" struct t753_transfer_status { CURL *curl; diff --git a/tests/libtest/lib757.c b/tests/libtest/lib757.c index 632818f94605..f3a1e0fdb408 100644 --- a/tests/libtest/lib757.c +++ b/tests/libtest/lib757.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* write callback that does nothing */ static size_t write_757(char *ptr, size_t size, size_t nmemb, void *userdata) { diff --git a/tests/libtest/lib758.c b/tests/libtest/lib758.c index ab6ce481b779..bc6a490d3d39 100644 --- a/tests/libtest/lib758.c +++ b/tests/libtest/lib758.c @@ -31,7 +31,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" #ifdef USE_OPENSSL @@ -121,14 +120,15 @@ static int t758_addFd(struct t758_Sockets *sockets, curl_socket_t fd, * Allocate array storage when required. */ if(!sockets->sockets) { - sockets->sockets = malloc(sizeof(curl_socket_t) * 20U); + sockets->sockets = curlx_malloc(sizeof(curl_socket_t) * 20U); if(!sockets->sockets) return 1; sockets->max_count = 20; } else if(sockets->count + 1 > sockets->max_count) { - curl_socket_t *ptr = realloc(sockets->sockets, sizeof(curl_socket_t) * - (sockets->max_count + 20)); + curl_socket_t *ptr = curlx_realloc(sockets->sockets, + sizeof(curl_socket_t) * + (sockets->max_count + 20)); if(!ptr) /* cleanup in test_cleanup */ return 1; @@ -487,8 +487,8 @@ static CURLcode t758_one(const char *URL, int timer_fail_at, curl_global_cleanup(); /* free local memory */ - free(sockets.read.sockets); - free(sockets.write.sockets); + curlx_free(sockets.read.sockets); + curlx_free(sockets.write.sockets); t758_msg("done"); return res; diff --git a/tests/libtest/lib766.c b/tests/libtest/lib766.c index 53f1dd97b551..bba08e263b84 100644 --- a/tests/libtest/lib766.c +++ b/tests/libtest/lib766.c @@ -24,8 +24,6 @@ #include "first.h" -#include "memdebug.h" - static int sockopt_766(void *clientp, curl_socket_t curlfd, curlsocktype purpose) diff --git a/tests/libtest/memptr.c b/tests/libtest/memptr.c index 64e9fd7f8a1a..400e72c41ab9 100644 --- a/tests/libtest/memptr.c +++ b/tests/libtest/memptr.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "curl_memory.h" - #ifndef CURL_STATICLIB #if defined(_MSC_VER) && defined(_DLL) diff --git a/tests/libtest/mk-lib1521.pl b/tests/libtest/mk-lib1521.pl index 156422eccc42..bfb0e590e78f 100755 --- a/tests/libtest/mk-lib1521.pl +++ b/tests/libtest/mk-lib1521.pl @@ -206,7 +206,6 @@ * ***************************************************************************/ #include "first.h" -#include "memdebug.h" /* This source code is generated by mk-lib1521.pl ! */ diff --git a/tests/libtest/testtrace.c b/tests/libtest/testtrace.c index 7c4517378751..a541d4e55c18 100644 --- a/tests/libtest/testtrace.c +++ b/tests/libtest/testtrace.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "testtrace.h" -#include "memdebug.h" - struct libtest_trace_cfg debug_config; static time_t epoch_offset; /* for test time tracing */ diff --git a/tests/libtest/testutil.c b/tests/libtest/testutil.c index b5cfa70369b7..02c041c4b132 100644 --- a/tests/libtest/testutil.c +++ b/tests/libtest/testutil.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "testutil.h" -#include "memdebug.h" - /* build request URL */ char *tutil_suburl(const char *base, int i) { diff --git a/tests/server/.checksrc b/tests/server/.checksrc index 163a217ee4be..2fb655e159fa 100644 --- a/tests/server/.checksrc +++ b/tests/server/.checksrc @@ -3,13 +3,18 @@ # SPDX-License-Identifier: curl allowfunc accept +allowfunc calloc allowfunc fprintf +allowfunc free allowfunc freeaddrinfo allowfunc getaddrinfo +allowfunc malloc allowfunc printf +allowfunc realloc allowfunc recv allowfunc send allowfunc snprintf allowfunc socket allowfunc sscanf +allowfunc strdup allowfunc vsnprintf diff --git a/tests/test1132.pl b/tests/test1132.pl deleted file mode 100755 index 966bd09a489a..000000000000 --- a/tests/test1132.pl +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env perl -#*************************************************************************** -# _ _ ____ _ -# Project ___| | | | _ \| | -# / __| | | | |_) | | -# | (__| |_| | _ <| |___ -# \___|\___/|_| \_\_____| -# -# Copyright (C) Daniel Stenberg, , et al. -# -# This software is licensed as described in the file COPYING, which -# you should have received as part of this distribution. The terms -# are also available at https://curl.se/docs/copyright.html. -# -# You may opt to use, copy, modify, merge, publish, distribute and/or sell -# copies of the Software, and permit persons to whom the Software is -# furnished to do so, under the terms of the COPYING file. -# -# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY -# KIND, either express or implied. -# -# SPDX-License-Identifier: curl -# -########################################################################### -# -# This script scans C source files. If they seem to use memory functions, -# it also makes sure that it #includes the correct two header files! -# -# You can also mark a C source as fine by using 'mem-include-scan' anywhere in -# it. -# - -use strict; -use warnings; - -my $dir = $ARGV[0] || die "specify directory!"; - -sub scanfile { - my ($file) = @_; - my $memfunc; - my $memdebug; - my $curlmem; - - print STDERR "checking $file...\n"; - - open(my $f, "<", "$file"); - while(<$f>) { - if($_ =~ /\W(free|alloc|strdup)\(/) { - $memfunc++; - } - elsif($_ =~ /^ *# *include \"memdebug.h\"/) { - $memdebug++; - } - elsif($_ =~ /^ *# *include \"curl_memory.h\"/) { - $curlmem++; - } - elsif($_ =~ /mem-include-scan/) { - # free pass - close($f); - return 0; - } - if($memfunc && $memdebug && $curlmem) { - last; - } - } - close($f); - - - if($memfunc) { - if($memdebug && $curlmem) { - return 0; - } - else { - if(!$memdebug) { - print STDERR "$file does not include \"memdebug.h\"!\n"; - } - if(!$curlmem) { - print STDERR "$file does not include \"curl_memory.h\"!\n"; - } - return 1; - } - } - return 0; -} - -opendir(my $dh, $dir) || die "cannot opendir $dir: $!"; -my @cfiles = grep { /\.c\z/ && -f "$dir/$_" } readdir($dh); -closedir $dh; - -my $errs; -for(@cfiles) { - $errs += scanfile("$dir/$_"); -} - -if($errs) { - print STDERR "----\n$errs errors detected!\n"; - exit 2; -} diff --git a/tests/tunit/tool1394.c b/tests/tunit/tool1394.c index 71be2c87c478..9d97dbb0de8f 100644 --- a/tests/tunit/tool1394.c +++ b/tests/tunit/tool1394.c @@ -25,8 +25,6 @@ #include "tool_getparam.h" -#include "memdebug.h" /* LAST include file */ - static CURLcode test_tool1394(const char *arg) { UNITTEST_BEGIN_SIMPLE @@ -120,9 +118,9 @@ static CURLcode test_tool1394(const char *arg) } } if(certname) - free(certname); + curlx_free(certname); if(passphrase) - free(passphrase); + curlx_free(passphrase); } UNITTEST_END_SIMPLE diff --git a/tests/tunit/tool1604.c b/tests/tunit/tool1604.c index 3b6f006e7cfd..dcfee4cbac62 100644 --- a/tests/tunit/tool1604.c +++ b/tests/tunit/tool1604.c @@ -26,12 +26,10 @@ #include "tool_cfgable.h" #include "tool_doswin.h" -#include "memdebug.h" /* LAST include file */ - #if defined(_WIN32) || defined(MSDOS) static char *getflagstr(int flags) { - char *buf = malloc(256); + char *buf = curlx_malloc(256); if(buf) { curl_msnprintf(buf, 256, "%s,%s", ((flags & SANITIZE_ALLOW_PATH) ? @@ -44,7 +42,7 @@ static char *getflagstr(int flags) static char *getcurlcodestr(int cc) { - char *buf = malloc(256); + char *buf = curlx_malloc(256); if(buf) { curl_msnprintf(buf, 256, "%s (%d)", (cc == SANITIZE_ERR_OK ? "SANITIZE_ERR_OK" : @@ -212,7 +210,7 @@ static CURLcode test_tool1604(const char *arg) ((!output && !data[i].expected_output) || (output && data[i].expected_output && !strcmp(output, data[i].expected_output)))) { /* OK */ - free(output); + curlx_free(output); continue; } @@ -240,10 +238,10 @@ static CURLcode test_tool1604(const char *arg) data[i].expected_output ? data[i].expected_output : "(null)", expected_ccstr); - free(output); - free(flagstr); - free(received_ccstr); - free(expected_ccstr); + curlx_free(output); + curlx_free(flagstr); + curlx_free(received_ccstr); + curlx_free(expected_ccstr); } /* END sanitize_file_name */ #else diff --git a/tests/tunit/tool1621.c b/tests/tunit/tool1621.c index bb709cf39d21..ba9e28029446 100644 --- a/tests/tunit/tool1621.c +++ b/tests/tunit/tool1621.c @@ -25,8 +25,6 @@ #include "tool_xattr.h" -#include "memdebug.h" /* LAST include file */ - static CURLcode test_tool1621(const char *arg) { UNITTEST_BEGIN_SIMPLE diff --git a/tests/unit/unit1302.c b/tests/unit/unit1302.c index 911432a8c833..d56f7b09f779 100644 --- a/tests/unit/unit1302.c +++ b/tests/unit/unit1302.c @@ -25,7 +25,6 @@ #include "urldata.h" #include "url.h" /* for Curl_safefree */ -#include "memdebug.h" /* LAST include file */ struct etest { const char *input; diff --git a/tests/unit/unit1303.c b/tests/unit/unit1303.c index 03673c544e29..9bed1ebff6f4 100644 --- a/tests/unit/unit1303.c +++ b/tests/unit/unit1303.c @@ -25,7 +25,6 @@ #include "urldata.h" #include "connect.h" -#include "memdebug.h" /* LAST include file */ static CURLcode t1303_setup(struct Curl_easy **easy) { diff --git a/tests/unit/unit1304.c b/tests/unit/unit1304.c index 041ce42691dd..100f3f58287e 100644 --- a/tests/unit/unit1304.c +++ b/tests/unit/unit1304.c @@ -23,7 +23,6 @@ ***************************************************************************/ #include "unitcheck.h" #include "netrc.h" -#include "memdebug.h" /* LAST include file */ #ifndef CURL_DISABLE_NETRC @@ -120,8 +119,8 @@ static CURLcode test_unit1304(const char *arg) * Test for the first existing host in our netrc file * with login[0] != 0. */ - free(password); - free(login); + curlx_free(password); + curlx_free(login); password = NULL; login = NULL; Curl_netrc_init(&store); @@ -139,9 +138,9 @@ static CURLcode test_unit1304(const char *arg) * Test for the second existing host in our netrc file * with login[0] = 0. */ - free(password); + curlx_free(password); password = NULL; - free(login); + curlx_free(login); login = NULL; Curl_netrc_init(&store); result = Curl_parsenetrc(&store, @@ -158,9 +157,9 @@ static CURLcode test_unit1304(const char *arg) * Test for the second existing host in our netrc file * with login[0] != 0. */ - free(password); + curlx_free(password); password = NULL; - free(login); + curlx_free(login); login = NULL; Curl_netrc_init(&store); result = Curl_parsenetrc(&store, diff --git a/tests/unit/unit1305.c b/tests/unit/unit1305.c index e95e2994535d..404d90bec9a9 100644 --- a/tests/unit/unit1305.c +++ b/tests/unit/unit1305.c @@ -36,8 +36,6 @@ #include "hash.h" #include "hostip.h" -#include "memdebug.h" /* LAST include file */ - static struct Curl_dnscache hp; static char *data_key; static struct Curl_dns_entry *data_node; @@ -52,9 +50,9 @@ static void t1305_stop(void) { if(data_node) { Curl_freeaddrinfo(data_node->addr); - free(data_node); + curlx_free(data_node); } - free(data_key); + curlx_free(data_key); Curl_dnscache_destroy(&hp); } @@ -64,8 +62,9 @@ static struct Curl_addrinfo *fake_ai(void) static const char dummy[] = "dummy"; size_t namelen = sizeof(dummy); /* including the null-terminator */ - ai = calloc(1, sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_in) + - namelen); + ai = curlx_calloc(1, + sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_in) + + namelen); if(!ai) return NULL; @@ -86,7 +85,7 @@ static CURLcode create_node(void) if(!data_key) return CURLE_OUT_OF_MEMORY; - data_node = calloc(1, sizeof(struct Curl_dns_entry)); + data_node = curlx_calloc(1, sizeof(struct Curl_dns_entry)); if(!data_node) return CURLE_OUT_OF_MEMORY; diff --git a/tests/unit/unit1330.c b/tests/unit/unit1330.c index bd7fc6e2592b..a98393b5325c 100644 --- a/tests/unit/unit1330.c +++ b/tests/unit/unit1330.c @@ -23,13 +23,11 @@ ***************************************************************************/ #include "unitcheck.h" -#include "memdebug.h" - static CURLcode test_unit1330(const char *arg) { UNITTEST_BEGIN_SIMPLE - char *ptr = malloc(1330); + char *ptr = curlx_malloc(1330); Curl_safefree(ptr); UNITTEST_END_SIMPLE diff --git a/tests/unit/unit1395.c b/tests/unit/unit1395.c index e6ac18f08107..395f3e7707d7 100644 --- a/tests/unit/unit1395.c +++ b/tests/unit/unit1395.c @@ -22,7 +22,6 @@ * ***************************************************************************/ #include "unitcheck.h" -#include "memdebug.h" #include "unitprotos.h" static CURLcode test_unit1395(const char *arg) @@ -133,7 +132,7 @@ static CURLcode test_unit1395(const char *arg) } else curl_mfprintf(stderr, "Test %u: OK\n", i); - free(out); + curlx_free(out); } fail_if(fails, "output mismatched"); diff --git a/tests/unit/unit1602.c b/tests/unit/unit1602.c index e397bdb5ca5f..5841717691e0 100644 --- a/tests/unit/unit1602.c +++ b/tests/unit/unit1602.c @@ -25,12 +25,10 @@ #include "hash.h" -#include "memdebug.h" /* LAST include file */ - static void t1602_mydtor(void *p) { int *ptr = (int *)p; - free(ptr); + curlx_free(ptr); } static CURLcode t1602_setup(struct Curl_hash *hash) @@ -59,22 +57,22 @@ static CURLcode test_unit1602(const char *arg) int key = 20; int key2 = 25; - value = malloc(sizeof(int)); + value = curlx_malloc(sizeof(int)); abort_unless(value != NULL, "Out of memory"); *value = 199; nodep = Curl_hash_add(&hash, &key, klen, value); if(!nodep) - free(value); + curlx_free(value); abort_unless(nodep, "insertion into hash failed"); Curl_hash_clean(&hash); /* Attempt to add another key/value pair */ - value2 = malloc(sizeof(int)); + value2 = curlx_malloc(sizeof(int)); abort_unless(value2 != NULL, "Out of memory"); *value2 = 204; nodep = Curl_hash_add(&hash, &key2, klen, value2); if(!nodep) - free(value2); + curlx_free(value2); abort_unless(nodep, "insertion into hash failed"); UNITTEST_END(t1602_stop(&hash)) diff --git a/tests/unit/unit1603.c b/tests/unit/unit1603.c index b4ec152936ee..81db398cb19e 100644 --- a/tests/unit/unit1603.c +++ b/tests/unit/unit1603.c @@ -25,8 +25,6 @@ #include "hash.h" -#include "memdebug.h" /* LAST include file */ - static const size_t slots = 3; static void t1603_mydtor(void *p) diff --git a/tests/unit/unit1607.c b/tests/unit/unit1607.c index f60b5b58a1e4..233866da18b6 100644 --- a/tests/unit/unit1607.c +++ b/tests/unit/unit1607.c @@ -27,8 +27,6 @@ #include "connect.h" #include "curl_share.h" -#include "memdebug.h" /* LAST include file */ - static CURLcode t1607_setup(void) { CURLcode res = CURLE_OK; @@ -135,7 +133,7 @@ static CURLcode test_unit1607(const char *arg) goto error; dns = Curl_hash_pick(&multi->dnscache.entries, entry_id, strlen(entry_id) + 1); - free(entry_id); + curlx_free(entry_id); entry_id = NULL; addr = dns ? dns->addr : NULL; diff --git a/tests/unit/unit1609.c b/tests/unit/unit1609.c index 2a3098c6ef2e..bf912b99cd1a 100644 --- a/tests/unit/unit1609.c +++ b/tests/unit/unit1609.c @@ -27,8 +27,6 @@ #include "connect.h" #include "curl_share.h" -#include "memdebug.h" /* LAST include file */ - static CURLcode t1609_setup(void) { CURLcode res = CURLE_OK; @@ -137,7 +135,7 @@ static CURLcode test_unit1609(const char *arg) dns = Curl_hash_pick(&multi->dnscache.entries, entry_id, strlen(entry_id) + 1); - free(entry_id); + curlx_free(entry_id); entry_id = NULL; addr = dns ? dns->addr : NULL; diff --git a/tests/unit/unit1616.c b/tests/unit/unit1616.c index 5d1e6f247e76..d898444613ce 100644 --- a/tests/unit/unit1616.c +++ b/tests/unit/unit1616.c @@ -25,13 +25,11 @@ #include "uint-hash.h" -#include "memdebug.h" /* LAST include file */ - static void t1616_mydtor(unsigned int id, void *elem) { int *ptr = (int *)elem; (void)id; - free(ptr); + curlx_free(ptr); } static CURLcode t1616_setup(struct uint_hash *hash) @@ -58,12 +56,12 @@ static CURLcode test_unit1616(const char *arg) unsigned int key = 20; unsigned int key2 = 25; - value = malloc(sizeof(int)); + value = curlx_malloc(sizeof(int)); abort_unless(value != NULL, "Out of memory"); *value = 199; ok = Curl_uint32_hash_set(&hash, key, value); if(!ok) - free(value); + curlx_free(value); abort_unless(ok, "insertion into hash failed"); v = Curl_uint32_hash_get(&hash, key); abort_unless(v == value, "lookup present entry failed"); @@ -72,12 +70,12 @@ static CURLcode test_unit1616(const char *arg) Curl_uint32_hash_clear(&hash); /* Attempt to add another key/value pair */ - value2 = malloc(sizeof(int)); + value2 = curlx_malloc(sizeof(int)); abort_unless(value2 != NULL, "Out of memory"); *value2 = 204; ok = Curl_uint32_hash_set(&hash, key2, value2); if(!ok) - free(value2); + curlx_free(value2); abort_unless(ok, "insertion into hash failed"); v = Curl_uint32_hash_get(&hash, key2); abort_unless(v == value2, "lookup present entry failed"); diff --git a/tests/unit/unit1620.c b/tests/unit/unit1620.c index 4851602eaa71..4c1674f5bd54 100644 --- a/tests/unit/unit1620.c +++ b/tests/unit/unit1620.c @@ -26,8 +26,6 @@ #include "urldata.h" #include "url.h" -#include "memdebug.h" /* LAST include file */ - static CURLcode t1620_setup(void) { CURLcode res = CURLE_OK; @@ -64,9 +62,9 @@ static void t1620_parse( "options should be equal to exp_options"); } - free(userstr); - free(passwdstr); - free(options); + curlx_free(userstr); + curlx_free(passwdstr); + curlx_free(options); } static CURLcode test_unit1620(const char *arg) diff --git a/tests/unit/unit1653.c b/tests/unit/unit1653.c index 8f6a5a51cc55..7ea7e380a80b 100644 --- a/tests/unit/unit1653.c +++ b/tests/unit/unit1653.c @@ -53,7 +53,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15]"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15]"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -67,7 +67,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15|"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15|"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -78,7 +78,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff;fea7:da15]:808"); + ipv6port = curlx_strdup("[fe80::250:56ff;fea7:da15]:808"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -95,7 +95,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]:80"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15%25eth3]:80"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -111,7 +111,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15%25eth3]"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -123,7 +123,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15]:81"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15]:81"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -139,7 +139,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15];81"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15];81"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -150,7 +150,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15]80"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15]80"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -163,7 +163,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15]:"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15]:"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, TRUE); @@ -175,7 +175,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15!25eth3]:180"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15!25eth3]:180"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -191,7 +191,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15%eth3]:80"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15%eth3]:80"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -204,14 +204,14 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaa:"); + ipv6port = curlx_strdup("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaa:"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); fail_unless(ret == CURLUE_BAD_PORT_NUMBER, "parse_port did wrong"); fail: - free(ipv6port); + curlx_free(ipv6port); curl_url_cleanup(u); UNITTEST_END_SIMPLE diff --git a/tests/unit/unit1661.c b/tests/unit/unit1661.c index 6cc448554401..d9aa2a61f14e 100644 --- a/tests/unit/unit1661.c +++ b/tests/unit/unit1661.c @@ -23,7 +23,6 @@ ***************************************************************************/ #include "unitcheck.h" #include "bufref.h" -#include "memdebug.h" static int freecount = 0; @@ -31,7 +30,7 @@ static void test_free(void *p) { fail_unless(p, "pointer to free may not be NULL"); freecount++; - free(p); + curlx_free(p); } static CURLcode t1661_setup(struct bufref *bufref) @@ -68,7 +67,7 @@ static CURLcode test_unit1661(const char *arg) /** * testing Curl_bufref_set */ - buffer = malloc(13); + buffer = curlx_malloc(13); abort_unless(buffer, "Out of memory"); Curl_bufref_set(&bufref, buffer, 13, test_free); diff --git a/tests/unit/unit1663.c b/tests/unit/unit1663.c index 0d6fb4bbbe50..e4431930a410 100644 --- a/tests/unit/unit1663.c +++ b/tests/unit/unit1663.c @@ -32,8 +32,6 @@ #include "cf-socket.h" -#include "memdebug.h" /* LAST include file */ - static CURLcode t1663_setup(void) { CURLcode res = CURLE_OK; @@ -67,9 +65,9 @@ static void t1663_parse( "host should be equal to exp_host"); } - free(dev); - free(iface); - free(host); + curlx_free(dev); + curlx_free(iface); + curlx_free(host); } static CURLcode test_unit1663(const char *arg) diff --git a/tests/unit/unit1664.c b/tests/unit/unit1664.c index 6903c70e9298..a24a859e5272 100644 --- a/tests/unit/unit1664.c +++ b/tests/unit/unit1664.c @@ -30,8 +30,6 @@ #include #endif -#include "memdebug.h" /* LAST include file */ - static CURLcode t1664_setup(void) { CURLcode res = CURLE_OK; diff --git a/tests/unit/unit2600.c b/tests/unit/unit2600.c index f2adc50eddd4..b69b675b3b1a 100644 --- a/tests/unit/unit2600.c +++ b/tests/unit/unit2600.c @@ -47,7 +47,6 @@ #include "multiif.h" #include "select.h" #include "curl_trc.h" -#include "memdebug.h" static CURLcode t2600_setup(CURL **easy) { @@ -126,7 +125,7 @@ static void cf_test_destroy(struct Curl_cfilter *cf, struct Curl_easy *data) #else (void)data; #endif - free(ctx); + curlx_free(ctx); cf->ctx = NULL; } @@ -193,7 +192,7 @@ static CURLcode cf_test_create(struct Curl_cfilter **pcf, (void)data; (void)conn; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { res = CURLE_OUT_OF_MEMORY; goto out; @@ -233,8 +232,8 @@ static CURLcode cf_test_create(struct Curl_cfilter **pcf, out: *pcf = (!res) ? cf : NULL; if(res) { - free(cf); - free(ctx); + curlx_free(cf); + curlx_free(ctx); } return res; } diff --git a/tests/unit/unit2604.c b/tests/unit/unit2604.c index 695b1210071e..fb05189714c3 100644 --- a/tests/unit/unit2604.c +++ b/tests/unit/unit2604.c @@ -23,7 +23,6 @@ ***************************************************************************/ #include "unitcheck.h" #include "vssh/vssh.h" -#include "memdebug.h" static CURLcode test_unit2604(const char *arg) { @@ -79,7 +78,7 @@ static CURLcode test_unit2604(const char *arg) #pragma GCC diagnostic pop #endif - char *cp0 = calloc(1, too_long + 1); + char *cp0 = curlx_calloc(1, too_long + 1); fail_unless(cp0, "could not alloc too long value"); memset(cp0, 'a', too_long); @@ -108,7 +107,7 @@ static CURLcode test_unit2604(const char *arg) } } - free(cp0); + curlx_free(cp0); #endif diff --git a/tests/unit/unit2605.c b/tests/unit/unit2605.c index 71c37f32cfcb..49d0b0b000e9 100644 --- a/tests/unit/unit2605.c +++ b/tests/unit/unit2605.c @@ -23,7 +23,6 @@ ***************************************************************************/ #include "unitcheck.h" #include "vssh/vssh.h" -#include "memdebug.h" static CURLcode test_unit2605(const char *arg) { diff --git a/tests/unit/unit3200.c b/tests/unit/unit3200.c index 0b3c87691157..fe00da939d57 100644 --- a/tests/unit/unit3200.c +++ b/tests/unit/unit3200.c @@ -23,7 +23,6 @@ ***************************************************************************/ #include "unitcheck.h" #include "curl_get_line.h" -#include "memdebug.h" static CURLcode test_unit3200(const char *arg) { From c10dda9ebb6ccaaff7b71000c7c54b86dbd80cc7 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Fri, 28 Nov 2025 15:48:03 +0200 Subject: [PATCH 106/140] curlx/fopen: fix typo in copyright Follow-up to 193cb00ce9b47e75d42157c650cc3de3fd96d35d #19626 Closes #19747 --- lib/curlx/fopen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/curlx/fopen.c b/lib/curlx/fopen.c index c8dff428fc94..caf4978af163 100644 --- a/lib/curlx/fopen.c +++ b/lib/curlx/fopen.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) Danieal Stenberg, , et al. + * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms From aad3c2e8e14317c99838e3766df6cd2ce8f3f279 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 28 Nov 2025 14:19:18 +0100 Subject: [PATCH 107/140] example: fix formatting nits Also: - drop non-portable `__STRING()` macro use where still used. Closes #19746 --- docs/examples/10-at-a-time.c | 2 +- docs/examples/anyauthput.c | 8 +-- docs/examples/block_ip.c | 6 +- docs/examples/certinfo.c | 4 +- docs/examples/cookie_interface.c | 3 +- docs/examples/crawler.c | 15 +++-- docs/examples/ephiperfifo.c | 65 +++++++++++---------- docs/examples/evhiperfifo.c | 35 ++++++------ docs/examples/externalsocket.c | 5 +- docs/examples/ftp-wildcard.c | 5 +- docs/examples/ftpget.c | 1 - docs/examples/ftpgetresp.c | 2 +- docs/examples/ftpuploadfrommem.c | 4 +- docs/examples/getinmemory.c | 7 +-- docs/examples/getredirect.c | 3 +- docs/examples/ghiper.c | 31 +++++----- docs/examples/headerapi.c | 1 - docs/examples/hiperfifo.c | 75 ++++++++++++++----------- docs/examples/hsts-preload.c | 3 +- docs/examples/htmltidy.c | 4 +- docs/examples/htmltitle.cpp | 7 +-- docs/examples/http2-pushinmemory.c | 1 - docs/examples/httpput-postfields.c | 2 +- docs/examples/httpput.c | 2 +- docs/examples/imap-append.c | 4 +- docs/examples/imap-ssl.c | 2 +- docs/examples/log_failed_transfers.c | 2 +- docs/examples/multi-app.c | 2 +- docs/examples/multi-event.c | 18 +++--- docs/examples/multi-legacy.c | 6 +- docs/examples/multi-uv.c | 18 +++--- docs/examples/multithread.c | 2 - docs/examples/netrc.c | 3 +- docs/examples/post-callback.c | 2 +- docs/examples/postinmemory.c | 5 +- docs/examples/sftpget.c | 4 +- docs/examples/sftpuploadresume.c | 1 - docs/examples/shared-connection-cache.c | 4 +- docs/examples/simplessl.c | 8 +-- docs/examples/smooth-gtk-thread.c | 9 ++- docs/examples/smtp-authzid.c | 4 +- docs/examples/smtp-mail.c | 4 +- docs/examples/smtp-multi.c | 4 +- docs/examples/smtp-ssl.c | 4 +- docs/examples/smtp-tls.c | 4 +- docs/examples/sslbackend.c | 2 +- docs/examples/synctime.c | 33 ++++++----- docs/examples/threaded-ssl.c | 2 +- docs/examples/usercertinmem.c | 4 +- docs/examples/xmlstream.c | 10 ++-- 50 files changed, 225 insertions(+), 227 deletions(-) diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index bddcd1563740..22db7c5fc461 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -81,7 +81,7 @@ static const char *urls[] = { }; #define MAX_PARALLEL 10 /* number of simultaneous transfers */ -#define NUM_URLS sizeof(urls)/sizeof(char *) +#define NUM_URLS (sizeof(urls) / sizeof(char *)) static size_t write_cb(char *data, size_t n, size_t l, void *userp) { diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index eb5959ca2263..247d4d0d3b3a 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -65,9 +65,9 @@ /* seek callback function */ static int my_seek(void *userp, curl_off_t offset, int origin) { - FILE *fp = (FILE *) userp; + FILE *fp = (FILE *)userp; - if(fseek(fp, (long) offset, origin) == -1) + if(fseek(fp, (long)offset, origin) == -1) /* could not seek */ return CURL_SEEKFUNC_CANTSEEK; @@ -128,13 +128,13 @@ int main(int argc, char **argv) curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb); /* which file to upload */ - curl_easy_setopt(curl, CURLOPT_READDATA, (void *) fp); + curl_easy_setopt(curl, CURLOPT_READDATA, (void *)fp); /* set the seek function */ curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, my_seek); /* pass the file descriptor to the seek callback as well */ - curl_easy_setopt(curl, CURLOPT_SEEKDATA, (void *) fp); + curl_easy_setopt(curl, CURLOPT_SEEKDATA, (void *)fp); /* enable "uploading" (which means PUT when doing HTTP) */ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); diff --git a/docs/examples/block_ip.c b/docs/examples/block_ip.c index ef7056dc4340..bf2193a26359 100644 --- a/docs/examples/block_ip.c +++ b/docs/examples/block_ip.c @@ -31,7 +31,11 @@ #ifdef __AMIGA__ #include -int main(void) { printf("Platform not supported.\n"); return 1; } +int main(void) +{ + printf("Platform not supported.\n"); + return 1; +} #else #ifdef _MSC_VER diff --git a/docs/examples/certinfo.c b/docs/examples/certinfo.c index 3176d0a1fcfc..e799cfc92879 100644 --- a/docs/examples/certinfo.c +++ b/docs/examples/certinfo.c @@ -29,7 +29,7 @@ #include -static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream) +static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream) { (void)stream; (void)ptr; @@ -74,10 +74,8 @@ int main(void) for(slist = certinfo->certinfo[i]; slist; slist = slist->next) printf("%s\n", slist->data); - } } - } curl_easy_cleanup(curl); diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index a031380f1207..0398cdf164ff 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -71,8 +71,7 @@ static int print_cookies(CURL *curl) return 0; } -int -main(void) +int main(void) { CURL *curl; CURLcode res; diff --git a/docs/examples/crawler.c b/docs/examples/crawler.c index 419ceab26d06..9207199cdfc9 100644 --- a/docs/examples/crawler.c +++ b/docs/examples/crawler.c @@ -65,7 +65,7 @@ struct memory { static size_t write_cb(void *contents, size_t sz, size_t nmemb, void *ctx) { size_t realsize = sz * nmemb; - struct memory *mem = (struct memory*) ctx; + struct memory *mem = (struct memory *)ctx; char *ptr = realloc(mem->buf, mem->size + realsize); if(!ptr) { /* out of memory */ @@ -109,7 +109,7 @@ static CURL *make_handle(const char *url) curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 2000L); /* skip files larger than a gigabyte */ curl_easy_setopt(curl, CURLOPT_MAXFILESIZE_LARGE, - (curl_off_t)1024*1024*1024); + (curl_off_t)1024 * 1024 * 1024); curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); curl_easy_setopt(curl, CURLOPT_FILETIME, 1L); curl_easy_setopt(curl, CURLOPT_USERAGENT, "mini crawler"); @@ -121,8 +121,7 @@ static CURL *make_handle(const char *url) } /* HREF finder implemented in libxml2 but could be any HTML parser */ -static size_t follow_links(CURLM *multi, struct memory *mem, - const char *url) +static size_t follow_links(CURLM *multi, struct memory *mem, const char *url) { int opts = HTML_PARSE_NOBLANKS | HTML_PARSE_NOERROR | \ HTML_PARSE_NOWARNING | HTML_PARSE_NONET; @@ -135,7 +134,7 @@ static size_t follow_links(CURLM *multi, struct memory *mem, xmlXPathObjectPtr result; if(!doc) return 0; - xpath = (xmlChar*) "//a/@href"; + xpath = (xmlChar *)"//a/@href"; context = xmlXPathNewContext(doc); result = xmlXPathEvalExpression(xpath, context); xmlXPathFreeContext(context); @@ -155,10 +154,10 @@ static size_t follow_links(CURLM *multi, struct memory *mem, char *link; if(follow_relative_links) { xmlChar *orig = href; - href = xmlBuildURI(href, (xmlChar *) url); + href = xmlBuildURI(href, (xmlChar *)url); xmlFree(orig); } - link = (char *) href; + link = (char *)href; if(!link || strlen(link) < 20) continue; if(!strncmp(link, "http://", 7) || !strncmp(link, "https://", 8)) { @@ -240,7 +239,7 @@ int main(void) } } else { - printf("[%d] HTTP %d: %s\n", complete, (int) res_status, url); + printf("[%d] HTTP %d: %s\n", complete, (int)res_status, url); } } else { diff --git a/docs/examples/ephiperfifo.c b/docs/examples/ephiperfifo.c index b47cbbedbfb1..e572fffad887 100644 --- a/docs/examples/ephiperfifo.c +++ b/docs/examples/ephiperfifo.c @@ -58,7 +58,6 @@ This is purely a demo app, all retrieved data is simply discarded by the write callback. */ - #include #include #include @@ -77,7 +76,6 @@ callback. #define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ - /* Global information, common to all connections */ struct GlobalInfo { int epfd; /* epoll filedescriptor */ @@ -105,23 +103,35 @@ struct SockInfo { struct GlobalInfo *global; }; -#define mycase(code) \ - case code: s = __STRING(code) - /* Die if we get a bad CURLMcode somewhere */ static void mcode_or_die(const char *where, CURLMcode code) { if(CURLM_OK != code) { const char *s; switch(code) { - mycase(CURLM_BAD_HANDLE); break; - mycase(CURLM_BAD_EASY_HANDLE); break; - mycase(CURLM_OUT_OF_MEMORY); break; - mycase(CURLM_INTERNAL_ERROR); break; - mycase(CURLM_UNKNOWN_OPTION); break; - mycase(CURLM_LAST); break; - default: s = "CURLM_unknown"; break; - mycase(CURLM_BAD_SOCKET); + case CURLM_BAD_HANDLE: + s = "CURLM_BAD_HANDLE"; + break; + case CURLM_BAD_EASY_HANDLE: + s = "CURLM_BAD_EASY_HANDLE"; + break; + case CURLM_OUT_OF_MEMORY: + s = "CURLM_OUT_OF_MEMORY"; + break; + case CURLM_INTERNAL_ERROR: + s = "CURLM_INTERNAL_ERROR"; + break; + case CURLM_UNKNOWN_OPTION: + s = "CURLM_UNKNOWN_OPTION"; + break; + case CURLM_LAST: + s = "CURLM_LAST"; + break; + default: + s = "CURLM_unknown"; + break; + case CURLM_BAD_SOCKET: + s = "CURLM_BAD_SOCKET"; fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); /* ignore this error */ return; @@ -161,7 +171,7 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, struct GlobalInfo *g) memset(&its, 0, sizeof(its)); } - timerfd_settime(g->tfd, /* flags= */0, &its, NULL); + timerfd_settime(g->tfd, /* flags= */ 0, &its, NULL); return 0; } @@ -281,7 +291,7 @@ static void setsock(struct SockInfo *f, curl_socket_t s, CURL *e, int act, static void addsock(curl_socket_t s, CURL *curl, int action, struct GlobalInfo *g) { - struct SockInfo *fdp = (struct SockInfo*)calloc(1, sizeof(struct SockInfo)); + struct SockInfo *fdp = (struct SockInfo *)calloc(1, sizeof(struct SockInfo)); fdp->global = g; setsock(fdp, s, curl, action, g); @@ -291,12 +301,11 @@ static void addsock(curl_socket_t s, CURL *curl, int action, /* CURLMOPT_SOCKETFUNCTION */ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { - struct GlobalInfo *g = (struct GlobalInfo*) cbp; - struct SockInfo *fdp = (struct SockInfo*) sockp; - const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; + struct GlobalInfo *g = (struct GlobalInfo *)cbp; + struct SockInfo *fdp = (struct SockInfo *)sockp; + const char *whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"}; - fprintf(MSG_OUT, - "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); + fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); if(what == CURL_POLL_REMOVE) { fprintf(MSG_OUT, "\n"); remsock(fdp, g); @@ -307,8 +316,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) addsock(s, e, what, g); } else { - fprintf(MSG_OUT, - "Changing action from %s to %s\n", + fprintf(MSG_OUT, "Changing action from %s to %s\n", whatstr[fdp->action], whatstr[what]); setsock(fdp, s, e, what, g); } @@ -342,7 +350,7 @@ static void new_conn(const char *url, struct GlobalInfo *g) struct ConnInfo *conn; CURLMcode rc; - conn = (struct ConnInfo*)calloc(1, sizeof(*conn)); + conn = (struct ConnInfo *)calloc(1, sizeof(*conn)); conn->error[0] = '\0'; conn->curl = curl_easy_init(); @@ -364,8 +372,8 @@ static void new_conn(const char *url, struct GlobalInfo *g) curl_easy_setopt(conn->curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(conn->curl, CURLOPT_LOW_SPEED_TIME, 3L); curl_easy_setopt(conn->curl, CURLOPT_LOW_SPEED_LIMIT, 10L); - fprintf(MSG_OUT, - "Adding easy %p to multi %p (%s)\n", conn->curl, g->multi, url); + fprintf(MSG_OUT, "Adding easy %p to multi %p (%s)\n", + conn->curl, g->multi, url); rc = curl_multi_add_handle(g->multi, conn->curl); mcode_or_die("new_conn: curl_multi_add_handle", rc); @@ -381,9 +389,9 @@ static void fifo_cb(struct GlobalInfo *g, int revents) int n = 0; do { - s[0]='\0'; + s[0] = '\0'; rv = fscanf(g->input, "%1023s%n", s, &n); - s[n]='\0'; + s[n] = '\0'; if(n && s[0]) { new_conn(s, g); /* if we read a URL, go get it! */ } @@ -437,7 +445,6 @@ static void clean_fifo(struct GlobalInfo *g) unlink(fifo); } - int g_should_exit_ = 0; void sigint_handler(int signo) @@ -506,7 +513,7 @@ int main(int argc, char **argv) while(!g_should_exit_) { int idx; int err = epoll_wait(g.epfd, events, - sizeof(events)/sizeof(struct epoll_event), 10000); + sizeof(events) / sizeof(struct epoll_event), 10000); if(err == -1) { /* !checksrc! disable ERRNOVAR 1 */ if(errno == EINTR) { diff --git a/docs/examples/evhiperfifo.c b/docs/examples/evhiperfifo.c index b6b957d54eb6..178be018a3a6 100644 --- a/docs/examples/evhiperfifo.c +++ b/docs/examples/evhiperfifo.c @@ -61,7 +61,6 @@ This is purely a demo app, all retrieved data is simply discarded by the write callback. */ - #include #include #include @@ -79,7 +78,6 @@ callback. #define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ - /* Global information, common to all connections */ struct GlobalInfo { struct ev_loop *loop; @@ -119,7 +117,7 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, struct GlobalInfo *g) ev_timer_stop(g->loop, &g->timer_event); if(timeout_ms >= 0) { /* -1 means delete, other values are timeout times in milliseconds */ - double t = timeout_ms / 1000; + double t = timeout_ms / 1000; ev_timer_init(&g->timer_event, timer_cb, t, 0.); ev_timer_start(g->loop, &g->timer_event); } @@ -196,7 +194,7 @@ static void event_cb(EV_P_ struct ev_io *w, int revents) int action; printf("%s w %p revents %i\n", __PRETTY_FUNCTION__, (void *)w, revents); - g = (struct GlobalInfo*) w->data; + g = (struct GlobalInfo *)w->data; action = ((revents & EV_READ) ? CURL_POLL_IN : 0) | ((revents & EV_WRITE) ? CURL_POLL_OUT : 0); @@ -270,15 +268,14 @@ static void addsock(curl_socket_t s, CURL *curl, int action, /* CURLMOPT_SOCKETFUNCTION */ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { - struct GlobalInfo *g = (struct GlobalInfo*) cbp; - struct SockInfo *fdp = (struct SockInfo*) sockp; - const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE"}; + struct GlobalInfo *g = (struct GlobalInfo *)cbp; + struct SockInfo *fdp = (struct SockInfo *)sockp; + const char *whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"}; printf("%s e %p s %i what %i cbp %p sockp %p\n", __PRETTY_FUNCTION__, e, s, what, cbp, sockp); - fprintf(MSG_OUT, - "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); + fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); if(what == CURL_POLL_REMOVE) { fprintf(MSG_OUT, "\n"); remsock(fdp, g); @@ -289,8 +286,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) addsock(s, e, what, g); } else { - fprintf(MSG_OUT, - "Changing action from %s to %s\n", + fprintf(MSG_OUT, "Changing action from %s to %s\n", whatstr[fdp->action], whatstr[what]); setsock(fdp, s, e, what, g); } @@ -302,7 +298,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) { size_t realsize = size * nmemb; - struct ConnInfo *conn = (struct ConnInfo*) data; + struct ConnInfo *conn = (struct ConnInfo *)data; (void)ptr; (void)conn; return realsize; @@ -316,8 +312,9 @@ static int xferinfo_cb(void *p, curl_off_t dltotal, curl_off_t dlnow, (void)ult; (void)uln; - fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T - "/%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); + fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T "/" + "%" CURL_FORMAT_CURL_OFF_T ")\n", + conn->url, dlnow, dltotal); return 0; } @@ -328,7 +325,7 @@ static void new_conn(const char *url, struct GlobalInfo *g) CURLMcode rc; conn = calloc(1, sizeof(*conn)); - conn->error[0]='\0'; + conn->error[0] = '\0'; conn->curl = curl_easy_init(); if(!conn->curl) { @@ -349,8 +346,8 @@ static void new_conn(const char *url, struct GlobalInfo *g) curl_easy_setopt(conn->curl, CURLOPT_LOW_SPEED_TIME, 3L); curl_easy_setopt(conn->curl, CURLOPT_LOW_SPEED_LIMIT, 10L); - fprintf(MSG_OUT, - "Adding easy %p to multi %p (%s)\n", conn->curl, g->multi, url); + fprintf(MSG_OUT, "Adding easy %p to multi %p (%s)\n", + conn->curl, g->multi, url); rc = curl_multi_add_handle(g->multi, conn->curl); mcode_or_die("new_conn: curl_multi_add_handle", rc); @@ -369,9 +366,9 @@ static void fifo_cb(EV_P_ struct ev_io *w, int revents) (void)revents; do { - s[0]='\0'; + s[0] = '\0'; rv = fscanf(g->input, "%1023s%n", s, &n); - s[n]='\0'; + s[n] = '\0'; if(n && s[0]) { new_conn(s, g); /* if we read a URL, go get it! */ } diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c index 610a835272a6..632d5f298168 100644 --- a/docs/examples/externalsocket.c +++ b/docs/examples/externalsocket.c @@ -124,7 +124,7 @@ int main(void) memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; - servaddr.sin_port = htons(PORTNUM); + servaddr.sin_port = htons(PORTNUM); servaddr.sin_addr.s_addr = inet_addr(IPADDR); if(INADDR_NONE == servaddr.sin_addr.s_addr) { @@ -132,8 +132,7 @@ int main(void) return 2; } - if(connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) == - -1) { + if(connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { close(sockfd); printf("client error: connect: %s\n", strerror(errno)); return 1; diff --git a/docs/examples/ftp-wildcard.c b/docs/examples/ftp-wildcard.c index 3bd2f690832b..fa66628f1655 100644 --- a/docs/examples/ftp-wildcard.c +++ b/docs/examples/ftp-wildcard.c @@ -85,8 +85,7 @@ static long file_is_downloaded(void *input) return CURL_CHUNK_END_FUNC_OK; } -static size_t write_cb(char *buff, size_t size, size_t nmemb, - void *cb_data) +static size_t write_cb(char *buff, size_t size, size_t nmemb, void *cb_data) { struct callback_data *data = cb_data; size_t written = 0; @@ -104,7 +103,7 @@ int main(int argc, char **argv) CURL *curl; /* help data */ - struct callback_data data = { 0 }; + struct callback_data data = {0}; /* global initialization */ CURLcode res = curl_global_init(CURL_GLOBAL_ALL); diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index f57974de1fb1..400102207474 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -52,7 +52,6 @@ static size_t write_cb(void *buffer, size_t size, size_t nmemb, void *stream) return fwrite(buffer, size, nmemb, out->stream); } - int main(void) { CURL *curl; diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index eec727bf943b..53ada7ccaee6 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -90,7 +90,7 @@ int main(void) curl_easy_cleanup(curl); } - fclose(ftpfile); /* close the local file */ + fclose(ftpfile); /* close the local file */ fclose(respfile); /* close the response file */ curl_global_cleanup(); diff --git a/docs/examples/ftpuploadfrommem.c b/docs/examples/ftpuploadfrommem.c index af88f52f1a7b..7c75f2b8d759 100644 --- a/docs/examples/ftpuploadfrommem.c +++ b/docs/examples/ftpuploadfrommem.c @@ -30,7 +30,7 @@ #include -static const char data[]= +static const char data[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " "___ rhoncus odio id venenatis volutpat. Vestibulum dapibus " "bibendum ullamcorper. Maecenas finibus elit augue, vel " @@ -64,7 +64,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) return copylen; } - return 0; /* no more data left to deliver */ + return 0; /* no more data left to deliver */ } int main(void) diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 1deeeda26667..d4d8960487a1 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -37,8 +37,7 @@ struct MemoryStruct { size_t size; }; -static size_t write_cb(void *contents, size_t size, size_t nmemb, - void *userp) +static size_t write_cb(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)userp; @@ -69,8 +68,8 @@ int main(void) if(res) return (int)res; - chunk.memory = malloc(1); /* grown as needed by the realloc above */ - chunk.size = 0; /* no data at this point */ + chunk.memory = malloc(1); /* grown as needed by the realloc above */ + chunk.size = 0; /* no data at this point */ /* init the curl session */ curl = curl_easy_init(); diff --git a/docs/examples/getredirect.c b/docs/examples/getredirect.c index b1f42dc9fdf4..6ad9b9c1aa5c 100644 --- a/docs/examples/getredirect.c +++ b/docs/examples/getredirect.c @@ -54,8 +54,7 @@ int main(void) curl_easy_strerror(res)); else { res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); - if((res == CURLE_OK) && - ((response_code / 100) != 3)) { + if((res == CURLE_OK) && ((response_code / 100) != 3)) { /* a redirect implies a 3xx response code */ fprintf(stderr, "Not a redirect.\n"); } diff --git a/docs/examples/ghiper.c b/docs/examples/ghiper.c index f27521971cd5..d7b19abb9be3 100644 --- a/docs/examples/ghiper.c +++ b/docs/examples/ghiper.c @@ -171,8 +171,8 @@ static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp) { struct timeval timeout; struct GlobalInfo *g = (struct GlobalInfo *)userp; - timeout.tv_sec = timeout_ms/1000; - timeout.tv_usec = (timeout_ms%1000)*1000; + timeout.tv_sec = timeout_ms / 1000; + timeout.tv_usec = (timeout_ms % 1000) * 1000; MSG_OUT("*** update_timeout_cb %ld => %ld:%ld ***\n", timeout_ms, timeout.tv_sec, timeout.tv_usec); @@ -191,7 +191,7 @@ static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp) /* Called by glib when we get action on a multi socket */ static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data) { - struct GlobalInfo *g = (struct GlobalInfo*) data; + struct GlobalInfo *g = (struct GlobalInfo *)data; CURLMcode rc; int fd = g_io_channel_unix_get_fd(ch); @@ -259,9 +259,9 @@ static void addsock(curl_socket_t s, CURL *curl, int action, /* CURLMOPT_SOCKETFUNCTION */ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { - struct GlobalInfo *g = (struct GlobalInfo*) cbp; - struct SockInfo *fdp = (struct SockInfo*) sockp; - static const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; + struct GlobalInfo *g = (struct GlobalInfo *)cbp; + struct SockInfo *fdp = (struct SockInfo *)sockp; + static const char *whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"}; MSG_OUT("socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); if(what == CURL_POLL_REMOVE) { @@ -276,8 +276,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) addsock(s, e, what, g); } else { - MSG_OUT( - "Changing action from %d to %d\n", fdp->action, what); + MSG_OUT("Changing action from %d to %d\n", fdp->action, what); setsock(fdp, s, e, what, g); } } @@ -288,7 +287,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) { size_t realsize = size * nmemb; - struct ConnInfo *conn = (struct ConnInfo*) data; + struct ConnInfo *conn = (struct ConnInfo *)data; (void)ptr; (void)conn; return realsize; @@ -302,8 +301,8 @@ static int xferinfo_cb(void *p, curl_off_t dltotal, curl_off_t dlnow, (void)ult; (void)uln; - fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T - "/%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); + fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T "/" + "%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); return 0; } @@ -357,18 +356,18 @@ static gboolean fifo_cb(GIOChannel *ch, GIOCondition condition, gpointer data) rv = g_io_channel_read_line(ch, &buf, &len, &tp, &err); if(buf) { if(tp) { - buf[tp]='\0'; + buf[tp] = '\0'; } - new_conn(buf, (struct GlobalInfo*)data); + new_conn(buf, (struct GlobalInfo *)data); g_free(buf); } else { buf = g_malloc(BUF_SIZE + 1); while(TRUE) { - buf[BUF_SIZE]='\0'; + buf[BUF_SIZE] = '\0'; g_io_channel_read_chars(ch, buf, BUF_SIZE, &len, &err); if(len) { - buf[len]='\0'; + buf[len] = '\0'; if(all) { tmp = all; all = g_strdup_printf("%s%s", tmp, buf); @@ -383,7 +382,7 @@ static gboolean fifo_cb(GIOChannel *ch, GIOCondition condition, gpointer data) } } if(all) { - new_conn(all, (struct GlobalInfo*)data); + new_conn(all, (struct GlobalInfo *)data); g_free(all); } g_free(buf); diff --git a/docs/examples/headerapi.c b/docs/examples/headerapi.c index 089a23a07013..e1fa33b8f62d 100644 --- a/docs/examples/headerapi.c +++ b/docs/examples/headerapi.c @@ -76,7 +76,6 @@ int main(void) printf(" %s: %s (%u)\n", h->name, h->value, (unsigned int)h->amount); prev = h; } while(h); - } /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index 60288b4bd263..576bbb8d2c2f 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -77,7 +77,6 @@ callback. #define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ - /* Global information, common to all connections */ struct GlobalInfo { struct event_base *evbase; @@ -107,23 +106,35 @@ struct SockInfo { struct GlobalInfo *global; }; -#define mycase(code) \ - case code: s = __STRING(code) - /* Die if we get a bad CURLMcode somewhere */ static void mcode_or_die(const char *where, CURLMcode code) { if(CURLM_OK != code) { const char *s; switch(code) { - mycase(CURLM_BAD_HANDLE); break; - mycase(CURLM_BAD_EASY_HANDLE); break; - mycase(CURLM_OUT_OF_MEMORY); break; - mycase(CURLM_INTERNAL_ERROR); break; - mycase(CURLM_UNKNOWN_OPTION); break; - mycase(CURLM_LAST); break; - default: s = "CURLM_unknown"; break; - mycase(CURLM_BAD_SOCKET); + case CURLM_BAD_HANDLE: + s = "CURLM_BAD_HANDLE"; + break; + case CURLM_BAD_EASY_HANDLE: + s = "CURLM_BAD_EASY_HANDLE"; + break; + case CURLM_OUT_OF_MEMORY: + s = "CURLM_OUT_OF_MEMORY"; + break; + case CURLM_INTERNAL_ERROR: + s = "CURLM_INTERNAL_ERROR"; + break; + case CURLM_UNKNOWN_OPTION: + s = "CURLM_UNKNOWN_OPTION"; + break; + case CURLM_LAST: + s = "CURLM_LAST"; + break; + default: + s = "CURLM_unknown"; + break; + case CURLM_BAD_SOCKET: + s = "CURLM_BAD_SOCKET"; fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); /* ignore this error */ return; @@ -139,8 +150,8 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, struct GlobalInfo *g) struct timeval timeout; (void)multi; - timeout.tv_sec = timeout_ms/1000; - timeout.tv_usec = (timeout_ms%1000)*1000; + timeout.tv_sec = timeout_ms / 1000; + timeout.tv_usec = (timeout_ms % 1000) * 1000; fprintf(MSG_OUT, "multi_timer_cb: Setting timeout to %ld ms\n", timeout_ms); /* @@ -185,7 +196,7 @@ static void check_multi_info(struct GlobalInfo *g) /* Called by libevent when we get action on a multi socket */ static void event_cb(int fd, short kind, void *userp) { - struct GlobalInfo *g = (struct GlobalInfo*) userp; + struct GlobalInfo *g = (struct GlobalInfo *)userp; CURLMcode rc; int action = @@ -261,12 +272,11 @@ static void addsock(curl_socket_t s, CURL *curl, int action, /* CURLMOPT_SOCKETFUNCTION */ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { - struct GlobalInfo *g = (struct GlobalInfo*) cbp; - struct SockInfo *fdp = (struct SockInfo*) sockp; - const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; + struct GlobalInfo *g = (struct GlobalInfo *)cbp; + struct SockInfo *fdp = (struct SockInfo *)sockp; + const char *whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"}; - fprintf(MSG_OUT, - "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); + fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); if(what == CURL_POLL_REMOVE) { fprintf(MSG_OUT, "\n"); remsock(fdp); @@ -277,8 +287,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) addsock(s, e, what, g); } else { - fprintf(MSG_OUT, - "Changing action from %s to %s\n", + fprintf(MSG_OUT, "Changing action from %s to %s\n", whatstr[fdp->action], whatstr[what]); setsock(fdp, s, e, what, g); } @@ -302,8 +311,8 @@ static int xferinfo_cb(void *p, curl_off_t dltotal, curl_off_t dlnow, (void)ult; (void)uln; - fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T - "/%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); + fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T "/" + "%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); return 0; } @@ -333,8 +342,8 @@ static void new_conn(const char *url, struct GlobalInfo *g) curl_easy_setopt(conn->curl, CURLOPT_XFERINFOFUNCTION, xferinfo_cb); curl_easy_setopt(conn->curl, CURLOPT_PROGRESSDATA, conn); curl_easy_setopt(conn->curl, CURLOPT_FOLLOWLOCATION, 1L); - fprintf(MSG_OUT, - "Adding easy %p to multi %p (%s)\n", conn->curl, g->multi, url); + fprintf(MSG_OUT, "Adding easy %p to multi %p (%s)\n", + conn->curl, g->multi, url); rc = curl_multi_add_handle(g->multi, conn->curl); mcode_or_die("new_conn: curl_multi_add_handle", rc); @@ -353,9 +362,9 @@ static void fifo_cb(int fd, short event, void *arg) (void)event; do { - s[0]='\0'; + s[0] = '\0'; rv = fscanf(g->input, "%1023s%n", s, &n); - s[n]='\0'; + s[n] = '\0'; if(n && s[0]) { if(!strcmp(s, "stop")) { g->stopped = 1; @@ -386,7 +395,7 @@ static int init_fifo(struct GlobalInfo *g) } } unlink(fifo); - if(mkfifo (fifo, 0600) == -1) { + if(mkfifo(fifo, 0600) == -1) { perror("mkfifo"); return 1; } @@ -398,7 +407,7 @@ static int init_fifo(struct GlobalInfo *g) g->input = fdopen(sockfd, "r"); fprintf(MSG_OUT, "Now, pipe some URL's into > %s\n", fifo); - event_assign(&g->fifo_event, g->evbase, sockfd, EV_READ|EV_PERSIST, + event_assign(&g->fifo_event, g->evbase, sockfd, EV_READ | EV_PERSIST, fifo_cb, g); event_add(&g->fifo_event, NULL); return 0; @@ -406,9 +415,9 @@ static int init_fifo(struct GlobalInfo *g) static void clean_fifo(struct GlobalInfo *g) { - event_del(&g->fifo_event); - fclose(g->input); - unlink(fifo); + event_del(&g->fifo_event); + fclose(g->input); + unlink(fifo); } int main(int argc, char **argv) diff --git a/docs/examples/hsts-preload.c b/docs/examples/hsts-preload.c index ad71c62cad96..b029df2a0a30 100644 --- a/docs/examples/hsts-preload.c +++ b/docs/examples/hsts-preload.c @@ -53,8 +53,7 @@ struct state { /* "read" is from the point of the library, it wants data from us. One domain entry per invoke. */ -static CURLSTScode hstsread(CURL *curl, struct curl_hstsentry *e, - void *userp) +static CURLSTScode hstsread(CURL *curl, struct curl_hstsentry *e, void *userp) { const char *host; const char *expire; diff --git a/docs/examples/htmltidy.c b/docs/examples/htmltidy.c index 04b4809317a9..9865a633efcd 100644 --- a/docs/examples/htmltidy.c +++ b/docs/examples/htmltidy.c @@ -48,14 +48,14 @@ static uint write_cb(char *in, uint size, uint nmemb, TidyBuffer *out) static void dumpNode(TidyDoc doc, TidyNode tnod, int indent) { TidyNode child; - for(child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) { + for(child = tidyGetChild(tnod); child; child = tidyGetNext(child)) { ctmbstr name = tidyNodeGetName(child); if(name) { /* if it has a name, then it is an HTML tag ... */ TidyAttr attr; printf("%*.*s%s ", indent, indent, "<", name); /* walk the attribute list */ - for(attr = tidyAttrFirst(child); attr; attr = tidyAttrNext(attr) ) { + for(attr = tidyAttrFirst(child); attr; attr = tidyAttrNext(attr)) { printf("%s", tidyAttrName(attr)); tidyAttrValue(attr) ? printf("=\"%s\" ", tidyAttrValue(attr)) : printf(" "); diff --git a/docs/examples/htmltitle.cpp b/docs/examples/htmltitle.cpp index 97b924b1802d..a6f944ff0eb9 100644 --- a/docs/examples/htmltitle.cpp +++ b/docs/examples/htmltitle.cpp @@ -55,9 +55,8 @@ // libxml callback context structure // -struct Context -{ - Context(): addTitle(false) { } +struct Context { + Context() : addTitle(false) {} bool addTitle; std::string title; @@ -79,7 +78,7 @@ static size_t writer(char *data, size_t size, size_t nmemb, if(writerData == NULL) return 0; - writerData->append(data, size*nmemb); + writerData->append(data, size * nmemb); return size * nmemb; } diff --git a/docs/examples/http2-pushinmemory.c b/docs/examples/http2-pushinmemory.c index 14f37dbbbcd3..df896e1af5d1 100644 --- a/docs/examples/http2-pushinmemory.c +++ b/docs/examples/http2-pushinmemory.c @@ -115,7 +115,6 @@ static int server_push_callback(CURL *parent, return CURL_PUSH_OK; } - /* * Download a file over HTTP/2, take care of server push. */ diff --git a/docs/examples/httpput-postfields.c b/docs/examples/httpput-postfields.c index 29fd6273d7eb..4fd92aaffbef 100644 --- a/docs/examples/httpput-postfields.c +++ b/docs/examples/httpput-postfields.c @@ -30,7 +30,7 @@ #include -static const char olivertwist[]= +static const char olivertwist[] = "Among other public buildings in a certain town, which for many reasons " "it will be prudent to refrain from mentioning, and to which I will assign " "no fictitious name, there is one anciently common to most towns, great or " diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 5c3fc314b801..026fde1210ea 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -77,7 +77,7 @@ int main(int argc, char **argv) { CURL *curl; CURLcode res; - FILE * hd_src; + FILE *hd_src; struct stat file_info; char *file; diff --git a/docs/examples/imap-append.c b/docs/examples/imap-append.c index 81ca682ffd26..91cbac69151a 100644 --- a/docs/examples/imap-append.c +++ b/docs/examples/imap-append.c @@ -64,7 +64,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) const char *data; size_t room = size * nmemb; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } @@ -95,7 +95,7 @@ int main(void) if(curl) { size_t filesize; long infilesize = LONG_MAX; - struct upload_status upload_ctx = { 0 }; + struct upload_status upload_ctx = {0}; /* Set username and password */ curl_easy_setopt(curl, CURLOPT_USERNAME, "user"); diff --git a/docs/examples/imap-ssl.c b/docs/examples/imap-ssl.c index 259eddc26f6a..52448f492d16 100644 --- a/docs/examples/imap-ssl.c +++ b/docs/examples/imap-ssl.c @@ -51,7 +51,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret"); /* This fetches message 1 from the user's inbox. Note the use of - * imaps:// rather than imap:// to request an SSL based connection. */ + * imaps:// rather than imap:// to request an SSL based connection. */ curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.example.com/INBOX/;UID=1"); diff --git a/docs/examples/log_failed_transfers.c b/docs/examples/log_failed_transfers.c index a0d209ffc395..0c5c1a3b5494 100644 --- a/docs/examples/log_failed_transfers.c +++ b/docs/examples/log_failed_transfers.c @@ -236,7 +236,7 @@ int main(void) curl_global_trace("all"); #endif - for(i = 0; i < sizeof(transfer)/sizeof(transfer[0]); ++i) { + for(i = 0; i < sizeof(transfer) / sizeof(transfer[0]); ++i) { int failed = 0; struct transfer *t = &transfer[i]; diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 460c93057ad5..d58181e027f4 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -66,7 +66,7 @@ int main(void) int still_running = 1; /* keep number of running handles */ - CURLMsg *msg; /* for picking up messages with the transfer status */ + CURLMsg *msg; /* for picking up messages with the transfer status */ int msgs_left; /* how many messages are left */ /* add the individual transfers */ diff --git a/docs/examples/multi-event.c b/docs/examples/multi-event.c index 2698e24678f9..901d7dd6e765 100644 --- a/docs/examples/multi-event.c +++ b/docs/examples/multi-event.c @@ -47,7 +47,7 @@ static struct curl_context *create_curl_context(curl_socket_t sockfd) { struct curl_context *context; - context = (struct curl_context *) malloc(sizeof(*context)); + context = (struct curl_context *)malloc(sizeof(*context)); context->sockfd = sockfd; @@ -134,10 +134,9 @@ static void curl_perform(int fd, short event, void *arg) if(event & EV_WRITE) flags |= CURL_CSELECT_OUT; - context = (struct curl_context *) arg; + context = (struct curl_context *)arg; - curl_multi_socket_action(multi, context->sockfd, flags, - &running_handles); + curl_multi_socket_action(multi, context->sockfd, flags, &running_handles); check_multi_info(); } @@ -148,8 +147,7 @@ static void on_timeout(evutil_socket_t fd, short events, void *arg) (void)fd; (void)events; (void)arg; - curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, - &running_handles); + curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, &running_handles); check_multi_info(); } @@ -186,9 +184,9 @@ static int handle_socket(CURL *curl, curl_socket_t s, int action, void *userp, case CURL_POLL_OUT: case CURL_POLL_INOUT: curl_context = socketp ? - (struct curl_context *) socketp : create_curl_context(s); + (struct curl_context *)socketp : create_curl_context(s); - curl_multi_assign(multi, s, (void *) curl_context); + curl_multi_assign(multi, s, (void *)curl_context); if(action != CURL_POLL_IN) events |= EV_WRITE; @@ -205,8 +203,8 @@ static int handle_socket(CURL *curl, curl_socket_t s, int action, void *userp, break; case CURL_POLL_REMOVE: if(socketp) { - event_del(((struct curl_context*) socketp)->event); - destroy_curl_context((struct curl_context*) socketp); + event_del(((struct curl_context *)socketp)->event); + destroy_curl_context((struct curl_context *)socketp); curl_multi_assign(multi, s, NULL); } break; diff --git a/docs/examples/multi-legacy.c b/docs/examples/multi-legacy.c index ca2c0a4c7afb..e34d1cd710a2 100644 --- a/docs/examples/multi-legacy.c +++ b/docs/examples/multi-legacy.c @@ -72,7 +72,7 @@ int main(void) int still_running = 0; /* keep number of running handles */ - CURLMsg *msg; /* for picking up messages with the transfer status */ + CURLMsg *msg; /* for picking up messages with the transfer status */ int msgs_left; /* how many messages are left */ /* add the individual transfers */ @@ -85,7 +85,7 @@ int main(void) while(still_running) { struct timeval timeout; - int rc; /* select() return code */ + int rc; /* select() return code */ CURLMcode mc; /* curl_multi_fdset() return code */ fd_set fdread; @@ -155,7 +155,7 @@ int main(void) case -1: /* select error */ break; - case 0: /* timeout */ + case 0: /* timeout */ default: /* action */ curl_multi_perform(multi, &still_running); break; diff --git a/docs/examples/multi-uv.c b/docs/examples/multi-uv.c index 1dac32048927..4053cb906112 100644 --- a/docs/examples/multi-uv.c +++ b/docs/examples/multi-uv.c @@ -60,7 +60,7 @@ static struct curl_context *create_curl_context(curl_socket_t sockfd, { struct curl_context *context; - context = (struct curl_context *) malloc(sizeof(*context)); + context = (struct curl_context *)malloc(sizeof(*context)); context->sockfd = sockfd; context->uv = uv; @@ -73,13 +73,13 @@ static struct curl_context *create_curl_context(curl_socket_t sockfd, static void curl_close_cb(uv_handle_t *handle) { - struct curl_context *context = (struct curl_context *) handle->data; + struct curl_context *context = (struct curl_context *)handle->data; free(context); } static void destroy_curl_context(struct curl_context *context) { - uv_close((uv_handle_t *) &context->poll_handle, curl_close_cb); + uv_close((uv_handle_t *)&context->poll_handle, curl_close_cb); } static void add_download(const char *url, int num, CURLM *multi) @@ -145,7 +145,7 @@ static void on_uv_socket(uv_poll_t *req, int status, int events) { int running_handles; int flags = 0; - struct curl_context *context = (struct curl_context *) req->data; + struct curl_context *context = (struct curl_context *)req->data; (void)status; if(events & UV_READABLE) flags |= CURL_CSELECT_IN; @@ -202,9 +202,9 @@ static int cb_socket(CURL *curl, curl_socket_t s, int action, case CURL_POLL_OUT: case CURL_POLL_INOUT: curl_context = socketp ? - (struct curl_context *) socketp : create_curl_context(s, uv); + (struct curl_context *)socketp : create_curl_context(s, uv); - curl_multi_assign(uv->multi, s, (void *) curl_context); + curl_multi_assign(uv->multi, s, (void *)curl_context); if(action != CURL_POLL_IN) events |= UV_WRITABLE; @@ -215,8 +215,8 @@ static int cb_socket(CURL *curl, curl_socket_t s, int action, break; case CURL_POLL_REMOVE: if(socketp) { - uv_poll_stop(&((struct curl_context*)socketp)->poll_handle); - destroy_curl_context((struct curl_context*) socketp); + uv_poll_stop(&((struct curl_context *)socketp)->poll_handle); + destroy_curl_context((struct curl_context *)socketp); curl_multi_assign(uv->multi, s, NULL); } break; @@ -230,7 +230,7 @@ static int cb_socket(CURL *curl, curl_socket_t s, int action, int main(int argc, char **argv) { CURLcode res; - struct datauv uv = { 0 }; + struct datauv uv = {0}; int running_handles; if(argc <= 1) diff --git a/docs/examples/multithread.c b/docs/examples/multithread.c index 7de1baea9085..308c1168e284 100644 --- a/docs/examples/multithread.c +++ b/docs/examples/multithread.c @@ -56,7 +56,6 @@ struct targ { const char *url; }; - static void *pull_one_url(void *p) { CURL *curl; @@ -72,7 +71,6 @@ static void *pull_one_url(void *p) return NULL; } - /* int pthread_create(pthread_t *new_thread_ID, const pthread_attr_t *attr, diff --git a/docs/examples/netrc.c b/docs/examples/netrc.c index 91f8df96dc31..a9eaebff88ee 100644 --- a/docs/examples/netrc.c +++ b/docs/examples/netrc.c @@ -40,8 +40,7 @@ int main(void) curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); - curl_easy_setopt(curl, CURLOPT_NETRC_FILE, - "/home/daniel/s3cr3ts.txt"); + curl_easy_setopt(curl, CURLOPT_NETRC_FILE, "/home/daniel/s3cr3ts.txt"); curl_easy_setopt(curl, CURLOPT_URL, "https://curl.se/"); res = curl_easy_perform(curl); diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index bbab00279091..c463e3785ceb 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -47,7 +47,7 @@ struct WriteThis { static size_t read_cb(char *dest, size_t size, size_t nmemb, void *userp) { struct WriteThis *wt = (struct WriteThis *)userp; - size_t buffer_size = size*nmemb; + size_t buffer_size = size * nmemb; if(wt->sizeleft) { /* copy as much as possible from the source to the destination */ diff --git a/docs/examples/postinmemory.c b/docs/examples/postinmemory.c index fc42251ddd12..089d9a9c743c 100644 --- a/docs/examples/postinmemory.c +++ b/docs/examples/postinmemory.c @@ -36,8 +36,7 @@ struct MemoryStruct { size_t size; }; -static size_t write_cb(void *contents, size_t size, size_t nmemb, - void *userp) +static size_t write_cb(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)userp; @@ -104,7 +103,7 @@ int main(void) * * Do something nice with it! */ - printf("%s\n",chunk.memory); + printf("%s\n", chunk.memory); } /* always cleanup */ diff --git a/docs/examples/sftpget.c b/docs/examples/sftpget.c index 287d5b253efb..470474cafd6c 100644 --- a/docs/examples/sftpget.c +++ b/docs/examples/sftpget.c @@ -50,8 +50,7 @@ struct FtpFile { FILE *stream; }; -static size_t write_cb(void *buffer, size_t size, size_t nmemb, - void *stream) +static size_t write_cb(void *buffer, size_t size, size_t nmemb, void *stream) { struct FtpFile *out = (struct FtpFile *)stream; if(!out->stream) { @@ -63,7 +62,6 @@ static size_t write_cb(void *buffer, size_t size, size_t nmemb, return fwrite(buffer, size, nmemb, out->stream); } - int main(void) { CURL *curl; diff --git a/docs/examples/sftpuploadresume.c b/docs/examples/sftpuploadresume.c index 84bb42554939..9b78f96ee4ab 100644 --- a/docs/examples/sftpuploadresume.c +++ b/docs/examples/sftpuploadresume.c @@ -83,7 +83,6 @@ static curl_off_t sftpGetRemoteFileSize(const char *i_remoteFile) return remoteFileSizeByte; } - static int sftpResumeUpload(CURL *curl, const char *remotepath, const char *localpath) { diff --git a/docs/examples/shared-connection-cache.c b/docs/examples/shared-connection-cache.c index bc1239428ba4..acaa610dec11 100644 --- a/docs/examples/shared-connection-cache.c +++ b/docs/examples/shared-connection-cache.c @@ -29,8 +29,8 @@ #include -static void my_lock(CURL *curl, curl_lock_data data, - curl_lock_access laccess, void *useptr) +static void my_lock(CURL *curl, curl_lock_data data, curl_lock_access laccess, + void *useptr) { (void)curl; (void)data; diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index a41a9ac29e6a..3cf4b462bd50 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -68,11 +68,11 @@ int main(void) const char *pKeyType; #ifdef USE_ENGINE - pKeyName = "rsa_test"; - pKeyType = "ENG"; + pKeyName = "rsa_test"; + pKeyType = "ENG"; #else - pKeyName = "testkey.pem"; - pKeyType = "PEM"; + pKeyName = "testkey.pem"; + pKeyType = "PEM"; #endif res = curl_global_init(CURL_GLOBAL_ALL); diff --git a/docs/examples/smooth-gtk-thread.c b/docs/examples/smooth-gtk-thread.c index 2a3cdbc0ef3c..6bf8946721aa 100644 --- a/docs/examples/smooth-gtk-thread.c +++ b/docs/examples/smooth-gtk-thread.c @@ -108,11 +108,10 @@ static void *pull_one_url(void *NaN) return NULL; } - static gboolean pulse_bar(gpointer data) { gdk_threads_enter(); - gtk_progress_bar_pulse(GTK_PROGRESS_BAR (data)); + gtk_progress_bar_pulse(GTK_PROGRESS_BAR(data)); gdk_threads_leave(); /* Return true so the function is called again; returning false removes this @@ -127,7 +126,7 @@ static void *create_thread(void *progress_bar) int i; /* Make sure I do not create more threads than urls. */ - for(i = 0; i < NUMT && i < num_urls ; i++) { + for(i = 0; i < NUMT && i < num_urls; i++) { int error = pthread_create(&tid[i], NULL, /* default attributes please */ pull_one_url, @@ -196,7 +195,7 @@ int main(int argc, char **argv) /* Progress bar */ progress_bar = gtk_progress_bar_new(); - gtk_progress_bar_pulse(GTK_PROGRESS_BAR (progress_bar)); + gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar)); /* Make uniform pulsing */ gint pulse_ref = g_timeout_add(300, pulse_bar, progress_bar); g_object_set_data(G_OBJECT(progress_bar), "pulse_id", @@ -206,7 +205,7 @@ int main(int argc, char **argv) gtk_widget_show_all(top_window); printf("gtk_widget_show_all\n"); - g_signal_connect(G_OBJECT (top_window), "delete-event", + g_signal_connect(G_OBJECT(top_window), "delete-event", G_CALLBACK(cb_delete), NULL); if(!g_thread_create(&create_thread, progress_bar, FALSE, NULL) != 0) diff --git a/docs/examples/smtp-authzid.c b/docs/examples/smtp-authzid.c index a375d839b131..e7dd20f59093 100644 --- a/docs/examples/smtp-authzid.c +++ b/docs/examples/smtp-authzid.c @@ -73,7 +73,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) size_t room = size * nmemb; size_t len; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } @@ -99,7 +99,7 @@ int main(void) curl = curl_easy_init(); if(curl) { struct curl_slist *recipients = NULL; - struct upload_status upload_ctx = { 0 }; + struct upload_status upload_ctx = {0}; /* This is the URL for your mailserver. In this example we connect to the smtp-submission port as we require an authenticated connection. */ diff --git a/docs/examples/smtp-mail.c b/docs/examples/smtp-mail.c index e6e77b97a39d..d5074abbf2f5 100644 --- a/docs/examples/smtp-mail.c +++ b/docs/examples/smtp-mail.c @@ -70,7 +70,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) size_t room = size * nmemb; size_t len; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } @@ -96,7 +96,7 @@ int main(void) curl = curl_easy_init(); if(curl) { struct curl_slist *recipients = NULL; - struct upload_status upload_ctx = { 0 }; + struct upload_status upload_ctx = {0}; /* This is the URL for your mailserver */ curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com"); diff --git a/docs/examples/smtp-multi.c b/docs/examples/smtp-multi.c index ab7165cd5277..8cb5e65a26b9 100644 --- a/docs/examples/smtp-multi.c +++ b/docs/examples/smtp-multi.c @@ -63,7 +63,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) size_t room = size * nmemb; size_t len; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } @@ -94,7 +94,7 @@ int main(void) if(multi) { int still_running = 1; struct curl_slist *recipients = NULL; - struct upload_status upload_ctx = { 0 }; + struct upload_status upload_ctx = {0}; /* This is the URL for your mailserver */ curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com"); diff --git a/docs/examples/smtp-ssl.c b/docs/examples/smtp-ssl.c index 4ebc58f1b5dd..3b140c904c5c 100644 --- a/docs/examples/smtp-ssl.c +++ b/docs/examples/smtp-ssl.c @@ -67,7 +67,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) size_t room = size * nmemb; size_t len; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } @@ -93,7 +93,7 @@ int main(void) curl = curl_easy_init(); if(curl) { struct curl_slist *recipients = NULL; - struct upload_status upload_ctx = { 0 }; + struct upload_status upload_ctx = {0}; /* Set username and password */ curl_easy_setopt(curl, CURLOPT_USERNAME, "user"); diff --git a/docs/examples/smtp-tls.c b/docs/examples/smtp-tls.c index f6b3bb6053c4..3bf3b0cddf11 100644 --- a/docs/examples/smtp-tls.c +++ b/docs/examples/smtp-tls.c @@ -67,7 +67,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) size_t room = size * nmemb; size_t len; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } @@ -93,7 +93,7 @@ int main(void) curl = curl_easy_init(); if(curl) { struct curl_slist *recipients = NULL; - struct upload_status upload_ctx = { 0 }; + struct upload_status upload_ctx = {0}; /* Set username and password */ curl_easy_setopt(curl, CURLOPT_USERNAME, "user"); diff --git a/docs/examples/sslbackend.c b/docs/examples/sslbackend.c index fd2b57534e65..5615bec72dc6 100644 --- a/docs/examples/sslbackend.c +++ b/docs/examples/sslbackend.c @@ -38,7 +38,7 @@ * SSL backend has to be configured). * * **** This example only works with libcurl 7.56.0 and later! **** -*/ + */ int main(int argc, char **argv) { diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index a9a746c30a20..b2a3b926072d 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -66,7 +66,11 @@ #include #ifndef _WIN32 -int main(void) { printf("Platform not supported.\n"); return 1; } +int main(void) +{ + printf("Platform not supported.\n"); + return 1; +} #else #if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \ @@ -79,7 +83,11 @@ int main(void) { printf("Platform not supported.\n"); return 1; } #endif #ifdef CURL_WINDOWS_UWP -int main(void) { printf("Platform not supported.\n"); return 1; } +int main(void) +{ + printf("Platform not supported.\n"); + return 1; +} #else #include @@ -123,8 +131,7 @@ static SYSTEMTIME LOCALTime; #define HTTP_COMMAND_HEAD 0 #define HTTP_COMMAND_GET 1 -static size_t write_cb(void *ptr, size_t size, size_t nmemb, - void *stream) +static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream) { fwrite(ptr, size, nmemb, stream); return nmemb * size; @@ -280,7 +287,7 @@ int main(int argc, char *argv[]) snprintf(conf->http_proxy, MAX_STRING, "%s", &argv[OptionIndex][8]); if((strcmp(argv[OptionIndex], "--help") == 0) || - (strcmp(argv[OptionIndex], "/?") == 0)) { + (strcmp(argv[OptionIndex], "/?") == 0)) { showUsage(); return 0; } @@ -317,9 +324,9 @@ int main(int argc, char *argv[]) gmt = gmtime(&tt); tt_gmt = mktime(gmt); tzonediffFloat = difftime(tt_local, tt_gmt); - tzonediffWord = (int)(tzonediffFloat/3600.0); + tzonediffWord = (int)(tzonediffFloat / 3600.0); - if(tzonediffWord == (int)(tzonediffFloat/3600.0)) + if(tzonediffWord == (int)(tzonediffFloat / 3600.0)) snprintf(tzoneBuf, sizeof(tzoneBuf), "%+03d'00'", tzonediffWord); else snprintf(tzoneBuf, sizeof(tzoneBuf), "%+03d'30'", tzonediffWord); @@ -329,9 +336,8 @@ int main(int argc, char *argv[]) GetLocalTime(&LOCALTime); snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ", DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay, - MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, - LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, - LOCALTime.wMilliseconds); + MthStr[LOCALTime.wMonth - 1], LOCALTime.wYear, LOCALTime.wHour, + LOCALTime.wMinute, LOCALTime.wSecond, LOCALTime.wMilliseconds); fprintf(stderr, "Fetch: %s\n\n", conf->timeserver); fprintf(stderr, "Before HTTP. Date: %s%s\n\n", timeBuf, tzoneBuf); @@ -343,9 +349,8 @@ int main(int argc, char *argv[]) GetLocalTime(&LOCALTime); snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ", DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay, - MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, - LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, - LOCALTime.wMilliseconds); + MthStr[LOCALTime.wMonth - 1], LOCALTime.wYear, LOCALTime.wHour, + LOCALTime.wMinute, LOCALTime.wSecond, LOCALTime.wMilliseconds); fprintf(stderr, "\nAfter HTTP. Date: %s%s\n", timeBuf, tzoneBuf); if(AutoSyncTime == 3) { @@ -359,7 +364,7 @@ int main(int argc, char *argv[]) GetLocalTime(&LOCALTime); snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ", DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay, - MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, + MthStr[LOCALTime.wMonth - 1], LOCALTime.wYear, LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, LOCALTime.wMilliseconds); fprintf(stderr, "\nNew System's Date: %s%s\n", timeBuf, tzoneBuf); diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c index 8119113695ea..8d5d1234fcb2 100644 --- a/docs/examples/threaded-ssl.c +++ b/docs/examples/threaded-ssl.c @@ -46,7 +46,7 @@ #define NUMT 4 /* List of URLs to fetch.*/ -static const char * const urls[]= { +static const char * const urls[] = { "https://www.example.com/", "https://www2.example.com/", "https://www3.example.com/", diff --git a/docs/examples/usercertinmem.c b/docs/examples/usercertinmem.c index 175dae11514f..44a0a15bc7b1 100644 --- a/docs/examples/usercertinmem.c +++ b/docs/examples/usercertinmem.c @@ -114,7 +114,7 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer) } /* tell SSL to use the X509 certificate */ - ret = SSL_CTX_use_certificate((SSL_CTX*)sslctx, cert); + ret = SSL_CTX_use_certificate((SSL_CTX *)sslctx, cert); if(ret != 1) { printf("Use certificate failed\n"); } @@ -132,7 +132,7 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer) } /* tell SSL to use the RSA key from memory */ - ret = SSL_CTX_use_RSAPrivateKey((SSL_CTX*)sslctx, rsa); + ret = SSL_CTX_use_RSAPrivateKey((SSL_CTX *)sslctx, rsa); if(ret != 1) { printf("Use Key failed\n"); } diff --git a/docs/examples/xmlstream.c b/docs/examples/xmlstream.c index 0aec24cc67a7..5b35d048619a 100644 --- a/docs/examples/xmlstream.c +++ b/docs/examples/xmlstream.c @@ -55,7 +55,7 @@ struct ParserStruct { static void startElement(void *userData, const XML_Char *name, const XML_Char **atts) { - struct ParserStruct *state = (struct ParserStruct *) userData; + struct ParserStruct *state = (struct ParserStruct *)userData; state->tags++; state->depth++; @@ -70,7 +70,7 @@ static void startElement(void *userData, const XML_Char *name, static void characterDataHandler(void *userData, const XML_Char *s, int len) { - struct ParserStruct *state = (struct ParserStruct *) userData; + struct ParserStruct *state = (struct ParserStruct *)userData; struct MemoryStruct *mem = &state->characters; char *ptr = realloc(mem->memory, mem->size + (unsigned long)len + 1); @@ -89,7 +89,7 @@ static void characterDataHandler(void *userData, const XML_Char *s, int len) static void endElement(void *userData, const XML_Char *name) { - struct ParserStruct *state = (struct ParserStruct *) userData; + struct ParserStruct *state = (struct ParserStruct *)userData; state->depth--; printf("%5lu %10lu %s\n", state->depth, state->characters.size, name); @@ -98,9 +98,9 @@ static void endElement(void *userData, const XML_Char *name) static size_t write_cb(void *contents, size_t length, size_t nmemb, void *userp) { - XML_Parser parser = (XML_Parser) userp; + XML_Parser parser = (XML_Parser)userp; size_t real_size = length * nmemb; - struct ParserStruct *state = (struct ParserStruct *) XML_GetUserData(parser); + struct ParserStruct *state = (struct ParserStruct *)XML_GetUserData(parser); /* Only parse if we are not already in a failure state. */ if(state->ok && XML_Parse(parser, contents, (int)real_size, 0) == 0) { From e25a3c6734458328412c55d236d3a2370593585c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 28 Nov 2025 15:16:08 +0100 Subject: [PATCH 108/140] GHA/curl-for-win: drop WINE install, do not run curl after build To reduce to amount of Debian packages to install, which hopefully removes some flakiness due to sometimes very slow Azure package distro servers. Possible also making these jobs finish 20s faster. Windows from Debian | llvm | gcc :------------------ | :----------------: | :----------------: build time | 2m41s -> 2m20s | 3m19s -> 2m57s installed packages | 288 -> 142 | 247 -> 99 downloads | 403 MB -> 240 MB | 297 MB -> 134 MB disk space | 2132 MB -> 1289 MB | 1582 MB -> 739 MB Before: https://github.com/curl/curl/actions/runs/19765983026 After: https://github.com/curl/curl/actions/runs/19766373960?pr=19749 Ref: https://github.com/curl/curl-for-win/commit/02149b7e364a1830d8fa2c947cfc713d925c186d Closes #19749 --- .github/workflows/curl-for-win.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/curl-for-win.yml b/.github/workflows/curl-for-win.yml index f0214b2874cb..f352529f723e 100644 --- a/.github/workflows/curl-for-win.yml +++ b/.github/workflows/curl-for-win.yml @@ -159,7 +159,7 @@ jobs: run: | git clone --depth 1 https://github.com/curl/curl-for-win mv curl-for-win/* . - export CW_CONFIG='-main-werror-unitybatch-win-x64' + export CW_CONFIG='-main-werror-unitybatch-win-x64-noWINE' export CW_REVISION="${GITHUB_SHA}" . ./_versions.sh sudo podman image trust set --type reject default @@ -186,7 +186,7 @@ jobs: run: | git clone --depth 1 https://github.com/curl/curl-for-win mv curl-for-win/* . - export CW_CONFIG='-main-werror-unitybatch-win-x64-gcc-zlibold' + export CW_CONFIG='-main-werror-unitybatch-win-x64-gcc-zlibold-noWINE' export CW_REVISION="${GITHUB_SHA}" . ./_versions.sh sudo podman image trust set --type reject default From 12a3182fc39cb948792e9cc189887cd85b587bb0 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Fri, 28 Nov 2025 12:49:16 +0100 Subject: [PATCH 109/140] ssh: tracing and better pollset handling Remove connection member `waitfor` and keep it in the SSH connection meta. Add `ssh` to supported tracing features, convert many DEBUGF printgs to traces. Closes #19745 --- docs/libcurl/curl_global_trace.md | 4 + lib/curl_trc.c | 28 +++++++ lib/curl_trc.h | 13 ++++ lib/urldata.h | 1 - lib/vssh/libssh.c | 124 ++++++++++++++++-------------- lib/vssh/libssh2.c | 112 +++++++++++++++------------ lib/vssh/ssh.h | 3 +- 7 files changed, 178 insertions(+), 107 deletions(-) diff --git a/docs/libcurl/curl_global_trace.md b/docs/libcurl/curl_global_trace.md index 0459eab6747d..10ec21b4bd43 100644 --- a/docs/libcurl/curl_global_trace.md +++ b/docs/libcurl/curl_global_trace.md @@ -130,6 +130,10 @@ states. Traces reading of upload data from the application in order to send it to the server. +## `ssh` + +Tracing of SSH related protocols SCP and SFTP. + ## `ssls` Tracing of SSL Session handling, e.g. caching/import/export. diff --git a/lib/curl_trc.c b/lib/curl_trc.c index cc06c77e9d9a..42711ed01c05 100644 --- a/lib/curl_trc.c +++ b/lib/curl_trc.c @@ -453,6 +453,24 @@ void Curl_trc_ssls(struct Curl_easy *data, const char *fmt, ...) } #endif /* USE_SSL */ +#ifdef USE_SSH +struct curl_trc_feat Curl_trc_feat_ssh = { + "SSH", + CURL_LOG_LVL_NONE, +}; + +void Curl_trc_ssh(struct Curl_easy *data, const char *fmt, ...) +{ + DEBUGASSERT(!strchr(fmt, '\n')); + if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssh)) { + va_list ap; + va_start(ap, fmt); + trc_infof(data, &Curl_trc_feat_ssh, NULL, 0, fmt, ap); + va_end(ap); + } +} +#endif /* USE_SSH */ + #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) struct curl_trc_feat Curl_trc_feat_ws = { "WS", @@ -500,6 +518,9 @@ static struct trc_feat_def trc_feats[] = { #ifdef USE_SSL { &Curl_trc_feat_ssls, TRC_CT_NETWORK }, #endif +#ifdef USE_SSH + { &Curl_trc_feat_ssh, TRC_CT_PROTOCOL }, +#endif #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) { &Curl_trc_feat_ws, TRC_CT_PROTOCOL }, #endif @@ -696,6 +717,13 @@ void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...) (void)data; (void)fmt; } #endif +#ifdef USE_SSH +void Curl_trc_ssh(struct Curl_easy *data, const char *fmt, ...) +{ + (void)data; + (void)fmt; +} +#endif #ifdef USE_SSL void Curl_trc_ssls(struct Curl_easy *data, const char *fmt, ...) { diff --git a/lib/curl_trc.h b/lib/curl_trc.h index 1a3f8f374e2d..0ce76ed7effa 100644 --- a/lib/curl_trc.h +++ b/lib/curl_trc.h @@ -117,6 +117,11 @@ extern struct curl_trc_feat Curl_trc_feat_ssls; void Curl_trc_ssls(struct Curl_easy *data, const char *fmt, ...) CURL_PRINTF(2, 3); #endif +#ifdef USE_SSH +extern struct curl_trc_feat Curl_trc_feat_ssh; +void Curl_trc_ssh(struct Curl_easy *data, + const char *fmt, ...) CURL_PRINTF(2, 3); +#endif #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) extern struct curl_trc_feat Curl_trc_feat_ws; void Curl_trc_ws(struct Curl_easy *data, @@ -168,6 +173,11 @@ void Curl_trc_ws(struct Curl_easy *data, do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssls)) \ Curl_trc_ssls(data, __VA_ARGS__); } while(0) #endif /* USE_SSL */ +#ifdef USE_SSH +#define CURL_TRC_SSH(data, ...) \ + do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssh)) \ + Curl_trc_ssh(data, __VA_ARGS__); } while(0) +#endif /* USE_SSH */ #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) #define CURL_TRC_WS(data, ...) \ do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) \ @@ -193,6 +203,9 @@ void Curl_trc_ws(struct Curl_easy *data, #ifdef USE_SSL #define CURL_TRC_SSLS Curl_trc_ssls #endif +#ifdef USE_SSH +#define CURL_TRC_SSH Curl_trc_ssh +#endif #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) #define CURL_TRC_WS Curl_trc_ws #endif diff --git a/lib/urldata.h b/lib/urldata.h index debc2a3e0aa0..2d28718181a9 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -713,7 +713,6 @@ struct connectdata { wrong connections. */ char *localdev; unsigned short localportrange; - int waitfor; /* current READ/WRITE bits to wait for */ #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI) int socks5_gssapi_enctype; #endif diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index a5997a6f6cf9..2b605e4a6184 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -210,26 +210,9 @@ static CURLcode sftp_error_to_CURLE(int err) return CURLE_SSH; } -#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) -#define myssh_to(x,y,z) myssh_set_state(x,y,z, __LINE__) -#else -#define myssh_to(x,y,z) myssh_set_state(x,y,z) -#endif - -/* - * SSH State machine related code - */ -/* This is the ONLY way to change SSH state! */ -static void myssh_set_state(struct Curl_easy *data, - struct ssh_conn *sshc, - sshstate nowstate -#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) - , int lineno -#endif - ) +#if !defined(CURL_DISABLE_VERBOSE_STRINGS) +static const char *myssh_statename(sshstate state) { -#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) - /* for debug purposes */ static const char *const names[] = { "SSH_STOP", "SSH_INIT", @@ -292,14 +275,34 @@ static void myssh_set_state(struct Curl_easy *data, "SSH_SESSION_FREE", "QUIT" }; + /* a precaution to make sure the lists are in sync */ + DEBUGASSERT(CURL_ARRAYSIZE(names) == SSH_LAST); + return ((size_t)state < CURL_ARRAYSIZE(names)) ? names[state] : ""; +} +#else +#define myssh_statename(x) "" +#endif /* !CURL_DISABLE_VERBOSE_STRINGS */ + +#define myssh_to(x,y,z) myssh_set_state(x,y,z) + +/* + * SSH State machine related code + */ +/* This is the ONLY way to change SSH state! */ +static void myssh_set_state(struct Curl_easy *data, + struct ssh_conn *sshc, + sshstate nowstate) +{ +#if !defined(CURL_DISABLE_VERBOSE_STRINGS) if(sshc->state != nowstate) { - infof(data, "SSH %p state change from %s to %s (line %d)", - (void *) sshc, names[sshc->state], names[nowstate], - lineno); + CURL_TRC_SSH(data, "[%s] -> [%s]", + myssh_statename(sshc->state), + myssh_statename(nowstate)); } -#endif +#else (void)data; +#endif sshc->state = nowstate; } @@ -887,7 +890,7 @@ static int myssh_in_S_STARTUP(struct Curl_easy *data, myssh_block2waitfor(conn, sshc, (rc == SSH_AGAIN)); if(rc == SSH_AGAIN) { - DEBUGF(infof(data, "ssh_connect -> EAGAIN")); + CURL_TRC_SSH(data, "connect -> EAGAIN"); } else if(rc != SSH_OK) { failf(data, "Failure establishing ssh session"); @@ -1259,10 +1262,6 @@ static int myssh_in_UPLOAD_INIT(struct Curl_easy *data, /* not set by Curl_xfer_setup to preserve keepon bits */ data->conn->recv_idx = FIRSTSOCKET; - /* store this original bitmask setup to use later on if we cannot - figure out a "real" bitmask */ - sshc->orig_waitfor = data->req.keepon; - /* since we do not really wait for anything at this point, we want the state machine to move on as soon as possible so we mark this as dirty */ Curl_multi_mark_dirty(data); @@ -1401,7 +1400,7 @@ static int myssh_in_SFTP_CLOSE(struct Curl_easy *data, } Curl_safefree(sshp->path); - DEBUGF(infof(data, "SFTP DONE done")); + CURL_TRC_SSH(data, "SFTP DONE done"); /* Check if nextstate is set and move .nextstate could be POSTQUOTE_INIT After nextstate is executed, the control should come back to @@ -1485,7 +1484,7 @@ static int myssh_in_SFTP_REALPATH(struct Curl_easy *data, we get the homedir here, we get the "workingpath" in the DO action since the homedir will remain the same between request but the working path will not. */ - DEBUGF(infof(data, "SSH CONNECT phase done")); + CURL_TRC_SSH(data, "CONNECT phase done"); myssh_to(data, sshc, SSH_STOP); return SSH_NO_ERROR; } @@ -2285,10 +2284,6 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, /* not set by Curl_xfer_setup to preserve keepon bits */ data->conn->recv_idx = FIRSTSOCKET; - /* store this original bitmask setup to use later on if we cannot - figure out a "real" bitmask */ - sshc->orig_waitfor = data->req.keepon; - myssh_to(data, sshc, SSH_STOP); break; @@ -2357,7 +2352,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, ssh_scp_free(sshc->scp_session); sshc->scp_session = NULL; } - DEBUGF(infof(data, "SCP DONE phase complete")); + CURL_TRC_SSH(data, "SCP DONE phase complete"); ssh_set_blocking(sshc->ssh_session, 0); @@ -2422,7 +2417,8 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, } if(!result && (sshc->state == SSH_STOP)) result = sshc->actualcode; - DEBUGF(infof(data, "SSH: myssh_statemach_act -> %d", result)); + CURL_TRC_SSH(data, "[%s] statemachine() -> %d, block=%d", + myssh_statename(sshc->state), result, *block); return result; } @@ -2432,33 +2428,45 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, static CURLcode myssh_pollset(struct Curl_easy *data, struct easy_pollset *ps) { - int flags = 0; struct connectdata *conn = data->conn; - if(conn->waitfor & KEEP_RECV) - flags |= CURL_POLL_IN; - if(conn->waitfor & KEEP_SEND) - flags |= CURL_POLL_OUT; - if(!conn->waitfor) - flags |= CURL_POLL_OUT; - return flags ? - Curl_pollset_change(data, ps, conn->sock[FIRSTSOCKET], flags, 0) : - CURLE_OK; + struct ssh_conn *sshc = Curl_conn_meta_get(conn, CURL_META_SSH_CONN); + curl_socket_t sock = conn->sock[FIRSTSOCKET]; + int waitfor; + + if(!sshc || (sock == CURL_SOCKET_BAD)) + return CURLE_FAILED_INIT; + + waitfor = sshc->waitfor ? sshc->waitfor : data->req.keepon; + if(waitfor) { + int flags = 0; + if(waitfor & KEEP_RECV) + flags |= CURL_POLL_IN; + if(waitfor & KEEP_SEND) + flags |= CURL_POLL_OUT; + DEBUGASSERT(flags); + CURL_TRC_SSH(data, "pollset, flags=%x", flags); + return Curl_pollset_change(data, ps, sock, flags, 0); + } + /* While we still have a session, we listen incoming data. */ + if(sshc->ssh_session) + return Curl_pollset_change(data, ps, sock, CURL_POLL_IN, 0); + return CURLE_OK; } static void myssh_block2waitfor(struct connectdata *conn, struct ssh_conn *sshc, bool block) { + (void)conn; if(block) { int dir = ssh_get_poll_flags(sshc->ssh_session); /* translate the libssh define bits into our own bit defines */ - conn->waitfor = + sshc->waitfor = ((dir & SSH_READ_PENDING) ? KEEP_RECV : 0) | ((dir & SSH_WRITE_PENDING) ? KEEP_SEND : 0); } else - /* if it did not block, use the original set */ - conn->waitfor = sshc->orig_waitfor; + sshc->waitfor = 0; } /* called repeatedly until done from multi.c */ @@ -2584,6 +2592,7 @@ static CURLcode myssh_connect(struct Curl_easy *data, bool *done) if(!sshc || !ssh) return CURLE_FAILED_INIT; + CURL_TRC_SSH(data, "myssh_connect"); if(conn->handler->protocol & CURLPROTO_SCP) { conn->recv[FIRSTSOCKET] = scp_recv; conn->send[FIRSTSOCKET] = scp_send; @@ -2618,6 +2627,7 @@ static CURLcode myssh_connect(struct Curl_easy *data, bool *done) /* ignore */ } + CURL_TRC_SSH(data, "myssh_connect, set socket=%" FMT_SOCKET_T, sock); rc = ssh_options_set(sshc->ssh_session, SSH_OPTIONS_FD, &sock); if(rc != SSH_OK) { failf(data, "Could not set socket"); @@ -2691,7 +2701,7 @@ static CURLcode scp_doing(struct Curl_easy *data, bool *dophase_done) result = myssh_multi_statemach(data, dophase_done); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; } @@ -2712,7 +2722,7 @@ CURLcode scp_perform(struct Curl_easy *data, CURLcode result = CURLE_OK; struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN); - DEBUGF(infof(data, "DO phase starts")); + CURL_TRC_SSH(data, "DO phase starts"); *dophase_done = FALSE; /* not done yet */ if(!sshc) @@ -2726,7 +2736,7 @@ CURLcode scp_perform(struct Curl_easy *data, *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; @@ -2959,7 +2969,7 @@ CURLcode sftp_perform(struct Curl_easy *data, struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN); CURLcode result = CURLE_OK; - DEBUGF(infof(data, "DO phase starts")); + CURL_TRC_SSH(data, "DO phase starts"); *dophase_done = FALSE; /* not done yet */ if(!sshc) @@ -2974,7 +2984,7 @@ CURLcode sftp_perform(struct Curl_easy *data, *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; @@ -2986,7 +2996,7 @@ static CURLcode sftp_doing(struct Curl_easy *data, { CURLcode result = myssh_multi_statemach(data, dophase_done); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; } @@ -3003,7 +3013,7 @@ static CURLcode sftp_disconnect(struct Curl_easy *data, CURLcode result = CURLE_OK; (void)dead_connection; - DEBUGF(infof(data, "SSH DISCONNECT starts now")); + CURL_TRC_SSH(data, "DISCONNECT starts now"); if(sshc && sshc->ssh_session) { /* only if there is a session still around to use! */ @@ -3011,7 +3021,7 @@ static CURLcode sftp_disconnect(struct Curl_easy *data, result = myssh_block_statemach(data, sshc, sshp, TRUE); } - DEBUGF(infof(data, "SSH DISCONNECT is done")); + CURL_TRC_SSH(data, "DISCONNECT is done"); return result; } diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index 4ac9d89f1ad5..31ef5092d3da 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -280,17 +280,10 @@ static LIBSSH2_FREE_FUNC(my_libssh2_free) Curl_cfree(ptr); } -/* - * SSH State machine related code - */ -/* This is the ONLY way to change SSH state! */ -static void myssh_state(struct Curl_easy *data, - struct ssh_conn *sshc, - sshstate nowstate) +#if !defined(CURL_DISABLE_VERBOSE_STRINGS) +static const char *myssh_statename(sshstate state) { -#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) - /* for debug purposes */ - static const char * const names[] = { + static const char *const names[] = { "SSH_STOP", "SSH_INIT", "SSH_S_STARTUP", @@ -352,16 +345,34 @@ static void myssh_state(struct Curl_easy *data, "SSH_SESSION_FREE", "QUIT" }; - /* a precaution to make sure the lists are in sync */ DEBUGASSERT(CURL_ARRAYSIZE(names) == SSH_LAST); + return ((size_t)state < CURL_ARRAYSIZE(names)) ? names[state] : ""; +} +#else +#define myssh_statename(x) "" +#endif /* !CURL_DISABLE_VERBOSE_STRINGS */ + +#define myssh_state(x,y,z) myssh_set_state(x,y,z) + +/* + * SSH State machine related code + */ +/* This is the ONLY way to change SSH state! */ +static void myssh_set_state(struct Curl_easy *data, + struct ssh_conn *sshc, + sshstate nowstate) +{ +#if !defined(CURL_DISABLE_VERBOSE_STRINGS) if(sshc->state != nowstate) { - infof(data, "SFTP %p state change from %s to %s", - (void *)sshc, names[sshc->state], names[nowstate]); + CURL_TRC_SSH(data, "[%s] -> [%s]", + myssh_statename(sshc->state), + myssh_statename(nowstate)); } -#endif +#else (void)data; +#endif sshc->state = nowstate; } @@ -1172,10 +1183,6 @@ sftp_upload_init(struct Curl_easy *data, /* not set by Curl_xfer_setup to preserve keepon bits */ data->conn->recv_idx = FIRSTSOCKET; - /* store this original bitmask setup to use later on if we cannot - figure out a "real" bitmask */ - sshc->orig_waitfor = data->req.keepon; - /* since we do not really wait for anything at this point, we want the state machine to move on as soon as possible so mark this as dirty */ Curl_multi_mark_dirty(data); @@ -1951,8 +1958,7 @@ static CURLcode ssh_state_sftp_realpath(struct Curl_easy *data, /* in this case, the error was not in the SFTP level but for example a time-out or similar */ result = CURLE_SSH; - DEBUGF(infof(data, "error = %lu makes libcurl = %d", - sftperr, (int)result)); + CURL_TRC_SSH(data, "error = %lu makes libcurl = %d", sftperr, (int)result); return result; } @@ -1960,7 +1966,7 @@ static CURLcode ssh_state_sftp_realpath(struct Curl_easy *data, get the homedir here, we get the "workingpath" in the DO action since the homedir will remain the same between request but the working path will not. */ - DEBUGF(infof(data, "SSH CONNECT phase done")); + CURL_TRC_SSH(data, "CONNECT phase done"); return CURLE_OK; } @@ -2418,7 +2424,7 @@ static CURLcode ssh_state_sftp_close(struct Curl_easy *data, Curl_safefree(sshp->path); - DEBUGF(infof(data, "SFTP DONE done")); + CURL_TRC_SSH(data, "SFTP DONE done"); /* Check if nextstate is set and move .nextstate could be POSTQUOTE_INIT After nextstate is executed, the control should come back to @@ -2542,10 +2548,6 @@ static CURLcode ssh_state_scp_upload_init(struct Curl_easy *data, /* not set by Curl_xfer_setup to preserve keepon bits */ data->conn->recv_idx = FIRSTSOCKET; - /* store this original bitmask setup to use later on if we cannot - figure out a "real" bitmask */ - sshc->orig_waitfor = data->req.keepon; - myssh_state(data, sshc, SSH_STOP); return CURLE_OK; @@ -3008,7 +3010,7 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, } sshc->ssh_channel = NULL; } - DEBUGF(infof(data, "SCP DONE phase complete")); + CURL_TRC_SSH(data, "SCP DONE phase complete"); myssh_state(data, sshc, SSH_STOP); break; @@ -3042,6 +3044,8 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, *block = TRUE; result = CURLE_OK; } + CURL_TRC_SSH(data, "[%s] statemachine() -> %d, block=%d", + myssh_statename(sshc->state), result, *block); return result; } @@ -3051,15 +3055,29 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, static CURLcode ssh_pollset(struct Curl_easy *data, struct easy_pollset *ps) { - int flags = 0; struct connectdata *conn = data->conn; - if(conn->waitfor & KEEP_RECV) - flags |= CURL_POLL_IN; - if(conn->waitfor & KEEP_SEND) - flags |= CURL_POLL_OUT; - return flags ? - Curl_pollset_change(data, ps, conn->sock[FIRSTSOCKET], flags, 0) : - CURLE_OK; + struct ssh_conn *sshc = Curl_conn_meta_get(conn, CURL_META_SSH_CONN); + curl_socket_t sock = conn->sock[FIRSTSOCKET]; + int waitfor; + + if(!sshc || (sock == CURL_SOCKET_BAD)) + return CURLE_FAILED_INIT; + + waitfor = sshc->waitfor ? sshc->waitfor : data->req.keepon; + if(waitfor) { + int flags = 0; + if(waitfor & KEEP_RECV) + flags |= CURL_POLL_IN; + if(waitfor & KEEP_SEND) + flags |= CURL_POLL_OUT; + DEBUGASSERT(flags); + CURL_TRC_SSH(data, "pollset, flags=%x", flags); + return Curl_pollset_change(data, ps, sock, flags, 0); + } + /* While we still have a session, we listen incoming data. */ + if(sshc->ssh_session) + return Curl_pollset_change(data, ps, sock, CURL_POLL_IN, 0); + return CURLE_OK; } /* @@ -3073,20 +3091,18 @@ static void ssh_block2waitfor(struct Curl_easy *data, struct ssh_conn *sshc, bool block) { - struct connectdata *conn = data->conn; int dir = 0; + (void)data; if(block) { dir = libssh2_session_block_directions(sshc->ssh_session); if(dir) { /* translate the libssh2 define bits into our own bit defines */ - conn->waitfor = ((dir&LIBSSH2_SESSION_BLOCK_INBOUND) ? KEEP_RECV : 0) | + sshc->waitfor = ((dir&LIBSSH2_SESSION_BLOCK_INBOUND) ? KEEP_RECV : 0) | ((dir&LIBSSH2_SESSION_BLOCK_OUTBOUND) ? KEEP_SEND : 0); } } if(!dir) - /* It did not block or libssh2 did not reveal in which direction, put back - the original set */ - conn->waitfor = sshc->orig_waitfor; + sshc->waitfor = 0; } /* called repeatedly until done from multi.c */ @@ -3468,7 +3484,7 @@ CURLcode scp_perform(struct Curl_easy *data, struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN); CURLcode result = CURLE_OK; - DEBUGF(infof(data, "DO phase starts")); + CURL_TRC_SSH(data, "DO phase starts"); *dophase_done = FALSE; /* not done yet */ if(!sshc) @@ -3483,7 +3499,7 @@ CURLcode scp_perform(struct Curl_easy *data, *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; @@ -3497,7 +3513,7 @@ static CURLcode scp_doing(struct Curl_easy *data, result = ssh_multi_statemach(data, dophase_done); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; } @@ -3778,7 +3794,7 @@ CURLcode sftp_perform(struct Curl_easy *data, struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN); CURLcode result = CURLE_OK; - DEBUGF(infof(data, "DO phase starts")); + CURL_TRC_SSH(data, "DO phase starts"); *dophase_done = FALSE; /* not done yet */ if(!sshc) @@ -3793,7 +3809,7 @@ CURLcode sftp_perform(struct Curl_easy *data, *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; @@ -3806,7 +3822,7 @@ static CURLcode sftp_doing(struct Curl_easy *data, CURLcode result = ssh_multi_statemach(data, dophase_done); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; } @@ -3825,10 +3841,10 @@ static CURLcode sftp_disconnect(struct Curl_easy *data, if(sshc) { if(sshc->ssh_session) { /* only if there is a session still around to use! */ - DEBUGF(infof(data, "SSH DISCONNECT starts now")); + CURL_TRC_SSH(data, "DISCONNECT starts now"); myssh_state(data, sshc, SSH_SFTP_SHUTDOWN); result = ssh_block_statemach(data, sshc, sshp, TRUE); - DEBUGF(infof(data, "SSH DISCONNECT is done -> %d", result)); + CURL_TRC_SSH(data, "DISCONNECT is done -> %d", result); } sshc_cleanup(sshc, data, TRUE); } diff --git a/lib/vssh/ssh.h b/lib/vssh/ssh.h index 5317351478fc..92ae72a6a761 100644 --- a/lib/vssh/ssh.h +++ b/lib/vssh/ssh.h @@ -156,7 +156,8 @@ struct ssh_conn { int secondCreateDirs; /* counter use by the code to see if the second attempt has been made to change to/create a directory */ - int orig_waitfor; /* default READ/WRITE bits wait for */ + int waitfor; /* KEEP_RECV/KEEP_SEND bits overriding + pollset given flags */ char *slash_pos; /* used by the SFTP_CREATE_DIRS state */ #ifdef USE_LIBSSH From b06cd929bd9bdda2fe4dfced73a60bd503be6155 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Fri, 28 Nov 2025 14:05:34 +0100 Subject: [PATCH 110/140] libssh: fix state machine loop to progress as it should --- lib/vssh/libssh.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index 2b605e4a6184..d0f3d3de5cca 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -2408,7 +2408,9 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, break; } - } while(!rc && (sshc->state != SSH_STOP)); + /* break the loop only on STOP or SSH_AGAIN. If `rc` is some + * other error code, we will have progressed the state accordingly. */ + } while((rc != SSH_AGAIN) && (sshc->state != SSH_STOP)); if(rc == SSH_AGAIN) { /* we would block, we need to wait for the socket to be ready (in the From 8c68887d2d145b00a912824cc6962d0d64cb8419 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Fri, 28 Nov 2025 10:25:59 +0100 Subject: [PATCH 111/140] http1: parse header from uint8_t buffer To save casting the passed buffer when parsing HTTP/1 request headers from an uint8_t buffer. Closes #19742 --- lib/http1.c | 10 +++++----- lib/http1.h | 2 +- lib/http2.c | 2 +- lib/vquic/curl_ngtcp2.c | 2 +- lib/vquic/curl_osslq.c | 2 +- lib/vquic/curl_quiche.c | 2 +- tests/unit/unit2603.c | 6 +++--- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/http1.c b/lib/http1.c index 0a80fedfc722..657a674105fa 100644 --- a/lib/http1.c +++ b/lib/http1.c @@ -77,7 +77,7 @@ static CURLcode trim_line(struct h1_req_parser *parser, int options) } static CURLcode detect_line(struct h1_req_parser *parser, - const char *buf, const size_t buflen, + const uint8_t *buf, const size_t buflen, size_t *pnread) { const char *line_end; @@ -87,14 +87,14 @@ static CURLcode detect_line(struct h1_req_parser *parser, line_end = memchr(buf, '\n', buflen); if(!line_end) return CURLE_AGAIN; - parser->line = buf; - parser->line_len = line_end - buf + 1; + parser->line = (const char *)buf; + parser->line_len = line_end - parser->line + 1; *pnread = parser->line_len; return CURLE_OK; } static CURLcode next_line(struct h1_req_parser *parser, - const char *buf, const size_t buflen, int options, + const uint8_t *buf, const size_t buflen, int options, size_t *pnread) { CURLcode result; @@ -262,7 +262,7 @@ static CURLcode start_req(struct h1_req_parser *parser, } CURLcode Curl_h1_req_parse_read(struct h1_req_parser *parser, - const char *buf, size_t buflen, + const uint8_t *buf, size_t buflen, const char *scheme_default, const char *custom_method, int options, size_t *pnread) diff --git a/lib/http1.h b/lib/http1.h index 944e9038dd98..88bd99798e05 100644 --- a/lib/http1.h +++ b/lib/http1.h @@ -49,7 +49,7 @@ void Curl_h1_req_parse_init(struct h1_req_parser *parser, size_t max_line_len); void Curl_h1_req_parse_free(struct h1_req_parser *parser); CURLcode Curl_h1_req_parse_read(struct h1_req_parser *parser, - const char *buf, size_t buflen, + const uint8_t *buf, size_t buflen, const char *scheme_default, const char *custom_method, int options, size_t *pnread); diff --git a/lib/http2.c b/lib/http2.c index baaefd439d4f..e75d7431e72c 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -2277,7 +2277,7 @@ static CURLcode h2_submit(struct h2_stream_ctx **pstream, if(result) goto out; - result = Curl_h1_req_parse_read(&stream->h1, (const char *)buf, len, NULL, + result = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL, !data->state.http_ignorecustom ? data->set.str[STRING_CUSTOMREQUEST] : NULL, 0, &nwritten); diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index 4767780a922d..62255285b6a0 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -1548,7 +1548,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, goto out; } - result = Curl_h1_req_parse_read(&stream->h1, (const char *)buf, len, NULL, + result = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL, !data->state.http_ignorecustom ? data->set.str[STRING_CUSTOMREQUEST] : NULL, 0, pnwritten); diff --git a/lib/vquic/curl_osslq.c b/lib/vquic/curl_osslq.c index 1c3f0c55b66e..7bca97b4086d 100644 --- a/lib/vquic/curl_osslq.c +++ b/lib/vquic/curl_osslq.c @@ -1900,7 +1900,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, goto out; } - result = Curl_h1_req_parse_read(&stream->h1, (const char *)buf, len, NULL, + result = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL, !data->state.http_ignorecustom ? data->set.str[STRING_CUSTOMREQUEST] : NULL, 0, pnwritten); diff --git a/lib/vquic/curl_quiche.c b/lib/vquic/curl_quiche.c index c182e1490d23..5aca750c2cb9 100644 --- a/lib/vquic/curl_quiche.c +++ b/lib/vquic/curl_quiche.c @@ -976,7 +976,7 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, DEBUGASSERT(stream); - result = Curl_h1_req_parse_read(&stream->h1, (const char *)buf, blen, NULL, + result = Curl_h1_req_parse_read(&stream->h1, buf, blen, NULL, !data->state.http_ignorecustom ? data->set.str[STRING_CUSTOMREQUEST] : NULL, 0, pnwritten); diff --git a/tests/unit/unit2603.c b/tests/unit/unit2603.c index 61295de37e1d..1de774d26f8b 100644 --- a/tests/unit/unit2603.c +++ b/tests/unit/unit2603.c @@ -63,7 +63,7 @@ struct tcase { static void parse_success(const struct tcase *t) { struct h1_req_parser p; - const char *buf; + const uint8_t *buf; size_t buflen, i, in_len, in_consumed; CURLcode err; size_t nread; @@ -71,8 +71,8 @@ static void parse_success(const struct tcase *t) Curl_h1_req_parse_init(&p, 1024); in_len = in_consumed = 0; for(i = 0; t->input[i]; ++i) { - buf = t->input[i]; - buflen = strlen(buf); + buf = (const uint8_t *)t->input[i]; + buflen = strlen(t->input[i]); in_len += buflen; err = Curl_h1_req_parse_read(&p, buf, buflen, t->default_scheme, t->custom_method, 0, &nread); From 38961528434e6efdd4c1fba19e67ae0f0585007c Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Fri, 28 Nov 2025 10:44:05 +0100 Subject: [PATCH 112/140] connection: give send methods/prototypes an uint8_t buffer To conclude changing the send buffer type from `const void *` to `const uint8_t *`, change the top level send function and its implementations. Closes #19743 --- lib/cfilters.c | 2 +- lib/cfilters.h | 2 +- lib/curl_rtmp.c | 2 +- lib/urldata.h | 2 +- lib/vssh/libssh.c | 4 ++-- lib/vssh/libssh2.c | 9 +++++---- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/cfilters.c b/lib/cfilters.c index 7d1f0c3d9e4f..dd4cb5210acc 100644 --- a/lib/cfilters.c +++ b/lib/cfilters.c @@ -242,7 +242,7 @@ CURLcode Curl_cf_recv(struct Curl_easy *data, int num, char *buf, } CURLcode Curl_cf_send(struct Curl_easy *data, int num, - const void *mem, size_t len, bool eos, + const uint8_t *mem, size_t len, bool eos, size_t *pnwritten) { struct Curl_cfilter *cf; diff --git a/lib/cfilters.h b/lib/cfilters.h index 5d39725088ed..a3bd97a9f166 100644 --- a/lib/cfilters.h +++ b/lib/cfilters.h @@ -508,7 +508,7 @@ CURLcode Curl_cf_recv(struct Curl_easy *data, int sockindex, char *buf, * in `*pnwritten` or on error. */ CURLcode Curl_cf_send(struct Curl_easy *data, int sockindex, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten); /** diff --git a/lib/curl_rtmp.c b/lib/curl_rtmp.c index 351c9f494c3f..b2dd937008a5 100644 --- a/lib/curl_rtmp.c +++ b/lib/curl_rtmp.c @@ -352,7 +352,7 @@ static CURLcode rtmp_recv(struct Curl_easy *data, int sockindex, char *buf, } static CURLcode rtmp_send(struct Curl_easy *data, int sockindex, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct connectdata *conn = data->conn; diff --git a/lib/urldata.h b/lib/urldata.h index 2d28718181a9..561db56ecd8a 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -162,7 +162,7 @@ typedef unsigned int curl_prot_t; /* On error return, the value of `pnwritten` has no meaning */ typedef CURLcode (Curl_send)(struct Curl_easy *data, /* transfer */ int sockindex, /* socketindex */ - const void *buf, /* data to write */ + const uint8_t *buf, /* data to write */ size_t len, /* amount to send */ bool eos, /* last chunk */ size_t *pnwritten); /* how much sent */ diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index d0f3d3de5cca..db80bcbf8c96 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -2887,7 +2887,7 @@ static CURLcode scp_done(struct Curl_easy *data, CURLcode status, } static CURLcode scp_send(struct Curl_easy *data, int sockindex, - const void *mem, size_t len, bool eos, + const uint8_t *mem, size_t len, bool eos, size_t *pnwritten) { int rc; @@ -3048,7 +3048,7 @@ static CURLcode sftp_done(struct Curl_easy *data, CURLcode status, /* return number of sent bytes */ static CURLcode sftp_send(struct Curl_easy *data, int sockindex, - const void *mem, size_t len, bool eos, + const uint8_t *mem, size_t len, bool eos, size_t *pnwritten) { struct connectdata *conn = data->conn; diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index 31ef5092d3da..ce593d54874a 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -3715,7 +3715,7 @@ static CURLcode scp_done(struct Curl_easy *data, CURLcode status, } static CURLcode scp_send(struct Curl_easy *data, int sockindex, - const void *mem, size_t len, bool eos, + const uint8_t *mem, size_t len, bool eos, size_t *pnwritten) { struct connectdata *conn = data->conn; @@ -3731,7 +3731,8 @@ static CURLcode scp_send(struct Curl_easy *data, int sockindex, return CURLE_FAILED_INIT; /* libssh2_channel_write() returns int! */ - nwritten = (ssize_t) libssh2_channel_write(sshc->ssh_channel, mem, len); + nwritten = (ssize_t) libssh2_channel_write(sshc->ssh_channel, + (const char *)mem, len); ssh_block2waitfor(data, sshc, (nwritten == LIBSSH2_ERROR_EAGAIN)); @@ -3874,7 +3875,7 @@ static CURLcode sftp_done(struct Curl_easy *data, CURLcode status, /* return number of sent bytes */ static CURLcode sftp_send(struct Curl_easy *data, int sockindex, - const void *mem, size_t len, bool eos, + const uint8_t *mem, size_t len, bool eos, size_t *pnwritten) { struct connectdata *conn = data->conn; @@ -3888,7 +3889,7 @@ static CURLcode sftp_send(struct Curl_easy *data, int sockindex, if(!sshc) return CURLE_FAILED_INIT; - nwrite = libssh2_sftp_write(sshc->sftp_handle, mem, len); + nwrite = libssh2_sftp_write(sshc->sftp_handle, (const char *)mem, len); ssh_block2waitfor(data, sshc, (nwrite == LIBSSH2_ERROR_EAGAIN)); From 02aa75a8c240af1a8912145497806e8925859a87 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 28 Nov 2025 17:41:59 +0100 Subject: [PATCH 113/140] runtests: allow a test to switch off memdebug Test 3207 now uses this as its multi-threading is not fully memdebug compliant. Closes #19752 --- docs/tests/FILEFORMAT.md | 5 ++++- lib/memdebug.c | 2 -- tests/data/test3207 | 2 +- tests/runner.pm | 11 +++++++++++ tests/runtests.pl | 6 ++++-- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/tests/FILEFORMAT.md b/docs/tests/FILEFORMAT.md index 7851e08e2597..1f3aa78991b8 100644 --- a/docs/tests/FILEFORMAT.md +++ b/docs/tests/FILEFORMAT.md @@ -586,7 +586,7 @@ command has been run. If the variable name has no assignment, no `=`, then that variable is just deleted. -### `` +### `` Command line to run. If the command spans multiple lines, they are concatenated with a space added @@ -608,6 +608,9 @@ otherwise written to verify stdout. Set `option="no-include"` to prevent the test script to slap on the `--include` argument. +Set `option="no-memdebug"` to make the test run without the memdebug tracking +system. For tests that are incompatible - multi-threaded for example. + Set `option="no-q"` avoid using `-q` as the first argument in the curl command line. diff --git a/lib/memdebug.c b/lib/memdebug.c index f5b88731ee35..9fd54d026b69 100644 --- a/lib/memdebug.c +++ b/lib/memdebug.c @@ -111,8 +111,6 @@ void curl_dbg_memdebug(const char *logname) if(!curl_dbg_logfile) { if(logname && *logname) curl_dbg_logfile = CURLX_FOPEN_LOW(logname, FOPEN_WRITETEXT); - else - curl_dbg_logfile = stderr; #ifdef MEMDEBUG_LOG_SYNC /* Flush the log file after every line so the log is not lost in a crash */ if(curl_dbg_logfile) diff --git a/tests/data/test3207 b/tests/data/test3207 index 4806ef5474d6..9aa3ee5a365f 100644 --- a/tests/data/test3207 +++ b/tests/data/test3207 @@ -37,7 +37,7 @@ concurrent HTTPS GET using shared ssl session cache lib%TESTNUMBER # provide URL and ca-cert - + https://localhost:%HTTPSPORT/%TESTNUMBER %CERTDIR/certs/test-ca.crt diff --git a/tests/runner.pm b/tests/runner.pm index a73f9d599934..b69bbf2420aa 100644 --- a/tests/runner.pm +++ b/tests/runner.pm @@ -840,6 +840,7 @@ sub singletest_run { $tool = $tool_name . exe_ext('TOOL'); } + my $oldmemdebug; my $disablevalgrind; my $CMDLINE=""; my $cmdargs; @@ -1025,6 +1026,11 @@ sub singletest_run { # timestamp starting of test command $$testtimings{"timetoolini"} = Time::HiRes::time(); + if($cmdhash{'option'} && ($cmdhash{'option'} =~ /no-memdebug/)) { + $oldmemdebug = $ENV{'CURL_MEMDEBUG'}; + delete $ENV{'CURL_MEMDEBUG'}; + } + # run the command line we built if($torture) { $cmdres = torture($CMDLINE, @@ -1048,6 +1054,11 @@ sub singletest_run { ($cmdres, $dumped_core) = normalize_cmdres(runclient("$CMDLINE")); } + # restore contents + if($oldmemdebug) { + $ENV{'CURL_MEMDEBUG'} = $oldmemdebug; + } + # timestamp finishing of test command $$testtimings{"timetoolend"} = Time::HiRes::time(); diff --git a/tests/runtests.pl b/tests/runtests.pl index 3d557d1435ed..648666fd301e 100755 --- a/tests/runtests.pl +++ b/tests/runtests.pl @@ -1763,8 +1763,10 @@ sub singletest_check { if(! -f "$logdir/$MEMDUMP") { my %cmdhash = getpartattr("client", "command"); my $cmdtype = $cmdhash{'type'} || "default"; - logmsg "\n** ALERT! memory tracking with no output file?\n" - if($cmdtype ne "perl"); + if($cmdhash{'option'} !~ /no-memdebug/) { + logmsg "\n** ALERT! memory tracking with no output file?\n" + if($cmdtype ne "perl"); + } $ok .= "-"; # problem with memory checking } else { From 4be6707910192681c5cb52e7d9eb6c0947b28600 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 28 Nov 2025 17:39:04 +0100 Subject: [PATCH 114/140] curlx/multibyte: stop setting macros for non-Windows These macros are not used for non-Windows. Drop them with the unused mappings to standard allocators. Closes #19751 --- lib/curlx/multibyte.h | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/curlx/multibyte.h b/lib/curlx/multibyte.h index c992214a9575..fac07c2eeb24 100644 --- a/lib/curlx/multibyte.h +++ b/lib/curlx/multibyte.h @@ -26,10 +26,6 @@ #include "../curl_setup.h" #ifdef _WIN32 -/* MultiByte conversions using Windows kernel32 library. */ -wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8); -char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w); -#endif /* * Macros curlx_convert_UTF8_to_tchar(), curlx_convert_tchar_to_UTF8() @@ -48,7 +44,14 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w); * memory tracker memdebug functions. */ -#if defined(UNICODE) && defined(_WIN32) +/* MultiByte conversions using Windows kernel32 library. */ +wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8); +char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w); + +/* the purpose of this macro is to free() without being traced by memdebug */ +#define curlx_unicodefree(ptr) free(ptr) + +#ifdef UNICODE #define curlx_convert_UTF8_to_tchar(ptr) curlx_convert_UTF8_to_wchar((ptr)) #define curlx_convert_tchar_to_UTF8(ptr) curlx_convert_wchar_to_UTF8((ptr)) @@ -60,15 +63,10 @@ typedef union { const unsigned short *const_tbyte_ptr; } xcharp_u; -#else +#else /* !UNICODE */ -#ifdef _WIN32 #define curlx_convert_UTF8_to_tchar(ptr) _strdup(ptr) #define curlx_convert_tchar_to_UTF8(ptr) _strdup(ptr) -#else -#define curlx_convert_UTF8_to_tchar(ptr) strdup(ptr) -#define curlx_convert_tchar_to_UTF8(ptr) strdup(ptr) -#endif typedef union { char *tchar_ptr; @@ -77,9 +75,7 @@ typedef union { const unsigned char *const_tbyte_ptr; } xcharp_u; -#endif /* UNICODE && _WIN32 */ - -/* the purpose of this macro is to free() without being traced by memdebug */ -#define curlx_unicodefree(ptr) free(ptr) +#endif /* UNICODE */ +#endif /* _WIN32 */ #endif /* HEADER_CURL_MULTIBYTE_H */ From d73efc62c15f2d2a3da4b27b90825975298e5c88 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 28 Nov 2025 21:17:58 +0100 Subject: [PATCH 115/140] tests: fix formatting nits Also: - lib1948: fix checksrc error TYPEDEFSTRUCT. (detected after formatting) Closes #19754 --- .../http/testenv/mod_curltest/mod_curltest.c | 29 +- tests/libtest/cli_h2_pausing.c | 7 +- tests/libtest/cli_h2_upgrade_extreme.c | 2 +- tests/libtest/cli_hx_download.c | 6 +- tests/libtest/cli_hx_upload.c | 3 +- tests/libtest/cli_tls_session_reuse.c | 6 +- tests/libtest/cli_upload_pausing.c | 2 +- tests/libtest/cli_ws_data.c | 9 +- tests/libtest/first.c | 3 +- tests/libtest/first.h | 2 +- tests/libtest/lib1156.c | 18 +- tests/libtest/lib1308.c | 2 +- tests/libtest/lib1514.c | 2 +- tests/libtest/lib1517.c | 1 - tests/libtest/lib1520.c | 2 +- tests/libtest/lib1522.c | 2 +- tests/libtest/lib1523.c | 2 +- tests/libtest/lib1525.c | 2 +- tests/libtest/lib1526.c | 2 +- tests/libtest/lib1527.c | 2 +- tests/libtest/lib1533.c | 1 - tests/libtest/lib1534.c | 8 +- tests/libtest/lib1535.c | 8 +- tests/libtest/lib1536.c | 8 +- tests/libtest/lib1559.c | 4 +- tests/libtest/lib1560.c | 4 +- tests/libtest/lib1597.c | 2 +- tests/libtest/lib1662.c | 2 +- tests/libtest/lib1915.c | 3 +- tests/libtest/lib1919.c | 4 +- tests/libtest/lib1940.c | 2 +- tests/libtest/lib1945.c | 4 +- tests/libtest/lib1947.c | 6 +- tests/libtest/lib1948.c | 9 +- tests/libtest/lib1960.c | 8 +- tests/libtest/lib1977.c | 3 - tests/libtest/lib2023.c | 2 +- tests/libtest/lib2032.c | 6 +- tests/libtest/lib2402.c | 6 +- tests/libtest/lib2404.c | 6 +- tests/libtest/lib2405.c | 7 +- tests/libtest/lib2502.c | 6 +- tests/libtest/lib2700.c | 3 +- tests/libtest/lib3033.c | 3 +- tests/libtest/lib3102.c | 10 +- tests/libtest/lib3207.c | 6 +- tests/libtest/lib505.c | 3 +- tests/libtest/lib506.c | 92 +++--- tests/libtest/lib508.c | 2 +- tests/libtest/lib509.c | 1 - tests/libtest/lib510.c | 4 +- tests/libtest/lib526.c | 1 - tests/libtest/lib530.c | 2 +- tests/libtest/lib536.c | 3 +- tests/libtest/lib537.c | 2 +- tests/libtest/lib540.c | 4 +- tests/libtest/lib547.c | 2 +- tests/libtest/lib552.c | 8 +- tests/libtest/lib554.c | 2 +- tests/libtest/lib555.c | 2 +- tests/libtest/lib557.c | 43 +-- tests/libtest/lib568.c | 2 +- tests/libtest/lib570.c | 2 +- tests/libtest/lib572.c | 2 +- tests/libtest/lib573.c | 2 +- tests/libtest/lib574.c | 3 +- tests/libtest/lib579.c | 2 +- tests/libtest/lib582.c | 2 +- tests/libtest/lib586.c | 75 +++-- tests/libtest/lib591.c | 4 +- tests/libtest/lib597.c | 6 +- tests/libtest/lib643.c | 17 +- tests/libtest/lib650.c | 7 +- tests/libtest/lib651.c | 6 +- tests/libtest/lib652.c | 2 +- tests/libtest/lib654.c | 6 +- tests/libtest/lib666.c | 2 +- tests/libtest/lib667.c | 7 +- tests/libtest/lib668.c | 8 +- tests/libtest/lib670.c | 8 +- tests/libtest/lib678.c | 5 +- tests/libtest/lib758.c | 8 +- tests/server/dnsd.c | 17 +- tests/server/getpart.c | 17 +- tests/server/mqttd.c | 17 +- tests/server/resolve.c | 4 +- tests/server/rtspd.c | 46 ++- tests/server/sockfilt.c | 294 +++++++++--------- tests/server/socksd.c | 15 +- tests/server/sws.c | 67 ++-- tests/server/tftpd.c | 20 +- tests/server/util.c | 55 ++-- tests/unit/unit1300.c | 2 +- tests/unit/unit1302.c | 4 +- tests/unit/unit1304.c | 33 +- tests/unit/unit1307.c | 2 +- tests/unit/unit1309.c | 12 +- tests/unit/unit1397.c | 2 +- tests/unit/unit1398.c | 20 +- tests/unit/unit1601.c | 2 +- tests/unit/unit1606.c | 18 +- tests/unit/unit1610.c | 4 +- tests/unit/unit1611.c | 4 +- tests/unit/unit1612.c | 8 +- tests/unit/unit1614.c | 14 +- tests/unit/unit1615.c | 14 +- tests/unit/unit1620.c | 3 +- tests/unit/unit1650.c | 16 +- tests/unit/unit1651.c | 4 +- tests/unit/unit1655.c | 2 +- tests/unit/unit1656.c | 2 +- tests/unit/unit1657.c | 2 +- tests/unit/unit1660.c | 2 +- tests/unit/unit1661.c | 2 +- tests/unit/unit1663.c | 11 +- tests/unit/unit2600.c | 6 +- tests/unit/unit2601.c | 10 +- tests/unit/unit2602.c | 12 +- tests/unit/unit3200.c | 124 ++++---- tests/unit/unit3205.c | 4 +- tests/unit/unit3211.c | 4 +- tests/unit/unit3213.c | 2 +- tests/unit/unit3216.c | 2 +- 123 files changed, 680 insertions(+), 801 deletions(-) diff --git a/tests/http/testenv/mod_curltest/mod_curltest.c b/tests/http/testenv/mod_curltest/mod_curltest.c index cb236557e0a5..b45fd95286b2 100644 --- a/tests/http/testenv/mod_curltest/mod_curltest.c +++ b/tests/http/testenv/mod_curltest/mod_curltest.c @@ -62,7 +62,8 @@ static int curltest_post_config(apr_pool_t *p, apr_pool_t *plog, void *data = NULL; const char *key = "mod_curltest_init_counter"; - (void)plog;(void)ptemp; + (void)plog; + (void)ptemp; apr_pool_userdata_get(&data, key, s->process->pool); if(!data) { @@ -93,8 +94,8 @@ static void curltest_hooks(apr_pool_t *pool) ap_hook_handler(curltest_sslinfo_handler, NULL, NULL, APR_HOOK_MIDDLE); } -#define SECS_PER_HOUR (60*60) -#define SECS_PER_DAY (24*SECS_PER_HOUR) +#define SECS_PER_HOUR (60 * 60) +#define SECS_PER_DAY (24 * SECS_PER_HOUR) static apr_status_t duration_parse(apr_interval_time_t *ptimeout, const char *value, const char *def_unit) @@ -124,12 +125,12 @@ static apr_status_t duration_parse(apr_interval_time_t *ptimeout, break; case 's': case 'S': - *ptimeout = (apr_interval_time_t) apr_time_from_sec(n); + *ptimeout = (apr_interval_time_t)apr_time_from_sec(n); break; case 'h': case 'H': /* Time is in hours */ - *ptimeout = (apr_interval_time_t) apr_time_from_sec(n * SECS_PER_HOUR); + *ptimeout = (apr_interval_time_t)apr_time_from_sec(n * SECS_PER_HOUR); break; case 'm': case 'M': @@ -137,12 +138,12 @@ static apr_status_t duration_parse(apr_interval_time_t *ptimeout, /* Time is in milliseconds */ case 's': case 'S': - *ptimeout = (apr_interval_time_t) n * 1000; + *ptimeout = (apr_interval_time_t)n * 1000; break; /* Time is in minutes */ case 'i': case 'I': - *ptimeout = (apr_interval_time_t) apr_time_from_sec(n * 60); + *ptimeout = (apr_interval_time_t)apr_time_from_sec(n * 60); break; default: return APR_EGENERAL; @@ -154,7 +155,7 @@ static apr_status_t duration_parse(apr_interval_time_t *ptimeout, /* Time is in microseconds */ case 's': case 'S': - *ptimeout = (apr_interval_time_t) n; + *ptimeout = (apr_interval_time_t)n; break; default: return APR_EGENERAL; @@ -266,8 +267,7 @@ static int curltest_echo_handler(request_rec *r) apr_table_get(r->headers_in, "TE")); if(read_delay) { - ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, - "put_handler: read_delay"); + ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "put_handler: read_delay"); apr_sleep(read_delay); } @@ -343,7 +343,7 @@ static int curltest_tweak_handler(request_rec *r) apr_bucket_brigade *bb; apr_bucket *b; apr_status_t rv; - char buffer[16*1024]; + char buffer[16 * 1024]; int i, chunks = 3, error_bucket = 1; size_t chunk_size = sizeof(buffer); const char *request_id = "none"; @@ -579,7 +579,7 @@ static int curltest_put_handler(request_rec *r) apr_bucket_brigade *bb; apr_bucket *b; apr_status_t rv; - char buffer[128*1024]; + char buffer[128 * 1024]; const char *ct; apr_off_t rbody_len = 0; apr_off_t rbody_max_len = -1; @@ -650,8 +650,7 @@ static int curltest_put_handler(request_rec *r) ap_set_content_type(r, ct ? ct : "text/plain"); if(read_delay) { - ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, - "put_handler: read_delay"); + ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "put_handler: read_delay"); apr_sleep(read_delay); } bb = apr_brigade_create(r->pool, c->bucket_alloc); @@ -674,7 +673,7 @@ static int curltest_put_handler(request_rec *r) } } /* we are done */ - s_rbody_len = apr_psprintf(r->pool, "%"APR_OFF_T_FMT, rbody_len); + s_rbody_len = apr_psprintf(r->pool, "%" APR_OFF_T_FMT, rbody_len); apr_table_setn(r->headers_out, "Received-Length", s_rbody_len); rv = apr_brigade_puts(bb, NULL, NULL, s_rbody_len); if(APR_SUCCESS != rv) diff --git a/tests/libtest/cli_h2_pausing.c b/tests/libtest/cli_h2_pausing.c index 25b798af4b2b..30bcfcf043a6 100644 --- a/tests/libtest/cli_h2_pausing.c +++ b/tests/libtest/cli_h2_pausing.c @@ -38,8 +38,7 @@ static void usage_h2_pausing(const char *msg) ); } -struct handle -{ +struct handle { size_t idx; int paused; int resumed; @@ -51,7 +50,7 @@ struct handle static size_t cb(char *data, size_t size, size_t nmemb, void *clientp) { size_t realsize = size * nmemb; - struct handle *handle = (struct handle *) clientp; + struct handle *handle = (struct handle *)clientp; curl_off_t totalsize; (void)data; @@ -163,7 +162,7 @@ static CURLcode test_cli_h2_pausing(const char *URL) goto cleanup; } memset(&resolve, 0, sizeof(resolve)); - curl_msnprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1", + curl_msnprintf(resolve_buf, sizeof(resolve_buf) - 1, "%s:%s:127.0.0.1", host, port); resolve = curl_slist_append(resolve, resolve_buf); diff --git a/tests/libtest/cli_h2_upgrade_extreme.c b/tests/libtest/cli_h2_upgrade_extreme.c index bc28a6f4d05e..8d5bf8d82ca6 100644 --- a/tests/libtest/cli_h2_upgrade_extreme.c +++ b/tests/libtest/cli_h2_upgrade_extreme.c @@ -120,7 +120,7 @@ static CURLcode test_cli_h2_upgrade_extreme(const char *URL) curl_easy_getinfo(msg->easy_handle, CURLINFO_XFER_ID, &xfer_id); curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &status); if(msg->data.result == CURLE_SEND_ERROR || - msg->data.result == CURLE_RECV_ERROR) { + msg->data.result == CURLE_RECV_ERROR) { /* We get these if the server had a GOAWAY in transit on * reusing a connection */ } diff --git a/tests/libtest/cli_hx_download.c b/tests/libtest/cli_hx_download.c index a7f5d200903c..2a3614412369 100644 --- a/tests/libtest/cli_hx_download.c +++ b/tests/libtest/cli_hx_download.c @@ -88,7 +88,7 @@ static size_t my_write_d_cb(char *buf, size_t nitems, size_t buflen, "pause_at=%" CURL_FORMAT_CURL_OFF_T "\n", t->idx, blen, t->recv_size, t->pause_at); if(!t->out) { - curl_msnprintf(t->filename, sizeof(t->filename)-1, "download_%zu.data", + curl_msnprintf(t->filename, sizeof(t->filename) - 1, "download_%zu.data", t->idx); t->out = curlx_fopen(t->filename, "wb"); if(!t->out) @@ -149,7 +149,7 @@ static int my_progress_d_cb(void *userdata, switch(tls->backend) { #if defined(USE_QUICHE) || defined(USE_OPENSSL) case CURLSSLBACKEND_OPENSSL: { - const char *version = SSL_get_version((SSL*)tls->internals); + const char *version = SSL_get_version((SSL *)tls->internals); assert(version); assert(strcmp(version, "unknown")); curl_mfprintf(stderr, "[t-%zu] info OpenSSL using %s\n", @@ -159,7 +159,7 @@ static int my_progress_d_cb(void *userdata, #endif #ifdef USE_WOLFSSL case CURLSSLBACKEND_WOLFSSL: { - const char *version = wolfSSL_get_version((WOLFSSL*)tls->internals); + const char *version = wolfSSL_get_version((WOLFSSL *)tls->internals); assert(version); assert(strcmp(version, "unknown")); curl_mfprintf(stderr, "[t-%zu] info wolfSSL using %s\n", diff --git a/tests/libtest/cli_hx_upload.c b/tests/libtest/cli_hx_upload.c index f7036509fea2..1ffb7c243f94 100644 --- a/tests/libtest/cli_hx_upload.c +++ b/tests/libtest/cli_hx_upload.c @@ -72,7 +72,7 @@ static size_t my_write_u_cb(char *buf, size_t nitems, size_t buflen, "pause_at=%" CURL_FORMAT_CURL_OFF_T "\n", t->idx, blen, t->recv_size, t->pause_at); if(!t->out) { - curl_msnprintf(t->filename, sizeof(t->filename)-1, "download_%zu.data", + curl_msnprintf(t->filename, sizeof(t->filename) - 1, "download_%zu.data", t->idx); t->out = curlx_fopen(t->filename, "wb"); if(!t->out) @@ -462,7 +462,6 @@ static CURLcode test_cli_hx_upload(const char *URL) } } - /* nothing happening, maintenance */ if(abort_paused) { /* abort paused transfers */ diff --git a/tests/libtest/cli_tls_session_reuse.c b/tests/libtest/cli_tls_session_reuse.c index aa56a0e28c66..a0e5901e5539 100644 --- a/tests/libtest/cli_tls_session_reuse.c +++ b/tests/libtest/cli_tls_session_reuse.c @@ -83,7 +83,6 @@ static CURL *tse_add_transfer(CURLM *multi, CURLSH *share, if(resolve) curl_easy_setopt(curl, CURLOPT_RESOLVE, resolve); - mc = curl_multi_add_handle(multi, curl); if(mc != CURLM_OK) { curl_mfprintf(stderr, "curl_multi_add_handle: %s\n", @@ -144,7 +143,7 @@ static CURLcode test_cli_tls_session_reuse(const char *URL) goto cleanup; } - curl_msnprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1", + curl_msnprintf(resolve_buf, sizeof(resolve_buf) - 1, "%s:%s:127.0.0.1", host, port); resolve = curl_slist_append(resolve, resolve_buf); @@ -161,7 +160,6 @@ static CURLcode test_cli_tls_session_reuse(const char *URL) } curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION); - if(!tse_add_transfer(multi, share, resolve, URL, http_version)) goto cleanup; ++ongoing; @@ -205,7 +203,7 @@ static CURLcode test_cli_tls_session_reuse(const char *URL) curl_easy_getinfo(msg->easy_handle, CURLINFO_XFER_ID, &xfer_id); curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &status); if(msg->data.result == CURLE_SEND_ERROR || - msg->data.result == CURLE_RECV_ERROR) { + msg->data.result == CURLE_RECV_ERROR) { /* We get these if the server had a GOAWAY in transit on * reusing a connection */ } diff --git a/tests/libtest/cli_upload_pausing.c b/tests/libtest/cli_upload_pausing.c index 042eddd7d7dc..cb94bcf0a83f 100644 --- a/tests/libtest/cli_upload_pausing.c +++ b/tests/libtest/cli_upload_pausing.c @@ -154,7 +154,7 @@ static CURLcode test_cli_upload_pausing(const char *URL) goto cleanup; } memset(&resolve, 0, sizeof(resolve)); - curl_msnprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1", + curl_msnprintf(resolve_buf, sizeof(resolve_buf) - 1, "%s:%s:127.0.0.1", host, port); resolve = curl_slist_append(resolve, resolve_buf); diff --git a/tests/libtest/cli_ws_data.c b/tests/libtest/cli_ws_data.c index 2276f0c92ce1..35da27788683 100644 --- a/tests/libtest/cli_ws_data.c +++ b/tests/libtest/cli_ws_data.c @@ -27,10 +27,9 @@ #ifndef CURL_DISABLE_WEBSOCKETS -static CURLcode -test_ws_data_m2_check_recv(const struct curl_ws_frame *frame, - size_t r_offset, size_t nread, - size_t exp_len) +static CURLcode test_ws_data_m2_check_recv(const struct curl_ws_frame *frame, + size_t r_offset, size_t nread, + size_t exp_len) { if(!frame) return CURLE_OK; @@ -362,7 +361,6 @@ static CURLcode test_ws_data_m1_echo(const char *url, r = CURLE_RECV_ERROR; goto out; } - } curl_multi_remove_handle(multi, m1_ctx.curl); @@ -393,7 +391,6 @@ static CURLcode test_ws_data_m1_echo(const char *url, return r; } - static void test_ws_data_usage(const char *msg) { if(msg) diff --git a/tests/libtest/first.c b/tests/libtest/first.c index 2f6553088211..e384971c7efc 100644 --- a/tests/libtest/first.c +++ b/tests/libtest/first.c @@ -62,7 +62,7 @@ int unitfail; /* for unittests */ int coptind; const char *coptarg; -int cgetopt(int argc, const char * const argv[], const char *optstring) +int cgetopt(int argc, const char *const argv[], const char *optstring) { static int optpos = 1; int coptopt; @@ -204,7 +204,6 @@ void ws_close(CURL *curl) } #endif /* CURL_DISABLE_WEBSOCKETS */ - int main(int argc, const char **argv) { const char *URL = ""; diff --git a/tests/libtest/first.h b/tests/libtest/first.h index f5cbc6023783..5fa587686b56 100644 --- a/tests/libtest/first.h +++ b/tests/libtest/first.h @@ -79,7 +79,7 @@ extern struct curltime tv_test_start; /* for test timing */ extern int coptind; extern const char *coptarg; -int cgetopt(int argc, const char * const argv[], const char *optstring); +int cgetopt(int argc, const char *const argv[], const char *optstring); extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc, struct timeval *tv); diff --git a/tests/libtest/lib1156.c b/tests/libtest/lib1156.c index 758f6e3f1ae9..1468b35e1cc7 100644 --- a/tests/libtest/lib1156.c +++ b/tests/libtest/lib1156.c @@ -96,27 +96,27 @@ static int onetest(CURL *curl, const char *url, const struct testparams *p, test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_RESUME_FROM, (p->flags & F_RESUME) ? 3L : 0L); test_setopt(curl, CURLOPT_RANGE, !(p->flags & F_RESUME) ? - "3-1000000": (char *)NULL); + "3-1000000" : (char *)NULL); test_setopt(curl, CURLOPT_FAILONERROR, (p->flags & F_FAIL) ? 1L : 0L); hasbody = 0; res = curl_easy_perform(curl); if(res != p->res) { curl_mprintf("%zu: bad error code (%d): resume=%s, fail=%s, http416=%s, " "content-range=%s, expected=%d\n", num, res, - (p->flags & F_RESUME) ? "yes": "no", - (p->flags & F_FAIL) ? "yes": "no", - (p->flags & F_HTTP416) ? "yes": "no", - (p->flags & F_CONTENTRANGE) ? "yes": "no", + (p->flags & F_RESUME) ? "yes" : "no", + (p->flags & F_FAIL) ? "yes" : "no", + (p->flags & F_HTTP416) ? "yes" : "no", + (p->flags & F_CONTENTRANGE) ? "yes" : "no", p->res); return 1; } if(hasbody && (p->flags & F_IGNOREBODY)) { curl_mprintf("body should be ignored and is not: resume=%s, fail=%s, " "http416=%s, content-range=%s\n", - (p->flags & F_RESUME) ? "yes": "no", - (p->flags & F_FAIL) ? "yes": "no", - (p->flags & F_HTTP416) ? "yes": "no", - (p->flags & F_CONTENTRANGE) ? "yes": "no"); + (p->flags & F_RESUME) ? "yes" : "no", + (p->flags & F_FAIL) ? "yes" : "no", + (p->flags & F_HTTP416) ? "yes" : "no", + (p->flags & F_CONTENTRANGE) ? "yes" : "no"); return 1; } return 0; diff --git a/tests/libtest/lib1308.c b/tests/libtest/lib1308.c index 6f7b9c264eef..6a7e71d7923d 100644 --- a/tests/libtest/lib1308.c +++ b/tests/libtest/lib1308.c @@ -26,7 +26,7 @@ static size_t print_httppost_callback(void *arg, const char *buf, size_t len) { fwrite(buf, len, 1, stdout); - (*(size_t *) arg) += len; + (*(size_t *)arg) += len; return len; } diff --git a/tests/libtest/lib1514.c b/tests/libtest/lib1514.c index fa0aa0742439..0ae61d41e88e 100644 --- a/tests/libtest/lib1514.c +++ b/tests/libtest/lib1514.c @@ -37,7 +37,7 @@ static size_t t1514_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) { struct t1514_WriteThis *pooh = (struct t1514_WriteThis *)userp; - if(size*nmemb < 1) + if(size * nmemb < 1) return 0; if(pooh->sizeleft) { diff --git a/tests/libtest/lib1517.c b/tests/libtest/lib1517.c index cebdeab0a1b4..ab18efe11314 100644 --- a/tests/libtest/lib1517.c +++ b/tests/libtest/lib1517.c @@ -98,7 +98,6 @@ static CURLcode test_lib1517(const char *URL) /* detect HTTP error codes >= 400 */ /* test_setopt(curl, CURLOPT_FAILONERROR, 1L); */ - /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); diff --git a/tests/libtest/lib1520.c b/tests/libtest/lib1520.c index 4cf54388eb1a..076ab564d016 100644 --- a/tests/libtest/lib1520.c +++ b/tests/libtest/lib1520.c @@ -46,7 +46,7 @@ static size_t t1520_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) struct upload_status *upload_ctx = (struct upload_status *)userp; const char *data; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } diff --git a/tests/libtest/lib1522.c b/tests/libtest/lib1522.c index 1ac2332e8121..e90b39bc5676 100644 --- a/tests/libtest/lib1522.c +++ b/tests/libtest/lib1522.c @@ -78,7 +78,7 @@ static CURLcode test_lib1522(const char *URL) curl_mprintf("uploadSize = %" CURL_FORMAT_CURL_OFF_T "\n", uploadSize); - if((size_t) uploadSize == sizeof(g_Data)) { + if((size_t)uploadSize == sizeof(g_Data)) { curl_mprintf("!!!!!!!!!! PASS\n"); } else { diff --git a/tests/libtest/lib1523.c b/tests/libtest/lib1523.c index 711aa3f7140f..23ec23d82305 100644 --- a/tests/libtest/lib1523.c +++ b/tests/libtest/lib1523.c @@ -41,7 +41,7 @@ static size_t t1523_write_cb(char *d, size_t n, size_t l, void *p) /* take care of the data here, ignored in this example */ (void)d; (void)p; - return n*l; + return n * l; } static CURLcode run(CURL *curl, long limit, long time) diff --git a/tests/libtest/lib1525.c b/tests/libtest/lib1525.c index c9a1e1514f80..66c18df21e40 100644 --- a/tests/libtest/lib1525.c +++ b/tests/libtest/lib1525.c @@ -34,7 +34,7 @@ static const char t1525_testdata[] = "Hello Cloud!\n"; static size_t t1525_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) { - size_t amount = nmemb * size; /* Total bytes curl wants */ + size_t amount = nmemb * size; /* Total bytes curl wants */ if(amount < strlen(t1525_testdata)) { return strlen(t1525_testdata); } diff --git a/tests/libtest/lib1526.c b/tests/libtest/lib1526.c index 031f8bfd2746..400544b8e038 100644 --- a/tests/libtest/lib1526.c +++ b/tests/libtest/lib1526.c @@ -33,7 +33,7 @@ static const char t1526_testdata[] = "Hello Cloud!\n"; static size_t t1526_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) { - size_t amount = nmemb * size; /* Total bytes curl wants */ + size_t amount = nmemb * size; /* Total bytes curl wants */ if(amount < strlen(t1526_testdata)) { return strlen(t1526_testdata); } diff --git a/tests/libtest/lib1527.c b/tests/libtest/lib1527.c index 1d9a5821324b..e55672a3c0cc 100644 --- a/tests/libtest/lib1527.c +++ b/tests/libtest/lib1527.c @@ -33,7 +33,7 @@ static const char t1527_testdata[] = "Hello Cloud!\n"; static size_t t1527_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) { - size_t amount = nmemb * size; /* Total bytes curl wants */ + size_t amount = nmemb * size; /* Total bytes curl wants */ if(amount < strlen(t1527_testdata)) { return strlen(t1527_testdata); } diff --git a/tests/libtest/lib1533.c b/tests/libtest/lib1533.c index a2d541c4124f..b859ee36649c 100644 --- a/tests/libtest/lib1533.c +++ b/tests/libtest/lib1533.c @@ -119,7 +119,6 @@ static CURLcode perform_and_check_connections(CURL *curl, return TEST_ERR_SUCCESS; } - static CURLcode test_lib1533(const char *URL) { struct cb_data data; diff --git a/tests/libtest/lib1534.c b/tests/libtest/lib1534.c index 377df3b2fe19..94a02c2986b1 100644 --- a/tests/libtest/lib1534.c +++ b/tests/libtest/lib1534.c @@ -36,7 +36,7 @@ static CURLcode test_lib1534(const char *URL) easy_init(curl); /* Test that a filetime is properly initialized on curl_easy_init. - */ + */ res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime); if(res) { @@ -65,7 +65,7 @@ static CURLcode test_lib1534(const char *URL) } /* Test that a filetime is properly set after receiving an HTTP resource. - */ + */ res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime); if(res) { @@ -83,7 +83,7 @@ static CURLcode test_lib1534(const char *URL) } /* Test that a filetime is properly initialized on curl_easy_duphandle. - */ + */ dupe = curl_easy_duphandle(curl); if(!dupe) { @@ -109,7 +109,7 @@ static CURLcode test_lib1534(const char *URL) } /* Test that a filetime is properly initialized on curl_easy_reset. - */ + */ curl_easy_reset(curl); diff --git a/tests/libtest/lib1535.c b/tests/libtest/lib1535.c index c49c3076dfee..a9480429faaf 100644 --- a/tests/libtest/lib1535.c +++ b/tests/libtest/lib1535.c @@ -36,7 +36,7 @@ static CURLcode test_lib1535(const char *URL) easy_init(curl); /* Test that protocol is properly initialized on curl_easy_init. - */ + */ res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol); @@ -65,7 +65,7 @@ static CURLcode test_lib1535(const char *URL) } /* Test that a protocol is properly set after receiving an HTTP resource. - */ + */ res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol); @@ -85,7 +85,7 @@ static CURLcode test_lib1535(const char *URL) } /* Test that a protocol is properly initialized on curl_easy_duphandle. - */ + */ dupe = curl_easy_duphandle(curl); if(!dupe) { @@ -112,7 +112,7 @@ static CURLcode test_lib1535(const char *URL) } /* Test that a protocol is properly initialized on curl_easy_reset. - */ + */ curl_easy_reset(curl); diff --git a/tests/libtest/lib1536.c b/tests/libtest/lib1536.c index f89b50a19583..f03e9d98ed8e 100644 --- a/tests/libtest/lib1536.c +++ b/tests/libtest/lib1536.c @@ -36,7 +36,7 @@ static CURLcode test_lib1536(const char *URL) easy_init(curl); /* Test that scheme is properly initialized on curl_easy_init. - */ + */ res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme); if(res) { @@ -64,7 +64,7 @@ static CURLcode test_lib1536(const char *URL) } /* Test that a scheme is properly set after receiving an HTTP resource. - */ + */ res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme); if(res) { @@ -83,7 +83,7 @@ static CURLcode test_lib1536(const char *URL) } /* Test that a scheme is properly initialized on curl_easy_duphandle. - */ + */ dupe = curl_easy_duphandle(curl); if(!dupe) { @@ -108,7 +108,7 @@ static CURLcode test_lib1536(const char *URL) } /* Test that a scheme is properly initialized on curl_easy_reset. - */ + */ curl_easy_reset(curl); diff --git a/tests/libtest/lib1559.c b/tests/libtest/lib1559.c index c6851918a685..30773add7356 100644 --- a/tests/libtest/lib1559.c +++ b/tests/libtest/lib1559.c @@ -25,7 +25,7 @@ static CURLcode test_lib1559(const char *URL) { - static const int EXCESSIVE = 10*1000*1000; + static const int EXCESSIVE = 10 * 1000 * 1000; CURLcode res = CURLE_OK; CURL *curl = NULL; @@ -43,7 +43,7 @@ static CURLcode test_lib1559(const char *URL) } memset(longurl, 'a', EXCESSIVE); - longurl[EXCESSIVE-1] = 0; + longurl[EXCESSIVE - 1] = 0; res = curl_easy_setopt(curl, CURLOPT_URL, longurl); curl_mprintf("CURLOPT_URL %d bytes URL == %d\n", diff --git a/tests/libtest/lib1560.c b/tests/libtest/lib1560.c index 2f6608108cca..d080d38aa87e 100644 --- a/tests/libtest/lib1560.c +++ b/tests/libtest/lib1560.c @@ -68,10 +68,10 @@ static int checkparts(CURLU *u, const char *in, const char *wanted, size_t n; rc = curl_url_get(u, parts[i].part, &p, getflags); if(!rc && p) { - curl_msnprintf(bufp, len, "%s%s", buf[0]?" | ":"", p); + curl_msnprintf(bufp, len, "%s%s", buf[0] ? " | " : "", p); } else - curl_msnprintf(bufp, len, "%s[%d]", buf[0]?" | ":"", rc); + curl_msnprintf(bufp, len, "%s[%d]", buf[0] ? " | " : "", rc); n = strlen(bufp); bufp += n; diff --git a/tests/libtest/lib1597.c b/tests/libtest/lib1597.c index a338a53944fb..0e86517eadb1 100644 --- a/tests/libtest/lib1597.c +++ b/tests/libtest/lib1597.c @@ -80,7 +80,7 @@ static CURLcode test_lib1597(const char *URL) n = 0; for(proto = curlinfo->protocols; *proto; proto++) { - if((size_t) n >= sizeof(protolist)) { + if((size_t)n >= sizeof(protolist)) { puts("protolist buffer too small\n"); res = TEST_ERR_FAILURE; goto test_cleanup; diff --git a/tests/libtest/lib1662.c b/tests/libtest/lib1662.c index 41a1bc0bd4bb..f1e7b55df414 100644 --- a/tests/libtest/lib1662.c +++ b/tests/libtest/lib1662.c @@ -34,7 +34,7 @@ static size_t t1662_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) struct t1662_WriteThis *pooh = (struct t1662_WriteThis *)userp; size_t len = strlen(testdata); - if(size*nmemb < len) + if(size * nmemb < len) return 0; if(pooh->sizeleft) { diff --git a/tests/libtest/lib1915.c b/tests/libtest/lib1915.c index 367533aef64f..adb589a8c0fb 100644 --- a/tests/libtest/lib1915.c +++ b/tests/libtest/lib1915.c @@ -30,8 +30,7 @@ struct state { }; /* "read" is from the point of the library, it wants data from us */ -static CURLSTScode hstsread(CURL *curl, struct curl_hstsentry *e, - void *userp) +static CURLSTScode hstsread(CURL *curl, struct curl_hstsentry *e, void *userp) { struct entry { const char *name; diff --git a/tests/libtest/lib1919.c b/tests/libtest/lib1919.c index 79d31810a466..1a436b00cea3 100644 --- a/tests/libtest/lib1919.c +++ b/tests/libtest/lib1919.c @@ -33,9 +33,9 @@ static CURLcode test_lib1919(const char *URL) easy_init(curl); easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BEARER); easy_setopt(curl, CURLOPT_XOAUTH2_BEARER, - "c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca1"); + "c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca1"); easy_setopt(curl, CURLOPT_SASL_AUTHZID, - "c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca2"); + "c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca2"); easy_setopt(curl, CURLOPT_URL, URL); for(i = 0; i < 2; i++) { diff --git a/tests/libtest/lib1940.c b/tests/libtest/lib1940.c index 75b8f7818c02..1d9975534ad9 100644 --- a/tests/libtest/lib1940.c +++ b/tests/libtest/lib1940.c @@ -28,7 +28,7 @@ static size_t t1940_write_cb(char *data, size_t n, size_t l, void *userp) /* take care of the data here, ignored in this example */ (void)data; (void)userp; - return n*l; + return n * l; } static void t1940_showem(CURL *curl, int header_request, unsigned int type) diff --git a/tests/libtest/lib1945.c b/tests/libtest/lib1945.c index 99044880cfe8..07a010951415 100644 --- a/tests/libtest/lib1945.c +++ b/tests/libtest/lib1945.c @@ -41,7 +41,7 @@ static size_t t1945_write_cb(char *data, size_t n, size_t l, void *userp) /* take care of the data here, ignored in this example */ (void)data; (void)userp; - return n*l; + return n * l; } static CURLcode test_lib1945(const char *URL) @@ -67,7 +67,7 @@ static CURLcode test_lib1945(const char *URL) if(res) { curl_mprintf("badness: %d\n", res); } - t1945_showem(curl, CURLH_CONNECT|CURLH_HEADER|CURLH_TRAILER|CURLH_1XX); + t1945_showem(curl, CURLH_CONNECT | CURLH_HEADER | CURLH_TRAILER | CURLH_1XX); test_cleanup: curl_easy_cleanup(curl); diff --git a/tests/libtest/lib1947.c b/tests/libtest/lib1947.c index acbc260aa1d5..43e4c274b825 100644 --- a/tests/libtest/lib1947.c +++ b/tests/libtest/lib1947.c @@ -28,7 +28,7 @@ static size_t t1947_write_cb(char *data, size_t n, size_t l, void *userp) /* ignore the data */ (void)data; (void)userp; - return n*l; + return n * l; } static CURLcode test_lib1947(const char *URL) @@ -56,8 +56,8 @@ static CURLcode test_lib1947(const char *URL) /* count the number of requests by reading the first header of each request. */ - origins = (CURLH_HEADER|CURLH_TRAILER|CURLH_CONNECT| - CURLH_1XX|CURLH_PSEUDO); + origins = CURLH_HEADER | CURLH_TRAILER | CURLH_CONNECT | CURLH_1XX | + CURLH_PSEUDO; do { h = curl_easy_nextheader(curl, origins, count, NULL); if(h) diff --git a/tests/libtest/lib1948.c b/tests/libtest/lib1948.c index 2a138ac69554..024080e3e491 100644 --- a/tests/libtest/lib1948.c +++ b/tests/libtest/lib1948.c @@ -23,15 +23,14 @@ ***************************************************************************/ #include "first.h" -typedef struct -{ +struct put_buffer { const char *buf; size_t len; -} put_buffer; +}; static size_t put_callback(char *ptr, size_t size, size_t nmemb, void *stream) { - put_buffer *putdata = (put_buffer *)stream; + struct put_buffer *putdata = (struct put_buffer *)stream; size_t totalsize = size * nmemb; size_t tocopy = (putdata->len < totalsize) ? putdata->len : totalsize; memcpy(ptr, putdata->buf, tocopy); @@ -45,7 +44,7 @@ static CURLcode test_lib1948(const char *URL) CURL *curl; CURLcode res = CURLE_OK; static const char *testput = "This is test PUT data\n"; - put_buffer pbuf; + struct put_buffer pbuf; curl_global_init(CURL_GLOBAL_DEFAULT); diff --git a/tests/libtest/lib1960.c b/tests/libtest/lib1960.c index 2dbdf5995fd3..ff8ad76bc12b 100644 --- a/tests/libtest/lib1960.c +++ b/tests/libtest/lib1960.c @@ -63,12 +63,11 @@ static int sockopt_cb(void *clientp, } #ifdef __AMIGA__ -#define my_inet_pton(x,y,z) inet_pton(x,(unsigned char *)y,z) +#define my_inet_pton(x, y, z) inet_pton(x, (unsigned char *)y, z) #else -#define my_inet_pton(x,y,z) inet_pton(x,y,z) +#define my_inet_pton(x, y, z) inet_pton(x, y, z) #endif - /* Expected args: URL IP PORT */ static CURLcode test_lib1960(const char *URL) { @@ -109,7 +108,8 @@ static CURLcode test_lib1960(const char *URL) goto test_cleanup; } - status = connect(client_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); + status = connect(client_fd, (struct sockaddr *)&serv_addr, + sizeof(serv_addr)); if(status < 0) { curl_mfprintf(stderr, "connection failed\n"); goto test_cleanup; diff --git a/tests/libtest/lib1977.c b/tests/libtest/lib1977.c index 10412f66c0c4..06ab698c365e 100644 --- a/tests/libtest/lib1977.c +++ b/tests/libtest/lib1977.c @@ -48,7 +48,6 @@ static CURLcode test_lib1977(const char *URL) goto test_cleanup; curl_mprintf("effective URL: %s\n", effective); - /* second transfer: set URL + query in the second CURLU handle */ curl_url_set(curlu_2, CURLUPART_URL, URL, CURLU_DEFAULT_SCHEME); curl_url_set(curlu_2, CURLUPART_QUERY, "foo", 0); @@ -64,7 +63,6 @@ static CURLcode test_lib1977(const char *URL) goto test_cleanup; curl_mprintf("effective URL: %s\n", effective); - /* third transfer: append extra query in the second CURLU handle, but do not set CURLOPT_CURLU again. this is to test that the contents of the handle is allowed to change between transfers and is used without having to set @@ -81,7 +79,6 @@ static CURLcode test_lib1977(const char *URL) goto test_cleanup; curl_mprintf("effective URL: %s\n", effective); - test_cleanup: curl_easy_cleanup(curl); curl_url_cleanup(curlu); diff --git a/tests/libtest/lib2023.c b/tests/libtest/lib2023.c index 1475deb2d3f8..660d528b2a37 100644 --- a/tests/libtest/lib2023.c +++ b/tests/libtest/lib2023.c @@ -90,7 +90,7 @@ static CURLcode test_lib2023(const char *URL) /* libauthretry */ long fallback_auth_scheme = parse_auth_name(libtest_arg3); if(main_auth_scheme == CURLAUTH_NONE || - fallback_auth_scheme == CURLAUTH_NONE) { + fallback_auth_scheme == CURLAUTH_NONE) { curl_mfprintf(stderr, "auth schemes not found on commandline\n"); return TEST_ERR_MAJOR_BAD; } diff --git a/tests/libtest/lib2032.c b/tests/libtest/lib2032.c index a733f34e6fc0..a9cb29857130 100644 --- a/tests/libtest/lib2032.c +++ b/tests/libtest/lib2032.c @@ -32,7 +32,7 @@ static CURLcode ntlmcb_res = CURLE_OK; static size_t callback(char *ptr, size_t size, size_t nmemb, void *data) { - ssize_t idx = ((CURL **) data) - ntlm_curls; + ssize_t idx = ((CURL **)data) - ntlm_curls; curl_socket_t sock; long longdata; CURLcode code; @@ -195,8 +195,8 @@ static CURLcode test_lib2032(const char *URL) /* libntlmconnect */ #else itimeout = (int)timeout; #endif - interval.tv_sec = itimeout/1000; - interval.tv_usec = (itimeout%1000)*1000; + interval.tv_sec = itimeout / 1000; + interval.tv_usec = (itimeout % 1000) * 1000; } else { interval.tv_sec = 0; diff --git a/tests/libtest/lib2402.c b/tests/libtest/lib2402.c index 58c1b6c431fe..49d87d1cd4f1 100644 --- a/tests/libtest/lib2402.c +++ b/tests/libtest/lib2402.c @@ -38,8 +38,7 @@ static CURLcode test_lib2402(const char *URL) (void)URL; - curl_msnprintf(dnsentry, sizeof(dnsentry), "localhost:%s:%s", - port, address); + curl_msnprintf(dnsentry, sizeof(dnsentry), "localhost:%s:%s", port, address); curl_mprintf("%s\n", dnsentry); slist = curl_slist_append(slist, dnsentry); if(!slist) { @@ -61,8 +60,7 @@ static CURLcode test_lib2402(const char *URL) easy_init(curl[i]); /* specify target */ curl_msnprintf(target_url, sizeof(target_url), - "https://localhost:%s/path/2402%04zu", - port, i + 1); + "https://localhost:%s/path/2402%04zu", port, i + 1); target_url[sizeof(target_url) - 1] = '\0'; easy_setopt(curl[i], CURLOPT_URL, target_url); /* go http2 */ diff --git a/tests/libtest/lib2404.c b/tests/libtest/lib2404.c index 93a3ef926f40..c20259744771 100644 --- a/tests/libtest/lib2404.c +++ b/tests/libtest/lib2404.c @@ -38,8 +38,7 @@ static CURLcode test_lib2404(const char *URL) (void)URL; - curl_msnprintf(dnsentry, sizeof(dnsentry), "localhost:%s:%s", - port, address); + curl_msnprintf(dnsentry, sizeof(dnsentry), "localhost:%s:%s", port, address); curl_mprintf("%s\n", dnsentry); slist = curl_slist_append(slist, dnsentry); if(!slist) { @@ -61,8 +60,7 @@ static CURLcode test_lib2404(const char *URL) easy_init(curl[i]); /* specify target */ curl_msnprintf(target_url, sizeof(target_url), - "https://localhost:%s/path/2404%04zu", - port, i + 1); + "https://localhost:%s/path/2404%04zu", port, i + 1); target_url[sizeof(target_url) - 1] = '\0'; easy_setopt(curl[i], CURLOPT_URL, target_url); /* go http2 */ diff --git a/tests/libtest/lib2405.c b/tests/libtest/lib2405.c index 97d0d5d231e5..89ab659bdd4e 100644 --- a/tests/libtest/lib2405.c +++ b/tests/libtest/lib2405.c @@ -66,9 +66,10 @@ enum { TEST_USE_HTTP2_MPLEX }; -static size_t emptyWriteFunc(char *ptr, size_t size, size_t nmemb, - void *data) { - (void)ptr; (void)data; +static size_t emptyWriteFunc(char *ptr, size_t size, size_t nmemb, void *data) +{ + (void)ptr; + (void)data; return size * nmemb; } diff --git a/tests/libtest/lib2502.c b/tests/libtest/lib2502.c index 4b5e0ef6833e..48a8a93f0f8e 100644 --- a/tests/libtest/lib2502.c +++ b/tests/libtest/lib2502.c @@ -40,8 +40,7 @@ static CURLcode test_lib2502(const char *URL) (void)URL; - curl_msnprintf(dnsentry, sizeof(dnsentry), "localhost:%s:%s", - port, address); + curl_msnprintf(dnsentry, sizeof(dnsentry), "localhost:%s:%s", port, address); curl_mprintf("%s\n", dnsentry); slist = curl_slist_append(slist, dnsentry); if(!slist) { @@ -63,8 +62,7 @@ static CURLcode test_lib2502(const char *URL) easy_init(curl[i]); /* specify target */ curl_msnprintf(target_url, sizeof(target_url), - "https://localhost:%s/path/2502%04zu", - port, i + 1); + "https://localhost:%s/path/2502%04zu", port, i + 1); target_url[sizeof(target_url) - 1] = '\0'; easy_setopt(curl[i], CURLOPT_URL, target_url); /* go http2 */ diff --git a/tests/libtest/lib2700.c b/tests/libtest/lib2700.c index 1760d243ea1a..1c38f073d58c 100644 --- a/tests/libtest/lib2700.c +++ b/tests/libtest/lib2700.c @@ -120,8 +120,7 @@ static CURLcode send_chunk(CURL *curl, int flags, const char *buffer, size_t nsent; retry: - res = curl_ws_send(curl, buffer + *offset, size - *offset, &nsent, 0, - flags); + res = curl_ws_send(curl, buffer + *offset, size - *offset, &nsent, 0, flags); if(res == CURLE_AGAIN) { assert(nsent == 0); goto retry; diff --git a/tests/libtest/lib3033.c b/tests/libtest/lib3033.c index 428de8afc31d..e2f0099615f5 100644 --- a/tests/libtest/lib3033.c +++ b/tests/libtest/lib3033.c @@ -33,8 +33,7 @@ static CURLcode t3033_req_test(CURLM *multi, CURL *curl, int still_running = 0; if(index == 1) { - curl_multi_setopt(multi, CURLMOPT_NETWORK_CHANGED, - CURLMNWC_CLEAR_CONNS); + curl_multi_setopt(multi, CURLMOPT_NETWORK_CHANGED, CURLMNWC_CLEAR_CONNS); curl_mprintf("[1] signal network change\n"); } else { diff --git a/tests/libtest/lib3102.c b/tests/libtest/lib3102.c index 72da47551e40..094b32c1fc56 100644 --- a/tests/libtest/lib3102.c +++ b/tests/libtest/lib3102.c @@ -47,11 +47,11 @@ static bool is_chain_in_order(struct curl_certinfo *cert_info) static const char issuer_prefix[] = "Issuer:"; static const char subject_prefix[] = "Subject:"; - if(!strncmp(slist->data, issuer_prefix, sizeof(issuer_prefix)-1)) { - issuer = slist->data + sizeof(issuer_prefix)-1; + if(!strncmp(slist->data, issuer_prefix, sizeof(issuer_prefix) - 1)) { + issuer = slist->data + sizeof(issuer_prefix) - 1; } - if(!strncmp(slist->data, subject_prefix, sizeof(subject_prefix)-1)) { - subject = slist->data + sizeof(subject_prefix)-1; + if(!strncmp(slist->data, subject_prefix, sizeof(subject_prefix) - 1)) { + subject = slist->data + sizeof(subject_prefix) - 1; } } @@ -80,7 +80,7 @@ static bool is_chain_in_order(struct curl_certinfo *cert_info) return true; } -static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream) +static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream) { (void)stream; (void)ptr; diff --git a/tests/libtest/lib3207.c b/tests/libtest/lib3207.c index 7757643a269b..8b20b311ebbf 100644 --- a/tests/libtest/lib3207.c +++ b/tests/libtest/lib3207.c @@ -116,7 +116,7 @@ static unsigned int test_thread(void *ptr) static void t3207_test_lock(CURL *curl, curl_lock_data data, curl_lock_access laccess, void *useptr) { - curl_mutex_t *mutexes = (curl_mutex_t*) useptr; + curl_mutex_t *mutexes = (curl_mutex_t *)useptr; (void)curl; (void)laccess; Curl_mutex_acquire(&mutexes[data]); @@ -124,7 +124,7 @@ static void t3207_test_lock(CURL *curl, curl_lock_data data, static void t3207_test_unlock(CURL *curl, curl_lock_data data, void *useptr) { - curl_mutex_t *mutexes = (curl_mutex_t*) useptr; + curl_mutex_t *mutexes = (curl_mutex_t *)useptr; (void)curl; Curl_mutex_release(&mutexes[data]); } @@ -175,7 +175,7 @@ static CURLcode test_lib3207(const char *URL) { CURLcode res = CURLE_OK; size_t i; - CURLSH* share; + CURLSH *share; struct Ctx ctx[THREAD_SIZE]; curl_global_init(CURL_GLOBAL_ALL); diff --git a/tests/libtest/lib505.c b/tests/libtest/lib505.c index b28a01a9ce05..e33614fc58a8 100644 --- a/tests/libtest/lib505.c +++ b/tests/libtest/lib505.c @@ -127,8 +127,7 @@ static CURLcode test_lib505(const char *URL) test_setopt(curl, CURLOPT_READDATA, hd_src); /* and give the size of the upload (optional) */ - test_setopt(curl, CURLOPT_INFILESIZE_LARGE, - (curl_off_t)file_info.st_size); + test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size); /* Now run off and do what you have been told! */ res = curl_easy_perform(curl); diff --git a/tests/libtest/lib506.c b/tests/libtest/lib506.c index 3d2a3556fdb0..f5c44c3e4726 100644 --- a/tests/libtest/lib506.c +++ b/tests/libtest/lib506.c @@ -52,21 +52,21 @@ static void t506_test_lock(CURL *curl, curl_lock_data data, (void)laccess; switch(data) { - case CURL_LOCK_DATA_SHARE: - what = "share"; - locknum = 0; - break; - case CURL_LOCK_DATA_DNS: - what = "dns"; - locknum = 1; - break; - case CURL_LOCK_DATA_COOKIE: - what = "cookie"; - locknum = 2; - break; - default: - curl_mfprintf(stderr, "lock: no such data: %d\n", data); - return; + case CURL_LOCK_DATA_SHARE: + what = "share"; + locknum = 0; + break; + case CURL_LOCK_DATA_DNS: + what = "dns"; + locknum = 1; + break; + case CURL_LOCK_DATA_COOKIE: + what = "cookie"; + locknum = 2; + break; + default: + curl_mfprintf(stderr, "lock: no such data: %d\n", data); + return; } /* detect locking of locked locks */ @@ -88,21 +88,21 @@ static void t506_test_unlock(CURL *curl, curl_lock_data data, void *useptr) int locknum; (void)curl; switch(data) { - case CURL_LOCK_DATA_SHARE: - what = "share"; - locknum = 0; - break; - case CURL_LOCK_DATA_DNS: - what = "dns"; - locknum = 1; - break; - case CURL_LOCK_DATA_COOKIE: - what = "cookie"; - locknum = 2; - break; - default: - curl_mfprintf(stderr, "unlock: no such data: %d\n", data); - return; + case CURL_LOCK_DATA_SHARE: + what = "share"; + locknum = 0; + break; + case CURL_LOCK_DATA_DNS: + what = "dns"; + locknum = 1; + break; + case CURL_LOCK_DATA_COOKIE: + what = "cookie"; + locknum = 2; + break; + default: + curl_mfprintf(stderr, "unlock: no such data: %d\n", data); + return; } /* detect unlocking of unlocked locks */ @@ -128,7 +128,7 @@ static void *t506_test_fire(void *ptr) { CURLcode code; struct curl_slist *headers; - struct t506_Tdata *tdata = (struct t506_Tdata*)ptr; + struct t506_Tdata *tdata = (struct t506_Tdata *)ptr; CURL *curl; curl = curl_easy_init(); @@ -138,9 +138,9 @@ static void *t506_test_fire(void *ptr) } headers = sethost(NULL); - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(curl, CURLOPT_URL, tdata->url); + curl_easy_setopt(curl, CURLOPT_URL, tdata->url); curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); curl_mprintf("CURLOPT_SHARE\n"); curl_easy_setopt(curl, CURLOPT_SHARE, tdata->share); @@ -233,40 +233,38 @@ static CURLcode test_lib506(const char *URL) return TEST_ERR_MAJOR_BAD; } curl_mprintf("CURLOPT_SHARE\n"); - test_setopt(curl, CURLOPT_SHARE, share); + test_setopt(curl, CURLOPT_SHARE, share); curl_mprintf("CURLOPT_COOKIELIST injected_and_clobbered\n"); test_setopt(curl, CURLOPT_COOKIELIST, - "Set-Cookie: injected_and_clobbered=yes; " - "domain=host.foo.com; expires=Sat Feb 2 11:56:27 GMT 2030"); + "Set-Cookie: injected_and_clobbered=yes; " + "domain=host.foo.com; expires=Sat Feb 2 11:56:27 GMT 2030"); curl_mprintf("CURLOPT_COOKIELIST ALL\n"); test_setopt(curl, CURLOPT_COOKIELIST, "ALL"); curl_mprintf("CURLOPT_COOKIELIST session\n"); test_setopt(curl, CURLOPT_COOKIELIST, "Set-Cookie: session=elephants"); curl_mprintf("CURLOPT_COOKIELIST injected\n"); test_setopt(curl, CURLOPT_COOKIELIST, - "Set-Cookie: injected=yes; domain=host.foo.com; " - "expires=Sat Feb 2 11:56:27 GMT 2030"); + "Set-Cookie: injected=yes; domain=host.foo.com; " + "expires=Sat Feb 2 11:56:27 GMT 2030"); curl_mprintf("CURLOPT_COOKIELIST SESS\n"); test_setopt(curl, CURLOPT_COOKIELIST, "SESS"); curl_mprintf("CLEANUP\n"); curl_easy_cleanup(curl); - /* start treads */ for(i = 1; i <= THREADS; i++) { /* set thread data */ - tdata.url = tutil_suburl(URL, i); /* must be curl_free()d */ + tdata.url = tutil_suburl(URL, i); /* must be curl_free()d */ tdata.share = share; /* simulate thread, direct call of "thread" function */ - curl_mprintf("*** run %d\n",i); + curl_mprintf("*** run %d\n", i); t506_test_fire(&tdata); curl_free(tdata.url); } - /* fetch another one and save cookies */ curl_mprintf("*** run %d\n", i); curl = curl_easy_init(); @@ -280,11 +278,11 @@ static CURLcode test_lib506(const char *URL) url = tutil_suburl(URL, i); headers = sethost(NULL); test_setopt(curl, CURLOPT_HTTPHEADER, headers); - test_setopt(curl, CURLOPT_URL, url); + test_setopt(curl, CURLOPT_URL, url); curl_mprintf("CURLOPT_SHARE\n"); - test_setopt(curl, CURLOPT_SHARE, share); + test_setopt(curl, CURLOPT_SHARE, share); curl_mprintf("CURLOPT_COOKIEJAR\n"); - test_setopt(curl, CURLOPT_COOKIEJAR, jar); + test_setopt(curl, CURLOPT_COOKIEJAR, jar); curl_mprintf("CURLOPT_COOKIELIST FLUSH\n"); test_setopt(curl, CURLOPT_COOKIELIST, "FLUSH"); @@ -307,9 +305,9 @@ static CURLcode test_lib506(const char *URL) url = tutil_suburl(URL, i); headers = sethost(NULL); test_setopt(curl, CURLOPT_HTTPHEADER, headers); - test_setopt(curl, CURLOPT_URL, url); + test_setopt(curl, CURLOPT_URL, url); curl_mprintf("CURLOPT_SHARE\n"); - test_setopt(curl, CURLOPT_SHARE, share); + test_setopt(curl, CURLOPT_SHARE, share); curl_mprintf("CURLOPT_COOKIELIST ALL\n"); test_setopt(curl, CURLOPT_COOKIELIST, "ALL"); curl_mprintf("CURLOPT_COOKIEJAR\n"); diff --git a/tests/libtest/lib508.c b/tests/libtest/lib508.c index 697505150056..144f967f4a84 100644 --- a/tests/libtest/lib508.c +++ b/tests/libtest/lib508.c @@ -32,7 +32,7 @@ static size_t t508_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) { struct t508_WriteThis *pooh = (struct t508_WriteThis *)userp; - if(size*nmemb < 1) + if(size * nmemb < 1) return 0; if(pooh->sizeleft) { diff --git a/tests/libtest/lib509.c b/tests/libtest/lib509.c index b5a0c583e072..c065eb87c891 100644 --- a/tests/libtest/lib509.c +++ b/tests/libtest/lib509.c @@ -74,7 +74,6 @@ static void custom_free(void *ptr) free(ptr); } - static CURLcode test_lib509(const char *URL) { static const unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, diff --git a/tests/libtest/lib510.c b/tests/libtest/lib510.c index d2df0eaf203b..8d4b6ce15512 100644 --- a/tests/libtest/lib510.c +++ b/tests/libtest/lib510.c @@ -40,14 +40,14 @@ static size_t t510_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) struct t510_WriteThis *pooh = (struct t510_WriteThis *)userp; const char *data; - if(size*nmemb < 1) + if(size * nmemb < 1) return 0; data = testpost[pooh->counter]; if(data) { size_t len = strlen(data); - if(size*nmemb < len) { + if(size * nmemb < len) { curl_mfprintf(stderr, "read buffer is too small to run test\n"); return 0; } diff --git a/tests/libtest/lib526.c b/tests/libtest/lib526.c index a4d5ab6b1a1e..04e8759c1a71 100644 --- a/tests/libtest/lib526.c +++ b/tests/libtest/lib526.c @@ -155,7 +155,6 @@ static CURLcode test_lib526(const char *URL) curl_multi_cleanup(multi); curl_global_cleanup(); - } else if(testnum == 532) { /* undocumented cleanup sequence - type UB */ diff --git a/tests/libtest/lib530.c b/tests/libtest/lib530.c index 429a4869f5c9..f32d64b3033f 100644 --- a/tests/libtest/lib530.c +++ b/tests/libtest/lib530.c @@ -229,7 +229,7 @@ static ssize_t t530_getMicroSecondTimeout(struct curltime *timeout) /** * Update a fd_set with all of the sockets in use. */ -static void t530_updateFdSet(struct t530_Sockets *sockets, fd_set* fdset, +static void t530_updateFdSet(struct t530_Sockets *sockets, fd_set *fdset, curl_socket_t *maxFd) { int i; diff --git a/tests/libtest/lib536.c b/tests/libtest/lib536.c index 4810aba83fc3..82d839d772ea 100644 --- a/tests/libtest/lib536.c +++ b/tests/libtest/lib536.c @@ -27,8 +27,7 @@ static void proxystat(CURL *curl) { long wasproxy; if(!curl_easy_getinfo(curl, CURLINFO_USED_PROXY, &wasproxy)) { - curl_mprintf("This %sthe proxy\n", wasproxy ? "used ": - "DID NOT use "); + curl_mprintf("This %sthe proxy\n", wasproxy ? "used " : "DID NOT use "); } } diff --git a/tests/libtest/lib537.c b/tests/libtest/lib537.c index 8027a09c0286..31c5e306125a 100644 --- a/tests/libtest/lib537.c +++ b/tests/libtest/lib537.c @@ -118,7 +118,7 @@ static int t537_test_rlimit(int keep_open) /* If the OS allows a HUGE number of open files, we do not run. * Modern debian sid reports a limit of 134217724 and this tests * takes minutes. */ -#define LIMIT_CAP (256*1024) +#define LIMIT_CAP (256 * 1024) if(rl.rlim_cur > LIMIT_CAP) { curl_mfprintf(stderr, "soft limit above %ld, not running\n", (long)LIMIT_CAP); diff --git a/tests/libtest/lib540.c b/tests/libtest/lib540.c index 5e8890d98421..21886cfc74c5 100644 --- a/tests/libtest/lib540.c +++ b/tests/libtest/lib540.c @@ -138,8 +138,8 @@ static CURLcode loop(int num, CURLM *multi, const char *url, #else itimeout = (int)L; #endif - T.tv_sec = itimeout/1000; - T.tv_usec = (itimeout%1000)*1000; + T.tv_sec = itimeout / 1000; + T.tv_usec = (itimeout % 1000) * 1000; } else { T.tv_sec = 5; diff --git a/tests/libtest/lib547.c b/tests/libtest/lib547.c index 8f51fef088d8..797e6f1fc6b6 100644 --- a/tests/libtest/lib547.c +++ b/tests/libtest/lib547.c @@ -29,7 +29,7 @@ #include "first.h" static const char t547_uploadthis[] = "this is the blurb we want to upload\n"; -#define T547_DATALEN (sizeof(t547_uploadthis)-1) +#define T547_DATALEN (sizeof(t547_uploadthis) - 1) static size_t t547_read_cb(char *ptr, size_t size, size_t nmemb, void *clientp) { diff --git a/tests/libtest/lib552.c b/tests/libtest/lib552.c index 403ad6fec196..79cd877b1baa 100644 --- a/tests/libtest/lib552.c +++ b/tests/libtest/lib552.c @@ -35,10 +35,10 @@ static char databuf[70000]; /* MUST be more than 64k OR static size_t t552_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) { - size_t amount = nmemb * size; /* Total bytes curl wants */ - size_t available = sizeof(databuf) - current_offset; /* What we have to - give */ - size_t given = amount < available ? amount : available; /* What is given */ + size_t amount = nmemb * size; /* Total bytes curl wants */ + size_t available = sizeof(databuf) - current_offset; /* What we have to + give */ + size_t given = amount < available ? amount : available; /* What is given */ (void)stream; memcpy(ptr, databuf + current_offset, given); current_offset += given; diff --git a/tests/libtest/lib554.c b/tests/libtest/lib554.c index dd8c690ddbc3..0c8349159e55 100644 --- a/tests/libtest/lib554.c +++ b/tests/libtest/lib554.c @@ -32,7 +32,7 @@ static size_t t554_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) { struct t554_WriteThis *pooh = (struct t554_WriteThis *)userp; - if(size*nmemb < 1) + if(size * nmemb < 1) return 0; if(pooh->sizeleft) { diff --git a/tests/libtest/lib555.c b/tests/libtest/lib555.c index 005fefe72ff8..c9522f5eaeb5 100644 --- a/tests/libtest/lib555.c +++ b/tests/libtest/lib555.c @@ -33,7 +33,7 @@ #include "first.h" static const char t555_uploadthis[] = "this is the blurb we want to upload\n"; -#define T555_DATALEN (sizeof(t555_uploadthis)-1) +#define T555_DATALEN (sizeof(t555_uploadthis) - 1) static size_t t555_read_cb(char *ptr, size_t size, size_t nmemb, void *clientp) { diff --git a/tests/libtest/lib557.c b/tests/libtest/lib557.c index fa1ee2fa2fbc..9c4f7f9b9f3b 100644 --- a/tests/libtest/lib557.c +++ b/tests/libtest/lib557.c @@ -48,56 +48,48 @@ #define BUFSZ 256 - struct unsshort_st { unsigned short num; /* unsigned short */ const char *expected; /* expected string */ char result[BUFSZ]; /* result string */ }; - struct sigshort_st { short num; /* signed short */ const char *expected; /* expected string */ char result[BUFSZ]; /* result string */ }; - struct unsint_st { unsigned int num; /* unsigned int */ const char *expected; /* expected string */ char result[BUFSZ]; /* result string */ }; - struct sigint_st { int num; /* signed int */ const char *expected; /* expected string */ char result[BUFSZ]; /* result string */ }; - struct unslong_st { unsigned long num; /* unsigned long */ const char *expected; /* expected string */ char result[BUFSZ]; /* result string */ }; - struct siglong_st { long num; /* signed long */ const char *expected; /* expected string */ char result[BUFSZ]; /* result string */ }; - struct curloff_st { curl_off_t num; /* curl_off_t */ const char *expected; /* expected string */ char result[BUFSZ]; /* result string */ }; - static struct unsshort_st us_test[1 + 100]; static struct sigshort_st ss_test[1 + 100]; static struct unsint_st ui_test[1 + 100]; @@ -106,7 +98,6 @@ static struct unslong_st ul_test[1 + 100]; static struct siglong_st sl_test[1 + 100]; static struct curloff_st co_test[1 + 100]; - static int test_unsigned_short_formatting(void) { int i, j; @@ -136,7 +127,7 @@ static int test_unsigned_short_formatting(void) for(j = 0; j < BUFSZ; j++) us_test[i].result[j] = 'X'; - us_test[i].result[BUFSZ-1] = '\0'; + us_test[i].result[BUFSZ - 1] = '\0'; (void)curl_msprintf(us_test[i].result, "%hu", us_test[i].num); @@ -148,7 +139,6 @@ static int test_unsigned_short_formatting(void) i, us_test[i].expected, us_test[i].result); failed++; } - } if(!failed) @@ -159,7 +149,6 @@ static int test_unsigned_short_formatting(void) return failed; } - static int test_signed_short_formatting(void) { int i, j; @@ -211,7 +200,7 @@ static int test_signed_short_formatting(void) for(j = 0; j < BUFSZ; j++) ss_test[i].result[j] = 'X'; - ss_test[i].result[BUFSZ-1] = '\0'; + ss_test[i].result[BUFSZ - 1] = '\0'; (void)curl_msprintf(ss_test[i].result, "%hd", ss_test[i].num); @@ -222,7 +211,6 @@ static int test_signed_short_formatting(void) i, ss_test[i].expected, ss_test[i].result); failed++; } - } if(!failed) @@ -233,7 +221,6 @@ static int test_signed_short_formatting(void) return failed; } - static int test_unsigned_int_formatting(void) { int i, j; @@ -361,7 +348,7 @@ static int test_unsigned_int_formatting(void) for(j = 0; j < BUFSZ; j++) ui_test[i].result[j] = 'X'; - ui_test[i].result[BUFSZ-1] = '\0'; + ui_test[i].result[BUFSZ - 1] = '\0'; (void)curl_msprintf(ui_test[i].result, "%u", ui_test[i].num); @@ -372,7 +359,6 @@ static int test_unsigned_int_formatting(void) i, ui_test[i].expected, ui_test[i].result); failed++; } - } if(!failed) @@ -383,7 +369,6 @@ static int test_unsigned_int_formatting(void) return failed; } - static int test_signed_int_formatting(void) { int i, j; @@ -589,7 +574,7 @@ static int test_signed_int_formatting(void) for(j = 0; j < BUFSZ; j++) si_test[i].result[j] = 'X'; - si_test[i].result[BUFSZ-1] = '\0'; + si_test[i].result[BUFSZ - 1] = '\0'; (void)curl_msprintf(si_test[i].result, "%d", si_test[i].num); @@ -600,7 +585,6 @@ static int test_signed_int_formatting(void) i, si_test[i].expected, si_test[i].result); failed++; } - } if(!failed) @@ -611,7 +595,6 @@ static int test_signed_int_formatting(void) return failed; } - static int test_unsigned_long_formatting(void) { int i, j; @@ -738,7 +721,7 @@ static int test_unsigned_long_formatting(void) for(j = 0; j < BUFSZ; j++) ul_test[i].result[j] = 'X'; - ul_test[i].result[BUFSZ-1] = '\0'; + ul_test[i].result[BUFSZ - 1] = '\0'; (void)curl_msprintf(ul_test[i].result, "%lu", ul_test[i].num); @@ -749,7 +732,6 @@ static int test_unsigned_long_formatting(void) i, ul_test[i].expected, ul_test[i].result); failed++; } - } if(!failed) @@ -760,7 +742,6 @@ static int test_unsigned_long_formatting(void) return failed; } - static int test_signed_long_formatting(void) { int i, j; @@ -966,7 +947,7 @@ static int test_signed_long_formatting(void) for(j = 0; j < BUFSZ; j++) sl_test[i].result[j] = 'X'; - sl_test[i].result[BUFSZ-1] = '\0'; + sl_test[i].result[BUFSZ - 1] = '\0'; (void)curl_msprintf(sl_test[i].result, "%ld", sl_test[i].num); @@ -977,7 +958,6 @@ static int test_signed_long_formatting(void) i, sl_test[i].expected, sl_test[i].result); failed++; } - } if(!failed) @@ -988,7 +968,6 @@ static int test_signed_long_formatting(void) return failed; } - static int test_curl_off_t_formatting(void) { int i, j; @@ -1080,7 +1059,7 @@ static int test_curl_off_t_formatting(void) for(j = 0; j < BUFSZ; j++) co_test[i].result[j] = 'X'; - co_test[i].result[BUFSZ-1] = '\0'; + co_test[i].result[BUFSZ - 1] = '\0'; (void)curl_msprintf(co_test[i].result, "%" CURL_FORMAT_CURL_OFF_T, co_test[i].num); @@ -1092,7 +1071,6 @@ static int test_curl_off_t_formatting(void) i, co_test[i].expected, co_test[i].result); failed++; } - } if(!failed) @@ -1113,7 +1091,7 @@ static int string_check_low(int linenumber, char *buf, const char *buf2) } return 0; } -#define string_check(x,y) string_check_low(__LINE__, x, y) +#define string_check(x, y) string_check_low(__LINE__, x, y) static int strlen_check_low(int linenumber, char *buf, size_t len) { @@ -1126,7 +1104,7 @@ static int strlen_check_low(int linenumber, char *buf, size_t len) } return 0; } -#define strlen_check(x,y) strlen_check_low(__LINE__, x, y) +#define strlen_check(x, y) strlen_check_low(__LINE__, x, y) /* * The output strings in this test need to have been verified with a system @@ -1222,7 +1200,6 @@ static int test_width_precision(void) return errors; } - static int test_weird_arguments(void) { int errors = 0; @@ -1275,7 +1252,7 @@ static int test_weird_arguments(void) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 9 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 10 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 11 */ - 0, 1, 2, 3, 4, 5, 6, 7); /* 8 */ + 0, 1, 2, 3, 4, 5, 6, 7); /* 8 */ if(rc != 128) { curl_mprintf("curl_mprintf() returned %d and not 128!\n", rc); diff --git a/tests/libtest/lib568.c b/tests/libtest/lib568.c index 260061f5191f..46e94afb5390 100644 --- a/tests/libtest/lib568.c +++ b/tests/libtest/lib568.c @@ -84,7 +84,7 @@ static CURLcode test_lib568(const char *URL) test_setopt(curl, CURLOPT_READDATA, sdpf); test_setopt(curl, CURLOPT_UPLOAD, 1L); - test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size); + test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size); test_setopt(curl, CURLOPT_VERBOSE, 1L); /* Do the ANNOUNCE */ diff --git a/tests/libtest/lib570.c b/tests/libtest/lib570.c index f5ada6770b2e..1a1656d798f5 100644 --- a/tests/libtest/lib570.c +++ b/tests/libtest/lib570.c @@ -70,7 +70,7 @@ static CURLcode test_lib570(const char *URL) test_setopt(curl, CURLOPT_RTSP_CLIENT_CSEQ, 999L); test_setopt(curl, CURLOPT_RTSP_TRANSPORT, - "RAW/RAW/UDP;unicast;client_port=3056-3057"); + "RAW/RAW/UDP;unicast;client_port=3056-3057"); test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); stream_uri = tutil_suburl(URL, request++); diff --git a/tests/libtest/lib572.c b/tests/libtest/lib572.c index 4e20cb3da5b8..5e54f3549b92 100644 --- a/tests/libtest/lib572.c +++ b/tests/libtest/lib572.c @@ -102,7 +102,7 @@ static CURLcode test_lib572(const char *URL) test_setopt(curl, CURLOPT_READDATA, paramsf); test_setopt(curl, CURLOPT_UPLOAD, 1L); - test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size); + test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size); res = curl_easy_perform(curl); if(res) diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c index ed00bbb04243..b19782ce0d6f 100644 --- a/tests/libtest/lib573.c +++ b/tests/libtest/lib573.c @@ -41,7 +41,7 @@ static CURLcode test_lib573(const char *URL) dbl_epsilon = 1.0; do { dbl_epsilon /= 2.0; - } while((double)(1.0 + (dbl_epsilon/2.0)) > (double)1.0); + } while((double)(1.0 + (dbl_epsilon / 2.0)) > (double)1.0); start_test_timing(); diff --git a/tests/libtest/lib574.c b/tests/libtest/lib574.c index f74371e97383..52527c7f419c 100644 --- a/tests/libtest/lib574.c +++ b/tests/libtest/lib574.c @@ -23,8 +23,7 @@ ***************************************************************************/ #include "first.h" -static int new_fnmatch(void *ptr, - const char *pattern, const char *string) +static int new_fnmatch(void *ptr, const char *pattern, const char *string) { (void)ptr; curl_mfprintf(stderr, "lib574: match string '%s' against pattern '%s'\n", diff --git a/tests/libtest/lib579.c b/tests/libtest/lib579.c index aaa81baedeb1..05d4a8432e63 100644 --- a/tests/libtest/lib579.c +++ b/tests/libtest/lib579.c @@ -84,7 +84,7 @@ static size_t t579_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) struct t579_WriteThis *pooh = (struct t579_WriteThis *)userp; const char *data; - if(size*nmemb < 1) + if(size * nmemb < 1) return 0; data = testpost[pooh->counter]; diff --git a/tests/libtest/lib582.c b/tests/libtest/lib582.c index e99d5febdfab..dabebed6ce8f 100644 --- a/tests/libtest/lib582.c +++ b/tests/libtest/lib582.c @@ -175,7 +175,7 @@ static ssize_t t582_getMicroSecondTimeout(struct curltime *timeout) /** * Update a fd_set with all of the sockets in use. */ -static void t582_updateFdSet(struct t582_Sockets *sockets, fd_set* fdset, +static void t582_updateFdSet(struct t582_Sockets *sockets, fd_set *fdset, curl_socket_t *maxFd) { int i; diff --git a/tests/libtest/lib586.c b/tests/libtest/lib586.c index d0671b18fec3..310ad77f39f4 100644 --- a/tests/libtest/lib586.c +++ b/tests/libtest/lib586.c @@ -47,21 +47,21 @@ static void t586_test_lock(CURL *curl, curl_lock_data data, (void)laccess; switch(data) { - case CURL_LOCK_DATA_SHARE: - what = "share"; - break; - case CURL_LOCK_DATA_DNS: - what = "dns"; - break; - case CURL_LOCK_DATA_COOKIE: - what = "cookie"; - break; - case CURL_LOCK_DATA_SSL_SESSION: - what = "ssl_session"; - break; - default: - curl_mfprintf(stderr, "lock: no such data: %d\n", data); - return; + case CURL_LOCK_DATA_SHARE: + what = "share"; + break; + case CURL_LOCK_DATA_DNS: + what = "dns"; + break; + case CURL_LOCK_DATA_COOKIE: + what = "cookie"; + break; + case CURL_LOCK_DATA_SSL_SESSION: + what = "ssl_session"; + break; + default: + curl_mfprintf(stderr, "lock: no such data: %d\n", data); + return; } curl_mprintf("lock: %-6s [%s]: %d\n", what, user->text, user->counter); user->counter++; @@ -74,21 +74,21 @@ static void t586_test_unlock(CURL *curl, curl_lock_data data, void *useptr) struct t586_userdata *user = (struct t586_userdata *)useptr; (void)curl; switch(data) { - case CURL_LOCK_DATA_SHARE: - what = "share"; - break; - case CURL_LOCK_DATA_DNS: - what = "dns"; - break; - case CURL_LOCK_DATA_COOKIE: - what = "cookie"; - break; - case CURL_LOCK_DATA_SSL_SESSION: - what = "ssl_session"; - break; - default: - curl_mfprintf(stderr, "unlock: no such data: %d\n", data); - return; + case CURL_LOCK_DATA_SHARE: + what = "share"; + break; + case CURL_LOCK_DATA_DNS: + what = "dns"; + break; + case CURL_LOCK_DATA_COOKIE: + what = "cookie"; + break; + case CURL_LOCK_DATA_SSL_SESSION: + what = "ssl_session"; + break; + default: + curl_mfprintf(stderr, "unlock: no such data: %d\n", data); + return; } curl_mprintf("unlock: %-6s [%s]: %d\n", what, user->text, user->counter); user->counter++; @@ -98,7 +98,7 @@ static void t586_test_unlock(CURL *curl, curl_lock_data data, void *useptr) static void *t586_test_fire(void *ptr) { CURLcode code; - struct t586_Tdata *tdata = (struct t586_Tdata*)ptr; + struct t586_Tdata *tdata = (struct t586_Tdata *)ptr; CURL *curl; curl = curl_easy_init(); @@ -108,8 +108,8 @@ static void *t586_test_fire(void *ptr) } curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); - curl_easy_setopt(curl, CURLOPT_URL, tdata->url); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(curl, CURLOPT_URL, tdata->url); curl_mprintf("CURLOPT_SHARE\n"); curl_easy_setopt(curl, CURLOPT_SHARE, tdata->share); @@ -181,20 +181,18 @@ static CURLcode test_lib586(const char *URL) return TEST_ERR_MAJOR_BAD; } - /* start treads */ for(i = 1; i <= THREADS; i++) { /* set thread data */ - tdata.url = URL; + tdata.url = URL; tdata.share = share; /* simulate thread, direct call of "thread" function */ - curl_mprintf("*** run %d\n",i); + curl_mprintf("*** run %d\n", i); t586_test_fire(&tdata); } - /* fetch another one */ curl_mprintf("*** run %d\n", i); curl = curl_easy_init(); @@ -233,8 +231,7 @@ static CURLcode test_lib586(const char *URL) curl_mprintf("SHARE_CLEANUP\n"); scode = curl_share_cleanup(share); if(scode != CURLSHE_OK) - curl_mfprintf(stderr, "curl_share_cleanup failed, code errno %d\n", - scode); + curl_mfprintf(stderr, "curl_share_cleanup failed, code errno %d\n", scode); curl_mprintf("GLOBAL_CLEANUP\n"); curl_global_cleanup(); diff --git a/tests/libtest/lib591.c b/tests/libtest/lib591.c index 521cbb7503ab..b58a408a028d 100644 --- a/tests/libtest/lib591.c +++ b/tests/libtest/lib591.c @@ -114,8 +114,8 @@ static CURLcode test_lib591(const char *URL) #else itimeout = (int)timeout; #endif - interval.tv_sec = itimeout/1000; - interval.tv_usec = (itimeout%1000)*1000; + interval.tv_sec = itimeout / 1000; + interval.tv_usec = (itimeout % 1000) * 1000; } else { interval.tv_sec = 0; diff --git a/tests/libtest/lib597.c b/tests/libtest/lib597.c index 38e60c084486..e02acadab39f 100644 --- a/tests/libtest/lib597.c +++ b/tests/libtest/lib597.c @@ -94,11 +94,11 @@ static CURLcode test_lib597(const char *URL) #else itimeout = (int)timeout; #endif - interval.tv_sec = itimeout/1000; - interval.tv_usec = (itimeout%1000)*1000; + interval.tv_sec = itimeout / 1000; + interval.tv_usec = (itimeout % 1000) * 1000; } else { - interval.tv_sec = TEST_HANG_TIMEOUT/1000 - 1; + interval.tv_sec = TEST_HANG_TIMEOUT / 1000 - 1; interval.tv_usec = 0; } diff --git a/tests/libtest/lib643.c b/tests/libtest/lib643.c index 52ea1eb664cc..d096082143ac 100644 --- a/tests/libtest/lib643.c +++ b/tests/libtest/lib643.c @@ -33,7 +33,7 @@ static size_t t643_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) struct t643_WriteThis *pooh = (struct t643_WriteThis *)userp; int eof; - if(size*nmemb < 1) + if(size * nmemb < 1) return 0; if(testnum == 643) { @@ -100,8 +100,7 @@ static CURLcode t643_test_once(const char *URL, bool oldstyle) if(oldstyle) { res = curl_mime_name(part, "sendfile"); if(!res) - res = curl_mime_data_cb(part, datasize, t643_read_cb, - NULL, NULL, &pooh); + res = curl_mime_data_cb(part, datasize, t643_read_cb, NULL, NULL, &pooh); if(!res) res = curl_mime_filename(part, "postit2.c"); } @@ -109,8 +108,7 @@ static CURLcode t643_test_once(const char *URL, bool oldstyle) /* new style */ res = curl_mime_name(part, "sendfile alternative"); if(!res) - res = curl_mime_data_cb(part, datasize, t643_read_cb, - NULL, NULL, &pooh); + res = curl_mime_data_cb(part, datasize, t643_read_cb, NULL, NULL, &pooh); if(!res) res = curl_mime_filename(part, "filename 2 "); } @@ -137,8 +135,7 @@ static CURLcode t643_test_once(const char *URL, bool oldstyle) /* Fill in the file upload part */ res = curl_mime_name(part, "callbackdata"); if(!res) - res = curl_mime_data_cb(part, datasize, t643_read_cb, - NULL, NULL, &pooh2); + res = curl_mime_data_cb(part, datasize, t643_read_cb, NULL, NULL, &pooh2); if(res) curl_mprintf("curl_mime_xxx(2) = %s\n", curl_easy_strerror(res)); @@ -155,8 +152,7 @@ static CURLcode t643_test_once(const char *URL, bool oldstyle) /* Fill in the filename field */ res = curl_mime_name(part, "filename"); if(!res) - res = curl_mime_data(part, "postit2.c", - CURL_ZERO_TERMINATED); + res = curl_mime_data(part, "postit2.c", CURL_ZERO_TERMINATED); if(res) curl_mprintf("curl_mime_xxx(3) = %s\n", curl_easy_strerror(res)); @@ -172,8 +168,7 @@ static CURLcode t643_test_once(const char *URL, bool oldstyle) } res = curl_mime_name(part, "submit"); if(!res) - res = curl_mime_data(part, "send", - CURL_ZERO_TERMINATED); + res = curl_mime_data(part, "send", CURL_ZERO_TERMINATED); if(res) curl_mprintf("curl_mime_xxx(4) = %s\n", curl_easy_strerror(res)); diff --git a/tests/libtest/lib650.c b/tests/libtest/lib650.c index 4aa6ea9d8bb4..d749e67d27c7 100644 --- a/tests/libtest/lib650.c +++ b/tests/libtest/lib650.c @@ -30,7 +30,7 @@ /* curl_formget callback to count characters. */ static size_t count_chars(void *userp, const char *buf, size_t len) { - size_t *pcounter = (size_t *) userp; + size_t *pcounter = (size_t *)userp; (void)buf; *pcounter += len; @@ -51,8 +51,7 @@ static CURLcode test_lib650(const char *URL) long contentlength = 0; static const char testname[] = "fieldname"; - static char testdata[] = - "this is what we post to the silly web server"; + static char testdata[] = "this is what we post to the silly web server"; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { curl_mfprintf(stderr, "curl_global_init() failed\n"); @@ -141,7 +140,7 @@ static CURLcode test_lib650(const char *URL) * This is done before including stdin data because we want to reuse it * and stdin cannot be rewound. */ - curl_formget(formpost, (void *) &formlength, count_chars); + curl_formget(formpost, (void *)&formlength, count_chars); /* Include length in data for external check. */ curl_msnprintf(flbuf, sizeof(flbuf), "%zu", formlength); diff --git a/tests/libtest/lib651.c b/tests/libtest/lib651.c index 7d1d28563f15..1e38d18895cc 100644 --- a/tests/libtest/lib651.c +++ b/tests/libtest/lib651.c @@ -35,12 +35,12 @@ static CURLcode test_lib651(const char *URL) /* create a buffer with AAAA...BBBBB...CCCC...etc */ int i; - int size = (int)sizeof(testbuf)/1000; + int size = (int)sizeof(testbuf) / 1000; - for(i = 0; i < size ; i++) + for(i = 0; i < size; i++) memset(&testbuf[i * 1000], 65 + i, 1000); - testbuf[sizeof(testbuf)-1] = 0; /* null-terminate */ + testbuf[sizeof(testbuf) - 1] = 0; /* null-terminate */ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { curl_mfprintf(stderr, "curl_global_init() failed\n"); diff --git a/tests/libtest/lib652.c b/tests/libtest/lib652.c index 4fae340042b0..eea153742f03 100644 --- a/tests/libtest/lib652.c +++ b/tests/libtest/lib652.c @@ -37,7 +37,7 @@ static CURLcode test_lib652(const char *URL) int i; int size = (int)sizeof(testbuf) / 10; - for(i = 0; i < size ; i++) + for(i = 0; i < size; i++) memset(&testbuf[i * 10], 65 + (i % 26), 10); if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { diff --git a/tests/libtest/lib654.c b/tests/libtest/lib654.c index 1d93798d7c10..7d519d645331 100644 --- a/tests/libtest/lib654.c +++ b/tests/libtest/lib654.c @@ -31,7 +31,7 @@ struct t654_WriteThis { static void free_callback(void *userp) { - struct t654_WriteThis *pooh = (struct t654_WriteThis *) userp; + struct t654_WriteThis *pooh = (struct t654_WriteThis *)userp; pooh->freecount++; } @@ -41,7 +41,7 @@ static size_t t654_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) struct t654_WriteThis *pooh = (struct t654_WriteThis *)userp; int eof; - if(size*nmemb < 1) + if(size * nmemb < 1) return 0; eof = pooh->sizeleft <= 0; @@ -92,7 +92,7 @@ static CURLcode test_lib654(const char *URL) /* Prepare the callback structure. */ pooh.readptr = testdata; - pooh.sizeleft = (curl_off_t) strlen(testdata); + pooh.sizeleft = (curl_off_t)strlen(testdata); pooh.freecount = 0; /* Build the mime tree. */ diff --git a/tests/libtest/lib666.c b/tests/libtest/lib666.c index f47bacb9a807..e0a36412b012 100644 --- a/tests/libtest/lib666.c +++ b/tests/libtest/lib666.c @@ -40,7 +40,7 @@ static CURLcode test_lib666(const char *URL) if(i % 77 == 76) testbuf[i] = '\n'; else - testbuf[i] = (char) (0x41 + i % 26); /* A...Z */ + testbuf[i] = (char)(0x41 + i % 26); /* A...Z */ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { curl_mfprintf(stderr, "curl_global_init() failed\n"); diff --git a/tests/libtest/lib667.c b/tests/libtest/lib667.c index 1bd612f37797..3d835d500f86 100644 --- a/tests/libtest/lib667.c +++ b/tests/libtest/lib667.c @@ -33,7 +33,7 @@ static size_t t667_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) struct t667_WriteThis *pooh = (struct t667_WriteThis *)userp; int eof; - if(size*nmemb < 1) + if(size * nmemb < 1) return 0; eof = pooh->sizeleft <= 0; @@ -82,7 +82,7 @@ static CURLcode test_lib667(const char *URL) /* Prepare the callback structure. */ pooh.readptr = testdata; - pooh.sizeleft = (curl_off_t) strlen(testdata); + pooh.sizeleft = (curl_off_t)strlen(testdata); /* Build the mime tree. */ mime = curl_mime_init(curl); @@ -90,8 +90,7 @@ static CURLcode test_lib667(const char *URL) curl_mime_name(part, "field"); curl_mime_encoder(part, "base64"); /* Using an undefined length forces chunked transfer. */ - curl_mime_data_cb(part, (curl_off_t) -1, t667_read_cb, - NULL, NULL, &pooh); + curl_mime_data_cb(part, (curl_off_t)-1, t667_read_cb, NULL, NULL, &pooh); /* Bind mime data to its easy handle. */ test_setopt(curl, CURLOPT_MIMEPOST, mime); diff --git a/tests/libtest/lib668.c b/tests/libtest/lib668.c index 5011391736b1..e0f291d809e2 100644 --- a/tests/libtest/lib668.c +++ b/tests/libtest/lib668.c @@ -76,7 +76,7 @@ static CURLcode test_lib668(const char *URL) /* Prepare the callback structures. */ pooh1.readptr = testdata; - pooh1.sizeleft = (curl_off_t) strlen(testdata); + pooh1.sizeleft = (curl_off_t)strlen(testdata); pooh2 = pooh1; /* Build the mime tree. */ @@ -84,14 +84,14 @@ static CURLcode test_lib668(const char *URL) part = curl_mime_addpart(mime); curl_mime_name(part, "field1"); /* Early end of data detection can be done because the data size is known. */ - curl_mime_data_cb(part, (curl_off_t) strlen(testdata), + curl_mime_data_cb(part, (curl_off_t)strlen(testdata), t668_read_cb, NULL, NULL, &pooh1); part = curl_mime_addpart(mime); curl_mime_name(part, "field2"); /* Using an undefined length forces chunked transfer and disables early end of data detection for this part. */ - curl_mime_data_cb(part, (curl_off_t) -1, t668_read_cb, - NULL, NULL, &pooh2); + curl_mime_data_cb(part, (curl_off_t)-1, + t668_read_cb, NULL, NULL, &pooh2); part = curl_mime_addpart(mime); curl_mime_name(part, "field3"); /* Regular file part sources early end of data can be detected because diff --git a/tests/libtest/lib670.c b/tests/libtest/lib670.c index e97b04319e3c..886bf39a72bc 100644 --- a/tests/libtest/lib670.c +++ b/tests/libtest/lib670.c @@ -33,7 +33,7 @@ struct t670_ReadThis { static size_t t670_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) { - struct t670_ReadThis *pooh = (struct t670_ReadThis *) userp; + struct t670_ReadThis *pooh = (struct t670_ReadThis *)userp; time_t delta; if(size * nmemb < 1) @@ -61,7 +61,7 @@ static int t670_xferinfo(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { - struct t670_ReadThis *pooh = (struct t670_ReadThis *) clientp; + struct t670_ReadThis *pooh = (struct t670_ReadThis *)clientp; (void)dltotal; (void)dlnow; @@ -102,7 +102,7 @@ static CURLcode test_lib670(const char *URL) return TEST_ERR_MAJOR_BAD; } - pooh.origin = (time_t) 0; + pooh.origin = (time_t)0; pooh.count = 0; pooh.curl = curl_easy_init(); @@ -128,7 +128,7 @@ static CURLcode test_lib670(const char *URL) goto test_cleanup; } - res = curl_mime_data_cb(part, (curl_off_t) 2, t670_read_cb, + res = curl_mime_data_cb(part, (curl_off_t)2, t670_read_cb, NULL, NULL, &pooh); /* Bind mime data to its easy handle. */ diff --git a/tests/libtest/lib678.c b/tests/libtest/lib678.c index ed8731d20d5b..525407fddc37 100644 --- a/tests/libtest/lib678.c +++ b/tests/libtest/lib678.c @@ -43,8 +43,7 @@ static int loadfile(const char *filename, void **filedata, size_t *filesize) continue_reading = fseek(fInCert, 0, SEEK_SET) == 0; if(continue_reading) data = curlx_malloc(datasize + 1); - if((!data) || - ((int)fread(data, datasize, 1, fInCert) != 1)) + if((!data) || ((int)fread(data, datasize, 1, fInCert) != 1)) continue_reading = FALSE; curlx_fclose(fInCert); if(!continue_reading) { @@ -52,7 +51,7 @@ static int loadfile(const char *filename, void **filedata, size_t *filesize) datasize = 0; data = NULL; } - } + } } *filesize = datasize; *filedata = data; diff --git a/tests/libtest/lib758.c b/tests/libtest/lib758.c index bc6a490d3d39..fadb1db6fdd7 100644 --- a/tests/libtest/lib758.c +++ b/tests/libtest/lib758.c @@ -69,7 +69,6 @@ static void t758_msg(const char *msg) curl_mfprintf(stderr, "%s %s\n", t758_tag(), msg); } - struct t758_Sockets { curl_socket_t *sockets; int count; /* number of sockets actually stored in array */ @@ -203,7 +202,7 @@ static int t758_curlTimerCallback(CURLM *multi, long timeout_ms, void *userp) static int t758_cert_verify_callback(X509_STORE_CTX *ctx, void *arg) { - SSL * ssl; + SSL *ssl; (void)arg; ssl = (SSL *)X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx()); @@ -226,7 +225,7 @@ static int t758_cert_verify_callback(X509_STORE_CTX *ctx, void *arg) static CURLcode t758_set_ssl_ctx_callback(CURL *curl, void *ssl_ctx, void *clientp) { - SSL_CTX *ctx = (SSL_CTX *) ssl_ctx; + SSL_CTX *ctx = (SSL_CTX *)ssl_ctx; (void)curl; SSL_CTX_set_cert_verify_callback(ctx, t758_cert_verify_callback, clientp); return CURLE_OK; @@ -277,7 +276,7 @@ static ssize_t t758_getMicroSecondTimeout(struct curltime *timeout) /** * Update a fd_set with all of the sockets in use. */ -static void t758_updateFdSet(struct t758_Sockets *sockets, fd_set* fdset, +static void t758_updateFdSet(struct t758_Sockets *sockets, fd_set *fdset, curl_socket_t *maxFd) { int i; @@ -359,7 +358,6 @@ static CURLcode t758_one(const char *URL, int timer_fail_at, curl_global_trace("all"); - easy_init(curl); debug_config.nohex = TRUE; debug_config.tracetime = TRUE; diff --git a/tests/server/dnsd.c b/tests/server/dnsd.c index 9b3a42e1590c..58bbd2f3f88c 100644 --- a/tests/server/dnsd.c +++ b/tests/server/dnsd.c @@ -26,8 +26,7 @@ static int dnsd_wrotepidfile = 0; static int dnsd_wroteportfile = 0; -static unsigned short get16bit(const unsigned char **pkt, - size_t *size) +static unsigned short get16bit(const unsigned char **pkt, size_t *size) { const unsigned char *p = *pkt; (*pkt) += 2; @@ -140,7 +139,7 @@ static int store_incoming(const unsigned char *data, size_t size, fprintf(server, "Z: %x\n", (id & 0x70) >> 4); fprintf(server, "RCODE: %x\n", (id & 0x0f)); #endif - (void) get16bit(&data, &size); + (void)get16bit(&data, &size); data += 6; /* skip ANCOUNT, NSCOUNT and ARCOUNT */ size -= 6; @@ -153,10 +152,9 @@ static int store_incoming(const unsigned char *data, size_t size, qd = get16bit(&data, &size); fprintf(server, "QNAME %s QTYPE %s\n", name, type2string(qd)); *qtype = qd; - logmsg("Question for '%s' type %x / %s", name, qd, - type2string(qd)); + logmsg("Question for '%s' type %x / %s", name, qd, type2string(qd)); - (void) get16bit(&data, &size); + (void)get16bit(&data, &size); *qlen = qsize - size; /* total size of the query */ if(*qlen > qbuflen) { @@ -311,7 +309,7 @@ static int send_response(curl_socket_t sock, fprintf(stderr, "Not working\n"); return -1; #else - rc = sendto(sock, (const void *)bytes, (SENDTO3) i, 0, addr, addrlen); + rc = sendto(sock, (const void *)bytes, (SENDTO3)i, 0, addr, addrlen); if(rc != (ssize_t)i) { fprintf(stderr, "failed sending %d bytes\n", (int)i); } @@ -319,7 +317,6 @@ static int send_response(curl_socket_t sock, return 0; } - static void read_instructions(void) { char file[256]; @@ -412,7 +409,7 @@ static int test_dnsd(int argc, char **argv) #else "" #endif - ); + ); return 0; } else if(!strcmp("--pidfile", argv[arg])) { @@ -475,7 +472,7 @@ static int test_dnsd(int argc, char **argv) } snprintf(loglockfile, sizeof(loglockfile), "%s/%s/dnsd-%s.lock", - logdir, SERVERLOGS_LOCKDIR, ipv_inuse); + logdir, SERVERLOGS_LOCKDIR, ipv_inuse); #ifdef _WIN32 if(win32_init()) diff --git a/tests/server/getpart.c b/tests/server/getpart.c index efec3de634b6..becde4a9bb06 100644 --- a/tests/server/getpart.c +++ b/tests/server/getpart.c @@ -182,8 +182,8 @@ static int appenddata(char **dst_buf, /* dest buffer */ return GPE_OK; } -static int decodedata(char **buf, /* dest buffer */ - size_t *len) /* dest buffer data length */ +static int decodedata(char **buf, /* dest buffer */ + size_t *len) /* dest buffer data length */ { CURLcode error = CURLE_OK; unsigned char *buf64 = NULL; @@ -254,7 +254,7 @@ int getpart(char **outbuf, size_t *outlen, char *end; union { ssize_t sig; - size_t uns; + size_t uns; } len; size_t bufsize = 0; size_t outalloc = 256; @@ -288,8 +288,7 @@ int getpart(char **outbuf, size_t *outlen, if('<' != *ptr) { if(in_wanted_part) { show(("=> %s", buffer)); - error = appenddata(outbuf, outlen, &outalloc, buffer, datalen, - base64); + error = appenddata(outbuf, outlen, &outalloc, buffer, datalen, base64); if(error) break; } @@ -353,7 +352,6 @@ int getpart(char **outbuf, size_t *outlen, if(in_wanted_part) break; } - } else if(!in_wanted_part) { /* @@ -411,9 +409,9 @@ int getpart(char **outbuf, size_t *outlen, /* start of wanted part */ in_wanted_part = 1; if(strstr(patt, "base64=")) - /* bit rough test, but "mostly" functional, */ - /* treat wanted part data as base64 encoded */ - base64 = 1; + /* bit rough test, but "mostly" functional, */ + /* treat wanted part data as base64 encoded */ + base64 = 1; if(strstr(patt, "nonewline=")) { show(("* setting nonewline\n")); nonewline = 1; @@ -421,7 +419,6 @@ int getpart(char **outbuf, size_t *outlen, } continue; } - } if(in_wanted_part) { diff --git a/tests/server/mqttd.c b/tests/server/mqttd.c index 59c7540dcfc3..081b038d075b 100644 --- a/tests/server/mqttd.c +++ b/tests/server/mqttd.c @@ -156,7 +156,7 @@ static void logprotocol(mqttdir dir, /* return 0 on success */ static int connack(FILE *dump, curl_socket_t fd) { - unsigned char packet[]={ + unsigned char packet[] = { MQTT_MSG_CONNACK, 0x02, 0x00, 0x00 }; @@ -283,7 +283,6 @@ static size_t encode_length(size_t packetlen, return bytes; } - static size_t decode_length(unsigned char *buffer, size_t buflen, size_t *lenbytes) { @@ -304,7 +303,6 @@ static size_t decode_length(unsigned char *buffer, return len; } - /* return 0 on success */ static int publish(FILE *dump, curl_socket_t fd, unsigned short packetid, @@ -408,7 +406,7 @@ static int fixedheader(curl_socket_t fd, static curl_socket_t mqttit(curl_socket_t fd) { - size_t buff_size = 10*1024; + size_t buff_size = 10 * 1024; unsigned char *buffer = NULL; ssize_t rc; unsigned char byte; @@ -482,8 +480,7 @@ static curl_socket_t mqttit(curl_socket_t fd) } if(byte == MQTT_MSG_CONNECT) { - logprotocol(FROM_CLIENT, "CONNECT", remaining_length, - dump, buffer, rc); + logprotocol(FROM_CLIENT, "CONNECT", remaining_length, dump, buffer, rc); if(memcmp(protocol, buffer, sizeof(protocol))) { logmsg("Protocol preamble mismatch"); @@ -607,8 +604,7 @@ static curl_socket_t mqttit(curl_socket_t fd) size_t topiclen; logmsg("Incoming PUBLISH"); - logprotocol(FROM_CLIENT, "PUBLISH", remaining_length, - dump, buffer, rc); + logprotocol(FROM_CLIENT, "PUBLISH", remaining_length, dump, buffer, rc); topiclen = (size_t)(buffer[1 + bytes] << 8) | buffer[2 + bytes]; logmsg("Got %zu bytes topic", topiclen); @@ -754,7 +750,7 @@ static int test_mqttd(int argc, char *argv[]) #else "" #endif - ); + ); return 0; } else if(!strcmp("--pidfile", argv[arg])) { @@ -802,8 +798,7 @@ static int test_mqttd(int argc, char *argv[]) if(argc > arg) { opt = argv[arg]; if(curlx_str_number(&opt, &num, 0xffff)) { - fprintf(stderr, "mqttd: invalid --port argument (%s)\n", - argv[arg]); + fprintf(stderr, "mqttd: invalid --port argument (%s)\n", argv[arg]); return 0; } server_port = (unsigned short)num; diff --git a/tests/server/resolve.c b/tests/server/resolve.c index c41c2fc68ad2..ed54eef5f36b 100644 --- a/tests/server/resolve.c +++ b/tests/server/resolve.c @@ -47,7 +47,7 @@ static int test_resolve(int argc, char *argv[]) #else "" #endif - ); + ); return 0; } else if(!strcmp("--ipv6", argv[arg])) { @@ -79,7 +79,7 @@ static int test_resolve(int argc, char *argv[]) #ifdef CURLRES_IPV6 "\n --ipv6" #endif - ); + ); return 1; } diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index 335bbaaa69de..842562394058 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -50,10 +50,10 @@ typedef enum { RPROT_HTTP = 2 } reqprot_t; -#define SET_RTP_PKT_CHN(p,c) ((p)[1] = (char)((c) & 0xFF)) +#define SET_RTP_PKT_CHN(p, c) ((p)[1] = (char)((c) & 0xFF)) -#define SET_RTP_PKT_LEN(p,l) (((p)[2] = (char)(((l) >> 8) & 0xFF)), \ - ((p)[3] = (char)((l) & 0xFF))) +#define SET_RTP_PKT_LEN(p, l) (((p)[2] = (char)(((l) >> 8) & 0xFF)), \ + ((p)[3] = (char)((l) & 0xFF))) struct rtspd_httprequest { char reqbuf[150000]; /* buffer area for the incoming request */ @@ -105,10 +105,8 @@ struct rtspd_httprequest { #define END_OF_HEADERS "\r\n\r\n" - /* sent as reply to a QUIT */ -static const char *docquit_rtsp = -"HTTP/1.1 200 Goodbye" END_OF_HEADERS; +static const char *docquit_rtsp = "HTTP/1.1 200 Goodbye" END_OF_HEADERS; /* sent as reply to a CONNECT */ static const char *docconnect = @@ -180,7 +178,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) return 1; } - req->prot_version = prot_major*10 + prot_minor; + req->prot_version = prot_major * 10 + prot_minor; /* find the last slash */ ptr = strrchr(doc, '/'); @@ -285,8 +283,8 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) if(num < 0) logmsg("negative pipe size ignored"); else if(num > 0) - req->pipe = num-1; /* decrease by one since we do not count the - first request in this number */ + req->pipe = num - 1; /* decrease by one since we do not count + the first request in this number */ } else if(sscanf(ptr, "skip: %d", &num) == 1) { logmsg("instructed to skip this number of bytes %d", num); @@ -569,7 +567,7 @@ static void rtspd_storerequest(char *reqbuf, size_t totalsize) writeleft = totalsize; do { - written = fwrite(&reqbuf[totalsize-writeleft], 1, writeleft, dump); + written = fwrite(&reqbuf[totalsize - writeleft], 1, writeleft, dump); if(got_exit_signal) goto storerequest_cleanup; if(written > 0) @@ -584,7 +582,7 @@ static void rtspd_storerequest(char *reqbuf, size_t totalsize) logmsg("Error writing file %s error (%d) %s", dumpfile, error, curlx_strerror(error, errbuf, sizeof(errbuf))); logmsg("Wrote only (%zu bytes) of (%zu bytes) request input to %s", - totalsize-writeleft, totalsize, dumpfile); + totalsize - writeleft, totalsize, dumpfile); } storerequest_cleanup: @@ -636,7 +634,7 @@ static int rtspd_get_request(curl_socket_t sock, struct rtspd_httprequest *req) /*** end of httprequest init ***/ - while(!done_processing && (req->offset < sizeof(req->reqbuf)-1)) { + while(!done_processing && (req->offset < sizeof(req->reqbuf) - 1)) { if(pipereq_length && pipereq) { memmove(reqbuf, pipereq, pipereq_length); got = curlx_uztosz(pipereq_length); @@ -650,7 +648,7 @@ static int rtspd_get_request(curl_socket_t sock, struct rtspd_httprequest *req) got = sread(sock, reqbuf + req->offset, req->cl); else got = sread(sock, reqbuf + req->offset, - sizeof(req->reqbuf)-1 - req->offset); + sizeof(req->reqbuf) - 1 - req->offset); } if(got_exit_signal) return 1; @@ -686,16 +684,16 @@ static int rtspd_get_request(curl_socket_t sock, struct rtspd_httprequest *req) } } - if((req->offset == sizeof(req->reqbuf)-1) && (got > 0)) { + if((req->offset == sizeof(req->reqbuf) - 1) && (got > 0)) { logmsg("Request would overflow buffer, closing connection"); /* dump request received so far to external file anyway */ - reqbuf[sizeof(req->reqbuf)-1] = '\0'; + reqbuf[sizeof(req->reqbuf) - 1] = '\0'; fail = 1; } - else if(req->offset > sizeof(req->reqbuf)-1) { + else if(req->offset > sizeof(req->reqbuf) - 1) { logmsg("Request buffer overflow, closing connection"); /* dump request received so far to external file anyway */ - reqbuf[sizeof(req->reqbuf)-1] = '\0'; + reqbuf[sizeof(req->reqbuf) - 1] = '\0'; fail = 1; } else @@ -739,10 +737,10 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) case RCMD_STREAM: { static const char streamthis[] = "a string to stream 01234567890\n"; for(;;) { - written = swrite(sock, streamthis, sizeof(streamthis)-1); + written = swrite(sock, streamthis, sizeof(streamthis) - 1); if(got_exit_signal) return -1; - if(written != (ssize_t)(sizeof(streamthis)-1)) { + if(written != (ssize_t)(sizeof(streamthis) - 1)) { logmsg("Stopped streaming"); break; } @@ -803,7 +801,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) } else { FILE *stream = test2fopen(req->testno, logdir); - char partbuf[80]="data"; + char partbuf[80] = "data"; if(req->partno) snprintf(partbuf, sizeof(partbuf), "data%ld", req->partno); if(!stream) { @@ -942,7 +940,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) if(sendfailure) { logmsg("Sending response failed. Only (%zu bytes) of " "(%zu bytes) were sent", - responsesize-count, responsesize); + responsesize - count, responsesize); free(ptr); free(cmd); return -1; @@ -997,7 +995,6 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) return 0; } - static int test_rtspd(int argc, char *argv[]) { srvr_sockaddr_union_t me; @@ -1031,7 +1028,7 @@ static int test_rtspd(int argc, char *argv[]) #else "" #endif - ); + ); return 0; } else if(!strcmp("--pidfile", argv[arg])) { @@ -1126,8 +1123,7 @@ static int test_rtspd(int argc, char *argv[]) } flag = 1; - if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, - (void *)&flag, sizeof(flag))) { + if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&flag, sizeof(flag))) { error = SOCKERRNO; logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s", error, curlx_strerror(error, errbuf, sizeof(errbuf))); diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c index 08ece51ea141..9560a3967646 100644 --- a/tests/server/sockfilt.c +++ b/tests/server/sockfilt.c @@ -420,7 +420,7 @@ static DWORD WINAPI select_ws_wait_thread(void *lpParameter) DWORD type, length, ret; /* retrieve handles from internal structure */ - data = (struct select_ws_wait_data *) lpParameter; + data = (struct select_ws_wait_data *)lpParameter; if(data) { handle = data->handle; handles[0] = data->abort; @@ -434,120 +434,120 @@ static DWORD WINAPI select_ws_wait_thread(void *lpParameter) /* retrieve the type of file to wait on */ type = GetFileType(handle); switch(type) { - case FILE_TYPE_DISK: - /* The handle represents a file on disk, this means: - * - WaitForMultipleObjectsEx will always be signalled for it. - * - comparison of current position in file and total size of - * the file can be used to check if we reached the end yet. - * - * Approach: Loop till either the internal event is signalled - * or if the end of the file has already been reached. - */ - while(WaitForMultipleObjectsEx(1, handles, FALSE, 0, FALSE) - == WAIT_TIMEOUT) { - /* get total size of file */ - length = 0; - size.QuadPart = 0; - size.LowPart = GetFileSize(handle, &length); - if((size.LowPart != INVALID_FILE_SIZE) || + case FILE_TYPE_DISK: + /* The handle represents a file on disk, this means: + * - WaitForMultipleObjectsEx will always be signalled for it. + * - comparison of current position in file and total size of + * the file can be used to check if we reached the end yet. + * + * Approach: Loop till either the internal event is signalled + * or if the end of the file has already been reached. + */ + while(WaitForMultipleObjectsEx(1, handles, FALSE, 0, FALSE) + == WAIT_TIMEOUT) { + /* get total size of file */ + length = 0; + size.QuadPart = 0; + size.LowPart = GetFileSize(handle, &length); + if((size.LowPart != INVALID_FILE_SIZE) || + (GetLastError() == NO_ERROR)) { + size.HighPart = (LONG)length; + /* get the current position within the file */ + pos.QuadPart = 0; + pos.LowPart = SetFilePointer(handle, 0, &pos.HighPart, FILE_CURRENT); + if((pos.LowPart != INVALID_SET_FILE_POINTER) || (GetLastError() == NO_ERROR)) { - size.HighPart = (LONG)length; - /* get the current position within the file */ - pos.QuadPart = 0; - pos.LowPart = SetFilePointer(handle, 0, &pos.HighPart, FILE_CURRENT); - if((pos.LowPart != INVALID_SET_FILE_POINTER) || - (GetLastError() == NO_ERROR)) { - /* compare position with size, abort if not equal */ - if(size.QuadPart == pos.QuadPart) { - /* sleep and continue waiting */ - SleepEx(0, FALSE); - continue; - } + /* compare position with size, abort if not equal */ + if(size.QuadPart == pos.QuadPart) { + /* sleep and continue waiting */ + SleepEx(0, FALSE); + continue; } } - /* there is some data available, stop waiting */ - logmsg("[select_ws_wait_thread] data available, DISK: %p", handle); - SetEvent(signal); } - break; + /* there is some data available, stop waiting */ + logmsg("[select_ws_wait_thread] data available, DISK: %p", handle); + SetEvent(signal); + } + break; - case FILE_TYPE_CHAR: - /* The handle represents a character input, this means: - * - WaitForMultipleObjectsEx will be signalled on any kind of input, - * including mouse and window size events we do not care about. - * - * Approach: Loop till either the internal event is signalled - * or we get signalled for an actual key-event. - */ - while(WaitForMultipleObjectsEx(2, handles, FALSE, INFINITE, FALSE) - == WAIT_OBJECT_0 + 1) { - /* check if this is an actual console handle */ - if(GetConsoleMode(handle, &ret)) { - /* retrieve an event from the console buffer */ - length = 0; - if(PeekConsoleInput(handle, &inputrecord, 1, &length)) { - /* check if the event is not an actual key-event */ - if(length == 1 && inputrecord.EventType != KEY_EVENT) { - /* purge the non-key-event and continue waiting */ - ReadConsoleInput(handle, &inputrecord, 1, &length); - continue; - } + case FILE_TYPE_CHAR: + /* The handle represents a character input, this means: + * - WaitForMultipleObjectsEx will be signalled on any kind of input, + * including mouse and window size events we do not care about. + * + * Approach: Loop till either the internal event is signalled + * or we get signalled for an actual key-event. + */ + while(WaitForMultipleObjectsEx(2, handles, FALSE, INFINITE, FALSE) + == WAIT_OBJECT_0 + 1) { + /* check if this is an actual console handle */ + if(GetConsoleMode(handle, &ret)) { + /* retrieve an event from the console buffer */ + length = 0; + if(PeekConsoleInput(handle, &inputrecord, 1, &length)) { + /* check if the event is not an actual key-event */ + if(length == 1 && inputrecord.EventType != KEY_EVENT) { + /* purge the non-key-event and continue waiting */ + ReadConsoleInput(handle, &inputrecord, 1, &length); + continue; } } - /* there is some data available, stop waiting */ - logmsg("[select_ws_wait_thread] data available, CHAR: %p", handle); - SetEvent(signal); } - break; + /* there is some data available, stop waiting */ + logmsg("[select_ws_wait_thread] data available, CHAR: %p", handle); + SetEvent(signal); + } + break; - case FILE_TYPE_PIPE: - /* The handle represents an anonymous or named pipe, this means: - * - WaitForMultipleObjectsEx will always be signalled for it. - * - peek into the pipe and retrieve the amount of data available. - * - * Approach: Loop till either the internal event is signalled - * or there is data in the pipe available for reading. - */ - while(WaitForMultipleObjectsEx(1, handles, FALSE, 0, FALSE) - == WAIT_TIMEOUT) { - /* peek into the pipe and retrieve the amount of data available */ - length = 0; - if(PeekNamedPipe(handle, NULL, 0, NULL, &length, NULL)) { - /* if there is no data available, sleep and continue waiting */ - if(length == 0) { - SleepEx(0, FALSE); - continue; - } - else { - logmsg("[select_ws_wait_thread] PeekNamedPipe len: %lu", length); - } + case FILE_TYPE_PIPE: + /* The handle represents an anonymous or named pipe, this means: + * - WaitForMultipleObjectsEx will always be signalled for it. + * - peek into the pipe and retrieve the amount of data available. + * + * Approach: Loop till either the internal event is signalled + * or there is data in the pipe available for reading. + */ + while(WaitForMultipleObjectsEx(1, handles, FALSE, 0, FALSE) + == WAIT_TIMEOUT) { + /* peek into the pipe and retrieve the amount of data available */ + length = 0; + if(PeekNamedPipe(handle, NULL, 0, NULL, &length, NULL)) { + /* if there is no data available, sleep and continue waiting */ + if(length == 0) { + SleepEx(0, FALSE); + continue; } else { - /* if the pipe has NOT been closed, sleep and continue waiting */ - ret = GetLastError(); - if(ret != ERROR_BROKEN_PIPE) { - logmsg("[select_ws_wait_thread] PeekNamedPipe error (%lu)", ret); - SleepEx(0, FALSE); - continue; - } - else { - logmsg("[select_ws_wait_thread] pipe closed, PIPE: %p", handle); - } + logmsg("[select_ws_wait_thread] PeekNamedPipe len: %lu", length); } - /* there is some data available, stop waiting */ - logmsg("[select_ws_wait_thread] data available, PIPE: %p", handle); - SetEvent(signal); } - break; - - default: - /* The handle has an unknown type, try to wait on it */ - if(WaitForMultipleObjectsEx(2, handles, FALSE, INFINITE, FALSE) - == WAIT_OBJECT_0 + 1) { - logmsg("[select_ws_wait_thread] data available, HANDLE: %p", handle); - SetEvent(signal); + else { + /* if the pipe has NOT been closed, sleep and continue waiting */ + ret = GetLastError(); + if(ret != ERROR_BROKEN_PIPE) { + logmsg("[select_ws_wait_thread] PeekNamedPipe error (%lu)", ret); + SleepEx(0, FALSE); + continue; + } + else { + logmsg("[select_ws_wait_thread] pipe closed, PIPE: %p", handle); + } } - break; + /* there is some data available, stop waiting */ + logmsg("[select_ws_wait_thread] data available, PIPE: %p", handle); + SetEvent(signal); + } + break; + + default: + /* The handle has an unknown type, try to wait on it */ + if(WaitForMultipleObjectsEx(2, handles, FALSE, INFINITE, FALSE) + == WAIT_OBJECT_0 + 1) { + logmsg("[select_ws_wait_thread] data available, HANDLE: %p", handle); + SetEvent(signal); + } + break; } return 0; @@ -658,12 +658,12 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds, if(FD_ISSET(wsasock, readfds)) { FD_SET(wsasock, &readsock); - wsaevents.lNetworkEvents |= FD_READ|FD_ACCEPT|FD_CLOSE; + wsaevents.lNetworkEvents |= FD_READ | FD_ACCEPT | FD_CLOSE; } if(FD_ISSET(wsasock, writefds)) { FD_SET(wsasock, &writesock); - wsaevents.lNetworkEvents |= FD_WRITE|FD_CONNECT|FD_CLOSE; + wsaevents.lNetworkEvents |= FD_WRITE | FD_CONNECT | FD_CLOSE; } if(FD_ISSET(wsasock, exceptfds)) { @@ -800,11 +800,11 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds, wsaevents.lNetworkEvents |= data[i].wsastate; /* remove from descriptor set if not ready for read/accept/close */ - if(!(wsaevents.lNetworkEvents & (FD_READ|FD_ACCEPT|FD_CLOSE))) + if(!(wsaevents.lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE))) FD_CLR(wsasock, readfds); /* remove from descriptor set if not ready for write/connect */ - if(!(wsaevents.lNetworkEvents & (FD_WRITE|FD_CONNECT|FD_CLOSE))) + if(!(wsaevents.lNetworkEvents & (FD_WRITE | FD_CONNECT | FD_CLOSE))) FD_CLR(wsasock, writefds); /* remove from descriptor set if not exceptional */ @@ -851,10 +851,10 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds, return ret; } -#define SOCKFILT_select(a,b,c,d,e) select_ws(a,b,c,d,e) +#define SOCKFILT_select(a, b, c, d, e) select_ws(a, b, c, d, e) #else -#define SOCKFILT_select(a,b,c,d,e) select(a,b,c,d,e) -#endif /* USE_WINSOCK */ +#define SOCKFILT_select(a, b, c, d, e) select(a, b, c, d, e) +#endif /* USE_WINSOCK */ /* Perform the disconnect handshake with sockfilt * This involves waiting for the disconnect acknowledgment after the DISC @@ -867,46 +867,45 @@ static bool disc_handshake(void) return FALSE; do { - unsigned char buffer[BUFFER_SIZE]; - ssize_t buffer_len; - if(!read_stdin(buffer, 5)) - return FALSE; - logmsg("Received %c%c%c%c (on stdin)", - buffer[0], buffer[1], buffer[2], buffer[3]); - - if(!memcmp("ACKD", buffer, 4)) { - /* got the ack we were waiting for */ - break; - } - else if(!memcmp("DISC", buffer, 4)) { - logmsg("Crikey! Client also wants to disconnect"); - if(!write_stdout("ACKD\n", 5)) - return FALSE; - } - else if(!memcmp("DATA", buffer, 4)) { - /* We must read more data to stay in sync */ - logmsg("Throwing away data bytes"); - if(!read_data_block(buffer, sizeof(buffer), &buffer_len)) - return FALSE; + unsigned char buffer[BUFFER_SIZE]; + ssize_t buffer_len; + if(!read_stdin(buffer, 5)) + return FALSE; + logmsg("Received %c%c%c%c (on stdin)", + buffer[0], buffer[1], buffer[2], buffer[3]); - } - else if(!memcmp("QUIT", buffer, 4)) { - /* just die */ - logmsg("quits"); + if(!memcmp("ACKD", buffer, 4)) { + /* got the ack we were waiting for */ + break; + } + else if(!memcmp("DISC", buffer, 4)) { + logmsg("Crikey! Client also wants to disconnect"); + if(!write_stdout("ACKD\n", 5)) return FALSE; - } - else { - logmsg("Unexpected message error; aborting"); - /* - * The only other messages that could occur here are PING and PORT, - * and both of them occur at the start of a test when nothing should be - * trying to DISC. Therefore, we should not ever get here, but if we - * do, it is probably due to some kind of unclean shutdown situation so - * us shutting down is what we probably ought to be doing, anyway. - */ + } + else if(!memcmp("DATA", buffer, 4)) { + /* We must read more data to stay in sync */ + logmsg("Throwing away data bytes"); + if(!read_data_block(buffer, sizeof(buffer), &buffer_len)) return FALSE; - } + } + else if(!memcmp("QUIT", buffer, 4)) { + /* just die */ + logmsg("quits"); + return FALSE; + } + else { + logmsg("Unexpected message error; aborting"); + /* + * The only other messages that could occur here are PING and PORT, + * and both of them occur at the start of a test when nothing should be + * trying to DISC. Therefore, we should not ever get here, but if we + * do, it is probably due to some kind of unclean shutdown situation so + * us shutting down is what we probably ought to be doing, anyway. + */ + return FALSE; + } } while(TRUE); return TRUE; } @@ -1034,7 +1033,6 @@ static bool juggle(curl_socket_t *sockfdp, } /* switch(*mode) */ - do { /* select() blocking behavior call on blocking descriptors please */ @@ -1058,7 +1056,6 @@ static bool juggle(curl_socket_t *sockfdp, /* timeout */ return TRUE; - if(FD_ISSET(fileno(stdin), &fds_read)) { ssize_t buffer_len; /* read from stdin, commands/data to be dealt with and possibly passed on @@ -1146,8 +1143,7 @@ static bool juggle(curl_socket_t *sockfdp, } } - - if((sockfd != CURL_SOCKET_BAD) && (FD_ISSET(sockfd, &fds_read)) ) { + if((sockfd != CURL_SOCKET_BAD) && (FD_ISSET(sockfd, &fds_read))) { ssize_t nread_socket; if(*mode == PASSIVE_LISTEN) { /* there is no stream set up yet, this is an indication that there is a @@ -1228,7 +1224,7 @@ static int test_sockfilt(int argc, char *argv[]) #else "" #endif - ); + ); return 0; } else if(!strcmp("--verbose", argv[arg])) { diff --git a/tests/server/socksd.c b/tests/server/socksd.c index 4205d26880bd..f9fadd211328 100644 --- a/tests/server/socksd.c +++ b/tests/server/socksd.c @@ -289,8 +289,8 @@ static curl_socket_t socks4(curl_socket_t fd, static curl_socket_t sockit(curl_socket_t fd) { - unsigned char buffer[2*256 + 16]; - unsigned char response[2*256 + 16]; + unsigned char buffer[2 * 256 + 16]; + unsigned char response[2 * 256 + 16]; ssize_t rc; unsigned char len; unsigned char type; @@ -483,7 +483,7 @@ static curl_socket_t sockit(curl_socket_t fd) case 3: /* The first octet of the address field contains the number of octets of name that follow */ - fprintf(dump, " %.*s\n", len-1, &address[1]); + fprintf(dump, " %.*s\n", len - 1, &address[1]); break; case 4: /* 16 bytes IPv6 address */ @@ -579,8 +579,7 @@ static int tunnel(struct perclient *cp, fd_set *fds) /* read from client, send to remote */ nread = recv(cp->clientfd, buffer, sizeof(buffer), 0); if(nread > 0) { - nwrite = send(cp->remotefd, (char *)buffer, - (SEND_TYPE_ARG3)nread, 0); + nwrite = send(cp->remotefd, (char *)buffer, (SEND_TYPE_ARG3)nread, 0); if(nwrite != nread) return 1; cp->fromclient += nwrite; @@ -592,8 +591,7 @@ static int tunnel(struct perclient *cp, fd_set *fds) /* read from remote, send to client */ nread = recv(cp->remotefd, buffer, sizeof(buffer), 0); if(nread > 0) { - nwrite = send(cp->clientfd, (char *)buffer, - (SEND_TYPE_ARG3)nread, 0); + nwrite = send(cp->clientfd, (char *)buffer, (SEND_TYPE_ARG3)nread, 0); if(nwrite != nread) return 1; cp->fromremote += nwrite; @@ -725,7 +723,6 @@ static bool socksd_incoming(curl_socket_t listenfd) cp->used = TRUE; clients++; } - } } for(i = 0; i < 2; i++) { @@ -777,7 +774,7 @@ static int test_socksd(int argc, char *argv[]) #else "" #endif - ); + ); return 0; } else if(!strcmp("--pidfile", argv[arg])) { diff --git a/tests/server/sws.c b/tests/server/sws.c index b070614f525e..13f745546983 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -51,7 +51,7 @@ static bool sws_prevbounce = FALSE; /* instructs the server to override the #define RCMD_STREAM 2 /* told to stream */ struct sws_httprequest { - char reqbuf[2*1024*1024]; /* buffer area for the incoming request */ + char reqbuf[2 * 1024 * 1024]; /* buffer area for the incoming request */ bool connect_request; /* if a CONNECT */ unsigned short connect_port; /* the port number CONNECT used */ size_t checkindex; /* where to start checking of the request */ @@ -138,8 +138,7 @@ static const char *cmdfile = "log/server.cmd"; static const char *end_of_headers = END_OF_HEADERS; /* sent as reply to a QUIT */ -static const char *docquit_sws = -"HTTP/1.1 200 Goodbye" END_OF_HEADERS; +static const char *docquit_sws = "HTTP/1.1 200 Goodbye" END_OF_HEADERS; /* send back this on 404 file not found */ static const char *doc404 = "HTTP/1.1 404 Not Found\r\n" @@ -169,7 +168,7 @@ static bool socket_domain_is_ip(void) #endif return true; default: - /* case AF_UNIX: */ + /* case AF_UNIX: */ return false; } } @@ -334,12 +333,10 @@ static int sws_ProcessRequest(struct sws_httprequest *req) size_t npath = 0; /* httppath length */ if(sscanf(line, - "%" REQUEST_KEYWORD_SIZE_TXT"s ", request) == 1) { + "%" REQUEST_KEYWORD_SIZE_TXT "s ", request) == 1) { http = strstr(line + strlen(request), "HTTP/"); - if(http && sscanf(http, "HTTP/%d.%d", - &prot_major, - &prot_minor) == 2) { + if(http && sscanf(http, "HTTP/%d.%d", &prot_major, &prot_minor) == 2) { /* between the request keyword and HTTP/ there is a path */ httppath = line + strlen(request); npath = http - httppath; @@ -361,7 +358,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req) if(fine) { char *ptr; - req->prot_version = prot_major*10 + prot_minor; + req->prot_version = prot_major * 10 + prot_minor; /* find the last slash */ ptr = &httppath[npath]; @@ -746,7 +743,7 @@ static void sws_storerequest(const char *reqbuf, size_t totalsize) writeleft = totalsize; do { - written = fwrite(&reqbuf[totalsize-writeleft], 1, writeleft, dump); + written = fwrite(&reqbuf[totalsize - writeleft], 1, writeleft, dump); if(got_exit_signal) goto storerequest_cleanup; if(written > 0) @@ -761,7 +758,7 @@ static void sws_storerequest(const char *reqbuf, size_t totalsize) logmsg("Error writing file %s error (%d) %s", dumpfile, error, curlx_strerror(error, errbuf, sizeof(errbuf))); logmsg("Wrote only (%zu bytes) of (%zu bytes) request input to %s", - totalsize-writeleft, totalsize, dumpfile); + totalsize - writeleft, totalsize, dumpfile); } storerequest_cleanup: @@ -876,7 +873,7 @@ static int sws_get_request(curl_socket_t sock, struct sws_httprequest *req) return -1; } - if(req->offset >= sizeof(req->reqbuf)-1) { + if(req->offset >= sizeof(req->reqbuf) - 1) { /* buffer is already full; do nothing */ overflow = 1; } @@ -888,7 +885,7 @@ static int sws_get_request(curl_socket_t sock, struct sws_httprequest *req) got = sread(sock, reqbuf + req->offset, req->cl); else got = sread(sock, reqbuf + req->offset, - sizeof(req->reqbuf)-1 - req->offset); + sizeof(req->reqbuf) - 1 - req->offset); if(got_exit_signal) return -1; @@ -924,16 +921,16 @@ static int sws_get_request(curl_socket_t sock, struct sws_httprequest *req) return -1; } - if(overflow || (req->offset == sizeof(req->reqbuf)-1 && got > 0)) { + if(overflow || (req->offset == sizeof(req->reqbuf) - 1 && got > 0)) { logmsg("Request would overflow buffer, closing connection"); /* dump request received so far to external file anyway */ - reqbuf[sizeof(req->reqbuf)-1] = '\0'; + reqbuf[sizeof(req->reqbuf) - 1] = '\0'; fail = 1; } - else if(req->offset > sizeof(req->reqbuf)-1) { + else if(req->offset > sizeof(req->reqbuf) - 1) { logmsg("Request buffer overflow, closing connection"); /* dump request received so far to external file anyway */ - reqbuf[sizeof(req->reqbuf)-1] = '\0'; + reqbuf[sizeof(req->reqbuf) - 1] = '\0'; fail = 1; } else @@ -978,10 +975,10 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req) case RCMD_STREAM: { static const char streamthis[] = "a string to stream 01234567890\n"; for(;;) { - written = swrite(sock, streamthis, sizeof(streamthis)-1); + written = swrite(sock, streamthis, sizeof(streamthis) - 1); if(got_exit_signal) return -1; - if(written != (ssize_t)(sizeof(streamthis)-1)) { + if(written != (ssize_t)(sizeof(streamthis) - 1)) { logmsg("Stopped streaming"); break; } @@ -1144,7 +1141,7 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req) if(req->writedelay) { int msecs_left = req->writedelay; int intervals = msecs_left / MAX_SLEEP_TIME_MS; - if(msecs_left%MAX_SLEEP_TIME_MS) + if(msecs_left % MAX_SLEEP_TIME_MS) intervals++; logmsg("Pausing %d milliseconds after writing %zd bytes", msecs_left, written); @@ -1172,7 +1169,7 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req) if(sendfailure) { logmsg("Sending response failed. Only (%zu bytes) of (%zu bytes) " "were sent", - responsesize-count, responsesize); + responsesize - count, responsesize); sws_prevtestno = req->testno; sws_prevpartno = req->partno; free(ptr); @@ -1247,9 +1244,7 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port) if(!ipaddr) return CURL_SOCKET_BAD; - logmsg("about to connect to %s%s%s:%hu", - op_br, ipaddr, cl_br, port); - + logmsg("about to connect to %s%s%s:%hu", op_br, ipaddr, cl_br, port); serverfd = socket(socket_domain, SOCK_STREAM, 0); if(CURL_SOCKET_BAD == serverfd) { @@ -1389,7 +1384,7 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port) * must accept a new connection and deal with it appropriately. */ -#define data_or_ctrl(x) ((x)?"DATA":"CTRL") +#define data_or_ctrl(x) ((x) ? "DATA" : "CTRL") #define SWS_CTRL 0 #define SWS_DATA 1 @@ -1644,7 +1639,7 @@ static void http_connect(curl_socket_t *infdp, } } if(serverfd[i] != CURL_SOCKET_BAD) { - len = sizeof(readserver[i])-toc[i]; + len = sizeof(readserver[i]) - toc[i]; if(len && FD_ISSET(serverfd[i], &input)) { /* read from server */ rc = sread(serverfd[i], &readserver[i][toc[i]], len); @@ -1676,7 +1671,7 @@ static void http_connect(curl_socket_t *infdp, logmsg("[%s] SENT \"%s\"", data_or_ctrl(i), data_to_hex(readserver[i], rc)); if(toc[i] - rc) - memmove(&readserver[i][0], &readserver[i][rc], toc[i]-rc); + memmove(&readserver[i][0], &readserver[i][rc], toc[i] - rc); toc[i] -= rc; } } @@ -1696,7 +1691,7 @@ static void http_connect(curl_socket_t *infdp, logmsg("[%s] SENT \"%s\"", data_or_ctrl(i), data_to_hex(readclient[i], rc)); if(tos[i] - rc) - memmove(&readclient[i][0], &readclient[i][rc], tos[i]-rc); + memmove(&readclient[i][0], &readclient[i][rc], tos[i] - rc); tos[i] -= rc; } } @@ -1826,7 +1821,6 @@ static void http_upgrade(struct sws_httprequest *req) /* left to implement */ } - /* returns a socket handle, or 0 if there are no more waiting sockets, or < 0 if there was an error */ static curl_socket_t accept_connection(curl_socket_t sock) @@ -2021,12 +2015,12 @@ static int test_sws(int argc, char *argv[]) if(!strcmp("--version", argv[arg])) { puts("sws IPv4" #ifdef USE_IPV6 - "/IPv6" + "/IPv6" #endif #ifdef USE_UNIX_SOCKETS - "/unix" + "/unix" #endif - ); + ); return 0; } else if(!strcmp("--pidfile", argv[arg])) { @@ -2097,8 +2091,7 @@ static int test_sws(int argc, char *argv[]) if(argc > arg) { opt = argv[arg]; if(curlx_str_number(&opt, &num, 0xffff)) { - fprintf(stderr, "sws: invalid --port argument (%s)\n", - argv[arg]); + fprintf(stderr, "sws: invalid --port argument (%s)\n", argv[arg]); return 0; } port = (unsigned short)num; @@ -2327,9 +2320,9 @@ static int test_sws(int argc, char *argv[]) /* Clear out closed sockets */ for(socket_idx = num_sockets - 1; socket_idx >= 1; --socket_idx) { if(CURL_SOCKET_BAD == all_sockets[socket_idx]) { - char *dst = (char *) (all_sockets + socket_idx); - char *src = (char *) (all_sockets + socket_idx + 1); - char *end = (char *) (all_sockets + num_sockets); + char *dst = (char *)(all_sockets + socket_idx); + char *src = (char *)(all_sockets + socket_idx + 1); + char *end = (char *)(all_sockets + num_sockets); memmove(dst, src, end - src); num_sockets -= 1; } diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index 2eb31ff5ece8..99c008031eab 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -380,7 +380,7 @@ static void read_ahead(struct testcase *test, } p = dp->th_data; - for(i = 0 ; i < SEGSIZE; i++) { + for(i = 0; i < SEGSIZE; i++) { if(newline) { if(prevchar == '\n') c = '\n'; /* lf to cr,lf */ @@ -536,8 +536,7 @@ static int synchnet(curl_socket_t f /* socket to flush */) else fromaddrlen = sizeof(fromaddr.sa6); #endif - (void)recvfrom(f, rbuf, sizeof(rbuf), 0, - &fromaddr.sa, &fromaddrlen); + (void)recvfrom(f, rbuf, sizeof(rbuf), 0, &fromaddr.sa, &fromaddrlen); } else break; @@ -578,7 +577,7 @@ static int test_tftpd(int argc, char **argv) #else "" #endif - ); + ); return 0; } else if(!strcmp("--pidfile", argv[arg])) { @@ -674,8 +673,7 @@ static int test_tftpd(int argc, char **argv) } flag = 1; - if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, - (void *)&flag, sizeof(flag))) { + if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&flag, sizeof(flag))) { error = SOCKERRNO; logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s", error, curlx_strerror(error, errbuf, sizeof(errbuf))); @@ -825,7 +823,7 @@ static int test_tftpd(int argc, char **argv) } #endif - maxtimeout = 5*TIMEOUT; + maxtimeout = 5 * TIMEOUT; tp = &trsbuf.hdr; tp->th_opcode = ntohs(tp->th_opcode); @@ -1076,7 +1074,6 @@ static int tftpd_parse_servercmd(struct testcase *req) return 0; /* OK! */ } - /* * Validate file access. */ @@ -1104,7 +1101,7 @@ static int validate_access(struct testcase *test, ptr = strrchr(filename, '/'); if(ptr) { - char partbuf[80]="data"; + char partbuf[80] = "data"; long partno; long testno; const char *pval; @@ -1209,7 +1206,7 @@ static void sendtftp(struct testcase *test, const struct formats *pf) if(test->writedelay) { logmsg("Pausing %d seconds before %d bytes", test->writedelay, size); - curlx_wait_ms(1000*test->writedelay); + curlx_wait_ms(1000 * test->writedelay); } send_data: @@ -1249,11 +1246,10 @@ static void sendtftp(struct testcase *test, const struct formats *pf) } /* Re-synchronize with the other side */ (void)synchnet(peer); - if(sap->th_block == (sendblock-1)) { + if(sap->th_block == (sendblock - 1)) { goto send_data; } } - } sendblock++; } while(size == SEGSIZE); diff --git a/tests/server/util.c b/tests/server/util.c index ae21ff8b1af8..624826571a9f 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -37,7 +37,7 @@ */ char *data_to_hex(char *data, size_t len) { - static char buf[256*3]; + static char buf[256 * 3]; size_t i; char *optr = buf; char *iptr = data; @@ -177,18 +177,18 @@ int win32_init(void) } if(LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) || - HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested) ) { + HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested)) { WSACleanup(); win32_perror("Winsock init failed"); logmsg("No suitable winsock.dll found -- aborting"); return 1; } } -#endif /* USE_WINSOCK */ +#endif /* USE_WINSOCK */ atexit(win32_cleanup); return 0; } -#endif /* _WIN32 */ +#endif /* _WIN32 */ /* fopens the test case file */ FILE *test2fopen(long testno, const char *logdir2) @@ -370,8 +370,7 @@ static void exit_signal_handler(int signum) fd != -1) { #else /* !checksrc! disable BANNEDFUNC 1 */ - fd = open(serverlogfile, - O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR); + fd = open(serverlogfile, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR); if(fd != -1) { #endif static const char msg[] = "exit_signal_handler: called\n"; @@ -546,7 +545,7 @@ static SIGHANDLER_T set_signal(int signum, SIGHANDLER_T handler, #ifdef HAVE_SIGINTERRUPT if(oldhdlr != SIG_ERR) - siginterrupt(signum, (int) restartable); + siginterrupt(signum, (int)restartable); #else (void)restartable; #endif @@ -693,7 +692,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket, return -1; } strcpy(sau->sun_path, unix_socket); - rc = bind(sock, (struct sockaddr*)sau, sizeof(struct sockaddr_un)); + rc = bind(sock, (struct sockaddr *)sau, sizeof(struct sockaddr_un)); if(rc && SOCKERRNO == SOCKEADDRINUSE) { struct_stat statbuf; /* socket already exists. Perhaps it is stale? */ @@ -738,7 +737,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket, return rc; } /* stale socket is gone, retry bind */ - rc = bind(sock, (struct sockaddr*)sau, sizeof(struct sockaddr_un)); + rc = bind(sock, (struct sockaddr *)sau, sizeof(struct sockaddr_un)); } return rc; } @@ -805,29 +804,29 @@ curl_socket_t sockdaemon(curl_socket_t sock, request to let the system choose a non-zero available port. */ switch(socket_domain) { - case AF_INET: - memset(&listener.sa4, 0, sizeof(listener.sa4)); - listener.sa4.sin_family = AF_INET; - listener.sa4.sin_addr.s_addr = INADDR_ANY; - listener.sa4.sin_port = htons(*listenport); - rc = bind(sock, &listener.sa, sizeof(listener.sa4)); - break; + case AF_INET: + memset(&listener.sa4, 0, sizeof(listener.sa4)); + listener.sa4.sin_family = AF_INET; + listener.sa4.sin_addr.s_addr = INADDR_ANY; + listener.sa4.sin_port = htons(*listenport); + rc = bind(sock, &listener.sa, sizeof(listener.sa4)); + break; #ifdef USE_IPV6 - case AF_INET6: - memset(&listener.sa6, 0, sizeof(listener.sa6)); - listener.sa6.sin6_family = AF_INET6; - listener.sa6.sin6_addr = in6addr_any; - listener.sa6.sin6_port = htons(*listenport); - rc = bind(sock, &listener.sa, sizeof(listener.sa6)); - break; + case AF_INET6: + memset(&listener.sa6, 0, sizeof(listener.sa6)); + listener.sa6.sin6_family = AF_INET6; + listener.sa6.sin6_addr = in6addr_any; + listener.sa6.sin6_port = htons(*listenport); + rc = bind(sock, &listener.sa, sizeof(listener.sa6)); + break; #endif /* USE_IPV6 */ #ifdef USE_UNIX_SOCKETS - case AF_UNIX: - rc = bind_unix_socket(sock, unix_socket, &listener.sau); - break; + case AF_UNIX: + rc = bind_unix_socket(sock, unix_socket, &listener.sau); + break; #endif - default: - rc = 1; + default: + rc = 1; } if(rc) { diff --git a/tests/unit/unit1300.c b/tests/unit/unit1300.c index 77fb1fb38639..53da9dd4f661 100644 --- a/tests/unit/unit1300.c +++ b/tests/unit/unit1300.c @@ -65,7 +65,7 @@ static CURLcode test_unit1300(const char *arg) * 2: list head will be NULL * 3: list tail will be NULL * 4: list dtor will be NULL - */ + */ fail_unless(Curl_llist_count(&llist) == 0, "list initial size should be zero"); diff --git a/tests/unit/unit1302.c b/tests/unit/unit1302.c index d56f7b09f779..157f1f61ed9c 100644 --- a/tests/unit/unit1302.c +++ b/tests/unit/unit1302.c @@ -124,7 +124,7 @@ static CURLcode test_unit1302(const char *arg) {"", 0, "aWlpaWlpaQ=", 15} /* unaligned size, missing a padding char */ }; - for(i = 0 ; i < CURL_ARRAYSIZE(encode); i++) { + for(i = 0; i < CURL_ARRAYSIZE(encode); i++) { struct etest *e = &encode[i]; char *out; unsigned char *decoded; @@ -180,7 +180,7 @@ static CURLcode test_unit1302(const char *arg) Curl_safefree(out); } - for(i = 0 ; i < CURL_ARRAYSIZE(badecode); i++) { + for(i = 0; i < CURL_ARRAYSIZE(badecode); i++) { struct etest *e = &badecode[i]; unsigned char *decoded; size_t dlen; diff --git a/tests/unit/unit1304.c b/tests/unit/unit1304.c index 100f3f58287e..3e09a0c27761 100644 --- a/tests/unit/unit1304.c +++ b/tests/unit/unit1304.c @@ -46,8 +46,7 @@ static CURLcode test_unit1304(const char *arg) * Test a non existent host in our netrc file. */ Curl_netrc_init(&store); - result = Curl_parsenetrc(&store, - "test.example.com", &login, &password, arg); + result = Curl_parsenetrc(&store, "test.example.com", &login, &password, arg); fail_unless(result == 1, "Host not found should return 1"); abort_unless(password == NULL, "password did not return NULL!"); abort_unless(login == NULL, "user did not return NULL!"); @@ -58,8 +57,7 @@ static CURLcode test_unit1304(const char *arg) */ login = (char *)CURL_UNCONST("me"); Curl_netrc_init(&store); - result = Curl_parsenetrc(&store, - "example.com", &login, &password, arg); + result = Curl_parsenetrc(&store, "example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password == NULL, "password is not NULL!"); Curl_netrc_cleanup(&store); @@ -69,8 +67,7 @@ static CURLcode test_unit1304(const char *arg) */ login = (char *)CURL_UNCONST("me"); Curl_netrc_init(&store); - result = Curl_parsenetrc(&store, - "test.example.com", &login, &password, arg); + result = Curl_parsenetrc(&store, "test.example.com", &login, &password, arg); fail_unless(result == 1, "Host not found should return 1"); abort_unless(password == NULL, "password is not NULL!"); Curl_netrc_cleanup(&store); @@ -81,8 +78,7 @@ static CURLcode test_unit1304(const char *arg) */ login = (char *)CURL_UNCONST("admi"); /* spellchecker:disable-line */ Curl_netrc_init(&store); - result = Curl_parsenetrc(&store, - "example.com", &login, &password, arg); + result = Curl_parsenetrc(&store, "example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password == NULL, "password is not NULL!"); Curl_netrc_cleanup(&store); @@ -93,8 +89,7 @@ static CURLcode test_unit1304(const char *arg) */ login = (char *)CURL_UNCONST("adminn"); Curl_netrc_init(&store); - result = Curl_parsenetrc(&store, - "example.com", &login, &password, arg); + result = Curl_parsenetrc(&store, "example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password == NULL, "password is not NULL!"); Curl_netrc_cleanup(&store); @@ -105,8 +100,7 @@ static CURLcode test_unit1304(const char *arg) */ login = NULL; Curl_netrc_init(&store); - result = Curl_parsenetrc(&store, - "example.com", &login, &password, arg); + result = Curl_parsenetrc(&store, "example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(strncmp(password, "passwd", 6) == 0, @@ -124,8 +118,7 @@ static CURLcode test_unit1304(const char *arg) password = NULL; login = NULL; Curl_netrc_init(&store); - result = Curl_parsenetrc(&store, - "example.com", &login, &password, arg); + result = Curl_parsenetrc(&store, "example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(strncmp(password, "passwd", 6) == 0, @@ -143,12 +136,10 @@ static CURLcode test_unit1304(const char *arg) curlx_free(login); login = NULL; Curl_netrc_init(&store); - result = Curl_parsenetrc(&store, - "curl.example.com", &login, &password, arg); + result = Curl_parsenetrc(&store, "curl.example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); - fail_unless(strncmp(password, "none", 4) == 0, - "password should be 'none'"); + fail_unless(strncmp(password, "none", 4) == 0, "password should be 'none'"); abort_unless(login != NULL, "returned NULL!"); fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'"); Curl_netrc_cleanup(&store); @@ -162,12 +153,10 @@ static CURLcode test_unit1304(const char *arg) curlx_free(login); login = NULL; Curl_netrc_init(&store); - result = Curl_parsenetrc(&store, - "curl.example.com", &login, &password, arg); + result = Curl_parsenetrc(&store, "curl.example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); - fail_unless(strncmp(password, "none", 4) == 0, - "password should be 'none'"); + fail_unless(strncmp(password, "none", 4) == 0, "password should be 'none'"); abort_unless(login != NULL, "returned NULL!"); fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'"); Curl_netrc_cleanup(&store); diff --git a/tests/unit/unit1307.c b/tests/unit/unit1307.c index d5fcf5c6b1ed..3651b341ed39 100644 --- a/tests/unit/unit1307.c +++ b/tests/unit/unit1307.c @@ -290,7 +290,7 @@ static CURLcode test_unit1307(const char *arg) for(i = 0; i < CURL_ARRAYSIZE(tests); i++) { int result = tests[i].result; int rc = Curl_fnmatch(NULL, tests[i].pattern, tests[i].string); - if(result & (LINUX_DIFFER|MAC_DIFFER)) { + if(result & (LINUX_DIFFER | MAC_DIFFER)) { if((result & LINUX_DIFFER) && (machine == SYSTEM_LINUX)) result >>= LINUX_SHIFT; else if((result & MAC_DIFFER) && (machine == SYSTEM_MACOS)) diff --git a/tests/unit/unit1309.c b/tests/unit/unit1309.c index 2e2af21f2c75..af9a29e11085 100644 --- a/tests/unit/unit1309.c +++ b/tests/unit/unit1309.c @@ -63,8 +63,8 @@ static CURLcode test_unit1309(const char *arg) #define NUM_NODES 50 struct Curl_tree *root, *removed; - struct Curl_tree nodes[NUM_NODES*3]; - size_t storage[NUM_NODES*3]; + struct Curl_tree nodes[NUM_NODES * 3]; + size_t storage[NUM_NODES * 3]; int rc; int i, j; struct curltime tv_now = {0, 0}; @@ -75,7 +75,7 @@ static CURLcode test_unit1309(const char *arg) struct curltime key; key.tv_sec = 0; - key.tv_usec = (541*i)%1023; + key.tv_usec = (541 * i) % 1023; storage[i] = key.tv_usec; Curl_splayset(&nodes[i], &storage[i]); root = Curl_splayinsert(key, root, &nodes[i]); @@ -85,7 +85,7 @@ static CURLcode test_unit1309(const char *arg) splayprint(root, 0, 1); for(i = 0; i < NUM_NODES; i++) { - int rem = (i + 7)%NUM_NODES; + int rem = (i + 7) % NUM_NODES; curl_mprintf("Tree look:\n"); splayprint(root, 0, 1); curl_mprintf("remove pointer %d, payload %zu\n", rem, @@ -105,11 +105,11 @@ static CURLcode test_unit1309(const char *arg) struct curltime key; key.tv_sec = 0; - key.tv_usec = (541*i)%1023; + key.tv_usec = (541 * i) % 1023; /* add some nodes with the same key */ for(j = 0; j <= i % 3; j++) { - storage[i * 3 + j] = key.tv_usec*10 + j; + storage[i * 3 + j] = key.tv_usec * 10 + j; Curl_splayset(&nodes[i * 3 + j], &storage[i * 3 + j]); root = Curl_splayinsert(key, root, &nodes[i * 3 + j]); } diff --git a/tests/unit/unit1397.c b/tests/unit/unit1397.c index 7d3d4fd7f798..e56b894e36b3 100644 --- a/tests/unit/unit1397.c +++ b/tests/unit/unit1397.c @@ -103,7 +103,7 @@ static CURLcode test_unit1397(const char *arg) "did %sMATCH\n", tests[i].host, tests[i].pattern, - tests[i].match ? "NOT ": ""); + tests[i].match ? "NOT " : ""); unitfail++; } } diff --git a/tests/unit/unit1398.c b/tests/unit/unit1398.c index 1b72bf1163b1..abd4447ca464 100644 --- a/tests/unit/unit1398.c +++ b/tests/unit/unit1398.c @@ -118,7 +118,7 @@ static CURLcode test_unit1398(const char *arg) "%s%s%s%s%s%s%s%s%s%s" /* 100 */ "%s%s%s%s%s%s%s%s%s%s" /* 110 */ "%s%s%s%s%s%s%s%s%s%s" /* 120 */ - "%s%s%s%s%s%s%s%s%s", /* 129 */ + "%s%s%s%s%s%s%s%s%s", /* 129 */ "a", "", "", "", "", "", "", "", "", "", /* 10 */ "b", "", "", "", "", "", "", "", "", "", /* 20 */ @@ -132,8 +132,8 @@ static CURLcode test_unit1398(const char *arg) "j", "", "", "", "", "", "", "", "", "", /* 100 */ "k", "", "", "", "", "", "", "", "", "", /* 110 */ "l", "", "", "", "", "", "", "", "", "", /* 120 */ - "m", "", "", "", "", "", "", "", "" /* 129 */ - ); + "m", "", "", "", "", "", "", "", "" /* 129 */ + ); fail_unless(rc == 0, "return code should be 0"); /* 128 input % flags */ @@ -150,7 +150,7 @@ static CURLcode test_unit1398(const char *arg) "%s%s%s%s%s%s%s%s%s%s" /* 100 */ "%s%s%s%s%s%s%s%s%s%s" /* 110 */ "%s%s%s%s%s%s%s%s%s%s" /* 120 */ - "%s%s%s%s%s%s%s%s", /* 128 */ + "%s%s%s%s%s%s%s%s", /* 128 */ "a", "", "", "", "", "", "", "", "", "", /* 10 */ "b", "", "", "", "", "", "", "", "", "", /* 20 */ @@ -164,8 +164,8 @@ static CURLcode test_unit1398(const char *arg) "j", "", "", "", "", "", "", "", "", "", /* 100 */ "k", "", "", "", "", "", "", "", "", "", /* 110 */ "l", "", "", "", "", "", "", "", "", "", /* 120 */ - "m", "", "", "", "", "", "", "" /* 128 */ - ); + "m", "", "", "", "", "", "", "" /* 128 */ + ); fail_unless(rc == 13, "return code should be 13"); /* 129 output segments */ @@ -176,8 +176,8 @@ static CURLcode test_unit1398(const char *arg) "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 80 */ "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 100 */ "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 120 */ - "%%%%%%%%%%%%%%%%%%" /* 129 */ - ); + "%%%%%%%%%%%%%%%%%%" /* 129 */ + ); fail_unless(rc == 0, "return code should be 0"); /* 128 output segments */ @@ -188,8 +188,8 @@ static CURLcode test_unit1398(const char *arg) "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 80 */ "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 100 */ "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 120 */ - "%%%%%%%%%%%%%%%%" /* 128 */ - ); + "%%%%%%%%%%%%%%%%" /* 128 */ + ); fail_unless(rc == 128, "return code should be 128"); UNITTEST_END_SIMPLE diff --git a/tests/unit/unit1601.c b/tests/unit/unit1601.c index d31866bb741a..fa7743785dcf 100644 --- a/tests/unit/unit1601.c +++ b/tests/unit/unit1601.c @@ -37,7 +37,7 @@ static CURLcode test_unit1601(const char *arg) unsigned char output[MD5_DIGEST_LEN]; unsigned char *testp = output; - Curl_md5it(output, (const unsigned char *) string1, strlen(string1)); + Curl_md5it(output, (const unsigned char *)string1, strlen(string1)); verify_memory(testp, "\xc4\xca\x42\x38\xa0\xb9\x23\x82\x0d\xcc\x50\x9a\x6f" "\x75\x84\x9b", MD5_DIGEST_LEN); diff --git a/tests/unit/unit1606.c b/tests/unit/unit1606.c index 4e290db72a76..c7f3d718c7d4 100644 --- a/tests/unit/unit1606.c +++ b/tests/unit/unit1606.c @@ -82,18 +82,12 @@ static CURLcode test_unit1606(const char *arg) UNITTEST_BEGIN(t1606_setup(&easy)) - fail_unless(runawhile(easy, 41, 41, 40, 0) == 41, - "wrong low speed timeout"); - fail_unless(runawhile(easy, 21, 21, 20, 0) == 21, - "wrong low speed timeout"); - fail_unless(runawhile(easy, 60, 60, 40, 0) == 60, - "wrong log speed timeout"); - fail_unless(runawhile(easy, 50, 50, 40, 0) == 50, - "wrong log speed timeout"); - fail_unless(runawhile(easy, 40, 40, 40, 0) == 99, - "should not time out"); - fail_unless(runawhile(easy, 10, 50, 100, 2) == 36, - "bad timeout"); + fail_unless(runawhile(easy, 41, 41, 40, 0) == 41, "wrong low speed timeout"); + fail_unless(runawhile(easy, 21, 21, 20, 0) == 21, "wrong low speed timeout"); + fail_unless(runawhile(easy, 60, 60, 40, 0) == 60, "wrong log speed timeout"); + fail_unless(runawhile(easy, 50, 50, 40, 0) == 50, "wrong log speed timeout"); + fail_unless(runawhile(easy, 40, 40, 40, 0) == 99, "should not time out"); + fail_unless(runawhile(easy, 10, 50, 100, 2) == 36, "bad timeout"); UNITTEST_END(t1606_stop(easy)) } diff --git a/tests/unit/unit1610.c b/tests/unit/unit1610.c index 73a546a85eaf..5c47fe28e2c6 100644 --- a/tests/unit/unit1610.c +++ b/tests/unit/unit1610.c @@ -44,14 +44,14 @@ static CURLcode test_unit1610(const char *arg) unsigned char output[CURL_SHA256_DIGEST_LENGTH]; unsigned char *testp = output; - Curl_sha256it(output, (const unsigned char *) string1, strlen(string1)); + Curl_sha256it(output, (const unsigned char *)string1, strlen(string1)); verify_memory(testp, "\x6b\x86\xb2\x73\xff\x34\xfc\xe1\x9d\x6b\x80\x4e\xff\x5a\x3f" "\x57\x47\xad\xa4\xea\xa2\x2f\x1d\x49\xc0\x1e\x52\xdd\xb7\x87" "\x5b\x4b", CURL_SHA256_DIGEST_LENGTH); - Curl_sha256it(output, (const unsigned char *) string2, strlen(string2)); + Curl_sha256it(output, (const unsigned char *)string2, strlen(string2)); verify_memory(testp, "\xcb\xb1\x6a\x8a\xb9\xcb\xb9\x35\xa8\xcb\xa0\x2e\x28\xc0\x26" diff --git a/tests/unit/unit1611.c b/tests/unit/unit1611.c index 5337aa33a319..88c79eb3d9af 100644 --- a/tests/unit/unit1611.c +++ b/tests/unit/unit1611.c @@ -35,13 +35,13 @@ static CURLcode test_unit1611(const char *arg) unsigned char output[MD4_DIGEST_LENGTH]; unsigned char *testp = output; - Curl_md4it(output, (const unsigned char *) string1, strlen(string1)); + Curl_md4it(output, (const unsigned char *)string1, strlen(string1)); verify_memory(testp, "\x8b\xe1\xec\x69\x7b\x14\xad\x3a\x53\xb3\x71\x43\x61\x20\x64" "\x1d", MD4_DIGEST_LENGTH); - Curl_md4it(output, (const unsigned char *) string2, strlen(string2)); + Curl_md4it(output, (const unsigned char *)string2, strlen(string2)); verify_memory(testp, "\xa7\x16\x1c\xad\x7e\xbe\xdb\xbc\xf8\xc7\x23\x10\x2d\x2c\xe2" diff --git a/tests/unit/unit1612.c b/tests/unit/unit1612.c index 0cc0c0254667..7d8c9acf96b6 100644 --- a/tests/unit/unit1612.c +++ b/tests/unit/unit1612.c @@ -40,8 +40,8 @@ static CURLcode test_unit1612(const char *arg) unsigned char *testp = output; Curl_hmacit(&Curl_HMAC_MD5, - (const unsigned char *) password, strlen(password), - (const unsigned char *) string1, strlen(string1), + (const unsigned char *)password, strlen(password), + (const unsigned char *)string1, strlen(string1), output); verify_memory(testp, @@ -49,8 +49,8 @@ static CURLcode test_unit1612(const char *arg) "\x37", HMAC_MD5_LENGTH); Curl_hmacit(&Curl_HMAC_MD5, - (const unsigned char *) password, strlen(password), - (const unsigned char *) string2, strlen(string2), + (const unsigned char *)password, strlen(password), + (const unsigned char *)string2, strlen(string2), output); verify_memory(testp, diff --git a/tests/unit/unit1614.c b/tests/unit/unit1614.c index 10140ee60282..675133e5adf6 100644 --- a/tests/unit/unit1614.c +++ b/tests/unit/unit1614.c @@ -34,12 +34,12 @@ static CURLcode test_unit1614(const char *arg) int err = 0; struct check { - const char *a; + const char *a; const char *n; unsigned int bits; bool match; }; - struct check list4[]= { + struct check list4[] = { { "192.160.0.1", "192.160.0.1", 33, FALSE}, { "192.160.0.1", "192.160.0.1", 32, TRUE}, { "192.160.0.1", "192.160.0.1", 0, TRUE}, @@ -55,7 +55,7 @@ static CURLcode test_unit1614(const char *arg) { NULL, NULL, 0, FALSE} /* end marker */ }; #ifdef USE_IPV6 - struct check list6[]= { + struct check list6[] = { { "::1", "::1", 0, TRUE}, { "::1", "::1", 128, TRUE}, { "::1", "0:0::1", 128, TRUE}, @@ -69,7 +69,7 @@ static CURLcode test_unit1614(const char *arg) const char *n; bool match; }; - struct noproxy list[]= { + struct noproxy list[] = { { "www.example.com", "localhost .example.com .example.de", FALSE}, { "www.example.com", "localhost,.example.com,.example.de", TRUE}, { "www.example.com.", "localhost,.example.com,.example.de", TRUE}, @@ -161,7 +161,7 @@ static CURLcode test_unit1614(const char *arg) if(match != list4[i].match) { curl_mfprintf(stderr, "%s in %s/%u should %smatch\n", list4[i].a, list4[i].n, list4[i].bits, - list4[i].match ? "": "not "); + list4[i].match ? "" : "not "); err++; } } @@ -171,7 +171,7 @@ static CURLcode test_unit1614(const char *arg) if(match != list6[i].match) { curl_mfprintf(stderr, "%s in %s/%u should %smatch\n", list6[i].a, list6[i].n, list6[i].bits, - list6[i].match ? "": "not "); + list6[i].match ? "" : "not "); err++; } } @@ -181,7 +181,7 @@ static CURLcode test_unit1614(const char *arg) if(match != list[i].match) { curl_mfprintf(stderr, "%s in %s should %smatch\n", list[i].a, list[i].n, - list[i].match ? "": "not "); + list[i].match ? "" : "not "); err++; } } diff --git a/tests/unit/unit1615.c b/tests/unit/unit1615.c index 44dc1ae04545..fadb1aaa59b4 100644 --- a/tests/unit/unit1615.c +++ b/tests/unit/unit1615.c @@ -113,31 +113,31 @@ static CURLcode test_unit1615(const char *arg) /* Mute compiler warnings in 'verify_memory' macros below */ computed_hash = output_buf; - Curl_sha512_256it(output_buf, (const unsigned char *) test_str1, + Curl_sha512_256it(output_buf, (const unsigned char *)test_str1, CURL_ARRAYSIZE(test_str1) - 1); verify_memory(computed_hash, precomp_hash1, CURL_SHA512_256_DIGEST_LENGTH); - Curl_sha512_256it(output_buf, (const unsigned char *) test_str2, + Curl_sha512_256it(output_buf, (const unsigned char *)test_str2, CURL_ARRAYSIZE(test_str2) - 1); verify_memory(computed_hash, precomp_hash2, CURL_SHA512_256_DIGEST_LENGTH); - Curl_sha512_256it(output_buf, (const unsigned char *) test_str3, + Curl_sha512_256it(output_buf, (const unsigned char *)test_str3, CURL_ARRAYSIZE(test_str3) - 1); verify_memory(computed_hash, precomp_hash3, CURL_SHA512_256_DIGEST_LENGTH); - Curl_sha512_256it(output_buf, (const unsigned char *) test_str4, + Curl_sha512_256it(output_buf, (const unsigned char *)test_str4, CURL_ARRAYSIZE(test_str4) - 1); verify_memory(computed_hash, precomp_hash4, CURL_SHA512_256_DIGEST_LENGTH); - Curl_sha512_256it(output_buf, (const unsigned char *) test_str5, + Curl_sha512_256it(output_buf, (const unsigned char *)test_str5, CURL_ARRAYSIZE(test_str5) - 1); verify_memory(computed_hash, precomp_hash5, CURL_SHA512_256_DIGEST_LENGTH); - Curl_sha512_256it(output_buf, (const unsigned char *) test_str6, + Curl_sha512_256it(output_buf, (const unsigned char *)test_str6, CURL_ARRAYSIZE(test_str6) - 1); verify_memory(computed_hash, precomp_hash6, CURL_SHA512_256_DIGEST_LENGTH); - Curl_sha512_256it(output_buf, (const unsigned char *) test_str7, + Curl_sha512_256it(output_buf, (const unsigned char *)test_str7, CURL_ARRAYSIZE(test_str7) - 1); verify_memory(computed_hash, precomp_hash7, CURL_SHA512_256_DIGEST_LENGTH); diff --git a/tests/unit/unit1620.c b/tests/unit/unit1620.c index 4c1674f5bd54..b04424ae3bd3 100644 --- a/tests/unit/unit1620.c +++ b/tests/unit/unit1620.c @@ -116,8 +116,7 @@ static CURLcode test_unit1620(const char *arg) Curl_freeset(empty); for(i = (enum dupstring)0; i < STRING_LAST; i++) { - fail_unless(empty->set.str[i] == NULL, - "Curl_free() did not set to NULL"); + fail_unless(empty->set.str[i] == NULL, "Curl_free() did not set to NULL"); } rc = Curl_close(&empty); diff --git a/tests/unit/unit1650.c b/tests/unit/unit1650.c index 89e72262d384..309515d9b125 100644 --- a/tests/unit/unit1650.c +++ b/tests/unit/unit1650.c @@ -205,7 +205,7 @@ static CURLcode test_unit1650(const char *arg) int j; for(j = 0; j < 16; j += 2) { size_t l; - curl_msnprintf(ptr, len, "%s%02x%02x", j?":":"", a->ip.v6[j], + curl_msnprintf(ptr, len, "%s%02x%02x", j ? ":" : "", a->ip.v6[j], a->ip.v6[j + 1]); l = strlen(ptr); len -= l; @@ -232,12 +232,12 @@ static CURLcode test_unit1650(const char *arg) } /* pass all sizes into the decoder until full */ - for(i = 0; i < sizeof(full49)-1; i++) { + for(i = 0; i < sizeof(full49) - 1; i++) { struct dohentry d; DOHcode rc; memset(&d, 0, sizeof(d)); - rc = doh_resp_decode((const unsigned char *)full49, i, CURL_DNS_TYPE_A, - &d); + rc = doh_resp_decode((const unsigned char *)full49, + i, CURL_DNS_TYPE_A, &d); if(!rc) { /* none of them should work */ curl_mfprintf(stderr, "%zu: %d\n", i, rc); @@ -250,8 +250,8 @@ static CURLcode test_unit1650(const char *arg) struct dohentry d; DOHcode rc; memset(&d, 0, sizeof(d)); - rc = doh_resp_decode((const unsigned char *)&full49[i], sizeof(full49)-i-1, - CURL_DNS_TYPE_A, &d); + rc = doh_resp_decode((const unsigned char *)&full49[i], + sizeof(full49) - i - 1, CURL_DNS_TYPE_A, &d); if(!rc) { /* none of them should work */ curl_mfprintf(stderr, "2 %zu: %d\n", i, rc); @@ -264,8 +264,8 @@ static CURLcode test_unit1650(const char *arg) struct dohentry d; struct dohaddr *a; memset(&d, 0, sizeof(d)); - rc = doh_resp_decode((const unsigned char *)full49, sizeof(full49)-1, - CURL_DNS_TYPE_A, &d); + rc = doh_resp_decode((const unsigned char *)full49, + sizeof(full49) - 1, CURL_DNS_TYPE_A, &d); fail_if(d.numaddr != 1, "missing address"); a = &d.addr[0]; p = &a->ip.v4[0]; diff --git a/tests/unit/unit1651.c b/tests/unit/unit1651.c index d3620d99f299..ffaea47b20ea 100644 --- a/tests/unit/unit1651.c +++ b/tests/unit/unit1651.c @@ -360,10 +360,10 @@ static CURLcode test_unit1651(const char *arg) /* a poor man's fuzzing of some initial data to make sure nothing bad happens */ - for(byte = 1 ; byte < 255; byte += 17) { + for(byte = 1; byte < 255; byte += 17) { for(i = 0; i < 45; i++) { unsigned char backup = cert[i]; - cert[i] = (unsigned char) (byte & 0xff); + cert[i] = (unsigned char)(byte & 0xff); (void)Curl_extract_certinfo(data, 0, beg, end); cert[i] = backup; } diff --git a/tests/unit/unit1655.c b/tests/unit/unit1655.c index ab42b971ef51..91aca3f1a4a3 100644 --- a/tests/unit/unit1655.c +++ b/tests/unit/unit1655.c @@ -121,7 +121,7 @@ static CURLcode test_unit1655(const char *arg) else { if(d == DOH_OK) { fail_unless(olen <= sizeof(victim.dohbuffer), - "wrote outside bounds"); + "wrote outside bounds"); fail_unless(olen > strlen(name), "unrealistic low size"); } } diff --git a/tests/unit/unit1656.c b/tests/unit/unit1656.c index 322aa2dbe329..7cdca884b808 100644 --- a/tests/unit/unit1656.c +++ b/tests/unit/unit1656.c @@ -95,7 +95,7 @@ static CURLcode test_unit1656(const char *arg) struct dynbuf dbuf; bool all_ok = TRUE; - curlx_dyn_init(&dbuf, 32*1024); + curlx_dyn_init(&dbuf, 32 * 1024); if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { curl_mfprintf(stderr, "curl_global_init() failed\n"); diff --git a/tests/unit/unit1657.c b/tests/unit/unit1657.c index c03cd51f55a8..850b3ef73086 100644 --- a/tests/unit/unit1657.c +++ b/tests/unit/unit1657.c @@ -93,7 +93,7 @@ static CURLcode test_unit1657(const char *arg) bool all_ok = TRUE; struct dynbuf dbuf; - curlx_dyn_init(&dbuf, 32*1024); + curlx_dyn_init(&dbuf, 32 * 1024); if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { curl_mfprintf(stderr, "curl_global_init() failed\n"); diff --git a/tests/unit/unit1660.c b/tests/unit/unit1660.c index 376f6bdcfa45..6b1dcce9fc4d 100644 --- a/tests/unit/unit1660.c +++ b/tests/unit/unit1660.c @@ -130,7 +130,7 @@ static CURLcode test_unit1660(const char *arg) Curl_hsts_loadfile(easy, h, arg); - for(i = 0; headers[i].host ; i++) { + for(i = 0; headers[i].host; i++) { if(headers[i].hdr) { res = Curl_hsts_parse(h, headers[i].host, headers[i].hdr); diff --git a/tests/unit/unit1661.c b/tests/unit/unit1661.c index d9aa2a61f14e..569b06760b2b 100644 --- a/tests/unit/unit1661.c +++ b/tests/unit/unit1661.c @@ -78,7 +78,7 @@ static CURLcode test_unit1661(const char *arg) /** * testing Curl_bufref_ptr */ - fail_unless((const char *) Curl_bufref_ptr(&bufref) == buffer, + fail_unless((const char *)Curl_bufref_ptr(&bufref) == buffer, "Wrong pointer value returned"); /** diff --git a/tests/unit/unit1663.c b/tests/unit/unit1663.c index e4431930a410..e0c77c9d7849 100644 --- a/tests/unit/unit1663.c +++ b/tests/unit/unit1663.c @@ -39,12 +39,11 @@ static CURLcode t1663_setup(void) return res; } -static void t1663_parse( - const char *input_data, - const char *exp_dev, - const char *exp_iface, - const char *exp_host, - CURLcode exp_rc) +static void t1663_parse(const char *input_data, + const char *exp_dev, + const char *exp_iface, + const char *exp_host, + CURLcode exp_rc) { char *dev = NULL; char *iface = NULL; diff --git a/tests/unit/unit2600.c b/tests/unit/unit2600.c index b69b675b3b1a..9af844ca6387 100644 --- a/tests/unit/unit2600.c +++ b/tests/unit/unit2600.c @@ -238,8 +238,7 @@ static CURLcode cf_test_create(struct Curl_cfilter **pcf, return res; } -static void check_result(const struct test_case *tc, - struct test_result *tr) +static void check_result(const struct test_case *tc, struct test_result *tr) { char msg[256]; timediff_t duration_ms; @@ -247,8 +246,7 @@ static void check_result(const struct test_case *tc, duration_ms = curlx_timediff_ms(tr->ended, tr->started); curl_mfprintf(stderr, "%d: test case took %dms\n", tc->id, (int)duration_ms); - if(tr->res != tc->exp_res - && CURLE_OPERATION_TIMEDOUT != tr->res) { + if(tr->res != tc->exp_res && CURLE_OPERATION_TIMEDOUT != tr->res) { /* on CI we encounter the TIMEOUT result, since images get less CPU * and events are not as sharply timed. */ curl_msprintf(msg, "%d: expected result %d but got %d", diff --git a/tests/unit/unit2601.c b/tests/unit/unit2601.c index 8411c19e9878..6a1ca2f1bd36 100644 --- a/tests/unit/unit2601.c +++ b/tests/unit/unit2601.c @@ -80,7 +80,7 @@ static void check_bufq(size_t pool_spares, size_t chunk_size, size_t max_chunks, size_t wsize, size_t rsize, int opts) { - static unsigned char test_data[32*1024]; + static unsigned char test_data[32 * 1024]; struct bufq q; struct bufc_pool pool; @@ -167,7 +167,7 @@ static void check_bufq(size_t pool_spares, /* Test SOFT_LIMIT option */ Curl_bufq_free(&q); - Curl_bufq_init2(&q, chunk_size, max_chunks, (opts|BUFQ_OPT_SOFT_LIMIT)); + Curl_bufq_init2(&q, chunk_size, max_chunks, (opts | BUFQ_OPT_SOFT_LIMIT)); nwritten = 0; while(!Curl_bufq_is_full(&q)) { res = Curl_bufq_write(&q, test_data, wsize, &n2); @@ -212,9 +212,9 @@ static CURLcode test_unit2601(const char *arg) struct bufq q; size_t n; CURLcode res; - unsigned char buf[16*1024]; + unsigned char buf[16 * 1024]; - Curl_bufq_init(&q, 8*1024, 12); + Curl_bufq_init(&q, 8 * 1024, 12); res = Curl_bufq_read(&q, buf, 128, &n); fail_unless(res && res == CURLE_AGAIN, "read empty fail"); Curl_bufq_free(&q); @@ -225,7 +225,7 @@ static CURLcode test_unit2601(const char *arg) check_bufq(0, 1024, 4, 16000, 3000, BUFQ_OPT_NONE); check_bufq(0, 8000, 10, 1234, 1234, BUFQ_OPT_NONE); - check_bufq(0, 8000, 10, 8*1024, 4*1024, BUFQ_OPT_NONE); + check_bufq(0, 8000, 10, 8 * 1024, 4 * 1024, BUFQ_OPT_NONE); check_bufq(0, 1024, 4, 128, 128, BUFQ_OPT_NO_SPARES); check_bufq(0, 1024, 4, 129, 127, BUFQ_OPT_NO_SPARES); diff --git a/tests/unit/unit2602.c b/tests/unit/unit2602.c index da2b7dba5496..684fa3db8332 100644 --- a/tests/unit/unit2602.c +++ b/tests/unit/unit2602.c @@ -85,7 +85,7 @@ static CURLcode test_unit2602(const char *arg) Curl_dynhds_reset(&hds); Curl_dynhds_free(&hds); - Curl_dynhds_init(&hds, 128, 4*1024); + Curl_dynhds_init(&hds, 128, 4 * 1024); fail_if(Curl_dynhds_add(&hds, "test1", 5, "123", 3), "add failed"); fail_if(Curl_dynhds_add(&hds, "test1", 5, "123", 3), "add failed"); fail_if(Curl_dynhds_cadd(&hds, "blablabla", "thingies"), "add failed"); @@ -100,18 +100,18 @@ static CURLcode test_unit2602(const char *arg) fail_unless(Curl_dynhds_ccount_name(&hds, "bLABlaBlA") == 0, "should"); fail_if(Curl_dynhds_cadd(&hds, "Bla-Bla", "thingies"), "add failed"); - curlx_dyn_init(&dbuf, 32*1024); + curlx_dyn_init(&dbuf, 32 * 1024); fail_if(Curl_dynhds_h1_dprint(&hds, &dbuf), "h1 print failed"); if(curlx_dyn_ptr(&dbuf)) { fail_if(strcmp(curlx_dyn_ptr(&dbuf), "test1: 123\r\ntest1: 123\r\nBla-Bla: thingies\r\n"), - "h1 format differs"); + "h1 format differs"); } curlx_dyn_free(&dbuf); } Curl_dynhds_free(&hds); - Curl_dynhds_init(&hds, 128, 4*1024); + Curl_dynhds_init(&hds, 128, 4 * 1024); /* continuation without previous header fails */ res = Curl_dynhds_h1_cadd_line(&hds, " indented value"); fail_unless(res, "add should have failed"); @@ -124,13 +124,13 @@ static CURLcode test_unit2602(const char *arg) fail_if(Curl_dynhds_h1_cadd_line(&hds, "ti3: val1"), "add"); fail_if(Curl_dynhds_h1_cadd_line(&hds, " val2"), "add indent"); - curlx_dyn_init(&dbuf, 32*1024); + curlx_dyn_init(&dbuf, 32 * 1024); fail_if(Curl_dynhds_h1_dprint(&hds, &dbuf), "h1 print failed"); if(curlx_dyn_ptr(&dbuf)) { curl_mfprintf(stderr, "indent concat: %s\n", curlx_dyn_ptr(&dbuf)); fail_if(strcmp(curlx_dyn_ptr(&dbuf), "ti1: val1 val2\r\nti2: val1 val2\r\nti3: val1 val2\r\n"), - "wrong format"); + "wrong format"); } curlx_dyn_free(&dbuf); diff --git a/tests/unit/unit3200.c b/tests/unit/unit3200.c index fe00da939d57..bfd4d1181b84 100644 --- a/tests/unit/unit3200.c +++ b/tests/unit/unit3200.c @@ -94,68 +94,68 @@ static CURLcode test_unit3200(const char *arg) curl_mfprintf(stderr, "Test %zd...", i); switch(i) { - case 0: - res = Curl_get_line(&buf, fp, &eof); - line = curlx_dyn_ptr(&buf); - fail_unless(!res && line && !strcmp("LINE1\n", line), - "First line failed (1)"); - res = Curl_get_line(&buf, fp, &eof); - line = curlx_dyn_ptr(&buf); - fail_unless(!res && line && !strcmp("LINE2 NEWLINE\n", line), - "Second line failed (1)"); - res = Curl_get_line(&buf, fp, &eof); - abort_unless(eof, "Missed EOF (1)"); - break; - case 1: - res = Curl_get_line(&buf, fp, &eof); - line = curlx_dyn_ptr(&buf); - fail_unless(!res && line && !strcmp("LINE1\n", line), - "First line failed (2)"); - res = Curl_get_line(&buf, fp, &eof); - line = curlx_dyn_ptr(&buf); - fail_unless(!res && line && !strcmp("LINE2 NONEWLINE\n", line), - "Second line failed (2)"); - res = Curl_get_line(&buf, fp, &eof); - abort_unless(eof, "Missed EOF (2)"); - break; - case 2: - res = Curl_get_line(&buf, fp, &eof); - line = curlx_dyn_ptr(&buf); - fail_unless(!res && line && !strcmp("LINE1\n", line), - "First line failed (3)"); - res = Curl_get_line(&buf, fp, &eof); - fail_unless(!curlx_dyn_len(&buf), - "Did not detect max read on EOF (3)"); - break; - case 3: - res = Curl_get_line(&buf, fp, &eof); - line = curlx_dyn_ptr(&buf); - fail_unless(!res && line && !strcmp("LINE1\n", line), - "First line failed (4)"); - res = Curl_get_line(&buf, fp, &eof); - fail_unless(!curlx_dyn_len(&buf), - "Did not ignore partial on EOF (4)"); - break; - case 4: - res = Curl_get_line(&buf, fp, &eof); - line = curlx_dyn_ptr(&buf); - fail_unless(!res && line && !strcmp("LINE1\n", line), - "First line failed (5)"); - res = Curl_get_line(&buf, fp, &eof); - fail_unless(!curlx_dyn_len(&buf), - "Did not bail out on too long line"); - break; - case 5: - res = Curl_get_line(&buf, fp, &eof); - line = curlx_dyn_ptr(&buf); - fail_unless(!res && line && !strcmp("LINE1\x1aTEST\n", line), - "Missed/Misinterpreted ^Z (6)"); - res = Curl_get_line(&buf, fp, &eof); - abort_unless(eof, "Missed EOF (6)"); - break; - default: - abort_unless(1, "Unknown case"); - break; + case 0: + res = Curl_get_line(&buf, fp, &eof); + line = curlx_dyn_ptr(&buf); + fail_unless(!res && line && !strcmp("LINE1\n", line), + "First line failed (1)"); + res = Curl_get_line(&buf, fp, &eof); + line = curlx_dyn_ptr(&buf); + fail_unless(!res && line && !strcmp("LINE2 NEWLINE\n", line), + "Second line failed (1)"); + res = Curl_get_line(&buf, fp, &eof); + abort_unless(eof, "Missed EOF (1)"); + break; + case 1: + res = Curl_get_line(&buf, fp, &eof); + line = curlx_dyn_ptr(&buf); + fail_unless(!res && line && !strcmp("LINE1\n", line), + "First line failed (2)"); + res = Curl_get_line(&buf, fp, &eof); + line = curlx_dyn_ptr(&buf); + fail_unless(!res && line && !strcmp("LINE2 NONEWLINE\n", line), + "Second line failed (2)"); + res = Curl_get_line(&buf, fp, &eof); + abort_unless(eof, "Missed EOF (2)"); + break; + case 2: + res = Curl_get_line(&buf, fp, &eof); + line = curlx_dyn_ptr(&buf); + fail_unless(!res && line && !strcmp("LINE1\n", line), + "First line failed (3)"); + res = Curl_get_line(&buf, fp, &eof); + fail_unless(!curlx_dyn_len(&buf), + "Did not detect max read on EOF (3)"); + break; + case 3: + res = Curl_get_line(&buf, fp, &eof); + line = curlx_dyn_ptr(&buf); + fail_unless(!res && line && !strcmp("LINE1\n", line), + "First line failed (4)"); + res = Curl_get_line(&buf, fp, &eof); + fail_unless(!curlx_dyn_len(&buf), + "Did not ignore partial on EOF (4)"); + break; + case 4: + res = Curl_get_line(&buf, fp, &eof); + line = curlx_dyn_ptr(&buf); + fail_unless(!res && line && !strcmp("LINE1\n", line), + "First line failed (5)"); + res = Curl_get_line(&buf, fp, &eof); + fail_unless(!curlx_dyn_len(&buf), + "Did not bail out on too long line"); + break; + case 5: + res = Curl_get_line(&buf, fp, &eof); + line = curlx_dyn_ptr(&buf); + fail_unless(!res && line && !strcmp("LINE1\x1aTEST\n", line), + "Missed/Misinterpreted ^Z (6)"); + res = Curl_get_line(&buf, fp, &eof); + abort_unless(eof, "Missed EOF (6)"); + break; + default: + abort_unless(1, "Unknown case"); + break; } curlx_dyn_free(&buf); curlx_fclose(fp); diff --git a/tests/unit/unit3205.c b/tests/unit/unit3205.c index bb42e9e0c629..bb35fb2f8eae 100644 --- a/tests/unit/unit3205.c +++ b/tests/unit/unit3205.c @@ -561,9 +561,9 @@ static CURLcode test_unit3205(const char *arg) /* suites matched by EDH alias will return the DHE name */ if(test->id >= 0x0011 && test->id < 0x0017) { if(expect && memcmp(expect, "EDH-", 4) == 0) - expect = (char *) memcpy(strcpy(alt, expect), "DHE-", 4); + expect = (char *)memcpy(strcpy(alt, expect), "DHE-", 4); if(expect && memcmp(expect + 4, "EDH-", 4) == 0) - expect = (char *) memcpy(strcpy(alt, expect) + 4, "DHE-", 4) - 4; + expect = (char *)memcpy(strcpy(alt, expect) + 4, "DHE-", 4) - 4; } if(expect && strcmp(buf, expect) != 0) { diff --git a/tests/unit/unit3211.c b/tests/unit/unit3211.c index 1ec30ac9a2af..7f6c616909c0 100644 --- a/tests/unit/unit3211.c +++ b/tests/unit/unit3211.c @@ -84,7 +84,7 @@ static void check_set(const char *name, unsigned int capacity, } /* The count is half */ c = Curl_uint32_bset_count(&bset); - fail_unless(c == slen/2, "set count is wrong"); + fail_unless(c == slen / 2, "set count is wrong"); Curl_uint32_bset_clear(&bset); c = Curl_uint32_bset_count(&bset); @@ -107,7 +107,7 @@ static void check_set(const char *name, unsigned int capacity, for(i = 0; i < slen; i++) /* all still present after resize back */ fail_unless(Curl_uint32_bset_contains(&bset, s[i]), "unexpectedly lost"); - fail_unless(!Curl_uint32_bset_resize(&bset, capacity/2), + fail_unless(!Curl_uint32_bset_resize(&bset, capacity / 2), "resize half failed"); /* halved the size, what numbers remain in set? */ c = Curl_uint32_bset_capacity(&bset); diff --git a/tests/unit/unit3213.c b/tests/unit/unit3213.c index b0d4d2ced557..dbd26f4aa49c 100644 --- a/tests/unit/unit3213.c +++ b/tests/unit/unit3213.c @@ -75,7 +75,7 @@ static void check_spbset(const char *name, const unsigned int *s, size_t slen) } /* The count is half */ c = Curl_uint32_spbset_count(&bset); - fail_unless(c == slen/2, "set count is wrong"); + fail_unless(c == slen / 2, "set count is wrong"); Curl_uint32_spbset_clear(&bset); c = Curl_uint32_spbset_count(&bset); diff --git a/tests/unit/unit3216.c b/tests/unit/unit3216.c index cbe9a5f0bf51..0f9d27492c03 100644 --- a/tests/unit/unit3216.c +++ b/tests/unit/unit3216.c @@ -45,7 +45,7 @@ static CURLcode test_unit3216(const char *arg) fail_unless(Curl_rlimit_avail(&r, ts) == 0, "blocked inf"); Curl_rlimit_block(&r, FALSE, ts); fail_unless(Curl_rlimit_avail(&r, ts) == CURL_OFF_T_MAX, - "unblocked unlimited"); + "unblocked unlimited"); /* A ratelimit that give 10 tokens per second */ ts = curlx_now(); From 06e16167d62984976b7a3ea2fcfa61813fd6d81c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 28 Nov 2025 17:16:31 +0100 Subject: [PATCH 116/140] memdebug: buffer output data Instead of writing each line to file immediately, this now stores them in an in-memory buffer until that gets full or curl exits. To make it run faster and write to file less often. Closes #19750 --- lib/memdebug.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/memdebug.c b/lib/memdebug.c index 9fd54d026b69..329b11ea793b 100644 --- a/lib/memdebug.c +++ b/lib/memdebug.c @@ -62,6 +62,10 @@ static long memsize = 0; /* set number of mallocs allowed */ static struct backtrace_state *btstate; #endif +#define KEEPSIZE 10000 +static char membuf[KEEPSIZE]; +static size_t memwidx = 0; /* write index */ + /* LeakSantizier (LSAN) calls _exit() instead of exit() when a leak is detected on exit so the logfile must be closed explicitly or data could be lost. Though _exit() does not call atexit handlers such as this, LSAN's call to @@ -71,6 +75,8 @@ static void curl_dbg_cleanup(void) if(curl_dbg_logfile && curl_dbg_logfile != stderr && curl_dbg_logfile != stdout) { + if(memwidx) + fwrite(membuf, 1, memwidx, curl_dbg_logfile); /* !checksrc! disable BANNEDFUNC 1 */ fclose(curl_dbg_logfile); } @@ -506,7 +512,7 @@ int curl_dbg_fclose(FILE *file, int line, const char *source) void curl_dbg_log(const char *format, ...) { char buf[1024]; - int nchars; + size_t nchars; va_list ap; if(!curl_dbg_logfile) @@ -519,8 +525,20 @@ void curl_dbg_log(const char *format, ...) if(nchars > (int)sizeof(buf) - 1) nchars = (int)sizeof(buf) - 1; - if(nchars > 0) - fwrite(buf, 1, (size_t)nchars, curl_dbg_logfile); + if(nchars > 0) { + if(KEEPSIZE - nchars < memwidx) { + /* flush */ + fwrite(membuf, 1, memwidx, curl_dbg_logfile); + fflush(curl_dbg_logfile); + memwidx = 0; + } + if(memwidx) { + /* the previous line ends with a newline */ + DEBUGASSERT(membuf[memwidx - 1] == '\n'); + } + memcpy(&membuf[memwidx], buf, nchars); + memwidx += nchars; + } } #endif /* CURLDEBUG */ From 16f073ef49f94412000218c9f6ad04e3fd7e4d01 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Mar 2025 01:15:16 +0100 Subject: [PATCH 117/140] cmake: define dependencies as `IMPORTED` interface targets Rework the way curl's custom Find modules advertise their properties. Before this patch, Find modules returned detected dependency properties (header dirs, libs, libdirs, C flags, etc.) via global variables. curl's main `CMakeLists.txt` copied their values into global lists, which it later applied to targets. This solution worked internally, but it was unsuited for the public, distributed `CURLConfig.cmake` and publishing curl's Find modules with it, due to polluting the namespace of consumer projects. It's also impractical to apply the many individual variables to every targets depending on libcurl. To allow using Find modules in consumer projects, this patch makes them define as imported interface targets, named `CURL::`. Then store dependency information as target properties. It avoids namespace pollution and makes the dependency information apply automatically to all targets using `CURL::libcurl_static`. Find modules continue to return `*_FOUND` and `*_VERSION` variables. For dependencies detected via `pkg-config`, CMake 3.16+ is recommended. Older CMake versions have a varying degree of support for propagating/handling library directories. This may cause issues in envs where dependencies reside in non-system locations and detected via `pkg-config` (e.g. macOS + Homebrew). Use `CURL_USE_PKGCONFIG=OFF` to fix these issues. Or upgrade to newer CMake, or link libcurl dynamically. Also: - re-enable `pkg-config` for old cmake `find_library()` integration tests. - make `curlinfo` build after these changes. - distribute local Find modules. - export the raw list of lib dependencies via `CURL_LIBRARIES_PRIVATE`. - `CURLconfig.cmake`: use curl's Find modules to detect dependencies in the consumer env. - add custom property to target property debug function. - the curl build process no longer modifies `CMAKE_C_FLAGS`. Follow-up to e86542038dda88dadf8959584e803895f979310c #17047 Ref: #14930 Ref: https://github.com/libssh2/libssh2/pull/1535 Ref: https://github.com/libssh2/libssh2/pull/1571 Ref: https://github.com/libssh2/libssh2/pull/1581 Ref: https://github.com/libssh2/libssh2/pull/1623 Closes #16973 --- CMake/FindBrotli.cmake | 40 ++-- CMake/FindCares.cmake | 51 +++-- CMake/FindGSS.cmake | 73 +++--- CMake/FindGnuTLS.cmake | 47 ++-- CMake/FindLDAP.cmake | 42 ++-- CMake/FindLibbacktrace.cmake | 29 ++- CMake/FindLibgsasl.cmake | 46 ++-- CMake/FindLibidn2.cmake | 47 ++-- CMake/FindLibpsl.cmake | 47 ++-- CMake/FindLibrtmp.cmake | 53 +++-- CMake/FindLibssh.cmake | 51 +++-- CMake/FindLibssh2.cmake | 47 ++-- CMake/FindLibuv.cmake | 47 ++-- CMake/FindMbedTLS.cmake | 54 +++-- CMake/FindNGHTTP2.cmake | 47 ++-- CMake/FindNGHTTP3.cmake | 47 ++-- CMake/FindNGTCP2.cmake | 42 ++-- CMake/FindNettle.cmake | 47 ++-- CMake/FindQuiche.cmake | 47 ++-- CMake/FindRustls.cmake | 59 +++-- CMake/FindWolfSSL.cmake | 55 +++-- CMake/FindZstd.cmake | 47 ++-- CMake/Utilities.cmake | 1 + CMake/curl-config.cmake.in | 118 ++++++++++ CMakeLists.txt | 433 +++++++++++++++-------------------- lib/CMakeLists.txt | 26 ++- src/CMakeLists.txt | 3 +- tests/cmake/test.sh | 2 +- 28 files changed, 999 insertions(+), 649 deletions(-) diff --git a/CMake/FindBrotli.cmake b/CMake/FindBrotli.cmake index d2b50d962124..981b30cafd57 100644 --- a/CMake/FindBrotli.cmake +++ b/CMake/FindBrotli.cmake @@ -29,31 +29,27 @@ # - `BROTLICOMMON_LIBRARY`: Absolute path to `brotlicommon` library. # - `BROTLIDEC_LIBRARY`: Absolute path to `brotlidec` library. # -# Result variables: +# Defines: # # - `BROTLI_FOUND`: System has brotli. -# - `BROTLI_INCLUDE_DIRS`: The brotli include directories. -# - `BROTLI_LIBRARIES`: The brotli library names. -# - `BROTLI_LIBRARY_DIRS`: The brotli library directories. -# - `BROTLI_PC_REQUIRES`: The brotli pkg-config packages. -# - `BROTLI_CFLAGS`: Required compiler flags. # - `BROTLI_VERSION`: Version of brotli. +# - `CURL::brotli`: brotli library target. -set(BROTLI_PC_REQUIRES "libbrotlidec" "libbrotlicommon") # order is significant: brotlidec then brotlicommon +set(_brotli_pc_requires "libbrotlidec" "libbrotlicommon") # order is significant: brotlidec then brotlicommon if(CURL_USE_PKGCONFIG AND NOT DEFINED BROTLI_INCLUDE_DIR AND NOT DEFINED BROTLICOMMON_LIBRARY AND NOT DEFINED BROTLIDEC_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(BROTLI ${BROTLI_PC_REQUIRES}) + pkg_check_modules(_brotli ${_brotli_pc_requires}) endif() -if(BROTLI_FOUND) +if(_brotli_FOUND) set(Brotli_FOUND TRUE) - set(BROTLI_VERSION ${BROTLI_libbrotlicommon_VERSION}) - string(REPLACE ";" " " BROTLI_CFLAGS "${BROTLI_CFLAGS}") - message(STATUS "Found Brotli (via pkg-config): ${BROTLI_INCLUDE_DIRS} (found version \"${BROTLI_VERSION}\")") + set(BROTLI_FOUND TRUE) + set(BROTLI_VERSION ${_brotli_libbrotlicommon_VERSION}) + message(STATUS "Found Brotli (via pkg-config): ${_brotli_INCLUDE_DIRS} (found version \"${BROTLI_VERSION}\")") else() find_path(BROTLI_INCLUDE_DIR "brotli/decode.h") find_library(BROTLICOMMON_LIBRARY NAMES "brotlicommon") @@ -68,9 +64,25 @@ else() ) if(BROTLI_FOUND) - set(BROTLI_INCLUDE_DIRS ${BROTLI_INCLUDE_DIR}) - set(BROTLI_LIBRARIES ${BROTLIDEC_LIBRARY} ${BROTLICOMMON_LIBRARY}) + set(_brotli_INCLUDE_DIRS ${BROTLI_INCLUDE_DIR}) + set(_brotli_LIBRARIES ${BROTLIDEC_LIBRARY} ${BROTLICOMMON_LIBRARY}) endif() mark_as_advanced(BROTLI_INCLUDE_DIR BROTLIDEC_LIBRARY BROTLICOMMON_LIBRARY) endif() + +if(BROTLI_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_brotli_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::brotli) + add_library(CURL::brotli INTERFACE IMPORTED) + set_target_properties(CURL::brotli PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_brotli_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_brotli_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_brotli_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_brotli_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_brotli_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindCares.cmake b/CMake/FindCares.cmake index ae2db52d85aa..4a20bc0af471 100644 --- a/CMake/FindCares.cmake +++ b/CMake/FindCares.cmake @@ -25,32 +25,29 @@ # # Input variables: # -# - `CARES_INCLUDE_DIR`: Absolute path to c-ares include directory. -# - `CARES_LIBRARY`: Absolute path to `cares` library. +# - `CARES_INCLUDE_DIR`: Absolute path to c-ares include directory. +# - `CARES_LIBRARY`: Absolute path to `cares` library. # -# Result variables: +# Defines: # -# - `CARES_FOUND`: System has c-ares. -# - `CARES_INCLUDE_DIRS`: The c-ares include directories. -# - `CARES_LIBRARIES`: The c-ares library names. -# - `CARES_LIBRARY_DIRS`: The c-ares library directories. -# - `CARES_PC_REQUIRES`: The c-ares pkg-config packages. -# - `CARES_CFLAGS`: Required compiler flags. -# - `CARES_VERSION`: Version of c-ares. +# - `CARES_FOUND`: System has c-ares. +# - `CARES_VERSION`: Version of c-ares. +# - `CURL::cares`: c-ares library target. -set(CARES_PC_REQUIRES "libcares") +set(_cares_pc_requires "libcares") if(CURL_USE_PKGCONFIG AND NOT DEFINED CARES_INCLUDE_DIR AND NOT DEFINED CARES_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(CARES ${CARES_PC_REQUIRES}) + pkg_check_modules(_cares ${_cares_pc_requires}) endif() -if(CARES_FOUND) +if(_cares_FOUND) set(Cares_FOUND TRUE) - string(REPLACE ";" " " CARES_CFLAGS "${CARES_CFLAGS}") - message(STATUS "Found Cares (via pkg-config): ${CARES_INCLUDE_DIRS} (found version \"${CARES_VERSION}\")") + set(CARES_FOUND TRUE) + set(CARES_VERSION ${_cares_VERSION}) + message(STATUS "Found Cares (via pkg-config): ${_cares_INCLUDE_DIRS} (found version \"${CARES_VERSION}\")") else() find_path(CARES_INCLUDE_DIR NAMES "ares.h") find_library(CARES_LIBRARY NAMES ${CARES_NAMES} "cares") @@ -85,13 +82,29 @@ else() ) if(CARES_FOUND) - set(CARES_INCLUDE_DIRS ${CARES_INCLUDE_DIR}) - set(CARES_LIBRARIES ${CARES_LIBRARY}) + set(_cares_INCLUDE_DIRS ${CARES_INCLUDE_DIR}) + set(_cares_LIBRARIES ${CARES_LIBRARY}) endif() mark_as_advanced(CARES_INCLUDE_DIR CARES_LIBRARY) endif() -if(CARES_FOUND AND WIN32) - list(APPEND CARES_LIBRARIES "iphlpapi") # for if_indextoname and others +if(CARES_FOUND) + if(WIN32) + list(APPEND _cares_LIBRARIES "iphlpapi") # for if_indextoname and others + endif() + + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_cares_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::cares) + add_library(CURL::cares INTERFACE IMPORTED) + set_target_properties(CURL::cares PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_cares_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_cares_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_cares_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_cares_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_cares_LIBRARIES}") + endif() endif() diff --git a/CMake/FindGSS.cmake b/CMake/FindGSS.cmake index 89545aa74134..106c4c4edd71 100644 --- a/CMake/FindGSS.cmake +++ b/CMake/FindGSS.cmake @@ -25,19 +25,15 @@ # # Input variables: # -# - `GSS_ROOT_DIR`: Absolute path to the root installation of GSS. (also supported as environment) +# - `GSS_ROOT_DIR`: Absolute path to the root installation of GSS. (also supported as environment) # -# Result variables: +# Defines: # -# - `GSS_FOUND`: System has a GSS library. -# - `GSS_FLAVOUR`: "GNU" or "MIT" if anything found. -# - `GSS_INCLUDE_DIRS`: The GSS include directories. -# - `GSS_LIBRARIES`: The GSS library names. -# - `GSS_LIBRARY_DIRS`: The GSS library directories. -# - `GSS_PC_REQUIRES`: The GSS pkg-config packages. -# - `GSS_CFLAGS`: Required compiler flags. -# - `GSS_VERSION`: This is set to version advertised by pkg-config or read from manifest. -# In case the library is found but no version info available it is set to "unknown" +# - `GSS_FOUND`: System has a GSS library. +# - `GSS_VERSION`: This is set to version advertised by pkg-config or read from manifest. +# In case the library is found but no version info available it is set to "unknown" +# - `CURL::gss`: GSS library target. +# - CURL_GSS_FLAVOUR`: Custom property. "GNU" or "MIT" if detected. set(_gnu_modname "gss") set(_mit_modname "mit-krb5-gssapi") @@ -140,7 +136,7 @@ if(NOT _gss_FOUND) # Not found by pkg-config. Let us take more traditional appr # Older versions may not have the "--vendor" parameter. In this case we just do not care. if(NOT _gss_configure_failed AND NOT _gss_vendor MATCHES "Heimdal|heimdal") - set(GSS_FLAVOUR "MIT") # assume a default, should not really matter + set(_gss_flavour "MIT") # assume a default, should not really matter endif() else() # Either there is no config script or we are on a platform that does not provide one (Windows?) @@ -156,7 +152,7 @@ if(NOT _gss_FOUND) # Not found by pkg-config. Let us take more traditional appr cmake_pop_check_state() if(_gss_have_mit_headers) - set(GSS_FLAVOUR "MIT") + set(_gss_flavour "MIT") if(WIN32) if(CMAKE_SIZEOF_VOID_P EQUAL 8) list(APPEND _gss_libdir_suffixes "lib/AMD64") @@ -174,14 +170,14 @@ if(NOT _gss_FOUND) # Not found by pkg-config. Let us take more traditional appr find_path(_gss_INCLUDE_DIRS NAMES "gss.h" HINTS ${_gss_root_hints} PATH_SUFFIXES "include") if(_gss_INCLUDE_DIRS) - set(GSS_FLAVOUR "GNU") - set(GSS_PC_REQUIRES ${_gnu_modname}) + set(_gss_flavour "GNU") + set(_gss_pc_requires ${_gnu_modname}) set(_gss_libname "gss") endif() endif() # If we have headers, look up libraries - if(GSS_FLAVOUR) + if(_gss_flavour) set(_gss_libdir_hints ${_gss_root_hints}) if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20) cmake_path(GET _gss_INCLUDE_DIRS PARENT_PATH _gss_calculated_potential_root) @@ -193,34 +189,28 @@ if(NOT _gss_FOUND) # Not found by pkg-config. Let us take more traditional appr find_library(_gss_LIBRARIES NAMES ${_gss_libname} HINTS ${_gss_libdir_hints} PATH_SUFFIXES ${_gss_libdir_suffixes}) endif() endif() - if(NOT GSS_FLAVOUR) + if(NOT _gss_flavour) message(FATAL_ERROR "GNU or MIT GSS is required") endif() else() # _gss_MODULE_NAME set since CMake 3.16. # _pkg_check_modules_pkg_name is undocumented and used as a fallback for CMake <3.16 versions. if(_gss_MODULE_NAME STREQUAL _gnu_modname OR _pkg_check_modules_pkg_name STREQUAL _gnu_modname) - set(GSS_FLAVOUR "GNU") - set(GSS_PC_REQUIRES ${_gnu_modname}) + set(_gss_flavour "GNU") + set(_gss_pc_requires ${_gnu_modname}) elseif(_gss_MODULE_NAME STREQUAL _mit_modname OR _pkg_check_modules_pkg_name STREQUAL _mit_modname) - set(GSS_FLAVOUR "MIT") - set(GSS_PC_REQUIRES ${_mit_modname}) + set(_gss_flavour "MIT") + set(_gss_pc_requires ${_mit_modname}) else() message(FATAL_ERROR "GNU or MIT GSS is required") endif() - message(STATUS "Found GSS/${GSS_FLAVOUR} (via pkg-config): ${_gss_INCLUDE_DIRS} (found version \"${_gss_version}\")") + message(STATUS "Found GSS/${_gss_flavour} (via pkg-config): ${_gss_INCLUDE_DIRS} (found version \"${_gss_version}\")") endif() -string(REPLACE ";" " " _gss_CFLAGS "${_gss_CFLAGS}") - -set(GSS_INCLUDE_DIRS ${_gss_INCLUDE_DIRS}) -set(GSS_LIBRARIES ${_gss_LIBRARIES}) -set(GSS_LIBRARY_DIRS ${_gss_LIBRARY_DIRS}) -set(GSS_CFLAGS ${_gss_CFLAGS}) set(GSS_VERSION ${_gss_version}) if(NOT GSS_VERSION) - if(GSS_FLAVOUR STREQUAL "MIT") + if(_gss_flavour STREQUAL "MIT") if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) cmake_host_system_information(RESULT _mit_version QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/MIT/Kerberos/SDK/CurrentVersion" VALUE "VersionString") @@ -234,9 +224,9 @@ if(NOT GSS_VERSION) set(GSS_VERSION "MIT Unknown") endif() else() # GNU - if(GSS_INCLUDE_DIRS AND EXISTS "${GSS_INCLUDE_DIRS}/gss.h") + if(_gss_INCLUDE_DIRS AND EXISTS "${_gss_INCLUDE_DIRS}/gss.h") set(_version_regex "#[\t ]*define[\t ]+GSS_VERSION[\t ]+\"([^\"]*)\"") - file(STRINGS "${GSS_INCLUDE_DIRS}/gss.h" _version_str REGEX "${_version_regex}") + file(STRINGS "${_gss_INCLUDE_DIRS}/gss.h" _version_str REGEX "${_version_regex}") string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}") set(GSS_VERSION "${_version_str}") unset(_version_regex) @@ -248,8 +238,8 @@ endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GSS REQUIRED_VARS - GSS_FLAVOUR - GSS_LIBRARIES + _gss_flavour + _gss_LIBRARIES VERSION_VAR GSS_VERSION FAIL_MESSAGE @@ -266,3 +256,20 @@ mark_as_advanced( _gss_PREFIX _gss_version ) + +if(GSS_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_gss_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::gss) + add_library(CURL::gss INTERFACE IMPORTED) + set_target_properties(CURL::gss PROPERTIES + INTERFACE_CURL_GSS_FLAVOUR "${_gss_flavour}" + INTERFACE_LIBCURL_PC_MODULES "${_gss_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_gss_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_gss_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_gss_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_gss_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindGnuTLS.cmake b/CMake/FindGnuTLS.cmake index 4de4f82eee38..fff57b2c293a 100644 --- a/CMake/FindGnuTLS.cmake +++ b/CMake/FindGnuTLS.cmake @@ -25,32 +25,29 @@ # # Input variables: # -# - `GNUTLS_INCLUDE_DIR`: Absolute path to GnuTLS include directory. -# - `GNUTLS_LIBRARY`: Absolute path to `gnutls` library. +# - `GNUTLS_INCLUDE_DIR`: Absolute path to GnuTLS include directory. +# - `GNUTLS_LIBRARY`: Absolute path to `gnutls` library. # -# Result variables: +# Defines: # -# - `GNUTLS_FOUND`: System has GnuTLS. -# - `GNUTLS_INCLUDE_DIRS`: The GnuTLS include directories. -# - `GNUTLS_LIBRARIES`: The GnuTLS library names. -# - `GNUTLS_LIBRARY_DIRS`: The GnuTLS library directories. -# - `GNUTLS_PC_REQUIRES`: The GnuTLS pkg-config packages. -# - `GNUTLS_CFLAGS`: Required compiler flags. -# - `GNUTLS_VERSION`: Version of GnuTLS. +# - `GNUTLS_FOUND`: System has GnuTLS. +# - `GNUTLS_VERSION`: Version of GnuTLS. +# - `CURL::gnutls`: GnuTLS library target. -set(GNUTLS_PC_REQUIRES "gnutls") +set(_gnutls_pc_requires "gnutls") if(CURL_USE_PKGCONFIG AND NOT DEFINED GNUTLS_INCLUDE_DIR AND NOT DEFINED GNUTLS_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(GNUTLS ${GNUTLS_PC_REQUIRES}) + pkg_check_modules(_gnutls ${_gnutls_pc_requires}) endif() -if(GNUTLS_FOUND) +if(_gnutls_FOUND) set(GnuTLS_FOUND TRUE) - string(REPLACE ";" " " GNUTLS_CFLAGS "${GNUTLS_CFLAGS}") - message(STATUS "Found GnuTLS (via pkg-config): ${GNUTLS_INCLUDE_DIRS} (found version \"${GNUTLS_VERSION}\")") + set(GNUTLS_FOUND TRUE) + set(GNUTLS_VERSION ${_gnutls_VERSION}) + message(STATUS "Found GnuTLS (via pkg-config): ${_gnutls_INCLUDE_DIRS} (found version \"${GNUTLS_VERSION}\")") else() find_path(GNUTLS_INCLUDE_DIR NAMES "gnutls/gnutls.h") find_library(GNUTLS_LIBRARY NAMES "gnutls" "libgnutls") @@ -75,9 +72,25 @@ else() ) if(GNUTLS_FOUND) - set(GNUTLS_INCLUDE_DIRS ${GNUTLS_INCLUDE_DIR}) - set(GNUTLS_LIBRARIES ${GNUTLS_LIBRARY}) + set(_gnutls_INCLUDE_DIRS ${GNUTLS_INCLUDE_DIR}) + set(_gnutls_LIBRARIES ${GNUTLS_LIBRARY}) endif() mark_as_advanced(GNUTLS_INCLUDE_DIR GNUTLS_LIBRARY) endif() + +if(GNUTLS_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_gnutls_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::gnutls) + add_library(CURL::gnutls INTERFACE IMPORTED) + set_target_properties(CURL::gnutls PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_gnutls_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_gnutls_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_gnutls_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_gnutls_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_gnutls_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindLDAP.cmake b/CMake/FindLDAP.cmake index 0a897aa13f88..2f5cc713c72d 100644 --- a/CMake/FindLDAP.cmake +++ b/CMake/FindLDAP.cmake @@ -29,32 +29,28 @@ # - `LDAP_LIBRARY`: Absolute path to `ldap` library. # - `LDAP_LBER_LIBRARY`: Absolute path to `lber` library. # -# Result variables: +# Defines: # # - `LDAP_FOUND`: System has ldap. -# - `LDAP_INCLUDE_DIRS`: The ldap include directories. -# - `LDAP_LIBRARIES`: The ldap library names. -# - `LDAP_LIBRARY_DIRS`: The ldap library directories. -# - `LDAP_PC_REQUIRES`: The ldap pkg-config packages. -# - `LDAP_CFLAGS`: Required compiler flags. # - `LDAP_VERSION`: Version of ldap. +# - `CURL::ldap`: ldap library target. -set(LDAP_PC_REQUIRES "ldap" "lber") +set(_ldap_pc_requires "ldap" "lber") if(CURL_USE_PKGCONFIG AND NOT DEFINED LDAP_INCLUDE_DIR AND NOT DEFINED LDAP_LIBRARY AND NOT DEFINED LDAP_LBER_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(LDAP ${LDAP_PC_REQUIRES}) + pkg_check_modules(_ldap ${_ldap_pc_requires}) endif() -if(LDAP_FOUND) - set(LDAP_VERSION ${LDAP_ldap_VERSION}) - string(REPLACE ";" " " LDAP_CFLAGS "${LDAP_CFLAGS}") - message(STATUS "Found LDAP (via pkg-config): ${LDAP_INCLUDE_DIRS} (found version \"${LDAP_VERSION}\")") +if(_ldap_FOUND) + set(LDAP_FOUND TRUE) + set(LDAP_VERSION ${_ldap_ldap_VERSION}) + message(STATUS "Found LDAP (via pkg-config): ${_ldap_INCLUDE_DIRS} (found version \"${LDAP_VERSION}\")") else() - set(LDAP_PC_REQUIRES "") # Depend on pkg-config only when found via pkg-config + set(_ldap_pc_requires "") # Depend on pkg-config only when found via pkg-config # On Apple the SDK LDAP gets picked up from # 'MacOSX.sdk/System/Library/Frameworks/LDAP.framework/Headers', which contains @@ -99,9 +95,25 @@ else() ) if(LDAP_FOUND) - set(LDAP_INCLUDE_DIRS ${LDAP_INCLUDE_DIR}) - set(LDAP_LIBRARIES ${LDAP_LIBRARY} ${LDAP_LBER_LIBRARY}) + set(_ldap_INCLUDE_DIRS ${LDAP_INCLUDE_DIR}) + set(_ldap_LIBRARIES ${LDAP_LIBRARY} ${LDAP_LBER_LIBRARY}) endif() mark_as_advanced(LDAP_INCLUDE_DIR LDAP_LIBRARY LDAP_LBER_LIBRARY) endif() + +if(LDAP_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_ldap_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::ldap) + add_library(CURL::ldap INTERFACE IMPORTED) + set_target_properties(CURL::ldap PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_ldap_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_ldap_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_ldap_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_ldap_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_ldap_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindLibbacktrace.cmake b/CMake/FindLibbacktrace.cmake index 444c5f90fdcf..c6f7b700c43c 100644 --- a/CMake/FindLibbacktrace.cmake +++ b/CMake/FindLibbacktrace.cmake @@ -25,14 +25,13 @@ # # Input variables: # -# - `LIBBACKTRACE_INCLUDE_DIR`: Absolute path to libbacktrace include directory. -# - `LIBBACKTRACE_LIBRARY`: Absolute path to `libbacktrace` library. +# - `LIBBACKTRACE_INCLUDE_DIR`: Absolute path to libbacktrace include directory. +# - `LIBBACKTRACE_LIBRARY`: Absolute path to `libbacktrace` library. # -# Result variables: +# Defines: # -# - `LIBBACKTRACE_FOUND`: System has libbacktrace. -# - `LIBBACKTRACE_INCLUDE_DIRS`: The libbacktrace include directories. -# - `LIBBACKTRACE_LIBRARIES`: The libbacktrace library names. +# - `LIBBACKTRACE_FOUND`: System has libbacktrace. +# - `CURL::libbacktrace`: libbacktrace library target. find_path(LIBBACKTRACE_INCLUDE_DIR NAMES "backtrace.h") find_library(LIBBACKTRACE_LIBRARY NAMES "backtrace" "libbacktrace") @@ -45,8 +44,22 @@ find_package_handle_standard_args(Libbacktrace ) if(LIBBACKTRACE_FOUND) - set(LIBBACKTRACE_INCLUDE_DIRS ${LIBBACKTRACE_INCLUDE_DIR}) - set(LIBBACKTRACE_LIBRARIES ${LIBBACKTRACE_LIBRARY}) + set(_libbacktrace_INCLUDE_DIRS ${LIBBACKTRACE_INCLUDE_DIR}) + set(_libbacktrace_LIBRARIES ${LIBBACKTRACE_LIBRARY}) + + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_libbacktrace_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::libbacktrace) + add_library(CURL::libbacktrace INTERFACE IMPORTED) + set_target_properties(CURL::libbacktrace PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_libbacktrace_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_libbacktrace_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_libbacktrace_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_libbacktrace_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_libbacktrace_LIBRARIES}") + endif() endif() mark_as_advanced(LIBBACKTRACE_INCLUDE_DIR LIBBACKTRACE_LIBRARY) diff --git a/CMake/FindLibgsasl.cmake b/CMake/FindLibgsasl.cmake index e584f75371c0..5ddf957d72d8 100644 --- a/CMake/FindLibgsasl.cmake +++ b/CMake/FindLibgsasl.cmake @@ -25,32 +25,28 @@ # # Input variables: # -# - `LIBGSASL_INCLUDE_DIR`: Absolute path to libgsasl include directory. -# - `LIBGSASL_LIBRARY`: Absolute path to `libgsasl` library. +# - `LIBGSASL_INCLUDE_DIR`: Absolute path to libgsasl include directory. +# - `LIBGSASL_LIBRARY`: Absolute path to `libgsasl` library. # -# Result variables: +# Defines: # -# - `LIBGSASL_FOUND`: System has libgsasl. -# - `LIBGSASL_INCLUDE_DIRS`: The libgsasl include directories. -# - `LIBGSASL_LIBRARIES`: The libgsasl library names. -# - `LIBGSASL_LIBRARY_DIRS`: The libgsasl library directories. -# - `LIBGSASL_PC_REQUIRES`: The libgsasl pkg-config packages. -# - `LIBGSASL_CFLAGS`: Required compiler flags. -# - `LIBGSASL_VERSION`: Version of libgsasl. +# - `LIBGSASL_FOUND`: System has libgsasl. +# - `LIBGSASL_VERSION`: Version of libgsasl. +# - `CURL::libgsasl`: libgsasl library target. -set(LIBGSASL_PC_REQUIRES "libgsasl") +set(_libgsasl_pc_requires "libgsasl") if(CURL_USE_PKGCONFIG AND NOT DEFINED LIBGSASL_INCLUDE_DIR AND NOT DEFINED LIBGSASL_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(LIBGSASL ${LIBGSASL_PC_REQUIRES}) + pkg_check_modules(_libgsasl ${_libgsasl_pc_requires}) endif() -if(LIBGSASL_FOUND) +if(_libgsasl_FOUND) set(Libgsasl_FOUND TRUE) - string(REPLACE ";" " " LIBGSASL_CFLAGS "${LIBGSASL_CFLAGS}") - message(STATUS "Found Libgsasl (via pkg-config): ${LIBGSASL_INCLUDE_DIRS} (found version \"${LIBGSASL_VERSION}\")") + set(LIBGSASL_FOUND TRUE) + message(STATUS "Found Libgsasl (via pkg-config): ${_libgsasl_INCLUDE_DIRS} (found version \"${LIBGSASL_VERSION}\")") else() find_path(LIBGSASL_INCLUDE_DIR NAMES "gsasl.h") find_library(LIBGSASL_LIBRARY NAMES "gsasl" "libgsasl") @@ -75,9 +71,25 @@ else() ) if(LIBGSASL_FOUND) - set(LIBGSASL_INCLUDE_DIRS ${LIBGSASL_INCLUDE_DIR}) - set(LIBGSASL_LIBRARIES ${LIBGSASL_LIBRARY}) + set(_libgsasl_INCLUDE_DIRS ${LIBGSASL_INCLUDE_DIR}) + set(_libgsasl_LIBRARIES ${LIBGSASL_LIBRARY}) endif() mark_as_advanced(LIBGSASL_INCLUDE_DIR LIBGSASL_LIBRARY) endif() + +if(LIBGSASL_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_libgsasl_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::libgsasl) + add_library(CURL::libgsasl INTERFACE IMPORTED) + set_target_properties(CURL::libgsasl PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_libgsasl_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_libgsasl_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_libgsasl_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_libgsasl_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_libgsasl_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindLibidn2.cmake b/CMake/FindLibidn2.cmake index 9112428f37dc..336a7f7b404e 100644 --- a/CMake/FindLibidn2.cmake +++ b/CMake/FindLibidn2.cmake @@ -25,32 +25,29 @@ # # Input variables: # -# - `LIBIDN2_INCLUDE_DIR`: Absolute path to libidn2 include directory. -# - `LIBIDN2_LIBRARY`: Absolute path to `libidn2` library. +# - `LIBIDN2_INCLUDE_DIR`: Absolute path to libidn2 include directory. +# - `LIBIDN2_LIBRARY`: Absolute path to `libidn2` library. # -# Result variables: +# Defines: # -# - `LIBIDN2_FOUND`: System has libidn2. -# - `LIBIDN2_INCLUDE_DIRS`: The libidn2 include directories. -# - `LIBIDN2_LIBRARIES`: The libidn2 library names. -# - `LIBIDN2_LIBRARY_DIRS`: The libidn2 library directories. -# - `LIBIDN2_PC_REQUIRES`: The libidn2 pkg-config packages. -# - `LIBIDN2_CFLAGS`: Required compiler flags. -# - `LIBIDN2_VERSION`: Version of libidn2. +# - `LIBIDN2_FOUND`: System has libidn2. +# - `LIBIDN2_VERSION`: Version of libidn2. +# - `CURL::libidn2`: libidn2 library target. -set(LIBIDN2_PC_REQUIRES "libidn2") +set(_libidn2_pc_requires "libidn2") if(CURL_USE_PKGCONFIG AND NOT DEFINED LIBIDN2_INCLUDE_DIR AND NOT DEFINED LIBIDN2_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(LIBIDN2 ${LIBIDN2_PC_REQUIRES}) + pkg_check_modules(_libidn2 ${_libidn2_pc_requires}) endif() -if(LIBIDN2_FOUND) +if(_libidn2_FOUND) set(Libidn2_FOUND TRUE) - string(REPLACE ";" " " LIBIDN2_CFLAGS "${LIBIDN2_CFLAGS}") - message(STATUS "Found Libidn2 (via pkg-config): ${LIBIDN2_INCLUDE_DIRS} (found version \"${LIBIDN2_VERSION}\")") + set(LIBIDN2_FOUND TRUE) + set(LIBIDN2_VERSION ${_libidn2_VERSION}) + message(STATUS "Found Libidn2 (via pkg-config): ${_libidn2_INCLUDE_DIRS} (found version \"${LIBIDN2_VERSION}\")") else() find_path(LIBIDN2_INCLUDE_DIR NAMES "idn2.h") find_library(LIBIDN2_LIBRARY NAMES "idn2" "libidn2") @@ -75,9 +72,25 @@ else() ) if(LIBIDN2_FOUND) - set(LIBIDN2_INCLUDE_DIRS ${LIBIDN2_INCLUDE_DIR}) - set(LIBIDN2_LIBRARIES ${LIBIDN2_LIBRARY}) + set(_libidn2_INCLUDE_DIRS ${LIBIDN2_INCLUDE_DIR}) + set(_libidn2_LIBRARIES ${LIBIDN2_LIBRARY}) endif() mark_as_advanced(LIBIDN2_INCLUDE_DIR LIBIDN2_LIBRARY) endif() + +if(LIBIDN2_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_libidn2_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::libidn2) + add_library(CURL::libidn2 INTERFACE IMPORTED) + set_target_properties(CURL::libidn2 PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_libidn2_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_libidn2_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_libidn2_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_libidn2_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_libidn2_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindLibpsl.cmake b/CMake/FindLibpsl.cmake index 13740fa9b3fa..9b1a0cdd97b4 100644 --- a/CMake/FindLibpsl.cmake +++ b/CMake/FindLibpsl.cmake @@ -25,32 +25,29 @@ # # Input variables: # -# - `LIBPSL_INCLUDE_DIR`: Absolute path to libpsl include directory. -# - `LIBPSL_LIBRARY`: Absolute path to `libpsl` library. +# - `LIBPSL_INCLUDE_DIR`: Absolute path to libpsl include directory. +# - `LIBPSL_LIBRARY`: Absolute path to `libpsl` library. # -# Result variables: +# Defines: # -# - `LIBPSL_FOUND`: System has libpsl. -# - `LIBPSL_INCLUDE_DIRS`: The libpsl include directories. -# - `LIBPSL_LIBRARIES`: The libpsl library names. -# - `LIBPSL_LIBRARY_DIRS`: The libpsl library directories. -# - `LIBPSL_PC_REQUIRES`: The libpsl pkg-config packages. -# - `LIBPSL_CFLAGS`: Required compiler flags. -# - `LIBPSL_VERSION`: Version of libpsl. +# - `LIBPSL_FOUND`: System has libpsl. +# - `LIBPSL_VERSION`: Version of libpsl. +# - `CURL::libpsl`: libpsl library target. -set(LIBPSL_PC_REQUIRES "libpsl") +set(_libpsl_pc_requires "libpsl") if(CURL_USE_PKGCONFIG AND NOT DEFINED LIBPSL_INCLUDE_DIR AND NOT DEFINED LIBPSL_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(LIBPSL ${LIBPSL_PC_REQUIRES}) + pkg_check_modules(_libpsl ${_libpsl_pc_requires}) endif() -if(LIBPSL_FOUND AND LIBPSL_INCLUDE_DIRS) +if(_libpsl_FOUND AND _libpsl_INCLUDE_DIRS) set(Libpsl_FOUND TRUE) - string(REPLACE ";" " " LIBPSL_CFLAGS "${LIBPSL_CFLAGS}") - message(STATUS "Found Libpsl (via pkg-config): ${LIBPSL_INCLUDE_DIRS} (found version \"${LIBPSL_VERSION}\")") + set(LIBPSL_FOUND TRUE) + set(LIBPSL_VERSION ${_libpsl_VERSION}) + message(STATUS "Found Libpsl (via pkg-config): ${_libpsl_INCLUDE_DIRS} (found version \"${LIBPSL_VERSION}\")") else() find_path(LIBPSL_INCLUDE_DIR NAMES "libpsl.h") find_library(LIBPSL_LIBRARY NAMES "psl" "libpsl") @@ -75,9 +72,25 @@ else() ) if(LIBPSL_FOUND) - set(LIBPSL_INCLUDE_DIRS ${LIBPSL_INCLUDE_DIR}) - set(LIBPSL_LIBRARIES ${LIBPSL_LIBRARY}) + set(_libpsl_INCLUDE_DIRS ${LIBPSL_INCLUDE_DIR}) + set(_libpsl_LIBRARIES ${LIBPSL_LIBRARY}) endif() mark_as_advanced(LIBPSL_INCLUDE_DIR LIBPSL_LIBRARY) endif() + +if(LIBPSL_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_libpsl_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::libpsl) + add_library(CURL::libpsl INTERFACE IMPORTED) + set_target_properties(CURL::libpsl PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_libpsl_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_libpsl_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_libpsl_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_libpsl_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_libpsl_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindLibrtmp.cmake b/CMake/FindLibrtmp.cmake index be975794b773..070538578e4a 100644 --- a/CMake/FindLibrtmp.cmake +++ b/CMake/FindLibrtmp.cmake @@ -25,32 +25,29 @@ # # Input variables: # -# - `LIBRTMP_INCLUDE_DIR`: Absolute path to librtmp include directory. -# - `LIBRTMP_LIBRARY`: Absolute path to `librtmp` library. +# - `LIBRTMP_INCLUDE_DIR`: Absolute path to librtmp include directory. +# - `LIBRTMP_LIBRARY`: Absolute path to `librtmp` library. # -# Result variables: +# Defines: # -# - `LIBRTMP_FOUND`: System has librtmp. -# - `LIBRTMP_INCLUDE_DIRS`: The librtmp include directories. -# - `LIBRTMP_LIBRARIES`: The librtmp library names. -# - `LIBRTMP_LIBRARY_DIRS`: The librtmp library directories. -# - `LIBRTMP_PC_REQUIRES`: The librtmp pkg-config packages. -# - `LIBRTMP_CFLAGS`: Required compiler flags. -# - `LIBRTMP_VERSION`: Version of librtmp. +# - `LIBRTMP_FOUND`: System has librtmp. +# - `LIBRTMP_VERSION`: Version of librtmp. +# - `CURL::librtmp`: librtmp library target. -set(LIBRTMP_PC_REQUIRES "librtmp") +set(_librtmp_pc_requires "librtmp") if(CURL_USE_PKGCONFIG AND NOT DEFINED LIBRTMP_INCLUDE_DIR AND NOT DEFINED LIBRTMP_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(LIBRTMP ${LIBRTMP_PC_REQUIRES}) + pkg_check_modules(_librtmp ${_librtmp_pc_requires}) endif() -if(LIBRTMP_FOUND AND LIBRTMP_INCLUDE_DIRS) +if(_librtmp_FOUND AND _librtmp_INCLUDE_DIRS) set(Librtmp_FOUND TRUE) - string(REPLACE ";" " " LIBRTMP_CFLAGS "${LIBRTMP_CFLAGS}") - message(STATUS "Found Librtmp (via pkg-config): ${LIBRTMP_INCLUDE_DIRS} (found version \"${LIBRTMP_VERSION}\")") + set(LIBRTMP_FOUND TRUE) + set(LIBRTMP_VERSION ${_librtmp_VERSION}) + message(STATUS "Found Librtmp (via pkg-config): ${_librtmp_INCLUDE_DIRS} (found version \"${LIBRTMP_VERSION}\")") else() find_path(LIBRTMP_INCLUDE_DIR NAMES "librtmp/rtmp.h") find_library(LIBRTMP_LIBRARY NAMES "rtmp") @@ -85,8 +82,8 @@ else() ) if(LIBRTMP_FOUND) - set(LIBRTMP_INCLUDE_DIRS ${LIBRTMP_INCLUDE_DIR}) - set(LIBRTMP_LIBRARIES ${LIBRTMP_LIBRARY}) + set(_librtmp_INCLUDE_DIRS ${LIBRTMP_INCLUDE_DIR}) + set(_librtmp_LIBRARIES ${LIBRTMP_LIBRARY}) endif() mark_as_advanced(LIBRTMP_INCLUDE_DIR LIBRTMP_LIBRARY) @@ -94,10 +91,26 @@ else() # Necessary when linking a static librtmp find_package(OpenSSL) if(OPENSSL_FOUND) - list(APPEND LIBRTMP_LIBRARIES OpenSSL::SSL OpenSSL::Crypto) + list(APPEND _librtmp_LIBRARIES OpenSSL::SSL OpenSSL::Crypto) endif() endif() -if(LIBRTMP_FOUND AND WIN32) - list(APPEND LIBRTMP_LIBRARIES "winmm") +if(LIBRTMP_FOUND) + if(WIN32) + list(APPEND _librtmp_LIBRARIES "winmm") + endif() + + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_librtmp_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::librtmp) + add_library(CURL::librtmp INTERFACE IMPORTED) + set_target_properties(CURL::librtmp PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_librtmp_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_librtmp_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_librtmp_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_librtmp_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_librtmp_LIBRARIES}") + endif() endif() diff --git a/CMake/FindLibssh.cmake b/CMake/FindLibssh.cmake index cb895aa8d74b..ad1248fe00af 100644 --- a/CMake/FindLibssh.cmake +++ b/CMake/FindLibssh.cmake @@ -25,32 +25,29 @@ # # Input variables: # -# - `LIBSSH_INCLUDE_DIR`: Absolute path to libssh include directory. -# - `LIBSSH_LIBRARY`: Absolute path to `libssh` library. +# - `LIBSSH_INCLUDE_DIR`: Absolute path to libssh include directory. +# - `LIBSSH_LIBRARY`: Absolute path to `libssh` library. # -# Result variables: +# Defines: # -# - `LIBSSH_FOUND`: System has libssh. -# - `LIBSSH_INCLUDE_DIRS`: The libssh include directories. -# - `LIBSSH_LIBRARIES`: The libssh library names. -# - `LIBSSH_LIBRARY_DIRS`: The libssh library directories. -# - `LIBSSH_PC_REQUIRES`: The libssh pkg-config packages. -# - `LIBSSH_CFLAGS`: Required compiler flags. -# - `LIBSSH_VERSION`: Version of libssh. +# - `LIBSSH_FOUND`: System has libssh. +# - `LIBSSH_VERSION`: Version of libssh. +# - `CURL::libssh`: libssh library target. -set(LIBSSH_PC_REQUIRES "libssh") +set(_libssh_pc_requires "libssh") if(CURL_USE_PKGCONFIG AND NOT DEFINED LIBSSH_INCLUDE_DIR AND NOT DEFINED LIBSSH_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(LIBSSH ${LIBSSH_PC_REQUIRES}) + pkg_check_modules(_libssh ${_libssh_pc_requires}) endif() -if(LIBSSH_FOUND) +if(_libssh_FOUND) set(Libssh_FOUND TRUE) - string(REPLACE ";" " " LIBSSH_CFLAGS "${LIBSSH_CFLAGS}") - message(STATUS "Found Libssh (via pkg-config): ${LIBSSH_INCLUDE_DIRS} (found version \"${LIBSSH_VERSION}\")") + set(LIBSSH_FOUND TRUE) + set(LIBSSH_VERSION ${_libssh_VERSION}) + message(STATUS "Found Libssh (via pkg-config): ${_libssh_INCLUDE_DIRS} (found version \"${LIBSSH_VERSION}\")") else() find_path(LIBSSH_INCLUDE_DIR NAMES "libssh/libssh.h") find_library(LIBSSH_LIBRARY NAMES "ssh" "libssh") @@ -85,13 +82,29 @@ else() ) if(LIBSSH_FOUND) - set(LIBSSH_INCLUDE_DIRS ${LIBSSH_INCLUDE_DIR}) - set(LIBSSH_LIBRARIES ${LIBSSH_LIBRARY}) + set(_libssh_INCLUDE_DIRS ${LIBSSH_INCLUDE_DIR}) + set(_libssh_LIBRARIES ${LIBSSH_LIBRARY}) endif() mark_as_advanced(LIBSSH_INCLUDE_DIR LIBSSH_LIBRARY) endif() -if(LIBSSH_FOUND AND WIN32) - list(APPEND LIBSSH_LIBRARIES "iphlpapi") # for if_nametoindex +if(LIBSSH_FOUND) + if(WIN32) + list(APPEND _libssh_LIBRARIES "iphlpapi") # for if_nametoindex + endif() + + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_libssh_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::libssh) + add_library(CURL::libssh INTERFACE IMPORTED) + set_target_properties(CURL::libssh PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_libssh_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_libssh_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_libssh_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_libssh_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_libssh_LIBRARIES}") + endif() endif() diff --git a/CMake/FindLibssh2.cmake b/CMake/FindLibssh2.cmake index 08415533e0db..330611bfe55c 100644 --- a/CMake/FindLibssh2.cmake +++ b/CMake/FindLibssh2.cmake @@ -25,32 +25,29 @@ # # Input variables: # -# - `LIBSSH2_INCLUDE_DIR`: Absolute path to libssh2 include directory. -# - `LIBSSH2_LIBRARY`: Absolute path to `libssh2` library. +# - `LIBSSH2_INCLUDE_DIR`: Absolute path to libssh2 include directory. +# - `LIBSSH2_LIBRARY`: Absolute path to `libssh2` library. # -# Result variables: +# Defines: # -# - `LIBSSH2_FOUND`: System has libssh2. -# - `LIBSSH2_INCLUDE_DIRS`: The libssh2 include directories. -# - `LIBSSH2_LIBRARIES`: The libssh2 library names. -# - `LIBSSH2_LIBRARY_DIRS`: The libssh2 library directories. -# - `LIBSSH2_PC_REQUIRES`: The libssh2 pkg-config packages. -# - `LIBSSH2_CFLAGS`: Required compiler flags. -# - `LIBSSH2_VERSION`: Version of libssh2. +# - `LIBSSH2_FOUND`: System has libssh2. +# - `LIBSSH2_VERSION`: Version of libssh2. +# - `CURL::libssh2`: libssh2 library target. -set(LIBSSH2_PC_REQUIRES "libssh2") +set(_libssh2_pc_requires "libssh2") if(CURL_USE_PKGCONFIG AND NOT DEFINED LIBSSH2_INCLUDE_DIR AND NOT DEFINED LIBSSH2_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(LIBSSH2 ${LIBSSH2_PC_REQUIRES}) + pkg_check_modules(_libssh2 ${_libssh2_pc_requires}) endif() -if(LIBSSH2_FOUND AND LIBSSH2_INCLUDE_DIRS) +if(_libssh2_FOUND AND _libssh2_INCLUDE_DIRS) set(Libssh2_FOUND TRUE) - string(REPLACE ";" " " LIBSSH2_CFLAGS "${LIBSSH2_CFLAGS}") - message(STATUS "Found Libssh2 (via pkg-config): ${LIBSSH2_INCLUDE_DIRS} (found version \"${LIBSSH2_VERSION}\")") + set(LIBSSH2_FOUND TRUE) + set(LIBSSH2_VERSION ${_libssh2_VERSION}) + message(STATUS "Found Libssh2 (via pkg-config): ${_libssh2_INCLUDE_DIRS} (found version \"${LIBSSH2_VERSION}\")") else() find_path(LIBSSH2_INCLUDE_DIR NAMES "libssh2.h") find_library(LIBSSH2_LIBRARY NAMES "ssh2" "libssh2") @@ -75,9 +72,25 @@ else() ) if(LIBSSH2_FOUND) - set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR}) - set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY}) + set(_libssh2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR}) + set(_libssh2_LIBRARIES ${LIBSSH2_LIBRARY}) endif() mark_as_advanced(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY) endif() + +if(LIBSSH2_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_libssh2_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::libssh2) + add_library(CURL::libssh2 INTERFACE IMPORTED) + set_target_properties(CURL::libssh2 PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_libssh2_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_libssh2_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_libssh2_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_libssh2_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_libssh2_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindLibuv.cmake b/CMake/FindLibuv.cmake index 2565ba3a386a..f9d614bc067c 100644 --- a/CMake/FindLibuv.cmake +++ b/CMake/FindLibuv.cmake @@ -25,32 +25,29 @@ # # Input variables: # -# - `LIBUV_INCLUDE_DIR`: Absolute path to libuv include directory. -# - `LIBUV_LIBRARY`: Absolute path to `libuv` library. +# - `LIBUV_INCLUDE_DIR`: Absolute path to libuv include directory. +# - `LIBUV_LIBRARY`: Absolute path to `libuv` library. # -# Result variables: +# Defines: # -# - `LIBUV_FOUND`: System has libuv. -# - `LIBUV_INCLUDE_DIRS`: The libuv include directories. -# - `LIBUV_LIBRARIES`: The libuv library names. -# - `LIBUV_LIBRARY_DIRS`: The libuv library directories. -# - `LIBUV_PC_REQUIRES`: The libuv pkg-config packages. -# - `LIBUV_CFLAGS`: Required compiler flags. -# - `LIBUV_VERSION`: Version of libuv. +# - `LIBUV_FOUND`: System has libuv. +# - `LIBUV_VERSION`: Version of libuv. +# - `CURL::libuv`: libuv library target. -set(LIBUV_PC_REQUIRES "libuv") +set(_libuv_pc_requires "libuv") if(CURL_USE_PKGCONFIG AND NOT DEFINED LIBUV_INCLUDE_DIR AND NOT DEFINED LIBUV_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(LIBUV ${LIBUV_PC_REQUIRES}) + pkg_check_modules(_libuv ${_libuv_pc_requires}) endif() -if(LIBUV_FOUND) +if(_libuv_FOUND) set(Libuv_FOUND TRUE) - string(REPLACE ";" " " LIBUV_CFLAGS "${LIBUV_CFLAGS}") - message(STATUS "Found Libuv (via pkg-config): ${LIBUV_INCLUDE_DIRS} (found version \"${LIBUV_VERSION}\")") + set(LIBUV_FOUND TRUE) + set(LIBUV_VERSION ${_libuv_VERSION}) + message(STATUS "Found Libuv (via pkg-config): ${_libuv_INCLUDE_DIRS} (found version \"${LIBUV_VERSION}\")") else() find_path(LIBUV_INCLUDE_DIR NAMES "uv.h") find_library(LIBUV_LIBRARY NAMES "uv" "libuv") @@ -85,9 +82,25 @@ else() ) if(LIBUV_FOUND) - set(LIBUV_INCLUDE_DIRS ${LIBUV_INCLUDE_DIR}) - set(LIBUV_LIBRARIES ${LIBUV_LIBRARY}) + set(_libuv_INCLUDE_DIRS ${LIBUV_INCLUDE_DIR}) + set(_libuv_LIBRARIES ${LIBUV_LIBRARY}) endif() mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY) endif() + +if(LIBUV_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_libuv_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::libuv) + add_library(CURL::libuv INTERFACE IMPORTED) + set_target_properties(CURL::libuv PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_libuv_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_libuv_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_libuv_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_libuv_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_libuv_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindMbedTLS.cmake b/CMake/FindMbedTLS.cmake index 11b4f076f4dc..97201ab2b343 100644 --- a/CMake/FindMbedTLS.cmake +++ b/CMake/FindMbedTLS.cmake @@ -25,20 +25,16 @@ # # Input variables: # -# - `MBEDTLS_INCLUDE_DIR`: Absolute path to mbedTLS include directory. -# - `MBEDTLS_LIBRARY`: Absolute path to `mbedtls` library. -# - `MBEDX509_LIBRARY`: Absolute path to `mbedx509` library. -# - `MBEDCRYPTO_LIBRARY`: Absolute path to `mbedcrypto` library. +# - `MBEDTLS_INCLUDE_DIR`: Absolute path to mbedTLS include directory. +# - `MBEDTLS_LIBRARY`: Absolute path to `mbedtls` library. +# - `MBEDX509_LIBRARY`: Absolute path to `mbedx509` library. +# - `MBEDCRYPTO_LIBRARY`: Absolute path to `mbedcrypto` library. # -# Result variables: +# Defines: # -# - `MBEDTLS_FOUND`: System has mbedTLS. -# - `MBEDTLS_INCLUDE_DIRS`: The mbedTLS include directories. -# - `MBEDTLS_LIBRARIES`: The mbedTLS library names. -# - `MBEDTLS_LIBRARY_DIRS`: The mbedTLS library directories. -# - `MBEDTLS_PC_REQUIRES`: The mbedTLS pkg-config packages. -# - `MBEDTLS_CFLAGS`: Required compiler flags. -# - `MBEDTLS_VERSION`: Version of mbedTLS. +# - `MBEDTLS_FOUND`: System has mbedTLS. +# - `MBEDTLS_VERSION`: Version of mbedTLS. +# - `CURL::mbedtls`: mbedTLS library target. if(DEFINED MBEDTLS_INCLUDE_DIRS AND NOT DEFINED MBEDTLS_INCLUDE_DIR) message(WARNING "MBEDTLS_INCLUDE_DIRS is deprecated, use MBEDTLS_INCLUDE_DIR instead.") @@ -46,7 +42,7 @@ if(DEFINED MBEDTLS_INCLUDE_DIRS AND NOT DEFINED MBEDTLS_INCLUDE_DIR) unset(MBEDTLS_INCLUDE_DIRS) endif() -set(MBEDTLS_PC_REQUIRES "mbedtls" "mbedx509" "mbedcrypto") +set(_mbedtls_pc_requires "mbedtls" "mbedx509" "mbedcrypto") if(CURL_USE_PKGCONFIG AND NOT DEFINED MBEDTLS_INCLUDE_DIR AND @@ -54,16 +50,16 @@ if(CURL_USE_PKGCONFIG AND NOT DEFINED MBEDX509_LIBRARY AND NOT DEFINED MBEDCRYPTO_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(MBEDTLS ${MBEDTLS_PC_REQUIRES}) + pkg_check_modules(_mbedtls ${_mbedtls_pc_requires}) endif() -if(MBEDTLS_FOUND) +if(_mbedtls_FOUND) set(MbedTLS_FOUND TRUE) - set(MBEDTLS_VERSION ${MBEDTLS_mbedtls_VERSION}) - string(REPLACE ";" " " MBEDTLS_CFLAGS "${MBEDTLS_CFLAGS}") - message(STATUS "Found MbedTLS (via pkg-config): ${MBEDTLS_INCLUDE_DIRS} (found version \"${MBEDTLS_VERSION}\")") + set(MBEDTLS_FOUND TRUE) + set(MBEDTLS_VERSION ${_mbedtls_mbedtls_VERSION}) + message(STATUS "Found MbedTLS (via pkg-config): ${_mbedtls_INCLUDE_DIRS} (found version \"${MBEDTLS_VERSION}\")") else() - set(MBEDTLS_PC_REQUIRES "") # Depend on pkg-config only when found via pkg-config + set(_mbedtls_pc_requires "") # Depend on pkg-config only when found via pkg-config find_path(MBEDTLS_INCLUDE_DIR NAMES "mbedtls/ssl.h") find_library(MBEDTLS_LIBRARY NAMES "mbedtls" "libmbedtls") @@ -92,9 +88,25 @@ else() ) if(MBEDTLS_FOUND) - set(MBEDTLS_INCLUDE_DIRS ${MBEDTLS_INCLUDE_DIR}) - set(MBEDTLS_LIBRARIES ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY}) + set(_mbedtls_INCLUDE_DIRS ${MBEDTLS_INCLUDE_DIR}) + set(_mbedtls_LIBRARIES ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY}) endif() mark_as_advanced(MBEDTLS_INCLUDE_DIR MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) endif() + +if(MBEDTLS_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_mbedtls_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::mbedtls) + add_library(CURL::mbedtls INTERFACE IMPORTED) + set_target_properties(CURL::mbedtls PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_mbedtls_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_mbedtls_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_mbedtls_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_mbedtls_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_mbedtls_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindNGHTTP2.cmake b/CMake/FindNGHTTP2.cmake index 1ccf64158915..8304345a384b 100644 --- a/CMake/FindNGHTTP2.cmake +++ b/CMake/FindNGHTTP2.cmake @@ -25,31 +25,28 @@ # # Input variables: # -# - `NGHTTP2_INCLUDE_DIR`: Absolute path to nghttp2 include directory. -# - `NGHTTP2_LIBRARY`: Absolute path to `nghttp2` library. +# - `NGHTTP2_INCLUDE_DIR`: Absolute path to nghttp2 include directory. +# - `NGHTTP2_LIBRARY`: Absolute path to `nghttp2` library. # -# Result variables: +# Defines: # -# - `NGHTTP2_FOUND`: System has nghttp2. -# - `NGHTTP2_INCLUDE_DIRS`: The nghttp2 include directories. -# - `NGHTTP2_LIBRARIES`: The nghttp2 library names. -# - `NGHTTP2_LIBRARY_DIRS`: The nghttp2 library directories. -# - `NGHTTP2_PC_REQUIRES`: The nghttp2 pkg-config packages. -# - `NGHTTP2_CFLAGS`: Required compiler flags. -# - `NGHTTP2_VERSION`: Version of nghttp2. +# - `NGHTTP2_FOUND`: System has nghttp2. +# - `NGHTTP2_VERSION`: Version of nghttp2. +# - `CURL::nghttp2`: nghttp2 library target. -set(NGHTTP2_PC_REQUIRES "libnghttp2") +set(_nghttp2_pc_requires "libnghttp2") if(CURL_USE_PKGCONFIG AND NOT DEFINED NGHTTP2_INCLUDE_DIR AND NOT DEFINED NGHTTP2_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(NGHTTP2 ${NGHTTP2_PC_REQUIRES}) + pkg_check_modules(_nghttp2 ${_nghttp2_pc_requires}) endif() -if(NGHTTP2_FOUND) - string(REPLACE ";" " " NGHTTP2_CFLAGS "${NGHTTP2_CFLAGS}") - message(STATUS "Found NGHTTP2 (via pkg-config): ${NGHTTP2_INCLUDE_DIRS} (found version \"${NGHTTP2_VERSION}\")") +if(_nghttp2_FOUND) + set(NGHTTP2_FOUND TRUE) + set(NGHTTP2_VERSION ${_nghttp2_VERSION}) + message(STATUS "Found NGHTTP2 (via pkg-config): ${_nghttp2_INCLUDE_DIRS} (found version \"${NGHTTP2_VERSION}\")") else() find_path(NGHTTP2_INCLUDE_DIR NAMES "nghttp2/nghttp2.h") find_library(NGHTTP2_LIBRARY NAMES "nghttp2" "nghttp2_static") @@ -74,9 +71,25 @@ else() ) if(NGHTTP2_FOUND) - set(NGHTTP2_INCLUDE_DIRS ${NGHTTP2_INCLUDE_DIR}) - set(NGHTTP2_LIBRARIES ${NGHTTP2_LIBRARY}) + set(_nghttp2_INCLUDE_DIRS ${NGHTTP2_INCLUDE_DIR}) + set(_nghttp2_LIBRARIES ${NGHTTP2_LIBRARY}) endif() mark_as_advanced(NGHTTP2_INCLUDE_DIR NGHTTP2_LIBRARY) endif() + +if(NGHTTP2_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_nghttp2_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::nghttp2) + add_library(CURL::nghttp2 INTERFACE IMPORTED) + set_target_properties(CURL::nghttp2 PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_nghttp2_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_nghttp2_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_nghttp2_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_nghttp2_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_nghttp2_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindNGHTTP3.cmake b/CMake/FindNGHTTP3.cmake index fba2c5779b36..37ebfe1114fa 100644 --- a/CMake/FindNGHTTP3.cmake +++ b/CMake/FindNGHTTP3.cmake @@ -25,31 +25,28 @@ # # Input variables: # -# - `NGHTTP3_INCLUDE_DIR`: Absolute path to nghttp3 include directory. -# - `NGHTTP3_LIBRARY`: Absolute path to `nghttp3` library. +# - `NGHTTP3_INCLUDE_DIR`: Absolute path to nghttp3 include directory. +# - `NGHTTP3_LIBRARY`: Absolute path to `nghttp3` library. # -# Result variables: +# Defines: # -# - `NGHTTP3_FOUND`: System has nghttp3. -# - `NGHTTP3_INCLUDE_DIRS`: The nghttp3 include directories. -# - `NGHTTP3_LIBRARIES`: The nghttp3 library names. -# - `NGHTTP3_LIBRARY_DIRS`: The nghttp3 library directories. -# - `NGHTTP3_PC_REQUIRES`: The nghttp3 pkg-config packages. -# - `NGHTTP3_CFLAGS`: Required compiler flags. -# - `NGHTTP3_VERSION`: Version of nghttp3. +# - `NGHTTP3_FOUND`: System has nghttp3. +# - `NGHTTP3_VERSION`: Version of nghttp3. +# - `CURL::nghttp3`: nghttp3 library target. -set(NGHTTP3_PC_REQUIRES "libnghttp3") +set(_nghttp3_pc_requires "libnghttp3") if(CURL_USE_PKGCONFIG AND NOT DEFINED NGHTTP3_INCLUDE_DIR AND NOT DEFINED NGHTTP3_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(NGHTTP3 ${NGHTTP3_PC_REQUIRES}) + pkg_check_modules(_nghttp3 ${_nghttp3_pc_requires}) endif() -if(NGHTTP3_FOUND) - string(REPLACE ";" " " NGHTTP3_CFLAGS "${NGHTTP3_CFLAGS}") - message(STATUS "Found NGHTTP3 (via pkg-config): ${NGHTTP3_INCLUDE_DIRS} (found version \"${NGHTTP3_VERSION}\")") +if(_nghttp3_FOUND) + set(NGHTTP3_FOUND TRUE) + set(NGHTTP3_VERSION ${_nghttp3_VERSION}) + message(STATUS "Found NGHTTP3 (via pkg-config): ${_nghttp3_INCLUDE_DIRS} (found version \"${NGHTTP3_VERSION}\")") else() find_path(NGHTTP3_INCLUDE_DIR NAMES "nghttp3/nghttp3.h") find_library(NGHTTP3_LIBRARY NAMES "nghttp3") @@ -74,9 +71,25 @@ else() ) if(NGHTTP3_FOUND) - set(NGHTTP3_INCLUDE_DIRS ${NGHTTP3_INCLUDE_DIR}) - set(NGHTTP3_LIBRARIES ${NGHTTP3_LIBRARY}) + set(_nghttp3_INCLUDE_DIRS ${NGHTTP3_INCLUDE_DIR}) + set(_nghttp3_LIBRARIES ${NGHTTP3_LIBRARY}) endif() mark_as_advanced(NGHTTP3_INCLUDE_DIR NGHTTP3_LIBRARY) endif() + +if(NGHTTP3_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_nghttp3_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::nghttp3) + add_library(CURL::nghttp3 INTERFACE IMPORTED) + set_target_properties(CURL::nghttp3 PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_nghttp3_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_nghttp3_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_nghttp3_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_nghttp3_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_nghttp3_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindNGTCP2.cmake b/CMake/FindNGTCP2.cmake index cda3b0e08cb2..416ea459f6b1 100644 --- a/CMake/FindNGTCP2.cmake +++ b/CMake/FindNGTCP2.cmake @@ -44,15 +44,11 @@ # - `NGTCP2_CRYPTO_QUICTLS_LIBRARY`: Absolute path to `ngtcp2_crypto_quictls` library. # - `NGTCP2_CRYPTO_WOLFSSL_LIBRARY`: Absolute path to `ngtcp2_crypto_wolfssl` library. # -# Result variables: +# Defines: # # - `NGTCP2_FOUND`: System has ngtcp2. -# - `NGTCP2_INCLUDE_DIRS`: The ngtcp2 include directories. -# - `NGTCP2_LIBRARIES`: The ngtcp2 library names. -# - `NGTCP2_LIBRARY_DIRS`: The ngtcp2 library directories. -# - `NGTCP2_PC_REQUIRES`: The ngtcp2 pkg-config packages. -# - `NGTCP2_CFLAGS`: Required compiler flags. # - `NGTCP2_VERSION`: Version of ngtcp2. +# - `CURL::ngtcp2`: ngtcp2 library target. if(NGTCP2_FIND_COMPONENTS) set(_ngtcp2_crypto_backend "") @@ -71,9 +67,9 @@ if(NGTCP2_FIND_COMPONENTS) endif() endif() -set(NGTCP2_PC_REQUIRES "libngtcp2") +set(_ngtcp2_pc_requires "libngtcp2") if(_ngtcp2_crypto_backend) - list(APPEND NGTCP2_PC_REQUIRES "lib${_crypto_library_lower}") + list(APPEND _ngtcp2_pc_requires "lib${_crypto_library_lower}") endif() set(_tried_pkgconfig FALSE) @@ -81,14 +77,14 @@ if(CURL_USE_PKGCONFIG AND NOT DEFINED NGTCP2_INCLUDE_DIR AND NOT DEFINED NGTCP2_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(NGTCP2 ${NGTCP2_PC_REQUIRES}) + pkg_check_modules(_ngtcp2 ${_ngtcp2_pc_requires}) set(_tried_pkgconfig TRUE) endif() -if(NGTCP2_FOUND) - set(NGTCP2_VERSION ${NGTCP2_libngtcp2_VERSION}) - string(REPLACE ";" " " NGTCP2_CFLAGS "${NGTCP2_CFLAGS}") - message(STATUS "Found NGTCP2 (via pkg-config): ${NGTCP2_INCLUDE_DIRS} (found version \"${NGTCP2_VERSION}\")") +if(_ngtcp2_FOUND) + set(NGTCP2_FOUND TRUE) + set(NGTCP2_VERSION ${_ngtcp2_libngtcp2_VERSION}) + message(STATUS "Found NGTCP2 (via pkg-config): ${_ngtcp2_INCLUDE_DIRS} (found version \"${NGTCP2_VERSION}\")") else() find_path(NGTCP2_INCLUDE_DIR NAMES "ngtcp2/ngtcp2.h") find_library(NGTCP2_LIBRARY NAMES "ngtcp2") @@ -128,8 +124,8 @@ else() ) if(NGTCP2_FOUND) - set(NGTCP2_INCLUDE_DIRS ${NGTCP2_INCLUDE_DIR}) - set(NGTCP2_LIBRARIES ${NGTCP2_LIBRARY} ${NGTCP2_CRYPTO_LIBRARY}) + set(_ngtcp2_INCLUDE_DIRS ${NGTCP2_INCLUDE_DIR}) + set(_ngtcp2_LIBRARIES ${NGTCP2_LIBRARY} ${NGTCP2_CRYPTO_LIBRARY}) endif() mark_as_advanced(NGTCP2_INCLUDE_DIR NGTCP2_LIBRARY NGTCP2_CRYPTO_LIBRARY) @@ -139,3 +135,19 @@ else() unset(NGTCP2_LIBRARY CACHE) endif() endif() + +if(NGTCP2_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_ngtcp2_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::ngtcp2) + add_library(CURL::ngtcp2 INTERFACE IMPORTED) + set_target_properties(CURL::ngtcp2 PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_ngtcp2_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_ngtcp2_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_ngtcp2_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_ngtcp2_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_ngtcp2_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindNettle.cmake b/CMake/FindNettle.cmake index 7f2f69c1ca3e..d22865ffad69 100644 --- a/CMake/FindNettle.cmake +++ b/CMake/FindNettle.cmake @@ -25,32 +25,29 @@ # # Input variables: # -# - `NETTLE_INCLUDE_DIR`: Absolute path to nettle include directory. -# - `NETTLE_LIBRARY`: Absolute path to `nettle` library. +# - `NETTLE_INCLUDE_DIR`: Absolute path to nettle include directory. +# - `NETTLE_LIBRARY`: Absolute path to `nettle` library. # -# Result variables: +# Defines: # -# - `NETTLE_FOUND`: System has nettle. -# - `NETTLE_INCLUDE_DIRS`: The nettle include directories. -# - `NETTLE_LIBRARIES`: The nettle library names. -# - `NETTLE_LIBRARY_DIRS`: The nettle library directories. -# - `NETTLE_PC_REQUIRES`: The nettle pkg-config packages. -# - `NETTLE_CFLAGS`: Required compiler flags. -# - `NETTLE_VERSION`: Version of nettle. +# - `NETTLE_FOUND`: System has nettle. +# - `NETTLE_VERSION`: Version of nettle. +# - `CURL::nettle`: nettle library target. -set(NETTLE_PC_REQUIRES "nettle") +set(_nettle_pc_requires "nettle") if(CURL_USE_PKGCONFIG AND NOT DEFINED NETTLE_INCLUDE_DIR AND NOT DEFINED NETTLE_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(NETTLE ${NETTLE_PC_REQUIRES}) + pkg_check_modules(_nettle ${_nettle_pc_requires}) endif() -if(NETTLE_FOUND) +if(_nettle_FOUND) set(Nettle_FOUND TRUE) - string(REPLACE ";" " " NETTLE_CFLAGS "${NETTLE_CFLAGS}") - message(STATUS "Found Nettle (via pkg-config): ${NETTLE_INCLUDE_DIRS} (found version \"${NETTLE_VERSION}\")") + set(NETTLE_FOUND TRUE) + set(NETTLE_VERSION ${_nettle_VERSION}) + message(STATUS "Found Nettle (via pkg-config): ${_nettle_INCLUDE_DIRS} (found version \"${NETTLE_VERSION}\")") else() find_path(NETTLE_INCLUDE_DIR NAMES "nettle/sha2.h") find_library(NETTLE_LIBRARY NAMES "nettle") @@ -80,9 +77,25 @@ else() ) if(NETTLE_FOUND) - set(NETTLE_INCLUDE_DIRS ${NETTLE_INCLUDE_DIR}) - set(NETTLE_LIBRARIES ${NETTLE_LIBRARY}) + set(_nettle_INCLUDE_DIRS ${NETTLE_INCLUDE_DIR}) + set(_nettle_LIBRARIES ${NETTLE_LIBRARY}) endif() mark_as_advanced(NETTLE_INCLUDE_DIR NETTLE_LIBRARY) endif() + +if(NETTLE_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_nettle_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::nettle) + add_library(CURL::nettle INTERFACE IMPORTED) + set_target_properties(CURL::nettle PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_nettle_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_nettle_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_nettle_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_nettle_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_nettle_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindQuiche.cmake b/CMake/FindQuiche.cmake index 934cf9f69f15..22482d79fb4f 100644 --- a/CMake/FindQuiche.cmake +++ b/CMake/FindQuiche.cmake @@ -25,32 +25,29 @@ # # Input variables: # -# - `QUICHE_INCLUDE_DIR`: Absolute path to quiche include directory. -# - `QUICHE_LIBRARY`: Absolute path to `quiche` library. +# - `QUICHE_INCLUDE_DIR`: Absolute path to quiche include directory. +# - `QUICHE_LIBRARY`: Absolute path to `quiche` library. # -# Result variables: +# Defines: # -# - `QUICHE_FOUND`: System has quiche. -# - `QUICHE_INCLUDE_DIRS`: The quiche include directories. -# - `QUICHE_LIBRARIES`: The quiche library names. -# - `QUICHE_LIBRARY_DIRS`: The quiche library directories. -# - `QUICHE_PC_REQUIRES`: The quiche pkg-config packages. -# - `QUICHE_CFLAGS`: Required compiler flags. -# - `QUICHE_VERSION`: Version of quiche. +# - `QUICHE_FOUND`: System has quiche. +# - `QUICHE_VERSION`: Version of quiche. +# - `CURL::quiche`: quiche library target. -set(QUICHE_PC_REQUIRES "quiche") +set(_quiche_pc_requires "quiche") if(CURL_USE_PKGCONFIG AND NOT DEFINED QUICHE_INCLUDE_DIR AND NOT DEFINED QUICHE_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(QUICHE ${QUICHE_PC_REQUIRES}) + pkg_check_modules(_quiche ${_quiche_pc_requires}) endif() -if(QUICHE_FOUND) +if(_quiche_FOUND) set(Quiche_FOUND TRUE) - string(REPLACE ";" " " QUICHE_CFLAGS "${QUICHE_CFLAGS}") - message(STATUS "Found Quiche (via pkg-config): ${QUICHE_INCLUDE_DIRS} (found version \"${QUICHE_VERSION}\")") + set(QUICHE_FOUND TRUE) + set(QUICHE_VERSION ${_quiche_VERSION}) + message(STATUS "Found Quiche (via pkg-config): ${_quiche_INCLUDE_DIRS} (found version \"${QUICHE_VERSION}\")") else() find_path(QUICHE_INCLUDE_DIR NAMES "quiche.h") find_library(QUICHE_LIBRARY NAMES "quiche") @@ -63,9 +60,25 @@ else() ) if(QUICHE_FOUND) - set(QUICHE_INCLUDE_DIRS ${QUICHE_INCLUDE_DIR}) - set(QUICHE_LIBRARIES ${QUICHE_LIBRARY}) + set(_quiche_INCLUDE_DIRS ${QUICHE_INCLUDE_DIR}) + set(_quiche_LIBRARIES ${QUICHE_LIBRARY}) endif() mark_as_advanced(QUICHE_INCLUDE_DIR QUICHE_LIBRARY) endif() + +if(QUICHE_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_quiche_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::quiche) + add_library(CURL::quiche INTERFACE IMPORTED) + set_target_properties(CURL::quiche PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_quiche_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_quiche_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_quiche_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_quiche_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_quiche_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindRustls.cmake b/CMake/FindRustls.cmake index a29ce5fa098b..37b99be73ea9 100644 --- a/CMake/FindRustls.cmake +++ b/CMake/FindRustls.cmake @@ -25,34 +25,31 @@ # # Input variables: # -# - `RUSTLS_INCLUDE_DIR`: Absolute path to Rustls include directory. -# - `RUSTLS_LIBRARY`: Absolute path to `rustls` library. +# - `RUSTLS_INCLUDE_DIR`: Absolute path to Rustls include directory. +# - `RUSTLS_LIBRARY`: Absolute path to `rustls` library. # -# Result variables: +# Defines: # -# - `RUSTLS_FOUND`: System has Rustls. -# - `RUSTLS_INCLUDE_DIRS`: The Rustls include directories. -# - `RUSTLS_LIBRARIES`: The Rustls library names. -# - `RUSTLS_LIBRARY_DIRS`: The Rustls library directories. -# - `RUSTLS_PC_REQUIRES`: The Rustls pkg-config packages. -# - `RUSTLS_CFLAGS`: Required compiler flags. -# - `RUSTLS_VERSION`: Version of Rustls. +# - `RUSTLS_FOUND`: System has Rustls. +# - `RUSTLS_VERSION`: Version of Rustls. +# - `CURL::rustls`: Rustls library target. -set(RUSTLS_PC_REQUIRES "rustls") +set(_rustls_pc_requires "rustls") if(CURL_USE_PKGCONFIG AND NOT DEFINED RUSTLS_INCLUDE_DIR AND NOT DEFINED RUSTLS_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(RUSTLS ${RUSTLS_PC_REQUIRES}) + pkg_check_modules(_rustls ${_rustls_pc_requires}) endif() -if(RUSTLS_FOUND) +if(_rustls_FOUND) set(Rustls_FOUND TRUE) - string(REPLACE ";" " " RUSTLS_CFLAGS "${RUSTLS_CFLAGS}") - message(STATUS "Found Rustls (via pkg-config): ${RUSTLS_INCLUDE_DIRS} (found version \"${RUSTLS_VERSION}\")") + set(RUSTLS_FOUND TRUE) + set(RUSTLS_VERSION ${_rustls_VERSION}) + message(STATUS "Found Rustls (via pkg-config): ${_rustls_INCLUDE_DIRS} (found version \"${RUSTLS_VERSION}\")") else() - set(RUSTLS_PC_REQUIRES "") # Depend on pkg-config only when found via pkg-config + set(_rustls_pc_requires "") # Depend on pkg-config only when found via pkg-config find_path(RUSTLS_INCLUDE_DIR NAMES "rustls.h") find_library(RUSTLS_LIBRARY NAMES "rustls") @@ -65,8 +62,8 @@ else() ) if(RUSTLS_FOUND) - set(RUSTLS_INCLUDE_DIRS ${RUSTLS_INCLUDE_DIR}) - set(RUSTLS_LIBRARIES ${RUSTLS_LIBRARY}) + set(_rustls_INCLUDE_DIRS ${RUSTLS_INCLUDE_DIR}) + set(_rustls_LIBRARIES ${RUSTLS_LIBRARY}) endif() mark_as_advanced(RUSTLS_INCLUDE_DIR RUSTLS_LIBRARY) @@ -79,31 +76,47 @@ if(RUSTLS_FOUND) if(NOT SECURITY_FRAMEWORK) message(FATAL_ERROR "Security framework not found") endif() - list(APPEND RUSTLS_LIBRARIES "-framework Security") + list(APPEND _rustls_LIBRARIES "-framework Security") find_library(FOUNDATION_FRAMEWORK NAMES "Foundation") mark_as_advanced(FOUNDATION_FRAMEWORK) if(NOT FOUNDATION_FRAMEWORK) message(FATAL_ERROR "Foundation framework not found") endif() - list(APPEND RUSTLS_LIBRARIES "-framework Foundation") + list(APPEND _rustls_LIBRARIES "-framework Foundation") elseif(NOT WIN32) find_library(PTHREAD_LIBRARY NAMES "pthread") if(PTHREAD_LIBRARY) - list(APPEND RUSTLS_LIBRARIES ${PTHREAD_LIBRARY}) + list(APPEND _rustls_LIBRARIES ${PTHREAD_LIBRARY}) endif() mark_as_advanced(PTHREAD_LIBRARY) find_library(DL_LIBRARY NAMES "dl") if(DL_LIBRARY) - list(APPEND RUSTLS_LIBRARIES ${DL_LIBRARY}) + list(APPEND _rustls_LIBRARIES ${DL_LIBRARY}) endif() mark_as_advanced(DL_LIBRARY) find_library(MATH_LIBRARY NAMES "m") if(MATH_LIBRARY) - list(APPEND RUSTLS_LIBRARIES ${MATH_LIBRARY}) + list(APPEND _rustls_LIBRARIES ${MATH_LIBRARY}) endif() mark_as_advanced(MATH_LIBRARY) endif() endif() + +if(RUSTLS_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_rustls_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::rustls) + add_library(CURL::rustls INTERFACE IMPORTED) + set_target_properties(CURL::rustls PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_rustls_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_rustls_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_rustls_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_rustls_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_rustls_LIBRARIES}") + endif() +endif() diff --git a/CMake/FindWolfSSL.cmake b/CMake/FindWolfSSL.cmake index 4d172c029a39..3a3c05f0fd03 100644 --- a/CMake/FindWolfSSL.cmake +++ b/CMake/FindWolfSSL.cmake @@ -25,18 +25,14 @@ # # Input variables: # -# - `WOLFSSL_INCLUDE_DIR`: Absolute path to wolfSSL include directory. -# - `WOLFSSL_LIBRARY`: Absolute path to `wolfssl` library. +# - `WOLFSSL_INCLUDE_DIR`: Absolute path to wolfSSL include directory. +# - `WOLFSSL_LIBRARY`: Absolute path to `wolfssl` library. # -# Result variables: +# Defines: # -# - `WOLFSSL_FOUND`: System has wolfSSL. -# - `WOLFSSL_INCLUDE_DIRS`: The wolfSSL include directories. -# - `WOLFSSL_LIBRARIES`: The wolfSSL library names. -# - `WOLFSSL_LIBRARY_DIRS`: The wolfSSL library directories. -# - `WOLFSSL_PC_REQUIRES`: The wolfSSL pkg-config packages. -# - `WOLFSSL_CFLAGS`: Required compiler flags. -# - `WOLFSSL_VERSION`: Version of wolfSSL. +# - `WOLFSSL_FOUND`: System has wolfSSL. +# - `WOLFSSL_VERSION`: Version of wolfSSL. +# - `CURL::wolfssl`: wolfSSL library target. if(DEFINED WolfSSL_INCLUDE_DIR AND NOT DEFINED WOLFSSL_INCLUDE_DIR) message(WARNING "WolfSSL_INCLUDE_DIR is deprecated, use WOLFSSL_INCLUDE_DIR instead.") @@ -47,19 +43,20 @@ if(DEFINED WolfSSL_LIBRARY AND NOT DEFINED WOLFSSL_LIBRARY) set(WOLFSSL_LIBRARY "${WolfSSL_LIBRARY}") endif() -set(WOLFSSL_PC_REQUIRES "wolfssl") +set(_wolfssl_pc_requires "wolfssl") if(CURL_USE_PKGCONFIG AND NOT DEFINED WOLFSSL_INCLUDE_DIR AND NOT DEFINED WOLFSSL_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(WOLFSSL ${WOLFSSL_PC_REQUIRES}) + pkg_check_modules(_wolfssl ${_wolfssl_pc_requires}) endif() -if(WOLFSSL_FOUND) +if(_wolfssl_FOUND) set(WolfSSL_FOUND TRUE) - string(REPLACE ";" " " WOLFSSL_CFLAGS "${WOLFSSL_CFLAGS}") - message(STATUS "Found WolfSSL (via pkg-config): ${WOLFSSL_INCLUDE_DIRS} (found version \"${WOLFSSL_VERSION}\")") + set(WOLFSSL_FOUND TRUE) + set(WOLFSSL_VERSION ${_wolfssl_VERSION}) + message(STATUS "Found WolfSSL (via pkg-config): ${_wolfssl_INCLUDE_DIRS} (found version \"${WOLFSSL_VERSION}\")") else() find_path(WOLFSSL_INCLUDE_DIR NAMES "wolfssl/ssl.h") find_library(WOLFSSL_LIBRARY NAMES "wolfssl") @@ -84,8 +81,8 @@ else() ) if(WOLFSSL_FOUND) - set(WOLFSSL_INCLUDE_DIRS ${WOLFSSL_INCLUDE_DIR}) - set(WOLFSSL_LIBRARIES ${WOLFSSL_LIBRARY}) + set(_wolfssl_INCLUDE_DIRS ${WOLFSSL_INCLUDE_DIR}) + set(_wolfssl_LIBRARIES ${WOLFSSL_LIBRARY}) endif() mark_as_advanced(WOLFSSL_INCLUDE_DIR WOLFSSL_LIBRARY) @@ -98,19 +95,35 @@ if(WOLFSSL_FOUND) if(NOT SECURITY_FRAMEWORK) message(FATAL_ERROR "Security framework not found") endif() - list(APPEND WOLFSSL_LIBRARIES "-framework Security") + list(APPEND _wolfssl_LIBRARIES "-framework Security") find_library(COREFOUNDATION_FRAMEWORK NAMES "CoreFoundation") mark_as_advanced(COREFOUNDATION_FRAMEWORK) if(NOT COREFOUNDATION_FRAMEWORK) message(FATAL_ERROR "CoreFoundation framework not found") endif() - list(APPEND WOLFSSL_LIBRARIES "-framework CoreFoundation") - elseif(NOT WIN32) + list(APPEND _wolfssl_LIBRARIES "-framework CoreFoundation") + elseif(WIN32) + list(APPEND _wolfssl_LIBRARIES "crypt32") + else() find_library(MATH_LIBRARY NAMES "m") if(MATH_LIBRARY) - list(APPEND WOLFSSL_LIBRARIES ${MATH_LIBRARY}) # for log and pow + list(APPEND _wolfssl_LIBRARIES ${MATH_LIBRARY}) # for log and pow endif() mark_as_advanced(MATH_LIBRARY) endif() + + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_wolfssl_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::wolfssl) + add_library(CURL::wolfssl INTERFACE IMPORTED) + set_target_properties(CURL::wolfssl PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_wolfssl_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_wolfssl_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_wolfssl_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_wolfssl_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_wolfssl_LIBRARIES}") + endif() endif() diff --git a/CMake/FindZstd.cmake b/CMake/FindZstd.cmake index 655f0cc700a8..954a827b6fe4 100644 --- a/CMake/FindZstd.cmake +++ b/CMake/FindZstd.cmake @@ -25,18 +25,14 @@ # # Input variables: # -# - `ZSTD_INCLUDE_DIR`: Absolute path to zstd include directory. -# - `ZSTD_LIBRARY`: Absolute path to `zstd` library. +# - `ZSTD_INCLUDE_DIR`: Absolute path to zstd include directory. +# - `ZSTD_LIBRARY`: Absolute path to `zstd` library. # -# Result variables: +# Defines: # -# - `ZSTD_FOUND`: System has zstd. -# - `ZSTD_INCLUDE_DIRS`: The zstd include directories. -# - `ZSTD_LIBRARIES`: The zstd library names. -# - `ZSTD_LIBRARY_DIRS`: The zstd library directories. -# - `ZSTD_PC_REQUIRES`: The zstd pkg-config packages. -# - `ZSTD_CFLAGS`: Required compiler flags. -# - `ZSTD_VERSION`: Version of zstd. +# - `ZSTD_FOUND`: System has zstd. +# - `ZSTD_VERSION`: Version of zstd. +# - `CURL::zstd`: zstd library target. if(DEFINED Zstd_INCLUDE_DIR AND NOT DEFINED ZSTD_INCLUDE_DIR) message(WARNING "Zstd_INCLUDE_DIR is deprecated, use ZSTD_INCLUDE_DIR instead.") @@ -47,19 +43,20 @@ if(DEFINED Zstd_LIBRARY AND NOT DEFINED ZSTD_LIBRARY) set(ZSTD_LIBRARY "${Zstd_LIBRARY}") endif() -set(ZSTD_PC_REQUIRES "libzstd") +set(_zstd_pc_requires "libzstd") if(CURL_USE_PKGCONFIG AND NOT DEFINED ZSTD_INCLUDE_DIR AND NOT DEFINED ZSTD_LIBRARY) find_package(PkgConfig QUIET) - pkg_check_modules(ZSTD ${ZSTD_PC_REQUIRES}) + pkg_check_modules(_zstd ${_zstd_pc_requires}) endif() -if(ZSTD_FOUND) +if(_zstd_FOUND) set(Zstd_FOUND TRUE) - string(REPLACE ";" " " ZSTD_CFLAGS "${ZSTD_CFLAGS}") - message(STATUS "Found Zstd (via pkg-config): ${ZSTD_INCLUDE_DIRS} (found version \"${ZSTD_VERSION}\")") + set(ZSTD_FOUND TRUE) + set(ZSTD_VERSION ${_zstd_VERSION}) + message(STATUS "Found Zstd (via pkg-config): ${_zstd_INCLUDE_DIRS} (found version \"${ZSTD_VERSION}\")") else() find_path(ZSTD_INCLUDE_DIR NAMES "zstd.h") find_library(ZSTD_LIBRARY NAMES "zstd") @@ -94,9 +91,25 @@ else() ) if(ZSTD_FOUND) - set(ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR}) - set(ZSTD_LIBRARIES ${ZSTD_LIBRARY}) + set(_zstd_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR}) + set(_zstd_LIBRARIES ${ZSTD_LIBRARY}) endif() mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY) endif() + +if(ZSTD_FOUND) + if(CMAKE_VERSION VERSION_LESS 3.13) + link_directories(${_zstd_LIBRARY_DIRS}) + endif() + + if(NOT TARGET CURL::zstd) + add_library(CURL::zstd INTERFACE IMPORTED) + set_target_properties(CURL::zstd PROPERTIES + INTERFACE_LIBCURL_PC_MODULES "${_zstd_pc_requires}" + INTERFACE_COMPILE_OPTIONS "${_zstd_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${_zstd_INCLUDE_DIRS}" + INTERFACE_LINK_DIRECTORIES "${_zstd_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${_zstd_LIBRARIES}") + endif() +endif() diff --git a/CMake/Utilities.cmake b/CMake/Utilities.cmake index 335713c84cfe..efa28b75155b 100644 --- a/CMake/Utilities.cmake +++ b/CMake/Utilities.cmake @@ -59,6 +59,7 @@ function(curl_dumptargetprops _target) string(REPLACE "\n" ";" _cmake_property_list "${_cmake_property_list}") list(REMOVE_DUPLICATES _cmake_property_list) list(REMOVE_ITEM _cmake_property_list "") + list(APPEND _cmake_property_list "INTERFACE_LIBCURL_PC_MODULES") foreach(_prop IN LISTS _cmake_property_list) if(_prop MATCHES "") foreach(_config IN ITEMS "DEBUG" "RELEASE" "MINSIZEREL" "RELWITHDEBINFO") diff --git a/CMake/curl-config.cmake.in b/CMake/curl-config.cmake.in index d1582b8d41b9..99949198a305 100644 --- a/CMake/curl-config.cmake.in +++ b/CMake/curl-config.cmake.in @@ -23,7 +23,12 @@ ########################################################################### @PACKAGE_INIT@ +option(CURL_USE_PKGCONFIG "Enable pkg-config to detect @PROJECT_NAME@ dependencies. Default: @CURL_USE_PKGCONFIG@" "@CURL_USE_PKGCONFIG@") + include(CMakeFindDependencyMacro) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH}) + +set(_libs "") if("@USE_OPENSSL@") if("@OPENSSL_VERSION_MAJOR@") find_dependency(OpenSSL "@OPENSSL_VERSION_MAJOR@") @@ -34,6 +39,97 @@ endif() if("@HAVE_LIBZ@") find_dependency(ZLIB "@ZLIB_VERSION_MAJOR@") endif() +if("@HAVE_BROTLI@") + find_dependency(Brotli) + list(APPEND _libs CURL::brotli) +endif() +if("@USE_ARES@") + find_dependency(Cares) + list(APPEND _libs CURL::cares) +endif() +if("@HAVE_GSSAPI@") + find_dependency(GSS) + list(APPEND _libs CURL::gss) +endif() +if("@USE_BACKTRACE@") + find_dependency(Libbacktrace) + list(APPEND _libs CURL::libbacktrace) +endif() +if("@USE_GSASL@") + find_dependency(Libgsasl) + list(APPEND _libs CURL::libgsasl) +endif() +if(NOT "@USE_WIN32_LDAP@" AND NOT "@CURL_DISABLE_LDAP@") + find_dependency(LDAP) + list(APPEND _libs CURL::ldap) +endif() +if("@HAVE_LIBIDN2@") + find_dependency(Libidn2) + list(APPEND _libs CURL::libidn2) +endif() +if("@USE_LIBPSL@") + find_dependency(Libpsl) + list(APPEND _libs CURL::libpsl) +endif() +if("@USE_LIBRTMP@") + find_dependency(Librtmp) + list(APPEND _libs CURL::librtmp) +endif() +if("@USE_LIBSSH@") + find_dependency(Libssh) + list(APPEND _libs CURL::libssh) +endif() +if("@USE_LIBSSH2@") + find_dependency(Libssh2) + list(APPEND _libs CURL::libssh2) +endif() +if("@USE_LIBUV@") + find_dependency(Libuv) + list(APPEND _libs CURL::libuv) +endif() +if("@USE_MBEDTLS@") + find_dependency(MbedTLS) + list(APPEND _libs CURL::mbedtls) +endif() +if("@USE_NGHTTP2@") + find_dependency(NGHTTP2) + list(APPEND _libs CURL::nghttp2) +endif() +if("@USE_NGHTTP3@") + find_dependency(NGHTTP3) + list(APPEND _libs CURL::nghttp3) +endif() +if("@USE_NGTCP2@") + find_dependency(NGTCP2) + list(APPEND _libs CURL::ngtcp2) +endif() +if("@USE_GNUTLS@") + find_dependency(GnuTLS) + list(APPEND _libs CURL::gnutls) + find_dependency(Nettle) + list(APPEND _libs CURL::nettle) +endif() +if("@USE_QUICHE@") + find_dependency(Quiche) + list(APPEND _libs CURL::quiche) +endif() +if("@USE_RUSTLS@") + find_dependency(Rustls) + list(APPEND _libs CURL::rustls) +endif() +if("@USE_WOLFSSL@") + find_dependency(WolfSSL) + list(APPEND _libs CURL::wolfssl) +endif() +if("@HAVE_ZSTD@") + find_dependency(Zstd) + list(APPEND _libs CURL::zstd) +endif() + +if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND WIN32 AND NOT TARGET CURL::win32_winsock) + add_library(CURL::win32_winsock INTERFACE IMPORTED) + set_target_properties(CURL::win32_winsock PROPERTIES INTERFACE_LINK_LIBRARIES "@_win32_winsock@") +endif() include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") @@ -45,9 +141,31 @@ if(NOT TARGET @PROJECT_NAME@::@LIB_NAME@) add_library(@PROJECT_NAME@::@LIB_NAME@ ALIAS @PROJECT_NAME@::@LIB_SELECTED@) endif() +if(TARGET @PROJECT_NAME@::@LIB_STATIC@) + # CMake before CMP0099 (CMake 3.17 2020-03-20) did not propagate libdirs to + # targets. It expected libs to have an absolute filename. As a workaround, + # manually apply dependency libdirs, for CMake consumers without this policy. + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17) + cmake_policy(GET CMP0099 _has_CMP0099) # https://cmake.org/cmake/help/latest/policy/CMP0099.html + endif() + if(NOT _has_CMP0099 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.13 AND _libs) + set(_libdirs "") + foreach(_lib IN LISTS _libs) + get_target_property(_libdir "${_lib}" INTERFACE_LINK_DIRECTORIES) + if(_libdir) + list(APPEND _libdirs "${_libdir}") + endif() + endforeach() + if(_libdirs) + target_link_directories(@PROJECT_NAME@::@LIB_STATIC@ INTERFACE ${_libdirs}) + endif() + endif() +endif() + # For compatibility with CMake's FindCURL.cmake set(CURL_VERSION_STRING "@CURLVERSION@") set(CURL_LIBRARIES @PROJECT_NAME@::@LIB_NAME@) +set(CURL_LIBRARIES_PRIVATE "@LIBCURL_PC_LIBS_PRIVATE_LIST@") set_and_check(CURL_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@") set(CURL_SUPPORTED_PROTOCOLS "@CURL_SUPPORTED_PROTOCOLS_LIST@") diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d6e7ca3e667..2af1679c993f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -358,23 +358,14 @@ else() endif() option(CURL_USE_PKGCONFIG "Enable pkg-config to detect dependencies" ${_curl_use_pkgconfig_default}) -# Initialize variables collecting dependency libs, paths, pkg-config names. +# Initialize variables collecting system and dependency libs. set(CURL_NETWORK_AND_TIME_LIBS "") set(CURL_LIBS "") -set(CURL_LIBDIRS "") -set(LIBCURL_PC_REQUIRES_PRIVATE "") if(ENABLE_ARES) set(USE_ARES 1) find_package(Cares REQUIRED) - list(APPEND CURL_LIBS ${CARES_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${CARES_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${CARES_PC_REQUIRES}) - include_directories(SYSTEM ${CARES_INCLUDE_DIRS}) - link_directories(${CARES_LIBRARY_DIRS}) - if(CARES_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${CARES_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::cares) endif() include(CurlSymbolHiding) @@ -762,7 +753,7 @@ if(CURL_USE_OPENSSL) # Depend on OpenSSL via imported targets. This allows our dependents to # get our dependencies transitively. list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "openssl") + set_target_properties(OpenSSL::SSL PROPERTIES INTERFACE_LIBCURL_PC_MODULES "openssl") if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "openssl") set(_valid_default_ssl_backend TRUE) @@ -809,14 +800,7 @@ if(CURL_USE_MBEDTLS) endif() set(_ssl_enabled ON) set(USE_MBEDTLS ON) - list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${MBEDTLS_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${MBEDTLS_PC_REQUIRES}) - include_directories(SYSTEM ${MBEDTLS_INCLUDE_DIRS}) - link_directories(${MBEDTLS_LIBRARY_DIRS}) - if(MBEDTLS_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${MBEDTLS_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::mbedtls) if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "mbedtls") set(_valid_default_ssl_backend TRUE) @@ -828,9 +812,7 @@ if(CURL_USE_MBEDTLS) endif() if(NOT DEFINED HAVE_MBEDTLS_DES_CRYPT_ECB) cmake_push_check_state() - list(APPEND CMAKE_REQUIRED_INCLUDES "${MBEDTLS_INCLUDE_DIRS}") - list(APPEND CMAKE_REQUIRED_LIBRARIES "${MBEDTLS_LIBRARIES}") - curl_required_libpaths("${MBEDTLS_LIBRARY_DIRS}") + list(APPEND CMAKE_REQUIRED_LIBRARIES CURL::mbedtls) check_function_exists("mbedtls_des_crypt_ecb" HAVE_MBEDTLS_DES_CRYPT_ECB) # in mbedTLS <4 cmake_pop_check_state() endif() @@ -840,14 +822,7 @@ if(CURL_USE_WOLFSSL) find_package(WolfSSL REQUIRED) set(_ssl_enabled ON) set(USE_WOLFSSL ON) - list(APPEND CURL_LIBS ${WOLFSSL_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${WOLFSSL_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${WOLFSSL_PC_REQUIRES}) - include_directories(SYSTEM ${WOLFSSL_INCLUDE_DIRS}) - link_directories(${WOLFSSL_LIBRARY_DIRS}) - if(WOLFSSL_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${WOLFSSL_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::wolfssl) if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "wolfssl") set(_valid_default_ssl_backend TRUE) @@ -857,26 +832,11 @@ endif() if(CURL_USE_GNUTLS) find_package(GnuTLS REQUIRED) - list(APPEND CURL_LIBS ${GNUTLS_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${GNUTLS_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${GNUTLS_PC_REQUIRES}) - include_directories(SYSTEM ${GNUTLS_INCLUDE_DIRS}) - link_directories(${GNUTLS_LIBRARY_DIRS}) - if(GNUTLS_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${GNUTLS_CFLAGS}") - endif() - + list(APPEND CURL_LIBS CURL::gnutls) find_package(Nettle REQUIRED) + list(APPEND CURL_LIBS CURL::nettle) set(_ssl_enabled ON) set(USE_GNUTLS ON) - list(APPEND CURL_LIBS ${NETTLE_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${NETTLE_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${NETTLE_PC_REQUIRES}) - include_directories(SYSTEM ${NETTLE_INCLUDE_DIRS}) - link_directories(${NETTLE_LIBRARY_DIRS}) - if(NETTLE_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${NETTLE_CFLAGS}") - endif() if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "gnutls") set(_valid_default_ssl_backend TRUE) @@ -885,9 +845,7 @@ if(CURL_USE_GNUTLS) if(NOT DEFINED HAVE_GNUTLS_SRP AND NOT CURL_DISABLE_SRP) cmake_push_check_state() - list(APPEND CMAKE_REQUIRED_INCLUDES "${GNUTLS_INCLUDE_DIRS}") - list(APPEND CMAKE_REQUIRED_LIBRARIES "${GNUTLS_LIBRARIES}") - curl_required_libpaths("${GNUTLS_LIBRARY_DIRS}") + list(APPEND CMAKE_REQUIRED_LIBRARIES CURL::gnutls) # In GnuTLS 3.8.0 (2023-02-10) and upper, this check always succeeds. # Detecting actual TLS-SRP support needs poking the API at runtime. check_symbol_exists("gnutls_srp_verifier" "gnutls/gnutls.h" HAVE_GNUTLS_SRP) @@ -899,23 +857,14 @@ if(CURL_USE_RUSTLS) find_package(Rustls REQUIRED) set(_ssl_enabled ON) set(USE_RUSTLS ON) - list(APPEND CURL_LIBS ${RUSTLS_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${RUSTLS_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${RUSTLS_PC_REQUIRES}) - include_directories(SYSTEM ${RUSTLS_INCLUDE_DIRS}) - link_directories(${RUSTLS_LIBRARY_DIRS}) - if(RUSTLS_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${RUSTLS_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::rustls) if(NOT DEFINED HAVE_RUSTLS_SUPPORTED_HPKE) if(RUSTLS_VERSION AND RUSTLS_VERSION VERSION_GREATER_EQUAL 0.15) set(HAVE_RUSTLS_SUPPORTED_HPKE TRUE) elseif(NOT RUSTLS_VERSION) cmake_push_check_state() - list(APPEND CMAKE_REQUIRED_INCLUDES "${RUSTLS_INCLUDE_DIRS}") - list(APPEND CMAKE_REQUIRED_LIBRARIES "${RUSTLS_LIBRARIES}") - curl_required_libpaths("${RUSTLS_LIBRARY_DIRS}") + list(APPEND CMAKE_REQUIRED_LIBRARIES CURL::rustls) check_symbol_exists("rustls_supported_hpke" "rustls.h" HAVE_RUSTLS_SUPPORTED_HPKE) cmake_pop_check_state() endif() @@ -944,21 +893,14 @@ if(ZLIB_FOUND) # Depend on ZLIB via imported targets. This allows our dependents to # get our dependencies transitively. list(APPEND CURL_LIBS ZLIB::ZLIB) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "zlib") + set_target_properties(ZLIB::ZLIB PROPERTIES INTERFACE_LIBCURL_PC_MODULES "zlib") endif() set(HAVE_BROTLI OFF) curl_dependency_option(CURL_BROTLI Brotli "brotli") if(BROTLI_FOUND) set(HAVE_BROTLI ON) - list(APPEND CURL_LIBS ${BROTLI_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${BROTLI_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${BROTLI_PC_REQUIRES}) - include_directories(SYSTEM ${BROTLI_INCLUDE_DIRS}) - link_directories(${BROTLI_LIBRARY_DIRS}) - if(BROTLI_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${BROTLI_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::brotli) endif() set(HAVE_ZSTD OFF) @@ -966,14 +908,7 @@ curl_dependency_option(CURL_ZSTD Zstd "zstd") if(ZSTD_FOUND) if(ZSTD_VERSION VERSION_GREATER_EQUAL 1.0.0) set(HAVE_ZSTD ON) - list(APPEND CURL_LIBS ${ZSTD_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${ZSTD_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${ZSTD_PC_REQUIRES}) - include_directories(SYSTEM ${ZSTD_INCLUDE_DIRS}) - link_directories(${ZSTD_LIBRARY_DIRS}) - if(ZSTD_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${ZSTD_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::zstd) else() message(WARNING "zstd v1.0.0 or newer is required, disabling zstd support.") endif() @@ -993,9 +928,7 @@ macro(curl_openssl_check_exists) endif() endif() if(USE_WOLFSSL) - list(APPEND CMAKE_REQUIRED_INCLUDES "${WOLFSSL_INCLUDE_DIRS}") - list(APPEND CMAKE_REQUIRED_LIBRARIES "${WOLFSSL_LIBRARIES}") - curl_required_libpaths("${WOLFSSL_LIBRARY_DIRS}") + list(APPEND CMAKE_REQUIRED_LIBRARIES CURL::wolfssl) if(HAVE_LIBZ) list(APPEND CMAKE_REQUIRED_LIBRARIES ZLIB::ZLIB) # Public wolfSSL headers also require zlib headers endif() @@ -1097,14 +1030,7 @@ option(USE_NGHTTP2 "Use nghttp2 library" ON) if(USE_NGHTTP2) find_package(NGHTTP2) if(NGHTTP2_FOUND) - list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${NGHTTP2_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${NGHTTP2_PC_REQUIRES}) - include_directories(SYSTEM ${NGHTTP2_INCLUDE_DIRS}) - link_directories(${NGHTTP2_LIBRARY_DIRS}) - if(NGHTTP2_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${NGHTTP2_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::nghttp2) else() set(USE_NGHTTP2 OFF) endif() @@ -1140,25 +1066,11 @@ if(USE_NGTCP2) else() message(FATAL_ERROR "ngtcp2 requires a supported TLS-backend") endif() - list(APPEND CURL_LIBS ${NGTCP2_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${NGTCP2_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${NGTCP2_PC_REQUIRES}) - include_directories(SYSTEM ${NGTCP2_INCLUDE_DIRS}) - link_directories(${NGTCP2_LIBRARY_DIRS}) - if(NGTCP2_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${NGTCP2_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::ngtcp2) find_package(NGHTTP3 REQUIRED) set(USE_NGHTTP3 ON) - list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${NGHTTP3_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${NGHTTP3_PC_REQUIRES}) - include_directories(SYSTEM ${NGHTTP3_INCLUDE_DIRS}) - link_directories(${NGHTTP3_LIBRARY_DIRS}) - if(NGHTTP3_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${NGHTTP3_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::nghttp3) endif() option(USE_QUICHE "Use quiche library for HTTP/3 support" OFF) @@ -1173,18 +1085,10 @@ if(USE_QUICHE) message(FATAL_ERROR "quiche requires BoringSSL") endif() curl_openssl_check_quic() - list(APPEND CURL_LIBS ${QUICHE_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${QUICHE_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${QUICHE_PC_REQUIRES}) - include_directories(SYSTEM ${QUICHE_INCLUDE_DIRS}) - link_directories(${QUICHE_LIBRARY_DIRS}) - if(QUICHE_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${QUICHE_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::quiche) if(NOT DEFINED HAVE_QUICHE_CONN_SET_QLOG_FD) cmake_push_check_state() - list(APPEND CMAKE_REQUIRED_INCLUDES "${QUICHE_INCLUDE_DIRS}") - list(APPEND CMAKE_REQUIRED_LIBRARIES "${QUICHE_LIBRARIES}") + list(APPEND CMAKE_REQUIRED_LIBRARIES CURL::quiche) check_symbol_exists("quiche_conn_set_qlog_fd" "quiche.h" HAVE_QUICHE_CONN_SET_QLOG_FD) cmake_pop_check_state() endif() @@ -1200,14 +1104,7 @@ if(USE_OPENSSL_QUIC) find_package(NGHTTP3 REQUIRED) set(USE_NGHTTP3 ON) - list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${NGHTTP3_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${NGHTTP3_PC_REQUIRES}) - include_directories(SYSTEM ${NGHTTP3_INCLUDE_DIRS}) - link_directories(${NGHTTP3_LIBRARY_DIRS}) - if(NGHTTP3_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${NGHTTP3_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::nghttp3) endif() if(NOT CURL_DISABLE_SRP AND (HAVE_GNUTLS_SRP OR HAVE_OPENSSL_SRP)) @@ -1235,22 +1132,12 @@ if(NOT CURL_DISABLE_LDAP) find_package(LDAP) if(LDAP_FOUND) set(HAVE_LBER_H 1) - set(CURL_LIBS ${LDAP_LIBRARIES} ${CURL_LIBS}) - list(APPEND CURL_LIBDIRS ${LDAP_LIBRARY_DIRS}) - if(LDAP_PC_REQUIRES) - set(LIBCURL_PC_REQUIRES_PRIVATE ${LDAP_PC_REQUIRES} ${LIBCURL_PC_REQUIRES_PRIVATE}) - endif() - include_directories(SYSTEM ${LDAP_INCLUDE_DIRS}) - link_directories(${LDAP_LIBRARY_DIRS}) - if(LDAP_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${LDAP_CFLAGS}") - endif() + set(CURL_LIBS CURL::ldap ${CURL_LIBS}) # LDAP feature checks list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DLDAP_DEPRECATED=1") - list(APPEND CMAKE_REQUIRED_LIBRARIES "${LDAP_LIBRARIES}") - curl_required_libpaths("${LDAP_LIBRARY_DIRS}") + list(APPEND CMAKE_REQUIRED_LIBRARIES CURL::ldap) check_function_exists("ldap_url_parse" HAVE_LDAP_URL_PARSE) check_function_exists("ldap_init_fd" HAVE_LDAP_INIT_FD) @@ -1312,14 +1199,7 @@ set(HAVE_LIBIDN2 OFF) if(USE_LIBIDN2 AND NOT USE_APPLE_IDN AND NOT USE_WIN32_IDN) find_package(Libidn2) if(LIBIDN2_FOUND) - set(CURL_LIBS ${LIBIDN2_LIBRARIES} ${CURL_LIBS}) - list(APPEND CURL_LIBDIRS ${LIBIDN2_LIBRARY_DIRS}) - set(LIBCURL_PC_REQUIRES_PRIVATE ${LIBIDN2_PC_REQUIRES} ${LIBCURL_PC_REQUIRES_PRIVATE}) - include_directories(SYSTEM ${LIBIDN2_INCLUDE_DIRS}) - link_directories(${LIBIDN2_LIBRARY_DIRS}) - if(LIBIDN2_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${LIBIDN2_CFLAGS}") - endif() + set(CURL_LIBS CURL::libidn2 ${CURL_LIBS}) set(HAVE_IDN2_H 1) set(HAVE_LIBIDN2 1) endif() @@ -1329,17 +1209,9 @@ endif() option(CURL_USE_LIBPSL "Use libpsl" ON) mark_as_advanced(CURL_USE_LIBPSL) set(USE_LIBPSL OFF) - if(CURL_USE_LIBPSL) find_package(Libpsl REQUIRED) - list(APPEND CURL_LIBS ${LIBPSL_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${LIBPSL_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${LIBPSL_PC_REQUIRES}) - include_directories(SYSTEM ${LIBPSL_INCLUDE_DIRS}) - link_directories(${LIBPSL_LIBRARY_DIRS}) - if(LIBPSL_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${LIBPSL_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::libpsl) set(USE_LIBPSL ON) endif() @@ -1347,18 +1219,10 @@ endif() option(CURL_USE_LIBSSH2 "Use libssh2" ON) mark_as_advanced(CURL_USE_LIBSSH2) set(USE_LIBSSH2 OFF) - if(CURL_USE_LIBSSH2) find_package(Libssh2) if(LIBSSH2_FOUND) - set(CURL_LIBS ${LIBSSH2_LIBRARIES} ${CURL_LIBS}) # keep it before TLS-crypto, compression - list(APPEND CURL_LIBDIRS ${LIBSSH2_LIBRARY_DIRS}) - set(LIBCURL_PC_REQUIRES_PRIVATE ${LIBSSH2_PC_REQUIRES} ${LIBCURL_PC_REQUIRES_PRIVATE}) - include_directories(SYSTEM ${LIBSSH2_INCLUDE_DIRS}) - link_directories(${LIBSSH2_LIBRARY_DIRS}) - if(LIBSSH2_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${LIBSSH2_CFLAGS}") - endif() + set(CURL_LIBS CURL::libssh2 ${CURL_LIBS}) # keep it before TLS-crypto, compression set(USE_LIBSSH2 ON) endif() endif() @@ -1368,14 +1232,7 @@ option(CURL_USE_LIBSSH "Use libssh" OFF) mark_as_advanced(CURL_USE_LIBSSH) if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH) find_package(Libssh REQUIRED) - set(CURL_LIBS ${LIBSSH_LIBRARIES} ${CURL_LIBS}) # keep it before TLS-crypto, compression - list(APPEND CURL_LIBDIRS ${LIBSSH_LIBRARY_DIRS}) - set(LIBCURL_PC_REQUIRES_PRIVATE ${LIBSSH_PC_REQUIRES} ${LIBCURL_PC_REQUIRES_PRIVATE}) - include_directories(SYSTEM ${LIBSSH_INCLUDE_DIRS}) - link_directories(${LIBSSH_LIBRARY_DIRS}) - if(LIBSSH_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${LIBSSH_CFLAGS}") - endif() + set(CURL_LIBS CURL::libssh ${CURL_LIBS}) # keep it before TLS-crypto, compression set(USE_LIBSSH ON) endif() @@ -1383,14 +1240,7 @@ option(CURL_USE_GSASL "Use libgsasl" OFF) mark_as_advanced(CURL_USE_GSASL) if(CURL_USE_GSASL) find_package(Libgsasl REQUIRED) - list(APPEND CURL_LIBS ${LIBGSASL_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${LIBGSASL_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${LIBGSASL_PC_REQUIRES}) - include_directories(SYSTEM ${LIBGSASL_INCLUDE_DIRS}) - link_directories(${LIBGSASL_LIBRARY_DIRS}) - if(LIBGSASL_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${LIBGSASL_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::libgsasl) set(USE_GSASL ON) endif() @@ -1402,16 +1252,10 @@ if(CURL_USE_GSSAPI) set(HAVE_GSSAPI ${GSS_FOUND}) if(GSS_FOUND) - list(APPEND CURL_LIBS ${GSS_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${GSS_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${GSS_PC_REQUIRES}) - include_directories(SYSTEM ${GSS_INCLUDE_DIRS}) - link_directories(${GSS_LIBRARY_DIRS}) - if(GSS_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${GSS_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::gss) - if(GSS_FLAVOUR STREQUAL "GNU") + get_target_property(_gss_flavour CURL::gss INTERFACE_CURL_GSS_FLAVOUR) + if(_gss_flavour STREQUAL "GNU") set(HAVE_GSSGNU 1) elseif(GSS_VERSION) # MIT set(CURL_KRB5_VERSION "\"${GSS_VERSION}\"") @@ -1431,8 +1275,7 @@ if(CURL_USE_LIBBACKTRACE) message(FATAL_ERROR "libbacktrace requires debug information") endif() find_package(Libbacktrace REQUIRED) - list(APPEND CURL_LIBS ${LIBBACKTRACE_LIBRARIES}) - include_directories(SYSTEM ${LIBBACKTRACE_INCLUDE_DIRS}) + list(APPEND CURL_LIBS CURL::libbacktrace) set(USE_BACKTRACE ON) endif() @@ -1443,14 +1286,7 @@ if(CURL_USE_LIBUV) message(FATAL_ERROR "Using libuv without debug support enabled is useless") endif() find_package(Libuv REQUIRED) - list(APPEND CURL_LIBS ${LIBUV_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${LIBUV_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${LIBUV_PC_REQUIRES}) - include_directories(SYSTEM ${LIBUV_INCLUDE_DIRS}) - link_directories(${LIBUV_LIBRARY_DIRS}) - if(LIBUV_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${LIBUV_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::libuv) set(USE_LIBUV ON) set(HAVE_UV_H ON) endif() @@ -1458,14 +1294,7 @@ endif() option(USE_LIBRTMP "Enable librtmp from rtmpdump" OFF) if(USE_LIBRTMP) find_package(Librtmp REQUIRED) - list(APPEND CURL_LIBS ${LIBRTMP_LIBRARIES}) - list(APPEND CURL_LIBDIRS ${LIBRTMP_LIBRARY_DIRS}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${LIBRTMP_PC_REQUIRES}) - include_directories(SYSTEM ${LIBRTMP_INCLUDE_DIRS}) - link_directories(${LIBRTMP_LIBRARY_DIRS}) - if(LIBRTMP_CFLAGS) - string(APPEND CMAKE_C_FLAGS " ${LIBRTMP_CFLAGS}") - endif() + list(APPEND CURL_LIBS CURL::librtmp) endif() option(ENABLE_UNIX_SOCKETS "Enable Unix domain sockets support" ON) @@ -1964,6 +1793,28 @@ if(CURL_CODE_COVERAGE) list(APPEND CURL_LIBS ${CURL_COVERAGE_LIBS}) endif() +# Hack to add some libraries to the end of the library list to make binutils ld +# for GCC find symbols when linking statically. Necessary for libs detected via +# CMake's built-in find modules, which CMake adds to the beginning of the lib +# list on the linker command-line for some reason. This makes them appear +# before dependencies detected via curl's custom Find modules, and breaks +# linkers sensitive to lib order. There must be a better solution to this. +if(CMAKE_C_COMPILER_ID STREQUAL "GNU") + foreach(_lib IN ITEMS OpenSSL::Crypto ZLIB::ZLIB) + if(TARGET "${_lib}") + add_library(CURL::${_lib} INTERFACE IMPORTED) + get_target_property(_libname "${_lib}" LOCATION) + set_target_properties(${_lib} PROPERTIES INTERFACE_LINK_LIBRARIES "${_libname}") + list(APPEND CURL_LIBS ${_lib}) + endif() + endforeach() + if(WIN32) + add_library(CURL::win32_winsock INTERFACE IMPORTED) + set_target_properties(CURL::win32_winsock PROPERTIES INTERFACE_LINK_LIBRARIES "ws2_32") + list(APPEND CURL_LIBS CURL::win32_winsock) + endif() +endif() + if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") # MSVC but exclude clang-cl set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-MP") # Parallel compilation endif() @@ -2028,8 +1879,6 @@ endif() add_subdirectory(scripts) # for shell completions -list(REMOVE_DUPLICATES CURL_LIBDIRS) - add_subdirectory(lib) if(BUILD_CURL_EXE) @@ -2252,67 +2101,104 @@ if(NOT CURL_DISABLE_INSTALL) endif() endforeach() - foreach(_libdir IN LISTS _custom_libdirs CURL_LIBDIRS) - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20) - cmake_path(SET _libdir NORMALIZE "${_libdir}") - endif() - list(FIND _sys_libdirs "${_libdir}" _libdir_index) - if(_libdir_index LESS 0) - list(APPEND _ldflags "-L${_libdir}") - endif() - endforeach() - set(_implicit_libs "") if(NOT MINGW AND NOT UNIX) set(_implicit_libs "${CMAKE_C_IMPLICIT_LINK_LIBRARIES}") endif() - foreach(_lib IN LISTS _implicit_libs _custom_libs CURL_LIBS) + set(_explicit_libdirs "") + set(LIBCURL_PC_REQUIRES_PRIVATE "") + set(LIBCURL_PC_LIBS_PRIVATE_LIST "") + foreach(_lib IN LISTS CURL_LIBS _custom_libs _implicit_libs) if(TARGET "${_lib}") - set(_libname "${_lib}") - get_target_property(_imported "${_libname}" IMPORTED) + set(_explicit_libs "") + get_target_property(_imported "${_lib}" IMPORTED) if(NOT _imported) # Reading the LOCATION property on non-imported target will error out. # Assume the user will not need this information in the .pc file. continue() endif() - get_target_property(_lib "${_libname}" LOCATION) - if(NOT _lib) - message(WARNING "Bad lib in library list: ${_libname}") - continue() - endif() - endif() - if(_lib MATCHES "^-") # '-framework ' - list(APPEND _ldflags "${_lib}") - elseif(_lib MATCHES "/") - # This gets a bit more complex, because we want to specify the - # directory separately, and only once per directory - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20) - cmake_path(GET _lib PARENT_PATH _libdir) - cmake_path(GET _lib STEM _libname) + if(_lib MATCHES "CURL::") + # This is empty for 'CURL::*' targets and safe to ignore. + # Explicitly skip this query to avoid CMake v3.18 and older erroring out. + set(_libname "") else() - get_filename_component(_libdir "${_lib}" DIRECTORY) - get_filename_component(_libname "${_lib}" NAME_WE) + get_target_property(_libname "${_lib}" LOCATION) endif() - if(_libname MATCHES "^lib") - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20) - cmake_path(SET _libdir NORMALIZE "${_libdir}") + if(_libname) + list(APPEND _explicit_libs "${_libname}") + else() + get_target_property(_libs "${_lib}" INTERFACE_LINK_LIBRARIES) + if(_libs) + list(APPEND _explicit_libs "${_libs}") endif() - list(FIND _sys_libdirs "${_libdir}" _libdir_index) - if(_libdir_index LESS 0) - list(APPEND _ldflags "-L${_libdir}") + get_target_property(_libdirs "${_lib}" INTERFACE_LINK_DIRECTORIES) + if(_libdirs) + list(APPEND _explicit_libdirs "${_libdirs}") endif() - string(REGEX REPLACE "^lib" "" _libname "${_libname}") - list(APPEND LIBCURL_PC_LIBS_PRIVATE "-l${_libname}") - else() - list(APPEND LIBCURL_PC_LIBS_PRIVATE "${_lib}") endif() + if(NOT _libname AND NOT _libs AND NOT _libdirs) + message(WARNING "Bad lib in library list: ${_lib}") + endif() + get_target_property(_modules "${_lib}" INTERFACE_LIBCURL_PC_MODULES) + if(_modules) + list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "${_modules}") + endif() + + foreach(_lib IN LISTS _explicit_libs) + if(_lib MATCHES "/") + # This gets a bit more complex, because we want to specify the + # directory separately, and only once per directory + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20) + cmake_path(GET _lib PARENT_PATH _libdir) + cmake_path(GET _lib STEM _libname) + else() + get_filename_component(_libdir "${_lib}" DIRECTORY) + get_filename_component(_libname "${_lib}" NAME_WE) + endif() + if(_libname MATCHES "^lib") + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20) + cmake_path(SET _libdir NORMALIZE "${_libdir}") + endif() + list(FIND _sys_libdirs "${_libdir}" _libdir_index) + if(_libdir_index LESS 0) + list(APPEND _ldflags "-L${_libdir}") + endif() + string(REGEX REPLACE "^lib" "" _libname "${_libname}") + list(APPEND LIBCURL_PC_LIBS_PRIVATE "-l${_libname}") + list(APPEND LIBCURL_PC_LIBS_PRIVATE_LIST "${_lib}") + else() + list(APPEND LIBCURL_PC_LIBS_PRIVATE "${_lib}") + list(APPEND LIBCURL_PC_LIBS_PRIVATE_LIST "${_lib}") + endif() + else() + list(APPEND LIBCURL_PC_LIBS_PRIVATE "-l${_lib}") + list(APPEND LIBCURL_PC_LIBS_PRIVATE_LIST "${_lib}") + endif() + endforeach() + elseif(_lib MATCHES "^-") # '-framework ' + list(APPEND _ldflags "${_lib}") + list(APPEND LIBCURL_PC_LIBS_PRIVATE_LIST "${_lib}") else() list(APPEND LIBCURL_PC_LIBS_PRIVATE "-l${_lib}") + list(APPEND LIBCURL_PC_LIBS_PRIVATE_LIST "${_lib}") endif() endforeach() + foreach(_libdir IN LISTS _custom_libdirs _explicit_libdirs) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20) + cmake_path(SET _libdir NORMALIZE "${_libdir}") + endif() + list(FIND _sys_libdirs "${_libdir}" _libdir_index) + if(_libdir_index LESS 0) + list(APPEND _ldflags "-L${_libdir}") + endif() + endforeach() + + list(REMOVE_DUPLICATES _ldflags) + if(LIBCURL_PC_REQUIRES_PRIVATE) + list(REMOVE_DUPLICATES LIBCURL_PC_REQUIRES_PRIVATE) string(REPLACE ";" "," LIBCURL_PC_REQUIRES_PRIVATE "${LIBCURL_PC_REQUIRES_PRIVATE}") endif() if(LIBCURL_PC_LIBS_PRIVATE) @@ -2424,13 +2310,37 @@ if(NOT CURL_DISABLE_INSTALL) # Consumed custom variables: # CURLVERSION + # LIBCURL_PC_LIBS_PRIVATE_LIST # LIB_NAME # LIB_SELECTED + # LIB_STATIC # TARGETS_EXPORT_NAME - # USE_OPENSSL OPENSSL_VERSION_MAJOR - # HAVE_LIBZ ZLIB_VERSION_MAJOR # CURL_SUPPORTED_FEATURES_LIST # CURL_SUPPORTED_PROTOCOLS_LIST + # HAVE_BROTLI + # HAVE_GSSAPI + # HAVE_LIBIDN2 + # HAVE_LIBZ ZLIB_VERSION_MAJOR + # HAVE_ZSTD + # USE_ARES + # USE_BACKTRACE + # USE_GNUTLS + # USE_GSASL + # USE_LIBPSL + # USE_LIBRTMP + # USE_LIBSSH + # USE_LIBSSH2 + # USE_LIBUV + # USE_MBEDTLS + # USE_NGHTTP2 + # USE_NGHTTP3 + # USE_NGTCP2 + # USE_OPENSSL OPENSSL_VERSION_MAJOR + # USE_QUICHE + # USE_RUSTLS + # USE_WIN32_LDAP CURL_DISABLE_LDAP + # USE_WOLFSSL + # _win32_winsock configure_package_config_file("CMake/curl-config.cmake.in" "${_project_config}" INSTALL_DESTINATION ${_install_cmake_dir} @@ -2442,7 +2352,32 @@ if(NOT CURL_DISABLE_INSTALL) DESTINATION ${_install_cmake_dir}) endif() - install(FILES ${_version_config} ${_project_config} + install( + FILES + ${_version_config} + ${_project_config} + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindBrotli.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindCares.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindGSS.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindGnuTLS.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindLDAP.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindLibbacktrace.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindLibgsasl.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindLibidn2.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindLibpsl.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindLibrtmp.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindLibssh.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindLibssh2.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindLibuv.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindMbedTLS.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindNGHTTP2.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindNGHTTP3.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindNGTCP2.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindNettle.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindQuiche.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindRustls.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindWolfSSL.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindZstd.cmake" DESTINATION ${_install_cmake_dir}) if(NOT TARGET curl_uninstall) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index b468eec0a2e4..5ce288a0a897 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -44,7 +44,7 @@ if(CURL_BUILD_TESTING) # special libcurlu library just for unittests add_library(curlu STATIC EXCLUDE_FROM_ALL ${HHEADERS} ${CSOURCES}) target_compile_definitions(curlu PUBLIC "CURL_STATICLIB" "UNITTESTS") - target_link_libraries(curlu PRIVATE ${CURL_LIBS}) + target_link_libraries(curlu PUBLIC ${CURL_LIBS}) # There is plenty of parallelism when building the testdeps target. # Override the curlu batch size with the maximum to optimize performance. set_target_properties(curlu PROPERTIES UNITY_BUILD_BATCH_SIZE 0 C_CLANG_TIDY "") @@ -151,8 +151,7 @@ if(BUILD_STATIC_LIBS) set_target_properties(${LIB_STATIC} PROPERTIES PREFIX "" OUTPUT_NAME "${LIBCURL_OUTPUT_NAME}" SUFFIX "${STATIC_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}" - INTERFACE_COMPILE_DEFINITIONS "CURL_STATICLIB" - INTERFACE_LINK_DIRECTORIES "${CURL_LIBDIRS}") + INTERFACE_COMPILE_DEFINITIONS "CURL_STATICLIB") if(CURL_HIDES_PRIVATE_SYMBOLS) set_property(TARGET ${LIB_STATIC} APPEND PROPERTY COMPILE_OPTIONS "${CURL_CFLAG_SYMBOLS_HIDE}") set_property(TARGET ${LIB_STATIC} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS") @@ -174,6 +173,27 @@ if(BUILD_STATIC_LIBS) target_include_directories(${LIB_STATIC} INTERFACE "$" "$") + + # CMake before CMP0099 (CMake 3.17 2020-03-20) did not propagate libdirs to + # targets. It expected libs to have an absolute filename. As a workaround, + # manually apply dependency libdirs, for CMake consumers without this policy. + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17) + cmake_policy(GET CMP0099 _has_CMP0099) # https://cmake.org/cmake/help/latest/policy/CMP0099.html + endif() + if(NOT _has_CMP0099 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.13 AND CURL_LIBS) + set(_libdirs "") + foreach(_lib IN LISTS CURL_LIBS) + if(TARGET "${_lib}") + get_target_property(_libdir "${_lib}" INTERFACE_LINK_DIRECTORIES) + if(_libdir) + list(APPEND _libdirs "${_libdir}") + endif() + endif() + endforeach() + if(_libdirs) + target_link_directories(${LIB_STATIC} INTERFACE ${_libdirs}) + endif() + endif() endif() if(BUILD_SHARED_LIBS) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 33f288b91591..7d28434bd38e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -109,12 +109,13 @@ target_link_libraries(${EXE_NAME} ${LIB_SELECTED_FOR_EXE} ${CURL_LIBS}) add_executable(${PROJECT_NAME}::${EXE_NAME} ALIAS ${EXE_NAME}) add_executable(curlinfo EXCLUDE_FROM_ALL "curlinfo.c") +target_link_libraries(curlinfo PRIVATE ${CURL_LIBS}) set_target_properties(curlinfo PROPERTIES UNITY_BUILD OFF) # special libcurltool library just for unittests add_library(curltool STATIC EXCLUDE_FROM_ALL ${CURL_CFILES} ${CURL_HFILES} ${_curlx_cfiles_lib} ${_curlx_hfiles_lib}) target_compile_definitions(curltool PUBLIC "CURL_STATICLIB" "UNITTESTS") -target_link_libraries(curltool PRIVATE ${CURL_LIBS}) +target_link_libraries(curltool PUBLIC ${CURL_LIBS}) set_target_properties(curltool PROPERTIES C_CLANG_TIDY "") if(CURL_HAS_LTO) diff --git a/tests/cmake/test.sh b/tests/cmake/test.sh index 451235484ef6..a871372ab644 100755 --- a/tests/cmake/test.sh +++ b/tests/cmake/test.sh @@ -114,7 +114,7 @@ if [ "${mode}" = 'all' ] || [ "${mode}" = 'find_package' ]; then "${cmake_provider}" --install "${bldp}" else mkdir "${bldp}"; cd "${bldp}" - "${cmake_provider}" "${src}" -G "${gen}" ${cmake_opts} -DCURL_USE_PKGCONFIG=OFF ${TEST_CMAKE_FLAGS:-} "$@" \ + "${cmake_provider}" "${src}" -G "${gen}" ${cmake_opts} ${TEST_CMAKE_FLAGS:-} "$@" \ -DBUILD_SHARED_LIBS=ON \ -DBUILD_STATIC_LIBS=ON \ -DCMAKE_INSTALL_PREFIX="${prefix}" From ed331cea80c607344a19b400ab9abf25af09dc36 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 29 Nov 2025 14:17:04 +0100 Subject: [PATCH 118/140] cmake: save and restore `CMAKE_MODULE_PATH` in `curl-config.cmake` Reported-by: Kai Pastor Bug: https://github.com/curl/curl/pull/16973#discussion_r2572957270 Follow-up to 16f073ef49f94412000218c9f6ad04e3fd7e4d01 #16973 Closes #19758 --- CMake/curl-config.cmake.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMake/curl-config.cmake.in b/CMake/curl-config.cmake.in index 99949198a305..c4e9f59e863b 100644 --- a/CMake/curl-config.cmake.in +++ b/CMake/curl-config.cmake.in @@ -26,6 +26,8 @@ option(CURL_USE_PKGCONFIG "Enable pkg-config to detect @PROJECT_NAME@ dependencies. Default: @CURL_USE_PKGCONFIG@" "@CURL_USE_PKGCONFIG@") include(CMakeFindDependencyMacro) + +set(_curl_cmake_module_path_save ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH}) set(_libs "") @@ -126,6 +128,8 @@ if("@HAVE_ZSTD@") list(APPEND _libs CURL::zstd) endif() +set(CMAKE_MODULE_PATH ${_curl_cmake_module_path_save}) + if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND WIN32 AND NOT TARGET CURL::win32_winsock) add_library(CURL::win32_winsock INTERFACE IMPORTED) set_target_properties(CURL::win32_winsock PROPERTIES INTERFACE_LINK_LIBRARIES "@_win32_winsock@") From 545f2f387d41b4a356705a08c1154c807f4dbb7d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 29 Nov 2025 16:07:59 +0100 Subject: [PATCH 119/140] lib/sendf.h: forward declare two structs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To fix non-unity builds using certain header orders (seen in ntlm.c with the include order changed): ``` lib/vauth/../sendf.h:117:27: error: ‘struct Curl_cwriter’ declared inside parameter list will not be visible outside of this definition or declaration [-Werror] 117 | struct Curl_cwriter *writer); | ^~~~~~~~~~~~ lib/vauth/../sendf.h:215:54: error: ‘struct Curl_creader’ declared inside parameter list will not be visible outside of this definition or declaration [-Werror] 215 | CURLcode (*do_init)(struct Curl_easy *data, struct Curl_creader *reader); | ^~~~~~~~~~~~ [...] ``` Ref: https://github.com/curl/curl/actions/runs/19785420705/job/56691185397?pr=19760 Ref: #19760 Closes #19761 --- lib/sendf.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sendf.h b/lib/sendf.h index 686744390102..3a6dccba6a3d 100644 --- a/lib/sendf.h +++ b/lib/sendf.h @@ -52,6 +52,10 @@ #define CLIENTWRITE_EOS (1<<7) /* End Of transfer download Stream */ #define CLIENTWRITE_0LEN (1<<8) /* write even 0-length buffers */ +/* Forward declarations */ +struct Curl_creader; +struct Curl_cwriter; + /** * Write `len` bytes at `prt` to the client. `type` indicates what * kind of data is being written. From db32c0721f9cfbefe6a42b828ef7bfc4b40f71ac Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 28 Nov 2025 23:59:23 +0100 Subject: [PATCH 120/140] rustls: verify that verifier_builder is not NULL Since this function returns allocated resources there is probably at least a theoretical risk this can return NULL. Pointed out by ZeroPath Closes #19756 --- lib/vtls/rustls.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/vtls/rustls.c b/lib/vtls/rustls.c index e4251a915198..0c13cc81eebb 100644 --- a/lib/vtls/rustls.c +++ b/lib/vtls/rustls.c @@ -750,6 +750,10 @@ init_config_builder_verifier(struct Curl_easy *data, } verifier_builder = rustls_web_pki_server_cert_verifier_builder_new(roots); + if(!verifier_builder) { + result = CURLE_OUT_OF_MEMORY; + goto cleanup; + } if(conn_config->CRLfile) { result = init_config_builder_verifier_crl(data, From 985f86f0be42a69bae91e9209016e5f7fe3346da Mon Sep 17 00:00:00 2001 From: Daniel McCarney Date: Sat, 29 Nov 2025 09:30:48 -0500 Subject: [PATCH 121/140] rustls: simplify init err path Closes #19759 --- lib/vtls/rustls.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/vtls/rustls.c b/lib/vtls/rustls.c index 0c13cc81eebb..360a2454ac85 100644 --- a/lib/vtls/rustls.c +++ b/lib/vtls/rustls.c @@ -744,9 +744,7 @@ init_config_builder_verifier(struct Curl_easy *data, if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "failed to build trusted root certificate store"); result = CURLE_SSL_CACERT_BADFILE; - if(result) { - goto cleanup; - } + goto cleanup; } verifier_builder = rustls_web_pki_server_cert_verifier_builder_new(roots); From c3add7130d7d81add205edbbb75fdfd1f38b3c68 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 29 Nov 2025 19:51:45 +0100 Subject: [PATCH 122/140] mbedtls: replace macro constant with `CURL_ARRAYSIZE()` Also move from `int` to `size_t` for index variables. Closes #19762 --- lib/vtls/mbedtls_threadlock.c | 23 ++++++++++------------- lib/vtls/mbedtls_threadlock.h | 4 ++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/vtls/mbedtls_threadlock.c b/lib/vtls/mbedtls_threadlock.c index 91de9eceb59b..89cc2b7d38df 100644 --- a/lib/vtls/mbedtls_threadlock.c +++ b/lib/vtls/mbedtls_threadlock.c @@ -37,17 +37,14 @@ #include "mbedtls_threadlock.h" -/* number of thread locks */ -#define NUMT 2 - -/* This array stores the mutexes available to Mbedtls */ -static MBEDTLS_MUTEX_T mutex_buf[NUMT]; +/* This array stores the mutexes available to mbedTLS */ +static MBEDTLS_MUTEX_T mutex_buf[2]; int Curl_mbedtlsthreadlock_thread_setup(void) { - int i; + size_t i; - for(i = 0; i < NUMT; i++) { + for(i = 0; i < CURL_ARRAYSIZE(mutex_buf); i++) { #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) if(pthread_mutex_init(&mutex_buf[i], NULL)) return 0; /* pthread_mutex_init failed */ @@ -63,9 +60,9 @@ int Curl_mbedtlsthreadlock_thread_setup(void) int Curl_mbedtlsthreadlock_thread_cleanup(void) { - int i; + size_t i; - for(i = 0; i < NUMT; i++) { + for(i = 0; i < CURL_ARRAYSIZE(mutex_buf); i++) { #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) if(pthread_mutex_destroy(&mutex_buf[i])) return 0; /* pthread_mutex_destroy failed */ @@ -78,9 +75,9 @@ int Curl_mbedtlsthreadlock_thread_cleanup(void) return 1; /* OK */ } -int Curl_mbedtlsthreadlock_lock_function(int n) +int Curl_mbedtlsthreadlock_lock_function(size_t n) { - if(n < NUMT) { + if(n < CURL_ARRAYSIZE(mutex_buf)) { #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) if(pthread_mutex_lock(&mutex_buf[n])) { DEBUGF(curl_mfprintf(stderr, "Error: " @@ -98,9 +95,9 @@ int Curl_mbedtlsthreadlock_lock_function(int n) return 1; /* OK */ } -int Curl_mbedtlsthreadlock_unlock_function(int n) +int Curl_mbedtlsthreadlock_unlock_function(size_t n) { - if(n < NUMT) { + if(n < CURL_ARRAYSIZE(mutex_buf)) { #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) if(pthread_mutex_unlock(&mutex_buf[n])) { DEBUGF(curl_mfprintf(stderr, "Error: " diff --git a/lib/vtls/mbedtls_threadlock.h b/lib/vtls/mbedtls_threadlock.h index 9402af6e415a..1855d4cc0187 100644 --- a/lib/vtls/mbedtls_threadlock.h +++ b/lib/vtls/mbedtls_threadlock.h @@ -33,8 +33,8 @@ int Curl_mbedtlsthreadlock_thread_setup(void); int Curl_mbedtlsthreadlock_thread_cleanup(void); -int Curl_mbedtlsthreadlock_lock_function(int n); -int Curl_mbedtlsthreadlock_unlock_function(int n); +int Curl_mbedtlsthreadlock_lock_function(size_t n); +int Curl_mbedtlsthreadlock_unlock_function(size_t n); #else From 0eed8b73309fbfb113002f4da8a6d92acff4871f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 29 Nov 2025 23:44:23 +0100 Subject: [PATCH 123/140] tool_operatate: return error for OOM in append2query Closes #19763 --- src/tool_operate.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tool_operate.c b/src/tool_operate.c index 968dc864f9f6..71d29af8d8b0 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -848,6 +848,8 @@ static CURLcode append2query(struct OperationConfig *config, } curl_url_cleanup(uh); } + else + result = CURLE_OUT_OF_MEMORY; return result; } From 2253bc330f56315faaa287c29d7612f5a34d8058 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 29 Nov 2025 02:16:52 +0100 Subject: [PATCH 124/140] lib/subdirs: fix formatting nits Closes #19757 --- lib/curlx/base64.c | 20 +- lib/curlx/dynbuf.c | 1 - lib/curlx/dynbuf.h | 22 +-- lib/curlx/fopen.h | 11 +- lib/curlx/inet_ntop.c | 11 +- lib/curlx/inet_ntop.h | 4 +- lib/curlx/inet_pton.c | 23 +-- lib/curlx/inet_pton.h | 6 +- lib/curlx/nonblock.c | 2 +- lib/curlx/strerr.c | 3 +- lib/curlx/strparse.c | 8 +- lib/curlx/timediff.c | 2 +- lib/curlx/timeval.c | 34 ++-- lib/curlx/wait.c | 2 +- lib/curlx/warnless.c | 121 ++++++------ lib/curlx/warnless.h | 2 +- lib/curlx/winapi.c | 5 +- lib/vauth/cleartext.c | 7 +- lib/vauth/cram.c | 2 +- lib/vauth/digest.c | 76 ++++---- lib/vauth/digest_sspi.c | 16 +- lib/vauth/gsasl.c | 2 +- lib/vauth/krb5_gssapi.c | 2 +- lib/vauth/krb5_sspi.c | 3 +- lib/vauth/ntlm.c | 5 +- lib/vauth/ntlm_sspi.c | 13 +- lib/vauth/oauth2.c | 2 +- lib/vauth/spnego_sspi.c | 14 +- lib/vauth/vauth.c | 16 +- lib/vquic/curl_ngtcp2.c | 128 +++++++------ lib/vquic/curl_osslq.c | 99 +++++----- lib/vquic/curl_quiche.c | 31 ++- lib/vquic/vquic-tls.c | 7 +- lib/vquic/vquic-tls.h | 16 +- lib/vquic/vquic.c | 9 +- lib/vquic/vquic_int.h | 25 ++- lib/vssh/libssh.c | 333 ++++++++++++++++---------------- lib/vssh/libssh2.c | 347 ++++++++++++++++------------------ lib/vssh/ssh.h | 6 +- lib/vssh/vssh.c | 3 +- lib/vtls/apple.c | 5 +- lib/vtls/cipher_suite.c | 42 ++-- lib/vtls/gtls.c | 84 ++++---- lib/vtls/gtls.h | 3 +- lib/vtls/hostcheck.c | 4 +- lib/vtls/keylog.c | 19 +- lib/vtls/mbedtls.c | 73 ++++--- lib/vtls/mbedtls_threadlock.c | 5 +- lib/vtls/mbedtls_threadlock.h | 3 +- lib/vtls/openssl.c | 148 ++++++--------- lib/vtls/openssl.h | 3 +- lib/vtls/rustls.c | 176 ++++++++--------- lib/vtls/schannel.c | 160 +++++++--------- lib/vtls/schannel.h | 9 +- lib/vtls/schannel_verify.c | 51 ++--- lib/vtls/vtls.c | 53 +++--- lib/vtls/vtls.h | 12 +- lib/vtls/vtls_int.h | 20 +- lib/vtls/vtls_scache.c | 54 +++--- lib/vtls/vtls_scache.h | 26 ++- lib/vtls/vtls_spack.c | 31 ++- lib/vtls/wolfssl.c | 113 +++++------ lib/vtls/wolfssl.h | 9 +- lib/vtls/x509asn1.c | 54 +++--- 64 files changed, 1199 insertions(+), 1397 deletions(-) diff --git a/lib/curlx/base64.c b/lib/curlx/base64.c index 6a24c20ebdfb..4fc525387e5f 100644 --- a/lib/curlx/base64.c +++ b/lib/curlx/base64.c @@ -31,12 +31,12 @@ #include "base64.h" /* ---- Base64 Encoding/Decoding Table --- */ -const char Curl_base64encdec[]= +const char Curl_base64encdec[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /* The Base 64 encoding with a URL and filename safe alphabet, RFC 4648 section 5 */ -static const char base64url[]= +static const char base64url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; static const unsigned char decodetable[] = @@ -188,18 +188,18 @@ static CURLcode base64_encode(const char *table64, return CURLE_OUT_OF_MEMORY; while(insize >= 3) { - *output++ = table64[ in[0] >> 2 ]; - *output++ = table64[ ((in[0] & 0x03) << 4) | (in[1] >> 4) ]; - *output++ = table64[ ((in[1] & 0x0F) << 2) | ((in[2] & 0xC0) >> 6) ]; - *output++ = table64[ in[2] & 0x3F ]; + *output++ = table64[in[0] >> 2]; + *output++ = table64[((in[0] & 0x03) << 4) | (in[1] >> 4)]; + *output++ = table64[((in[1] & 0x0F) << 2) | ((in[2] & 0xC0) >> 6)]; + *output++ = table64[in[2] & 0x3F]; insize -= 3; in += 3; } if(insize) { /* this is only one or two bytes now */ - *output++ = table64[ in[0] >> 2 ]; + *output++ = table64[in[0] >> 2]; if(insize == 1) { - *output++ = table64[ ((in[0] & 0x03) << 4) ]; + *output++ = table64[((in[0] & 0x03) << 4)]; if(padbyte) { *output++ = padbyte; *output++ = padbyte; @@ -207,8 +207,8 @@ static CURLcode base64_encode(const char *table64, } else { /* insize == 2 */ - *output++ = table64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xF0) >> 4) ]; - *output++ = table64[ ((in[1] & 0x0F) << 2) ]; + *output++ = table64[((in[0] & 0x03) << 4) | ((in[1] & 0xF0) >> 4)]; + *output++ = table64[((in[1] & 0x0F) << 2)]; if(padbyte) *output++ = padbyte; } diff --git a/lib/curlx/dynbuf.c b/lib/curlx/dynbuf.c index e54865f933c7..a9ff48367f62 100644 --- a/lib/curlx/dynbuf.c +++ b/lib/curlx/dynbuf.c @@ -156,7 +156,6 @@ CURLcode curlx_dyn_tail(struct dynbuf *s, size_t trail) s->bufr[s->leng] = 0; } return CURLE_OK; - } /* diff --git a/lib/curlx/dynbuf.h b/lib/curlx/dynbuf.h index 00ca04789360..683b484610bb 100644 --- a/lib/curlx/dynbuf.h +++ b/lib/curlx/dynbuf.h @@ -32,7 +32,7 @@ struct dynbuf { size_t allc; /* size of the current allocation */ size_t toobig; /* size limit for the buffer */ #ifdef DEBUGBUILD - int init; /* detect API usage mistakes */ + int init; /* detect API usage mistakes */ #endif }; @@ -62,24 +62,24 @@ int curlx_dyn_vprintf(struct dynbuf *dyn, const char *format, va_list ap_save); char *curlx_dyn_take(struct dynbuf *s, size_t *plen); /* Dynamic buffer max sizes */ -#define MAX_DYNBUF_SIZE (SIZE_MAX/2) +#define MAX_DYNBUF_SIZE (SIZE_MAX / 2) #define DYN_DOH_RESPONSE 3000 #define DYN_DOH_CNAME 256 #define DYN_PAUSE_BUFFER (64 * 1024 * 1024) #define DYN_HAXPROXY 2048 -#define DYN_HTTP_REQUEST (1024*1024) +#define DYN_HTTP_REQUEST (1024 * 1024) #define DYN_APRINTF 8000000 -#define DYN_RTSP_REQ_HEADER (64*1024) -#define DYN_TRAILERS (64*1024) +#define DYN_RTSP_REQ_HEADER (64 * 1024) +#define DYN_TRAILERS (64 * 1024) #define DYN_PROXY_CONNECT_HEADERS 16384 #define DYN_QLOG_NAME 1024 #define DYN_H1_TRAILER 4096 -#define DYN_PINGPPONG_CMD (64*1024) -#define DYN_IMAP_CMD (64*1024) -#define DYN_MQTT_RECV (64*1024) +#define DYN_PINGPPONG_CMD (64 * 1024) +#define DYN_IMAP_CMD (64 * 1024) +#define DYN_MQTT_RECV (64 * 1024) #define DYN_MQTT_SEND 0xFFFFFFF -#define DYN_CRLFILE_SIZE (400*1024*1024) /* 400mb */ -#define DYN_CERTFILE_SIZE (100*1024) /* 100KiB */ -#define DYN_KEYFILE_SIZE (100*1024) /* 100KiB */ +#define DYN_CRLFILE_SIZE (400 * 1024 * 1024) /* 400MiB */ +#define DYN_CERTFILE_SIZE (100 * 1024) /* 100KiB */ +#define DYN_KEYFILE_SIZE (100 * 1024) /* 100KiB */ #endif diff --git a/lib/curlx/fopen.h b/lib/curlx/fopen.h index eeb3fda9469c..fb3277a17e7d 100644 --- a/lib/curlx/fopen.h +++ b/lib/curlx/fopen.h @@ -51,11 +51,12 @@ int curlx_win32_open(const char *filename, int oflag, ...); #endif #ifdef CURLDEBUG -#define curlx_fopen(file,mode) curl_dbg_fopen(file,mode,__LINE__,__FILE__) -#define curlx_freopen(file,mode,fh) \ - curl_dbg_freopen(file,mode,fh,__LINE__,__FILE__) -#define curlx_fdopen(file,mode) curl_dbg_fdopen(file,mode,__LINE__,__FILE__) -#define curlx_fclose(file) curl_dbg_fclose(file,__LINE__,__FILE__) +#define curlx_fopen(file, mode) curl_dbg_fopen(file, mode, __LINE__, __FILE__) +#define curlx_freopen(file, mode, fh) \ + curl_dbg_freopen(file, mode, fh, __LINE__, __FILE__) +#define curlx_fdopen(file, mode) \ + curl_dbg_fdopen(file, mode, __LINE__, __FILE__) +#define curlx_fclose(file) curl_dbg_fclose(file, __LINE__, __FILE__) #else #define curlx_fopen CURLX_FOPEN_LOW #define curlx_freopen CURLX_FREOPEN_LOW diff --git a/lib/curlx/inet_ntop.c b/lib/curlx/inet_ntop.c index 771af81474e7..96c58273e2a1 100644 --- a/lib/curlx/inet_ntop.c +++ b/lib/curlx/inet_ntop.c @@ -109,17 +109,18 @@ static char *inet_ntop6(const unsigned char *src, char *dst, size_t size) */ memset(words, '\0', sizeof(words)); for(i = 0; i < IN6ADDRSZ; i++) - words[i/2] |= ((unsigned int)src[i] << ((1 - (i % 2)) << 3)); + words[i / 2] |= ((unsigned int)src[i] << ((1 - (i % 2)) << 3)); best.base = -1; - cur.base = -1; + cur.base = -1; best.len = 0; cur.len = 0; for(i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { if(words[i] == 0) { if(cur.base == -1) { - cur.base = i; cur.len = 1; + cur.base = i; + cur.len = 1; } else cur.len++; @@ -152,7 +153,7 @@ static char *inet_ntop6(const unsigned char *src, char *dst, size_t size) /* Is this address an encapsulated IPv4? */ if(i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { + (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { if(!inet_ntop4(src + 12, tp, sizeof(tmp) - (tp - tmp))) { return NULL; } @@ -219,4 +220,4 @@ char *curlx_inet_ntop(int af, const void *src, char *buf, size_t size) return NULL; } } -#endif /* HAVE_INET_NTOP */ +#endif /* HAVE_INET_NTOP */ diff --git a/lib/curlx/inet_ntop.h b/lib/curlx/inet_ntop.h index 490f49e8a195..79cdc9e2afea 100644 --- a/lib/curlx/inet_ntop.h +++ b/lib/curlx/inet_ntop.h @@ -37,11 +37,11 @@ #include #endif #ifdef __AMIGA__ -#define curlx_inet_ntop(af,addr,buf,size) \ +#define curlx_inet_ntop(af, addr, buf, size) \ (char *)inet_ntop(af, CURL_UNCONST(addr), (unsigned char *)buf, \ (curl_socklen_t)(size)) #else -#define curlx_inet_ntop(af,addr,buf,size) \ +#define curlx_inet_ntop(af, addr, buf, size) \ inet_ntop(af, addr, buf, (curl_socklen_t)(size)) #endif #else diff --git a/lib/curlx/inet_pton.c b/lib/curlx/inet_pton.c index b78fa5d746fb..7b4a4043061d 100644 --- a/lib/curlx/inet_pton.c +++ b/lib/curlx/inet_pton.c @@ -54,8 +54,8 @@ * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ -static int inet_pton4(const char *src, unsigned char *dst); -static int inet_pton6(const char *src, unsigned char *dst); +static int inet_pton4(const char *src, unsigned char *dst); +static int inet_pton6(const char *src, unsigned char *dst); /* int * inet_pton(af, src, dst) @@ -73,8 +73,7 @@ static int inet_pton6(const char *src, unsigned char *dst); * author: * Paul Vixie, 1996. */ -int -curlx_inet_pton(int af, const char *src, void *dst) +int curlx_inet_pton(int af, const char *src, void *dst) { switch(af) { case AF_INET: @@ -98,8 +97,7 @@ curlx_inet_pton(int af, const char *src, void *dst) * author: * Paul Vixie, 1996. */ -static int -inet_pton4(const char *src, unsigned char *dst) +static int inet_pton4(const char *src, unsigned char *dst) { int saw_digit, octets, ch; unsigned char tmp[INADDRSZ], *tp; @@ -151,8 +149,7 @@ inet_pton4(const char *src, unsigned char *dst) * author: * Paul Vixie, 1996. */ -static int -inet_pton6(const char *src, unsigned char *dst) +static int inet_pton6(const char *src, unsigned char *dst) { unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp; const char *curtok; @@ -187,14 +184,14 @@ inet_pton6(const char *src, unsigned char *dst) } if(tp + INT16SZ > endp) return 0; - *tp++ = (unsigned char) ((val >> 8) & 0xff); - *tp++ = (unsigned char) (val & 0xff); + *tp++ = (unsigned char)((val >> 8) & 0xff); + *tp++ = (unsigned char)(val & 0xff); saw_xdigit = 0; val = 0; continue; } if(ch == '.' && ((tp + INADDRSZ) <= endp) && - inet_pton4(curtok, tp) > 0) { + inet_pton4(curtok, tp) > 0) { tp += INADDRSZ; saw_xdigit = 0; break; /* '\0' was seen by inet_pton4(). */ @@ -204,8 +201,8 @@ inet_pton6(const char *src, unsigned char *dst) if(saw_xdigit) { if(tp + INT16SZ > endp) return 0; - *tp++ = (unsigned char) ((val >> 8) & 0xff); - *tp++ = (unsigned char) (val & 0xff); + *tp++ = (unsigned char)((val >> 8) & 0xff); + *tp++ = (unsigned char)(val & 0xff); } if(colonp) { /* diff --git a/lib/curlx/inet_pton.h b/lib/curlx/inet_pton.h index a9ad24c9447f..a52ef145dac5 100644 --- a/lib/curlx/inet_pton.h +++ b/lib/curlx/inet_pton.h @@ -37,9 +37,11 @@ #include #endif #ifdef __AMIGA__ -#define curlx_inet_pton(x,y,z) inet_pton(x,(unsigned char *)CURL_UNCONST(y),z) +#define curlx_inet_pton(x, y, z) \ + inet_pton(x, (unsigned char *)CURL_UNCONST(y), z) #else -#define curlx_inet_pton(x,y,z) inet_pton(x,y,z) +#define curlx_inet_pton(x, y, z) \ + inet_pton(x, y, z) #endif #else int curlx_inet_pton(int, const char *, void *); diff --git a/lib/curlx/nonblock.c b/lib/curlx/nonblock.c index b944f9546bb5..23eb8c0e3ab2 100644 --- a/lib/curlx/nonblock.c +++ b/lib/curlx/nonblock.c @@ -88,6 +88,6 @@ int curlx_nonblock(curl_socket_t sockfd, /* operate on this */ return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); #else -# error "no non-blocking method was found/used/set" +#error "no non-blocking method was found/used/set" #endif } diff --git a/lib/curlx/strerr.c b/lib/curlx/strerr.c index 3dbeab82ee57..70ad1fb813e4 100644 --- a/lib/curlx/strerr.c +++ b/lib/curlx/strerr.c @@ -43,8 +43,7 @@ * codes (WSAGetLastError) to error messages. * Returns NULL if no error message was found for error code. */ -static const char * -get_winsock_error(int err, char *buf, size_t len) +static const char *get_winsock_error(int err, char *buf, size_t len) { #ifndef CURL_DISABLE_VERBOSE_STRINGS const char *p; diff --git a/lib/curlx/strparse.c b/lib/curlx/strparse.c index a29d8be2fdb7..c5a3ed2102e6 100644 --- a/lib/curlx/strparse.c +++ b/lib/curlx/strparse.c @@ -66,8 +66,7 @@ int curlx_str_until(const char **linep, struct Curl_str *out, /* Get a word until the first space or end of string. At least one byte long. return non-zero on error */ -int curlx_str_word(const char **linep, struct Curl_str *out, - const size_t max) +int curlx_str_word(const char **linep, struct Curl_str *out, const size_t max) { return curlx_str_until(linep, out, max, ' '); } @@ -95,7 +94,6 @@ int curlx_str_untilnl(const char **linep, struct Curl_str *out, return STRE_OK; } - /* Get a "quoted" word. No escaping possible. return non-zero on error */ int curlx_str_quotedword(const char **linep, struct Curl_str *out, @@ -141,8 +139,8 @@ int curlx_str_singlespace(const char **linep) } /* given an ASCII character and max ascii, return TRUE if valid */ -#define valid_digit(x,m) \ - (((x) >= '0') && ((x) <= m) && Curl_hexasciitable[(x)-'0']) +#define valid_digit(x, m) \ + (((x) >= '0') && ((x) <= m) && Curl_hexasciitable[(x) - '0']) /* We use 16 for the zero index (and the necessary bitwise AND in the loop) to be able to have a non-zero value there to make valid_digit() able to diff --git a/lib/curlx/timediff.c b/lib/curlx/timediff.c index a90da961ab83..d8baabe63e60 100644 --- a/lib/curlx/timediff.c +++ b/lib/curlx/timediff.c @@ -84,5 +84,5 @@ struct timeval *curlx_mstotv(struct timeval *tv, timediff_t ms) */ timediff_t curlx_tvtoms(struct timeval *tv) { - return (tv->tv_sec*1000) + (timediff_t)(tv->tv_usec/1000); + return (tv->tv_sec * 1000) + (timediff_t)(tv->tv_usec / 1000); } diff --git a/lib/curlx/timeval.c b/lib/curlx/timeval.c index a27525855b0a..ff49d7d27464 100644 --- a/lib/curlx/timeval.c +++ b/lib/curlx/timeval.c @@ -79,7 +79,7 @@ struct curltime curlx_now(void) return now; } -#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC) || \ +#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC) || \ defined(HAVE_CLOCK_GETTIME_MONOTONIC_RAW) struct curltime curlx_now(void) @@ -103,7 +103,7 @@ struct curltime curlx_now(void) ** called on unsupported OS version. */ #if defined(__APPLE__) && defined(HAVE_BUILTIN_AVAILABLE) && \ - (HAVE_BUILTIN_AVAILABLE == 1) + (HAVE_BUILTIN_AVAILABLE == 1) bool have_clock_gettime = FALSE; if(__builtin_available(macOS 10.12, iOS 10, tvOS 10, watchOS 3, *)) have_clock_gettime = TRUE; @@ -111,8 +111,8 @@ struct curltime curlx_now(void) #ifdef HAVE_CLOCK_GETTIME_MONOTONIC_RAW if( -#if defined(__APPLE__) && defined(HAVE_BUILTIN_AVAILABLE) && \ - (HAVE_BUILTIN_AVAILABLE == 1) +#if defined(__APPLE__) && defined(HAVE_BUILTIN_AVAILABLE) && \ + (HAVE_BUILTIN_AVAILABLE == 1) have_clock_gettime && #endif (clock_gettime(CLOCK_MONOTONIC_RAW, &tsnow) == 0)) { @@ -124,7 +124,7 @@ struct curltime curlx_now(void) if( #if defined(__APPLE__) && defined(HAVE_BUILTIN_AVAILABLE) && \ - (HAVE_BUILTIN_AVAILABLE == 1) + (HAVE_BUILTIN_AVAILABLE == 1) have_clock_gettime && #endif (clock_gettime(CLOCK_MONOTONIC, &tsnow) == 0)) { @@ -222,12 +222,12 @@ struct curltime curlx_now(void) */ timediff_t curlx_timediff_ms(struct curltime newer, struct curltime older) { - timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec; - if(diff >= (TIMEDIFF_T_MAX/1000)) + timediff_t diff = (timediff_t)newer.tv_sec - older.tv_sec; + if(diff >= (TIMEDIFF_T_MAX / 1000)) return TIMEDIFF_T_MAX; - else if(diff <= (TIMEDIFF_T_MIN/1000)) + else if(diff <= (TIMEDIFF_T_MIN / 1000)) return TIMEDIFF_T_MIN; - return diff * 1000 + (newer.tv_usec-older.tv_usec)/1000; + return diff * 1000 + (newer.tv_usec - older.tv_usec) / 1000; } /* @@ -237,12 +237,12 @@ timediff_t curlx_timediff_ms(struct curltime newer, struct curltime older) timediff_t curlx_timediff_ceil_ms(struct curltime newer, struct curltime older) { - timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec; - if(diff >= (TIMEDIFF_T_MAX/1000)) + timediff_t diff = (timediff_t)newer.tv_sec - older.tv_sec; + if(diff >= (TIMEDIFF_T_MAX / 1000)) return TIMEDIFF_T_MAX; - else if(diff <= (TIMEDIFF_T_MIN/1000)) + else if(diff <= (TIMEDIFF_T_MIN / 1000)) return TIMEDIFF_T_MIN; - return diff * 1000 + (newer.tv_usec - older.tv_usec + 999)/1000; + return diff * 1000 + (newer.tv_usec - older.tv_usec + 999) / 1000; } /* @@ -251,10 +251,10 @@ timediff_t curlx_timediff_ceil_ms(struct curltime newer, */ timediff_t curlx_timediff_us(struct curltime newer, struct curltime older) { - timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec; - if(diff >= (TIMEDIFF_T_MAX/1000000)) + timediff_t diff = (timediff_t)newer.tv_sec - older.tv_sec; + if(diff >= (TIMEDIFF_T_MAX / 1000000)) return TIMEDIFF_T_MAX; - else if(diff <= (TIMEDIFF_T_MIN/1000000)) + else if(diff <= (TIMEDIFF_T_MIN / 1000000)) return TIMEDIFF_T_MIN; - return diff * 1000000 + newer.tv_usec-older.tv_usec; + return diff * 1000000 + newer.tv_usec - older.tv_usec; } diff --git a/lib/curlx/wait.c b/lib/curlx/wait.c index 4e10a8297a93..f1dd6e7a7e27 100644 --- a/lib/curlx/wait.c +++ b/lib/curlx/wait.c @@ -74,7 +74,7 @@ int curlx_wait_ms(timediff_t timeout_ms) /* prevent overflow, timeout_ms is typecast to ULONG/DWORD. */ #if TIMEDIFF_T_MAX >= ULONG_MAX if(timeout_ms >= ULONG_MAX) - timeout_ms = ULONG_MAX-1; + timeout_ms = ULONG_MAX - 1; /* do not use ULONG_MAX, because that is equal to INFINITE */ #endif Sleep((DWORD)timeout_ms); diff --git a/lib/curlx/warnless.c b/lib/curlx/warnless.c index fafa83c98c97..45442bd46270 100644 --- a/lib/curlx/warnless.c +++ b/lib/curlx/warnless.c @@ -27,10 +27,10 @@ #if defined(__INTEL_COMPILER) && defined(__unix__) #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #endif /* __INTEL_COMPILER && __unix__ */ @@ -56,15 +56,15 @@ unsigned char curlx_ultouc(unsigned long ulnum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif - DEBUGASSERT(ulnum <= (unsigned long) CURL_MASK_UCHAR); - return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR); + DEBUGASSERT(ulnum <= (unsigned long)CURL_MASK_UCHAR); + return (unsigned char)(ulnum & (unsigned long)CURL_MASK_UCHAR); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -75,15 +75,15 @@ unsigned char curlx_ultouc(unsigned long ulnum) int curlx_uztosi(size_t uznum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif - DEBUGASSERT(uznum <= (size_t) CURL_MASK_SINT); - return (int)(uznum & (size_t) CURL_MASK_SINT); + DEBUGASSERT(uznum <= (size_t)CURL_MASK_SINT); + return (int)(uznum & (size_t)CURL_MASK_SINT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -94,17 +94,17 @@ int curlx_uztosi(size_t uznum) unsigned long curlx_uztoul(size_t uznum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif #if ULONG_MAX < SIZE_MAX - DEBUGASSERT(uznum <= (size_t) CURL_MASK_ULONG); + DEBUGASSERT(uznum <= (size_t)CURL_MASK_ULONG); #endif - return (unsigned long)(uznum & (size_t) CURL_MASK_ULONG); + return (unsigned long)(uznum & (size_t)CURL_MASK_ULONG); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -115,17 +115,17 @@ unsigned long curlx_uztoul(size_t uznum) unsigned int curlx_uztoui(size_t uznum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif #if UINT_MAX < SIZE_MAX - DEBUGASSERT(uznum <= (size_t) CURL_MASK_UINT); + DEBUGASSERT(uznum <= (size_t)CURL_MASK_UINT); #endif - return (unsigned int)(uznum & (size_t) CURL_MASK_UINT); + return (unsigned int)(uznum & (size_t)CURL_MASK_UINT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -136,18 +136,18 @@ unsigned int curlx_uztoui(size_t uznum) int curlx_sltosi(long slnum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif DEBUGASSERT(slnum >= 0); #if INT_MAX < LONG_MAX - DEBUGASSERT((unsigned long) slnum <= (unsigned long) CURL_MASK_SINT); + DEBUGASSERT((unsigned long)slnum <= (unsigned long)CURL_MASK_SINT); #endif - return (int)(slnum & (long) CURL_MASK_SINT); + return (int)(slnum & (long)CURL_MASK_SINT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -158,18 +158,18 @@ int curlx_sltosi(long slnum) unsigned int curlx_sltoui(long slnum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif DEBUGASSERT(slnum >= 0); #if UINT_MAX < LONG_MAX - DEBUGASSERT((unsigned long) slnum <= (unsigned long) CURL_MASK_UINT); + DEBUGASSERT((unsigned long)slnum <= (unsigned long)CURL_MASK_UINT); #endif - return (unsigned int)(slnum & (long) CURL_MASK_UINT); + return (unsigned int)(slnum & (long)CURL_MASK_UINT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -180,16 +180,16 @@ unsigned int curlx_sltoui(long slnum) unsigned short curlx_sltous(long slnum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif DEBUGASSERT(slnum >= 0); - DEBUGASSERT((unsigned long) slnum <= (unsigned long) CURL_MASK_USHORT); - return (unsigned short)(slnum & (long) CURL_MASK_USHORT); + DEBUGASSERT((unsigned long)slnum <= (unsigned long)CURL_MASK_USHORT); + return (unsigned short)(slnum & (long)CURL_MASK_USHORT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -200,15 +200,15 @@ unsigned short curlx_sltous(long slnum) ssize_t curlx_uztosz(size_t uznum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif - DEBUGASSERT(uznum <= (size_t) CURL_MASK_SSIZE_T); - return (ssize_t)(uznum & (size_t) CURL_MASK_SSIZE_T); + DEBUGASSERT(uznum <= (size_t)CURL_MASK_SSIZE_T); + return (ssize_t)(uznum & (size_t)CURL_MASK_SSIZE_T); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -219,15 +219,15 @@ ssize_t curlx_uztosz(size_t uznum) size_t curlx_sotouz(curl_off_t sonum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif DEBUGASSERT(sonum >= 0); - return (size_t)(sonum & (curl_off_t) CURL_MASK_USIZE_T); + return (size_t)(sonum & (curl_off_t)CURL_MASK_USIZE_T); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -238,18 +238,18 @@ size_t curlx_sotouz(curl_off_t sonum) int curlx_sztosi(ssize_t sznum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif DEBUGASSERT(sznum >= 0); #if INT_MAX < SSIZE_MAX - DEBUGASSERT((size_t) sznum <= (size_t) CURL_MASK_SINT); + DEBUGASSERT((size_t)sznum <= (size_t)CURL_MASK_SINT); #endif - return (int)(sznum & (ssize_t) CURL_MASK_SINT); + return (int)(sznum & (ssize_t)CURL_MASK_SINT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -260,15 +260,15 @@ int curlx_sztosi(ssize_t sznum) unsigned short curlx_uitous(unsigned int uinum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif - DEBUGASSERT(uinum <= (unsigned int) CURL_MASK_USHORT); - return (unsigned short) (uinum & (unsigned int) CURL_MASK_USHORT); + DEBUGASSERT(uinum <= (unsigned int)CURL_MASK_USHORT); + return (unsigned short)(uinum & (unsigned int)CURL_MASK_USHORT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -279,15 +279,15 @@ unsigned short curlx_uitous(unsigned int uinum) size_t curlx_sitouz(int sinum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif DEBUGASSERT(sinum >= 0); - return (size_t) sinum; + return (size_t)sinum; #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -333,7 +333,6 @@ bool curlx_sotouz_fits(curl_off_t sonum, size_t *puznum) return TRUE; } - bool curlx_sltouz(long slnum, size_t *puznum) { if(slnum < 0) { diff --git a/lib/curlx/warnless.h b/lib/curlx/warnless.h index 52e7ec2a5c5d..5f324ac37592 100644 --- a/lib/curlx/warnless.h +++ b/lib/curlx/warnless.h @@ -31,7 +31,7 @@ #endif #define CURLX_FUNCTION_CAST(target_type, func) \ - (target_type)(void (*) (void))(func) + (target_type)(void (*)(void))(func) unsigned char curlx_ultouc(unsigned long ulnum); diff --git a/lib/curlx/winapi.c b/lib/curlx/winapi.c index 4cacbcb618ea..3243f7cb4ad3 100644 --- a/lib/curlx/winapi.c +++ b/lib/curlx/winapi.c @@ -57,8 +57,8 @@ const char *curlx_get_winapi_error(DWORD err, char *buf, size_t buflen) /* Truncate multiple lines */ p = strchr(buf, '\n'); if(p) { - if(p > buf && *(p-1) == '\r') - *(p-1) = '\0'; + if(p > buf && *(p - 1) == '\r') + *(p - 1) = '\0'; else *p = '\0'; } @@ -89,7 +89,6 @@ const char *curlx_winapi_strerror(DWORD err, char *buf, size_t buflen) #if defined(__GNUC__) && __GNUC__ >= 7 #pragma GCC diagnostic pop #endif - } #else { diff --git a/lib/vauth/cleartext.c b/lib/vauth/cleartext.c index d259bc42b5b2..862310111e66 100644 --- a/lib/vauth/cleartext.c +++ b/lib/vauth/cleartext.c @@ -27,8 +27,8 @@ #include "../curl_setup.h" -#if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \ - !defined(CURL_DISABLE_POP3) || \ +#if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \ + !defined(CURL_DISABLE_POP3) || \ (!defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP)) #include @@ -110,8 +110,7 @@ void Curl_auth_create_login_message(const char *valuep, struct bufref *out) * * Returns void. */ -void Curl_auth_create_external_message(const char *user, - struct bufref *out) +void Curl_auth_create_external_message(const char *user, struct bufref *out) { /* This is the same formatting as the login message */ Curl_auth_create_login_message(user, out); diff --git a/lib/vauth/cram.c b/lib/vauth/cram.c index 3b02e5751fcc..9bc5544a64fa 100644 --- a/lib/vauth/cram.c +++ b/lib/vauth/cram.c @@ -63,7 +63,7 @@ CURLcode Curl_auth_create_cram_md5_message(const struct bufref *chlg, /* Compute the digest using the password as the key */ ctxt = Curl_HMAC_init(&Curl_HMAC_MD5, - (const unsigned char *) passwdp, + (const unsigned char *)passwdp, curlx_uztoui(strlen(passwdp))); if(!ctxt) return CURLE_OUT_OF_MEMORY; diff --git a/lib/vauth/digest.c b/lib/vauth/digest.c index 850891f17535..c5fea6739449 100644 --- a/lib/vauth/digest.c +++ b/lib/vauth/digest.c @@ -138,20 +138,20 @@ bool Curl_auth_digest_get_pair(const char *str, char *value, char *content, #ifndef USE_WINDOWS_SSPI /* Convert MD5 chunk to RFC2617 (section 3.1.3) -suitable ASCII string */ static void auth_digest_md5_to_ascii(unsigned char *source, /* 16 bytes */ - unsigned char *dest) /* 33 bytes */ + unsigned char *dest) /* 33 bytes */ { int i; for(i = 0; i < 16; i++) - curl_msnprintf((char *) &dest[i * 2], 3, "%02x", source[i]); + curl_msnprintf((char *)&dest[i * 2], 3, "%02x", source[i]); } /* Convert sha256 or SHA-512/256 chunk to RFC7616 -suitable ASCII string */ static void auth_digest_sha256_to_ascii(unsigned char *source, /* 32 bytes */ - unsigned char *dest) /* 65 bytes */ + unsigned char *dest) /* 65 bytes */ { int i; for(i = 0; i < 32; i++) - curl_msnprintf((char *) &dest[i * 2], 3, "%02x", source[i]); + curl_msnprintf((char *)&dest[i * 2], 3, "%02x", source[i]); } /* Perform quoted-string escaping as described in RFC2616 and its errata */ @@ -272,7 +272,7 @@ static CURLcode auth_decode_digest_md5_message(const struct bufref *chlgref, char *alg, size_t alen, char *qop, size_t qlen) { - const char *chlg = (const char *) Curl_bufref_ptr(chlgref); + const char *chlg = (const char *)Curl_bufref_ptr(chlgref); /* Ensure we have a valid challenge message */ if(!Curl_bufref_len(chlgref)) @@ -387,13 +387,13 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, if(!ctxt) return CURLE_OUT_OF_MEMORY; - Curl_MD5_update(ctxt, (const unsigned char *) userp, + Curl_MD5_update(ctxt, (const unsigned char *)userp, curlx_uztoui(strlen(userp))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) realm, + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)realm, curlx_uztoui(strlen(realm))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) passwdp, + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)passwdp, curlx_uztoui(strlen(passwdp))); Curl_MD5_final(ctxt, digest); @@ -401,12 +401,12 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, if(!ctxt) return CURLE_OUT_OF_MEMORY; - Curl_MD5_update(ctxt, (const unsigned char *) digest, MD5_DIGEST_LEN); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) nonce, + Curl_MD5_update(ctxt, (const unsigned char *)digest, MD5_DIGEST_LEN); + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)nonce, curlx_uztoui(strlen(nonce))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) cnonce, + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)cnonce, curlx_uztoui(strlen(cnonce))); Curl_MD5_final(ctxt, digest); @@ -427,10 +427,10 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, return CURLE_OUT_OF_MEMORY; } - Curl_MD5_update(ctxt, (const unsigned char *) method, + Curl_MD5_update(ctxt, (const unsigned char *)method, curlx_uztoui(strlen(method))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) spn, + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)spn, curlx_uztoui(strlen(spn))); Curl_MD5_final(ctxt, digest); @@ -445,23 +445,23 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, return CURLE_OUT_OF_MEMORY; } - Curl_MD5_update(ctxt, (const unsigned char *) HA1_hex, 2 * MD5_DIGEST_LEN); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) nonce, + Curl_MD5_update(ctxt, (const unsigned char *)HA1_hex, 2 * MD5_DIGEST_LEN); + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)nonce, curlx_uztoui(strlen(nonce))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) nonceCount, + Curl_MD5_update(ctxt, (const unsigned char *)nonceCount, curlx_uztoui(strlen(nonceCount))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) cnonce, + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)cnonce, curlx_uztoui(strlen(cnonce))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) qop, + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)qop, curlx_uztoui(strlen(qop))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) HA2_hex, 2 * MD5_DIGEST_LEN); + Curl_MD5_update(ctxt, (const unsigned char *)HA2_hex, 2 * MD5_DIGEST_LEN); Curl_MD5_final(ctxt, digest); for(i = 0; i < MD5_DIGEST_LEN; i++) @@ -553,7 +553,7 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg, if(curlx_str_casecompare(&out, DIGEST_QOP_VALUE_STRING_AUTH)) foundAuth = TRUE; else if(curlx_str_casecompare(&out, - DIGEST_QOP_VALUE_STRING_AUTH_INT)) + DIGEST_QOP_VALUE_STRING_AUTH_INT)) foundAuthInt = TRUE; if(curlx_str_single(&token, ',')) break; @@ -720,7 +720,7 @@ static CURLcode auth_create_digest_http_message( if(!hashthis) return CURLE_OUT_OF_MEMORY; - result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis)); + result = hash(hashbuf, (unsigned char *)hashthis, strlen(hashthis)); curlx_free(hashthis); if(result) return result; @@ -743,7 +743,7 @@ static CURLcode auth_create_digest_http_message( if(!hashthis) return CURLE_OUT_OF_MEMORY; - result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis)); + result = hash(hashbuf, (unsigned char *)hashthis, strlen(hashthis)); curlx_free(hashthis); if(result) return result; @@ -755,7 +755,7 @@ static CURLcode auth_create_digest_http_message( if(!tmp) return CURLE_OUT_OF_MEMORY; - result = hash(hashbuf, (unsigned char *) tmp, strlen(tmp)); + result = hash(hashbuf, (unsigned char *)tmp, strlen(tmp)); curlx_free(tmp); if(result) return result; @@ -799,7 +799,7 @@ static CURLcode auth_create_digest_http_message( if(!hashthis) return CURLE_OUT_OF_MEMORY; - result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis)); + result = hash(hashbuf, (unsigned char *)hashthis, strlen(hashthis)); curlx_free(hashthis); if(result) return result; @@ -816,7 +816,7 @@ static CURLcode auth_create_digest_http_message( if(!hashthis) return CURLE_OUT_OF_MEMORY; - result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis)); + result = hash(hashbuf, (unsigned char *)hashthis, strlen(hashthis)); curlx_free(hashthis); if(result) return result; @@ -1015,9 +1015,9 @@ void Curl_auth_digest_cleanup(struct digestdata *digest) digest->nc = 0; digest->algo = ALGO_MD5; /* default algorithm */ - digest->stale = FALSE; /* default means normal, not stale */ + digest->stale = FALSE; /* default means normal, not stale */ digest->userhash = FALSE; } -#endif /* !USE_WINDOWS_SSPI */ +#endif /* !USE_WINDOWS_SSPI */ -#endif /* !CURL_DISABLE_DIGEST_AUTH */ +#endif /* !CURL_DISABLE_DIGEST_AUTH */ diff --git a/lib/vauth/digest_sspi.c b/lib/vauth/digest_sspi.c index ea6a66af9fac..550810acda18 100644 --- a/lib/vauth/digest_sspi.c +++ b/lib/vauth/digest_sspi.c @@ -42,14 +42,14 @@ #include "../strerror.h" /* -* Curl_auth_is_digest_supported() -* -* This is used to evaluate if DIGEST is supported. -* -* Parameters: None -* -* Returns TRUE if DIGEST is supported by Windows SSPI. -*/ + * Curl_auth_is_digest_supported() + * + * This is used to evaluate if DIGEST is supported. + * + * Parameters: None + * + * Returns TRUE if DIGEST is supported by Windows SSPI. + */ bool Curl_auth_is_digest_supported(void) { PSecPkgInfo SecurityPackage; diff --git a/lib/vauth/gsasl.c b/lib/vauth/gsasl.c index debeda0604e2..8330a4bd7155 100644 --- a/lib/vauth/gsasl.c +++ b/lib/vauth/gsasl.c @@ -100,7 +100,7 @@ CURLcode Curl_auth_gsasl_token(struct Curl_easy *data, size_t outlen; res = gsasl_step(gsasl->client, - (const char *) Curl_bufref_ptr(chlg), Curl_bufref_len(chlg), + (const char *)Curl_bufref_ptr(chlg), Curl_bufref_len(chlg), &response, &outlen); if(res != GSASL_OK && res != GSASL_NEEDS_MORE) { failf(data, "GSASL step: %s", gsasl_strerror(res)); diff --git a/lib/vauth/krb5_gssapi.c b/lib/vauth/krb5_gssapi.c index 9ea36171faec..1590949d681a 100644 --- a/lib/vauth/krb5_gssapi.c +++ b/lib/vauth/krb5_gssapi.c @@ -159,7 +159,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data, gss_release_buffer(&unused_status, &output_token); } else - Curl_bufref_set(out, mutual_auth ? "": NULL, 0, NULL); + Curl_bufref_set(out, mutual_auth ? "" : NULL, 0, NULL); return result; } diff --git a/lib/vauth/krb5_sspi.c b/lib/vauth/krb5_sspi.c index 10fbac7644db..2f82345b98c7 100644 --- a/lib/vauth/krb5_sspi.c +++ b/lib/vauth/krb5_sspi.c @@ -278,8 +278,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, /* Get our response size information */ status = Curl_pSecFn->QueryContextAttributes(krb5->context, - SECPKG_ATTR_SIZES, - &sizes); + SECPKG_ATTR_SIZES, &sizes); if(status == SEC_E_INSUFFICIENT_MEMORY) return CURLE_OUT_OF_MEMORY; diff --git a/lib/vauth/ntlm.c b/lib/vauth/ntlm.c index a757d1c8f9fd..e5eb1de5ef8b 100644 --- a/lib/vauth/ntlm.c +++ b/lib/vauth/ntlm.c @@ -48,7 +48,6 @@ #include "vauth.h" #include "../curl_endian.h" - /* NTLM buffer fixed size, large enough for long user + host + domain */ #define NTLM_BUFSIZE 1024 @@ -158,7 +157,7 @@ #define NTLMSSP_SIGNATURE "\x4e\x54\x4c\x4d\x53\x53\x50" #if DEBUG_ME -# define DEBUG_OUT(x) x +#define DEBUG_OUT(x) x static void ntlm_print_flags(FILE *handle, unsigned long flags) { if(flags & NTLMFLAG_NEGOTIATE_UNICODE) @@ -236,7 +235,7 @@ static void ntlm_print_hex(FILE *handle, const char *buf, size_t len) curl_mfprintf(stderr, "%02.2x", (unsigned int)*p++); } #else -# define DEBUG_OUT(x) Curl_nop_stmt +#define DEBUG_OUT(x) Curl_nop_stmt #endif /* diff --git a/lib/vauth/ntlm_sspi.c b/lib/vauth/ntlm_sspi.c index d976bc5d2131..bab319671c48 100644 --- a/lib/vauth/ntlm_sspi.c +++ b/lib/vauth/ntlm_sspi.c @@ -221,7 +221,6 @@ CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data, } /* -* Curl_auth_create_ntlm_type3_message() * Curl_auth_create_ntlm_type3_message() * * This is used to generate an already encoded NTLM type-3 message ready for @@ -267,12 +266,12 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data, #ifdef SECPKG_ATTR_ENDPOINT_BINDINGS /* ssl context comes from schannel. - * When extended protection is used in IIS server, - * we have to pass a second SecBuffer to the SecBufferDesc - * otherwise IIS will not pass the authentication (401 response). - * Minimum supported version is Windows 7. - * https://learn.microsoft.com/security-updates/SecurityAdvisories/2009/973811 - */ + * When extended protection is used in IIS server, + * we have to pass a second SecBuffer to the SecBufferDesc + * otherwise IIS will not pass the authentication (401 response). + * Minimum supported version is Windows 7. + * https://learn.microsoft.com/security-updates/SecurityAdvisories/2009/973811 + */ if(ntlm->sslContext) { SEC_CHANNEL_BINDINGS channelBindings; SecPkgContext_Bindings pkgBindings; diff --git a/lib/vauth/oauth2.c b/lib/vauth/oauth2.c index 0bb7a9d6bdab..3b4d4164f094 100644 --- a/lib/vauth/oauth2.c +++ b/lib/vauth/oauth2.c @@ -27,7 +27,7 @@ #include "../curl_setup.h" #if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \ - !defined(CURL_DISABLE_POP3) || \ + !defined(CURL_DISABLE_POP3) || \ (!defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP)) #include diff --git a/lib/vauth/spnego_sspi.c b/lib/vauth/spnego_sspi.c index 90e622da3d4e..2b0504f630f8 100644 --- a/lib/vauth/spnego_sspi.c +++ b/lib/vauth/spnego_sspi.c @@ -139,7 +139,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, nego->output_token = curlx_malloc(nego->token_max); if(!nego->output_token) return CURLE_OUT_OF_MEMORY; - } + } if(!nego->credentials) { /* Do we have credentials to use or are we using single sign-on? */ @@ -200,12 +200,12 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, #ifdef SECPKG_ATTR_ENDPOINT_BINDINGS /* ssl context comes from Schannel. - * When extended protection is used in IIS server, - * we have to pass a second SecBuffer to the SecBufferDesc - * otherwise IIS will not pass the authentication (401 response). - * Minimum supported version is Windows 7. - * https://learn.microsoft.com/security-updates/SecurityAdvisories/2009/973811 - */ + * When extended protection is used in IIS server, + * we have to pass a second SecBuffer to the SecBufferDesc + * otherwise IIS will not pass the authentication (401 response). + * Minimum supported version is Windows 7. + * https://learn.microsoft.com/security-updates/SecurityAdvisories/2009/973811 + */ if(nego->sslContext) { SEC_CHANNEL_BINDINGS channelBindings; SecPkgContext_Bindings pkgBindings; diff --git a/lib/vauth/vauth.c b/lib/vauth/vauth.c index 6626ace8bc6a..4ca6cef7c8fe 100644 --- a/lib/vauth/vauth.c +++ b/lib/vauth/vauth.c @@ -171,13 +171,11 @@ static void ntlm_conn_dtor(void *key, size_t klen, void *entry) struct ntlmdata *Curl_auth_ntlm_get(struct connectdata *conn, bool proxy) { - const char *key = proxy ? CURL_META_NTLM_PROXY_CONN : - CURL_META_NTLM_CONN; + const char *key = proxy ? CURL_META_NTLM_PROXY_CONN : CURL_META_NTLM_CONN; struct ntlmdata *ntlm = Curl_conn_meta_get(conn, key); if(!ntlm) { ntlm = curlx_calloc(1, sizeof(*ntlm)); - if(!ntlm || - Curl_conn_meta_set(conn, key, ntlm, ntlm_conn_dtor)) + if(!ntlm || Curl_conn_meta_set(conn, key, ntlm, ntlm_conn_dtor)) return NULL; } return ntlm; @@ -185,8 +183,8 @@ struct ntlmdata *Curl_auth_ntlm_get(struct connectdata *conn, bool proxy) void Curl_auth_ntlm_remove(struct connectdata *conn, bool proxy) { - Curl_conn_meta_remove(conn, proxy ? - CURL_META_NTLM_PROXY_CONN : CURL_META_NTLM_CONN); + Curl_conn_meta_remove(conn, proxy ? CURL_META_NTLM_PROXY_CONN + : CURL_META_NTLM_CONN); } #endif /* USE_NTLM */ @@ -257,13 +255,11 @@ static void nego_conn_dtor(void *key, size_t klen, void *entry) struct negotiatedata *Curl_auth_nego_get(struct connectdata *conn, bool proxy) { - const char *key = proxy ? CURL_META_NEGO_PROXY_CONN : - CURL_META_NEGO_CONN; + const char *key = proxy ? CURL_META_NEGO_PROXY_CONN : CURL_META_NEGO_CONN; struct negotiatedata *nego = Curl_conn_meta_get(conn, key); if(!nego) { nego = curlx_calloc(1, sizeof(*nego)); - if(!nego || - Curl_conn_meta_set(conn, key, nego, nego_conn_dtor)) + if(!nego || Curl_conn_meta_set(conn, key, nego, nego_conn_dtor)) return NULL; } return nego; diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index 62255285b6a0..09b30229f08d 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -72,14 +72,14 @@ #include "../curlx/warnless.h" -#define QUIC_MAX_STREAMS (256*1024) -#define QUIC_HANDSHAKE_TIMEOUT (10*NGTCP2_SECONDS) +#define QUIC_MAX_STREAMS (256 * 1024) +#define QUIC_HANDSHAKE_TIMEOUT (10 * NGTCP2_SECONDS) /* A stream window is the maximum amount we need to buffer for * each active transfer. * Chunk size is large enough to take a full DATA frame */ #define H3_STREAM_WINDOW_SIZE (64 * 1024) -#define H3_STREAM_CHUNK_SIZE (16 * 1024) +#define H3_STREAM_CHUNK_SIZE (16 * 1024) #if H3_STREAM_CHUNK_SIZE < NGTCP2_MAX_UDP_PAYLOAD_SIZE #error H3_STREAM_CHUNK_SIZE smaller than NGTCP2_MAX_UDP_PAYLOAD_SIZE #endif @@ -150,8 +150,7 @@ struct cf_ngtcp2_ctx { /* How to access `call_data` from a cf_ngtcp2 filter */ #undef CF_CTX_CALL_DATA -#define CF_CTX_CALL_DATA(cf) \ - ((struct cf_ngtcp2_ctx *)(cf)->ctx)->call_data +#define CF_CTX_CALL_DATA(cf) ((struct cf_ngtcp2_ctx *)(cf)->ctx)->call_data static void h3_stream_hash_free(unsigned int id, void *stream); @@ -187,14 +186,14 @@ static void cf_ngtcp2_setup_keep_alive(struct Curl_cfilter *cf, struct cf_ngtcp2_ctx *ctx = cf->ctx; const ngtcp2_transport_params *rp; /* Peer should have sent us its transport parameters. If it - * announces a positive `max_idle_timeout` it will close the - * connection when it does not hear from us for that time. - * - * Some servers use this as a keep-alive timer at a rather low - * value. We are doing HTTP/3 here and waiting for the response - * to a request may take a considerable amount of time. We need - * to prevent the peer's QUIC stack from closing in this case. - */ + * announces a positive `max_idle_timeout` it will close the + * connection when it does not hear from us for that time. + * + * Some servers use this as a keep-alive timer at a rather low + * value. We are doing HTTP/3 here and waiting for the response + * to a request may take a considerable amount of time. We need + * to prevent the peer's QUIC stack from closing in this case. + */ if(!ctx->qconn) return; @@ -218,7 +217,6 @@ static void cf_ngtcp2_setup_keep_alive(struct Curl_cfilter *cf, } } - struct pkt_io_ctx; static CURLcode cf_progress_ingress(struct Curl_cfilter *cf, struct Curl_easy *data, @@ -231,20 +229,20 @@ static CURLcode cf_progress_egress(struct Curl_cfilter *cf, * All about the H3 internals of a stream */ struct h3_stream_ctx { - int64_t id; /* HTTP/3 protocol identifier */ - struct bufq sendbuf; /* h3 request body */ - struct h1_req_parser h1; /* h1 request parsing */ + int64_t id; /* HTTP/3 protocol identifier */ + struct bufq sendbuf; /* h3 request body */ + struct h1_req_parser h1; /* h1 request parsing */ size_t sendbuf_len_in_flight; /* sendbuf amount "in flight" */ - uint64_t error3; /* HTTP/3 stream error code */ - curl_off_t upload_left; /* number of request bytes left to upload */ - uint64_t download_unacked; /* bytes not acknowledged yet */ - int status_code; /* HTTP status code */ - CURLcode xfer_result; /* result from xfer_resp_write(_hd) */ - BIT(resp_hds_complete); /* we have a complete, final response */ - BIT(closed); /* TRUE on stream close */ - BIT(reset); /* TRUE on stream reset */ - BIT(send_closed); /* stream is local closed */ - BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ + uint64_t error3; /* HTTP/3 stream error code */ + curl_off_t upload_left; /* number of request bytes left to upload */ + uint64_t download_unacked; /* bytes not acknowledged yet */ + int status_code; /* HTTP status code */ + CURLcode xfer_result; /* result from xfer_resp_write(_hd) */ + BIT(resp_hds_complete); /* we have a complete, final response */ + BIT(closed); /* TRUE on stream close */ + BIT(reset); /* TRUE on stream reset */ + BIT(send_closed); /* stream is local closed */ + BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ }; static void h3_stream_ctx_free(struct h3_stream_ctx *stream) @@ -315,8 +313,8 @@ static bool cf_ngtcp2_sfind(uint32_t mid, void *value, void *user_data) return TRUE; /* continue */ } -static struct h3_stream_ctx * -cf_ngtcp2_get_stream(struct cf_ngtcp2_ctx *ctx, int64_t stream_id) +static struct h3_stream_ctx *cf_ngtcp2_get_stream(struct cf_ngtcp2_ctx *ctx, + int64_t stream_id) { struct cf_ngtcp2_sfind_ctx fctx; fctx.stream_id = stream_id; @@ -367,8 +365,7 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); (void)cf; if(stream) { - CURL_TRC_CF(data, cf, "[%" PRId64 "] easy handle is done", - stream->id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] easy handle is done", stream->id); cf_ngtcp2_stream_close(cf, data, stream); Curl_uint32_hash_remove(&ctx->streams, data->mid); if(!Curl_uint32_hash_count(&ctx->streams)) @@ -640,10 +637,9 @@ static int cb_recv_stream_data(ngtcp2_conn *tconn, uint32_t flags, return 0; } -static int -cb_acked_stream_data_offset(ngtcp2_conn *tconn, int64_t stream_id, - uint64_t offset, uint64_t datalen, void *user_data, - void *stream_user_data) +static int cb_acked_stream_data_offset(ngtcp2_conn *tconn, int64_t stream_id, + uint64_t offset, uint64_t datalen, + void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; @@ -830,8 +826,8 @@ static int cb_recv_rx_key(ngtcp2_conn *tconn, ngtcp2_encryption_level level, } #if defined(_MSC_VER) && defined(_DLL) -# pragma warning(push) -# pragma warning(disable:4232) /* MSVC extension, dllimport identity */ +#pragma warning(push) +#pragma warning(disable:4232) /* MSVC extension, dllimport identity */ #endif static ngtcp2_callbacks ng_callbacks = { @@ -881,7 +877,7 @@ static ngtcp2_callbacks ng_callbacks = { }; #if defined(_MSC_VER) && defined(_DLL) -# pragma warning(pop) +#pragma warning(pop) #endif /** @@ -1337,9 +1333,9 @@ static CURLcode init_ngh3_conn(struct Curl_cfilter *cf, } static CURLcode recv_closed_stream(struct Curl_cfilter *cf, - struct Curl_easy *data, - struct h3_stream_ctx *stream, - size_t *pnread) + struct Curl_easy *data, + struct h3_stream_ctx *stream, + size_t *pnread) { (void)cf; *pnread = 0; @@ -1452,11 +1448,10 @@ static int cb_h3_acked_req_body(nghttp3_conn *conn, int64_t stream_id, return 0; } -static nghttp3_ssize -cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, - nghttp3_vec *vec, size_t veccnt, - uint32_t *pflags, void *user_data, - void *stream_user_data) +static nghttp3_ssize cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, + nghttp3_vec *vec, size_t veccnt, + uint32_t *pflags, void *user_data, + void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; @@ -1504,8 +1499,7 @@ cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, } else if(!nwritten) { /* Not EOF, and nothing to give, we signal WOULDBLOCK. */ - CURL_TRC_CF(data, cf, "[%" PRId64 "] read req body -> AGAIN", - stream->id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] read req body -> AGAIN", stream->id); return NGHTTP3_ERR_WOULDBLOCK; } @@ -1961,7 +1955,7 @@ static CURLcode cf_progress_egress(struct Curl_cfilter *cf, */ max_payload_size = ngtcp2_conn_get_max_tx_udp_payload_size(ctx->qconn); path_max_payload_size = - ngtcp2_conn_get_path_max_tx_udp_payload_size(ctx->qconn); + ngtcp2_conn_get_path_max_tx_udp_payload_size(ctx->qconn); send_quantum = ngtcp2_conn_get_send_quantum(ctx->qconn); CURL_TRC_CF(data, cf, "egress, collect and send packets, quantum=%zu", send_quantum); @@ -1977,7 +1971,7 @@ static CURLcode cf_progress_egress(struct Curl_cfilter *cf, size_t buflen = Curl_bufq_len(&ctx->q.sendbuf); if((buflen >= send_quantum) || ((buflen + gsolen) >= ctx->q.sendbuf.chunk_size)) - break; + break; DEBUGASSERT(nread > 0); ++pktcnt; if(pktcnt == 1) { @@ -2283,16 +2277,26 @@ static int quic_ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) static const char *gtls_hs_msg_name(int mtype) { switch(mtype) { - case 1: return "ClientHello"; - case 2: return "ServerHello"; - case 4: return "SessionTicket"; - case 8: return "EncryptedExtensions"; - case 11: return "Certificate"; - case 13: return "CertificateRequest"; - case 15: return "CertificateVerify"; - case 20: return "Finished"; - case 24: return "KeyUpdate"; - case 254: return "MessageHash"; + case 1: + return "ClientHello"; + case 2: + return "ServerHello"; + case 4: + return "SessionTicket"; + case 8: + return "EncryptedExtensions"; + case 11: + return "Certificate"; + case 13: + return "CertificateRequest"; + case 15: + return "CertificateVerify"; + case 20: + return "Finished"; + case 24: + return "KeyUpdate"; + case 254: + return "MessageHash"; } return "Unknown"; } @@ -2458,7 +2462,7 @@ static CURLcode cf_ngtcp2_on_session_reuse(struct Curl_cfilter *cf, #endif /* WOLFSSL_EARLY_DATA */ #endif #if defined(USE_GNUTLS) || defined(USE_WOLFSSL) || \ - (defined(USE_OPENSSL) && defined(HAVE_OPENSSL_EARLYDATA)) + (defined(USE_OPENSSL) && defined(HAVE_OPENSSL_EARLYDATA)) if((!ctx->earlydata_max)) { CURL_TRC_CF(data, cf, "SSL session does not allow earlydata"); } @@ -2668,7 +2672,7 @@ static CURLcode cf_ngtcp2_connect(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "connection refused by server"); /* When a QUIC server instance is shutting down, it may send us a * CONNECTION_CLOSE with this code right away. We want - * to keep on trying in this case. */ + * to keep on trying in this case. */ result = CURLE_WEIRD_SERVER_REPLY; } } diff --git a/lib/vquic/curl_osslq.c b/lib/vquic/curl_osslq.c index 7bca97b4086d..ece4ce6ad570 100644 --- a/lib/vquic/curl_osslq.c +++ b/lib/vquic/curl_osslq.c @@ -453,29 +453,29 @@ static CURLcode cf_osslq_h3conn_add_stream(struct cf_osslq_h3conn *h3, * BUT OpenSSL does not offer this information to us. So, we silently * ignore all such streams we do not expect. */ switch(stype) { - case SSL_STREAM_TYPE_READ: { - struct cf_osslq_stream *nstream; - if(h3->remote_ctrl_n >= CURL_ARRAYSIZE(h3->remote_ctrl)) { - /* rejected, we are full */ - CURL_TRC_CF(data, cf, "[%" PRId64 "] reject remote uni stream", - stream_id); - SSL_free(stream_ssl); - return CURLE_OK; - } - nstream = &h3->remote_ctrl[h3->remote_ctrl_n++]; - nstream->id = stream_id; - nstream->ssl = stream_ssl; - Curl_bufq_initp(&nstream->recvbuf, &ctx->stream_bufcp, 1, BUFQ_OPT_NONE); - CURL_TRC_CF(data, cf, "[%" PRId64 "] accepted remote uni stream", + case SSL_STREAM_TYPE_READ: { + struct cf_osslq_stream *nstream; + if(h3->remote_ctrl_n >= CURL_ARRAYSIZE(h3->remote_ctrl)) { + /* rejected, we are full */ + CURL_TRC_CF(data, cf, "[%" PRId64 "] reject remote uni stream", stream_id); - return CURLE_OK; - } - default: - CURL_TRC_CF(data, cf, "[%" PRId64 "] reject remote %s" - " stream, type=%x", stream_id, - (stype == SSL_STREAM_TYPE_BIDI) ? "bidi" : "write", stype); SSL_free(stream_ssl); return CURLE_OK; + } + nstream = &h3->remote_ctrl[h3->remote_ctrl_n++]; + nstream->id = stream_id; + nstream->ssl = stream_ssl; + Curl_bufq_initp(&nstream->recvbuf, &ctx->stream_bufcp, 1, BUFQ_OPT_NONE); + CURL_TRC_CF(data, cf, "[%" PRId64 "] accepted remote uni stream", + stream_id); + return CURLE_OK; + } + default: + CURL_TRC_CF(data, cf, "[%" PRId64 "] reject remote %s" + " stream, type=%x", stream_id, + (stype == SSL_STREAM_TYPE_BIDI) ? "bidi" : "write", stype); + SSL_free(stream_ssl); + return CURLE_OK; } } @@ -505,8 +505,7 @@ static CURLcode cf_osslq_ssl_err(struct Curl_cfilter *cf, lerr = SSL_get_verify_result(ctx->tls.ossl.ssl); if(lerr != X509_V_OK) { ssl_config->certverifyresult = lerr; - curl_msnprintf(ebuf, sizeof(ebuf), - "SSL certificate problem: %s", + curl_msnprintf(ebuf, sizeof(ebuf), "SSL certificate problem: %s", X509_verify_cert_error_string(lerr)); } else @@ -540,7 +539,7 @@ static CURLcode cf_osslq_ssl_err(struct Curl_cfilter *cf, * the SO_ERROR is also lost. */ if(CURLE_SSL_CONNECT_ERROR == result && errdetail == 0) { - char extramsg[80]=""; + char extramsg[80] = ""; int sockerr = SOCKERRNO; struct ip_quadruple ip; @@ -570,20 +569,21 @@ static CURLcode cf_osslq_verify_peer(struct Curl_cfilter *cf, */ struct h3_stream_ctx { struct cf_osslq_stream s; - struct bufq sendbuf; /* h3 request body */ - struct bufq recvbuf; /* h3 response body */ - struct h1_req_parser h1; /* h1 request parsing */ + struct bufq sendbuf; /* h3 request body */ + struct bufq recvbuf; /* h3 response body */ + struct h1_req_parser h1; /* h1 request parsing */ size_t sendbuf_len_in_flight; /* sendbuf amount "in flight" */ - size_t recv_buf_nonflow; /* buffered bytes, not counting for flow control */ - uint64_t error3; /* HTTP/3 stream error code */ - curl_off_t upload_left; /* number of request bytes left to upload */ - curl_off_t download_recvd; /* number of response DATA bytes received */ - int status_code; /* HTTP status code */ - BIT(resp_hds_complete); /* we have a complete, final response */ - BIT(closed); /* TRUE on stream close */ - BIT(reset); /* TRUE on stream reset */ - BIT(send_closed); /* stream is local closed */ - BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ + size_t recv_buf_nonflow; /* buffered bytes, + not counting for flow control */ + uint64_t error3; /* HTTP/3 stream error code */ + curl_off_t upload_left; /* number of request bytes left to upload */ + curl_off_t download_recvd; /* number of response DATA bytes received */ + int status_code; /* HTTP status code */ + BIT(resp_hds_complete); /* we have a complete, final response */ + BIT(closed); /* TRUE on stream close */ + BIT(reset); /* TRUE on stream reset */ + BIT(send_closed); /* stream is local closed */ + BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ }; static void h3_stream_ctx_free(struct h3_stream_ctx *stream) @@ -645,8 +645,7 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) (void)cf; if(stream) { - CURL_TRC_CF(data, cf, "[%" PRIu64 "] easy handle is done", - stream->s.id); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] easy handle is done", stream->s.id); if(ctx->h3.conn && (stream->s.id >= 0) && !stream->closed) { nghttp3_conn_shutdown_stream_read(ctx->h3.conn, stream->s.id); nghttp3_conn_close_stream(ctx->h3.conn, stream->s.id, @@ -965,11 +964,10 @@ static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t stream_id, return 0; } -static nghttp3_ssize -cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, - nghttp3_vec *vec, size_t veccnt, - uint32_t *pflags, void *user_data, - void *stream_user_data) +static nghttp3_ssize cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, + nghttp3_vec *vec, size_t veccnt, + uint32_t *pflags, void *user_data, + void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_osslq_ctx *ctx = cf->ctx; @@ -1106,21 +1104,21 @@ static CURLcode cf_osslq_h3conn_init(struct cf_osslq_ctx *ctx, SSL *conn, } result = cf_osslq_stream_open(&h3->s_ctrl, conn, - SSL_STREAM_FLAG_ADVANCE|SSL_STREAM_FLAG_UNI, + SSL_STREAM_FLAG_ADVANCE | SSL_STREAM_FLAG_UNI, &ctx->stream_bufcp, NULL); if(result) { result = CURLE_QUIC_CONNECT_ERROR; goto out; } result = cf_osslq_stream_open(&h3->s_qpack_enc, conn, - SSL_STREAM_FLAG_ADVANCE|SSL_STREAM_FLAG_UNI, + SSL_STREAM_FLAG_ADVANCE | SSL_STREAM_FLAG_UNI, &ctx->stream_bufcp, NULL); if(result) { result = CURLE_QUIC_CONNECT_ERROR; goto out; } result = cf_osslq_stream_open(&h3->s_qpack_dec, conn, - SSL_STREAM_FLAG_ADVANCE|SSL_STREAM_FLAG_UNI, + SSL_STREAM_FLAG_ADVANCE | SSL_STREAM_FLAG_UNI, &ctx->stream_bufcp, NULL); if(result) { result = CURLE_QUIC_CONNECT_ERROR; @@ -1221,7 +1219,8 @@ static CURLcode cf_osslq_ctx_start(struct Curl_cfilter *cf, SSL_INCOMING_STREAM_POLICY_ACCEPT, 0); /* from our side, there is no idle timeout */ SSL_set_value_uint(ctx->tls.ossl.ssl, - SSL_VALUE_CLASS_FEATURE_REQUEST, SSL_VALUE_QUIC_IDLE_TIMEOUT, 0); + SSL_VALUE_CLASS_FEATURE_REQUEST, + SSL_VALUE_QUIC_IDLE_TIMEOUT, 0); /* setup the H3 things on top of the QUIC connection */ result = cf_osslq_h3conn_init(ctx, ctx->tls.ossl.ssl, cf); @@ -1532,7 +1531,7 @@ static CURLcode cf_osslq_check_and_unblock(struct Curl_cfilter *cf, fill_ctx.multi = data->multi; fill_ctx.n = 0; Curl_uint32_hash_visit(&ctx->streams, cf_osslq_collect_block_send, - &fill_ctx); + &fill_ctx); poll_count = fill_ctx.n; if(poll_count) { CURL_TRC_CF(data, cf, "polling %zu blocked streams", poll_count); @@ -1541,7 +1540,7 @@ static CURLcode cf_osslq_check_and_unblock(struct Curl_cfilter *cf, res = CURLE_UNRECOVERABLE_POLL; if(!SSL_poll(ctx->poll_items, poll_count, sizeof(SSL_POLL_ITEM), &timeout, 0, &result_count)) - goto out; + goto out; res = CURLE_OK; @@ -1617,7 +1616,7 @@ static CURLcode h3_send_streams(struct Curl_cfilter *cf, uint64_t flags = (eos && ((i + 1) == n)) ? SSL_WRITE_FLAG_CONCLUDE : 0; written = vec[i].len; ok = !s->ssl || SSL_write_ex2(s->ssl, vec[i].base, vec[i].len, flags, - &written); + &written); if(ok && flags & SSL_WRITE_FLAG_CONCLUDE) eos_written = TRUE; if(ok) { diff --git a/lib/vquic/curl_quiche.c b/lib/vquic/curl_quiche.c index 5aca750c2cb9..45f606ec6182 100644 --- a/lib/vquic/curl_quiche.c +++ b/lib/vquic/curl_quiche.c @@ -167,17 +167,17 @@ static CURLcode cf_flush_egress(struct Curl_cfilter *cf, * All about the H3 internals of a stream */ struct h3_stream_ctx { - uint64_t id; /* HTTP/3 protocol stream identifier */ - struct bufq recvbuf; /* h3 response */ + uint64_t id; /* HTTP/3 protocol stream identifier */ + struct bufq recvbuf; /* h3 response */ struct h1_req_parser h1; /* h1 request parsing */ - uint64_t error3; /* HTTP/3 stream error code */ - BIT(opened); /* TRUE after stream has been opened */ - BIT(closed); /* TRUE on stream close */ - BIT(reset); /* TRUE on stream reset */ - BIT(send_closed); /* stream is locally closed */ + uint64_t error3; /* HTTP/3 stream error code */ + BIT(opened); /* TRUE after stream has been opened */ + BIT(closed); /* TRUE on stream close */ + BIT(reset); /* TRUE on stream reset */ + BIT(send_closed); /* stream is locally closed */ BIT(resp_hds_complete); /* final response has been received */ - BIT(resp_got_header); /* TRUE when h3 stream has recvd some HEADER */ - BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ + BIT(resp_got_header); /* TRUE when h3 stream has recvd some HEADER */ + BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ }; static void h3_stream_ctx_free(struct h3_stream_ctx *stream) @@ -318,7 +318,7 @@ static void cf_quiche_expire_conn_closed(struct Curl_cfilter *cf, /* * write_resp_raw() copies response data in raw format to the `data`'s - * receive buffer. If not enough space is available, it appends to the + * receive buffer. If not enough space is available, it appends to the * `data`'s overflow buffer. */ static CURLcode write_resp_raw(struct Curl_cfilter *cf, @@ -813,7 +813,7 @@ static CURLcode cf_flush_egress(struct Curl_cfilter *cf, timeout_ns = quiche_conn_timeout_as_nanos(ctx->qconn); if(timeout_ns % 1000000) timeout_ns += 1000000; - /* expire resolution is milliseconds */ + /* expire resolution is milliseconds */ Curl_expire(data, (timeout_ns / 1000000), EXPIRE_QUIC); return result; } @@ -977,9 +977,9 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, DEBUGASSERT(stream); result = Curl_h1_req_parse_read(&stream->h1, buf, blen, NULL, - !data->state.http_ignorecustom ? - data->set.str[STRING_CUSTOMREQUEST] : NULL, - 0, pnwritten); + !data->state.http_ignorecustom ? + data->set.str[STRING_CUSTOMREQUEST] : NULL, + 0, pnwritten); if(result) goto out; if(!stream->h1.done) { @@ -1313,8 +1313,7 @@ static CURLcode cf_quiche_ctx_open(struct Curl_cfilter *cf, int qfd; (void)Curl_qlogdir(data, ctx->scid, sizeof(ctx->scid), &qfd); if(qfd != -1) - quiche_conn_set_qlog_fd(ctx->qconn, qfd, - "qlog title", "curl qlog"); + quiche_conn_set_qlog_fd(ctx->qconn, qfd, "qlog title", "curl qlog"); } #endif diff --git a/lib/vquic/vquic-tls.c b/lib/vquic/vquic-tls.c index 7a3c99b58441..99b19b369185 100644 --- a/lib/vquic/vquic-tls.c +++ b/lib/vquic/vquic-tls.c @@ -143,7 +143,9 @@ CURLcode Curl_vquic_tls_before_recv(struct curl_tls_ctx *ctx, return result; } #else - (void)ctx; (void)cf; (void)data; + (void)ctx; + (void)cf; + (void)data; #endif return CURLE_OK; } @@ -172,7 +174,7 @@ CURLcode Curl_vquic_tls_verify_peer(struct curl_tls_ctx *ctx, #elif defined(USE_WOLFSSL) (void)data; if(conn_config->verifyhost) { - WOLFSSL_X509* cert = wolfSSL_get_peer_certificate(ctx->wssl.ssl); + WOLFSSL_X509 *cert = wolfSSL_get_peer_certificate(ctx->wssl.ssl); if(!cert) result = CURLE_OUT_OF_MEMORY; else if(peer->sni && @@ -194,7 +196,6 @@ CURLcode Curl_vquic_tls_verify_peer(struct curl_tls_ctx *ctx, return result; } - bool Curl_vquic_tls_get_ssl_info(struct curl_tls_ctx *ctx, bool give_ssl_ctx, struct curl_tlssessioninfo *info) diff --git a/lib/vquic/vquic-tls.h b/lib/vquic/vquic-tls.h index c694e23e4e6d..7bddb42c99f3 100644 --- a/lib/vquic/vquic-tls.h +++ b/lib/vquic/vquic-tls.h @@ -69,14 +69,14 @@ typedef CURLcode Curl_vquic_session_reuse_cb(struct Curl_cfilter *cf, /** * Initialize the QUIC TLS instances based of the SSL configurations * for the connection filter, transfer and peer. - * @param ctx the TLS context to initialize - * @param cf the connection filter involved - * @param data the transfer involved - * @param peer the peer that will be connected to - * @param alpns the ALPN specifications to negotiate, may be NULL - * @param cb_setup optional callback for early TLS config - * @param cb_user_data user_data param for callback - * @param ssl_user_data optional pointer to set in TLS application context + * @param ctx the TLS context to initialize + * @param cf the connection filter involved + * @param data the transfer involved + * @param peer the peer that will be connected to + * @param alpns the ALPN specifications to negotiate, may be NULL + * @param cb_setup optional callback for early TLS config + * @param cb_user_data user_data param for callback + * @param ssl_user_data optional pointer to set in TLS application context * @param session_reuse_cb callback to handle session reuse, signal early data */ CURLcode Curl_vquic_tls_init(struct curl_tls_ctx *ctx, diff --git a/lib/vquic/vquic.c b/lib/vquic/vquic.c index c1267cef9ed0..a4dea8a77c43 100644 --- a/lib/vquic/vquic.c +++ b/lib/vquic/vquic.c @@ -266,7 +266,7 @@ static CURLcode vquic_send_packets(struct Curl_cfilter *cf, unsigned char c; *psent = 0; Curl_rand(data, &c, 1); - if(c >= ((100-qctx->wblock_percent)*256/100)) { + if(c >= ((100 - qctx->wblock_percent) * 256 / 100)) { CURL_TRC_CF(data, cf, "vquic_flush() simulate EWOULDBLOCK"); return CURLE_AGAIN; } @@ -334,8 +334,7 @@ CURLcode vquic_send_tail_split(struct Curl_cfilter *cf, struct Curl_easy *data, qctx->split_gsolen = gsolen; qctx->gsolen = tail_gsolen; CURL_TRC_CF(data, cf, "vquic_send_tail_split: [%zu gso=%zu][%zu gso=%zu]", - qctx->split_len, qctx->split_gsolen, - tail_len, qctx->gsolen); + qctx->split_len, qctx->split_gsolen, tail_len, qctx->gsolen); return vquic_flush(cf, data, qctx); } @@ -476,7 +475,7 @@ static CURLcode recvmsg_packets(struct Curl_cfilter *cf, { struct iovec msg_iov; struct msghdr msg; - uint8_t buf[64*1024]; + uint8_t buf[64 * 1024]; struct sockaddr_storage remote_addr; size_t total_nread, pkts, calls; ssize_t rc; @@ -551,7 +550,7 @@ static CURLcode recvfrom_packets(struct Curl_cfilter *cf, size_t max_pkts, vquic_recv_pkts_cb *recv_cb, void *userp) { - uint8_t buf[64*1024]; + uint8_t buf[64 * 1024]; int bufsize = (int)sizeof(buf); struct sockaddr_storage remote_addr; socklen_t remote_addrlen = sizeof(remote_addr); diff --git a/lib/vquic/vquic_int.h b/lib/vquic/vquic_int.h index ef92ab21b730..b4f2fd811680 100644 --- a/lib/vquic/vquic_int.h +++ b/lib/vquic/vquic_int.h @@ -33,25 +33,25 @@ #define MAX_UDP_PAYLOAD_SIZE 1452 struct cf_quic_ctx { - curl_socket_t sockfd; /* connected UDP socket */ + curl_socket_t sockfd; /* connected UDP socket */ struct sockaddr_storage local_addr; /* address socket is bound to */ - socklen_t local_addrlen; /* length of local address */ - - struct bufq sendbuf; /* buffer for sending one or more packets */ - struct curltime first_byte_at; /* when first byte was recvd */ - struct curltime last_op; /* last (attempted) send/recv operation */ - struct curltime last_io; /* last successful socket IO */ - size_t gsolen; /* length of individual packets in send buf */ - size_t split_len; /* if != 0, buffer length after which GSO differs */ + socklen_t local_addrlen; /* length of local address */ + + struct bufq sendbuf; /* buffer for sending one or more packets */ + struct curltime first_byte_at; /* when first byte was recvd */ + struct curltime last_op; /* last (attempted) send/recv operation */ + struct curltime last_io; /* last successful socket IO */ + size_t gsolen; /* length of individual packets in send buf */ + size_t split_len; /* if != 0, buffer length after which GSO differs */ size_t split_gsolen; /* length of individual packets after split_len */ #ifdef DEBUGBUILD - int wblock_percent; /* percent of writes doing EAGAIN */ + int wblock_percent; /* percent of writes doing EAGAIN */ #endif BIT(got_first_byte); /* if first byte was received */ - BIT(no_gso); /* do not use gso on sending */ + BIT(no_gso); /* do not use gso on sending */ }; -#define H3_STREAM_CTX(ctx,data) \ +#define H3_STREAM_CTX(ctx, data) \ (data ? Curl_uint32_hash_get(&(ctx)->streams, (data)->mid) : NULL) CURLcode vquic_ctx_init(struct cf_quic_ctx *qctx); @@ -77,7 +77,6 @@ CURLcode vquic_send_tail_split(struct Curl_cfilter *cf, struct Curl_easy *data, CURLcode vquic_flush(struct Curl_cfilter *cf, struct Curl_easy *data, struct cf_quic_ctx *qctx); - typedef CURLcode vquic_recv_pkts_cb(const unsigned char *buf, size_t buflen, size_t gso_size, struct sockaddr_storage *remote_addr, diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index db80bcbf8c96..cd3a7d6622e1 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -74,12 +74,12 @@ /* A recent macro provided by libssh. Or make our own. */ #ifndef SSH_STRING_FREE_CHAR -#define SSH_STRING_FREE_CHAR(x) \ - do { \ - if(x) { \ - ssh_string_free_char(x); \ - x = NULL; \ - } \ +#define SSH_STRING_FREE_CHAR(x) \ + do { \ + if(x) { \ + ssh_string_free_char(x); \ + x = NULL; \ + } \ } while(0) #endif @@ -111,10 +111,9 @@ static CURLcode sftp_doing(struct Curl_easy *data, static CURLcode sftp_disconnect(struct Curl_easy *data, struct connectdata *conn, bool dead); -static -CURLcode sftp_perform(struct Curl_easy *data, - bool *connected, - bool *dophase_done); +static CURLcode sftp_perform(struct Curl_easy *data, + bool *connected, + bool *dophase_done); static CURLcode myssh_pollset(struct Curl_easy *data, struct easy_pollset *ps); @@ -189,22 +188,22 @@ const struct Curl_handler Curl_handler_sftp = { static CURLcode sftp_error_to_CURLE(int err) { switch(err) { - case SSH_FX_OK: - return CURLE_OK; + case SSH_FX_OK: + return CURLE_OK; - case SSH_FX_NO_SUCH_FILE: - case SSH_FX_NO_SUCH_PATH: - return CURLE_REMOTE_FILE_NOT_FOUND; + case SSH_FX_NO_SUCH_FILE: + case SSH_FX_NO_SUCH_PATH: + return CURLE_REMOTE_FILE_NOT_FOUND; - case SSH_FX_PERMISSION_DENIED: - case SSH_FX_WRITE_PROTECT: - return CURLE_REMOTE_ACCESS_DENIED; + case SSH_FX_PERMISSION_DENIED: + case SSH_FX_WRITE_PROTECT: + return CURLE_REMOTE_ACCESS_DENIED; - case SSH_FX_FILE_ALREADY_EXISTS: - return CURLE_REMOTE_FILE_EXISTS; + case SSH_FX_FILE_ALREADY_EXISTS: + return CURLE_REMOTE_FILE_EXISTS; - default: - break; + default: + break; } return CURLE_SSH; @@ -213,7 +212,7 @@ static CURLcode sftp_error_to_CURLE(int err) #if !defined(CURL_DISABLE_VERBOSE_STRINGS) static const char *myssh_statename(sshstate state) { - static const char *const names[] = { + static const char * const names[] = { "SSH_STOP", "SSH_INIT", "SSH_S_STARTUP", @@ -284,7 +283,7 @@ static const char *myssh_statename(sshstate state) #endif /* !CURL_DISABLE_VERBOSE_STRINGS */ -#define myssh_to(x,y,z) myssh_set_state(x,y,z) +#define myssh_to(x, y, z) myssh_set_state(x, y, z) /* * SSH State machine related code @@ -328,8 +327,7 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc) enum curl_khmatch keymatch; struct curl_khkey foundkey; struct curl_khkey *knownkeyp = NULL; - curl_sshkeycallback func = - data->set.ssh_keyfunc; + curl_sshkeycallback func = data->set.ssh_keyfunc; struct ssh_knownhosts_entry *knownhostsentry = NULL; struct curl_khkey knownkey; @@ -343,8 +341,7 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc) char md5buffer[33]; const char *pubkey_md5 = data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5]; - rc = ssh_get_publickey_hash(pubkey, SSH_PUBLICKEY_HASH_MD5, - &hash, &hlen); + rc = ssh_get_publickey_hash(pubkey, SSH_PUBLICKEY_HASH_MD5, &hash, &hlen); if(rc != SSH_OK || hlen != 16) { failf(data, "Denied establishing ssh session: md5 fingerprint not available"); @@ -352,7 +349,7 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc) } for(i = 0; i < 16; i++) - curl_msnprintf(&md5buffer[i*2], 3, "%02x", (unsigned char)hash[i]); + curl_msnprintf(&md5buffer[i * 2], 3, "%02x", (unsigned char)hash[i]); infof(data, "SSH MD5 fingerprint: %s", md5buffer); @@ -461,7 +458,7 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc) Curl_set_in_callback(data, TRUE); rc = func(data, knownkeyp, /* from the knownhosts file */ - &foundkey, /* from the remote host */ + &foundkey, /* from the remote host */ keymatch, data->set.ssh_keyfunc_userp); Curl_set_in_callback(data, FALSE); @@ -519,8 +516,7 @@ static int myssh_to_SFTP_CLOSE(struct Curl_easy *data, struct ssh_conn *sshc) { myssh_to(data, sshc, SSH_SFTP_CLOSE); - sshc->actualcode = - sftp_error_to_CURLE(sftp_get_error(sshc->sftp_session)); + sshc->actualcode = sftp_error_to_CURLE(sftp_get_error(sshc->sftp_session)); return SSH_ERROR; } @@ -613,7 +609,6 @@ static int myssh_in_SFTP_READDIR(struct Curl_easy *data, sshc->actualcode = result; return SSH_NO_ERROR; } - } else { if(curlx_dyn_add(&sshc->readdir_buf, sshc->readdir_longentry)) { @@ -684,8 +679,7 @@ static int myssh_in_SFTP_READDIR_LINK(struct Curl_easy *data, Curl_safefree(sshc->readdir_linkPath); - if(curlx_dyn_addf(&sshc->readdir_buf, " -> %s", - sshc->readdir_filename)) { + if(curlx_dyn_addf(&sshc->readdir_buf, " -> %s", sshc->readdir_filename)) { /* Not using: * return myssh_to_SFTP_CLOSE(data, sshc); * @@ -808,56 +802,56 @@ static int myssh_auth_interactive(struct connectdata *conn, restart: switch(sshc->kbd_state) { - case 0: - rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL); - if(rc == SSH_AUTH_AGAIN) - return SSH_AGAIN; + case 0: + rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL); + if(rc == SSH_AUTH_AGAIN) + return SSH_AGAIN; - if(rc != SSH_AUTH_INFO) - return SSH_ERROR; + if(rc != SSH_AUTH_INFO) + return SSH_ERROR; - nprompts = ssh_userauth_kbdint_getnprompts(sshc->ssh_session); - if(nprompts != 1) - return SSH_ERROR; + nprompts = ssh_userauth_kbdint_getnprompts(sshc->ssh_session); + if(nprompts != 1) + return SSH_ERROR; - rc = ssh_userauth_kbdint_setanswer(sshc->ssh_session, 0, conn->passwd); - if(rc < 0) - return SSH_ERROR; + rc = ssh_userauth_kbdint_setanswer(sshc->ssh_session, 0, conn->passwd); + if(rc < 0) + return SSH_ERROR; - FALLTHROUGH(); - case 1: - sshc->kbd_state = 1; + FALLTHROUGH(); + case 1: + sshc->kbd_state = 1; - rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL); - if(rc == SSH_AUTH_AGAIN) - return SSH_AGAIN; - else if(rc == SSH_AUTH_SUCCESS) - rc = SSH_OK; - else if(rc == SSH_AUTH_INFO) { - nprompts = ssh_userauth_kbdint_getnprompts(sshc->ssh_session); - if(nprompts) - return SSH_ERROR; + rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL); + if(rc == SSH_AUTH_AGAIN) + return SSH_AGAIN; + else if(rc == SSH_AUTH_SUCCESS) + rc = SSH_OK; + else if(rc == SSH_AUTH_INFO) { + nprompts = ssh_userauth_kbdint_getnprompts(sshc->ssh_session); + if(nprompts) + return SSH_ERROR; - sshc->kbd_state = 2; - goto restart; - } - else - rc = SSH_ERROR; - break; - case 2: sshc->kbd_state = 2; + goto restart; + } + else + rc = SSH_ERROR; + break; + case 2: + sshc->kbd_state = 2; - rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL); - if(rc == SSH_AUTH_AGAIN) - return SSH_AGAIN; - else if(rc == SSH_AUTH_SUCCESS) - rc = SSH_OK; - else - rc = SSH_ERROR; + rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL); + if(rc == SSH_AUTH_AGAIN) + return SSH_AGAIN; + else if(rc == SSH_AUTH_SUCCESS) + rc = SSH_OK; + else + rc = SSH_ERROR; - break; - default: - return SSH_ERROR; + break; + default: + return SSH_ERROR; } sshc->kbd_state = 0; @@ -967,8 +961,7 @@ static int myssh_in_AUTH_PKEY_INIT(struct Curl_easy *data, * (2) use the "default" keys. */ if(data->set.str[STRING_SSH_PRIVATE_KEY]) { if(sshc->pubkey && !data->set.ssl.key_passwd) { - rc = ssh_userauth_try_publickey(sshc->ssh_session, NULL, - sshc->pubkey); + rc = ssh_userauth_try_publickey(sshc->ssh_session, NULL, sshc->pubkey); if(rc == SSH_AUTH_AGAIN) return SSH_AGAIN; @@ -993,7 +986,7 @@ static int myssh_in_AUTH_PKEY_INIT(struct Curl_easy *data, } else { rc = ssh_userauth_publickey_auto(sshc->ssh_session, NULL, - data->set.ssl.key_passwd); + data->set.ssl.key_passwd); if(rc == SSH_AUTH_AGAIN) return SSH_AGAIN; @@ -1166,7 +1159,7 @@ static int myssh_in_UPLOAD_INIT(struct Curl_easy *data, } else /* Clear file before writing (normal behavior) */ - flags = O_WRONLY|O_CREAT|O_TRUNC; + flags = O_WRONLY | O_CREAT | O_TRUNC; if(sshc->sftp_file) sftp_close(sshc->sftp_file); @@ -1214,7 +1207,7 @@ static int myssh_in_UPLOAD_INIT(struct Curl_easy *data, } /* seekerr == CURL_SEEKFUNC_CANTSEEK (cannot seek to offset) */ do { - char scratch[4*1024]; + char scratch[4 * 1024]; size_t readthisamountnow = (data->state.resume_from - passed > (curl_off_t)sizeof(scratch)) ? @@ -1363,8 +1356,7 @@ static int myssh_in_SFTP_DOWNLOAD_STAT(struct Curl_easy *data, /* Now store the number of bytes we are expected to download */ data->req.size = size - data->state.resume_from; data->req.maxdownload = size - data->state.resume_from; - Curl_pgrsSetDownloadSize(data, - size - data->state.resume_from); + Curl_pgrsSetDownloadSize(data, size - data->state.resume_from); rc = sftp_seek64(sshc->sftp_file, data->state.resume_from); if(rc) @@ -1877,8 +1869,7 @@ static void conn_forget_socket(struct Curl_easy *data, int sockindex) if(conn && CONN_SOCK_IDX_VALID(sockindex)) { struct Curl_cfilter *cf = conn->cfilter[sockindex]; if(cf) - (void)Curl_conn_cf_cntrl(cf, data, TRUE, - CF_CTRL_FORGET_SOCKET, 0, NULL); + (void)Curl_conn_cf_cntrl(cf, data, TRUE, CF_CTRL_FORGET_SOCKET, 0, NULL); fake_sclose(conn->sock[sockindex]); conn->sock[sockindex] = CURL_SOCKET_BAD; } @@ -2067,8 +2058,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, break; if(rc && !sshc->acceptfail) { Curl_safefree(sshc->quote_path1); - failf(data, "rm command failed: %s", - ssh_get_error(sshc->ssh_session)); + failf(data, "rm command failed: %s", ssh_get_error(sshc->ssh_session)); myssh_to(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; sshc->actualcode = CURLE_QUOTE_ERROR; @@ -2110,7 +2100,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, if(data->state.upload) myssh_to(data, sshc, SSH_SFTP_UPLOAD_INIT); else if(sshp) { - if(sshp->path[strlen(sshp->path)-1] == '/') + if(sshp->path[strlen(sshp->path) - 1] == '/') myssh_to(data, sshc, SSH_SFTP_READDIR_INIT); else myssh_to(data, sshc, SSH_SFTP_DOWNLOAD_INIT); @@ -2301,26 +2291,26 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, FALLTHROUGH(); case SSH_SCP_DOWNLOAD: { - curl_off_t bytecount; + curl_off_t bytecount; - rc = ssh_scp_pull_request(sshc->scp_session); - if(rc != SSH_SCP_REQUEST_NEWFILE) { - err_msg = ssh_get_error(sshc->ssh_session); - failf(data, "%s", err_msg); - rc = myssh_to_ERROR(data, sshc, CURLE_REMOTE_FILE_NOT_FOUND); - break; - } + rc = ssh_scp_pull_request(sshc->scp_session); + if(rc != SSH_SCP_REQUEST_NEWFILE) { + err_msg = ssh_get_error(sshc->ssh_session); + failf(data, "%s", err_msg); + rc = myssh_to_ERROR(data, sshc, CURLE_REMOTE_FILE_NOT_FOUND); + break; + } - /* download data */ - bytecount = ssh_scp_request_get_size(sshc->scp_session); - data->req.maxdownload = (curl_off_t) bytecount; - Curl_xfer_setup_recv(data, FIRSTSOCKET, bytecount); + /* download data */ + bytecount = ssh_scp_request_get_size(sshc->scp_session); + data->req.maxdownload = (curl_off_t)bytecount; + Curl_xfer_setup_recv(data, FIRSTSOCKET, bytecount); - /* not set by Curl_xfer_setup to preserve keepon bits */ - conn->send_idx = 0; + /* not set by Curl_xfer_setup to preserve keepon bits */ + conn->send_idx = 0; - myssh_to(data, sshc, SSH_STOP); - break; + myssh_to(data, sshc, SSH_STOP); + break; } case SSH_SCP_DONE: if(data->state.upload) @@ -2406,7 +2396,6 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, sshc->nextstate = SSH_NO_STATE; myssh_to(data, sshc, SSH_STOP); break; - } /* break the loop only on STOP or SSH_AGAIN. If `rc` is some * other error code, we will have progressed the state accordingly. */ @@ -2424,7 +2413,6 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, return result; } - /* called by the multi interface to figure out what socket(s) to wait for and for what actions in the DO_DONE, PERFORM and WAITPERFORM states */ static CURLcode myssh_pollset(struct Curl_easy *data, @@ -2525,7 +2513,6 @@ static CURLcode myssh_block_statemach(struct Curl_easy *data, (void)Curl_socket_check(fd_read, CURL_SOCKET_BAD, CURL_SOCKET_BAD, left_ms > 1000 ? 1000 : left_ms); } - } return result; @@ -2717,9 +2704,8 @@ static CURLcode scp_doing(struct Curl_easy *data, bool *dophase_done) * the options previously setup. */ -static -CURLcode scp_perform(struct Curl_easy *data, - bool *connected, bool *dophase_done) +static CURLcode scp_perform(struct Curl_easy *data, + bool *connected, bool *dophase_done) { CURLcode result = CURLE_OK; struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN); @@ -2871,7 +2857,6 @@ static CURLcode myssh_done(struct Curl_easy *data, return result; } - static CURLcode scp_done(struct Curl_easy *data, CURLcode status, bool premature) { @@ -2963,10 +2948,9 @@ static CURLcode scp_recv(struct Curl_easy *data, int sockindex, * the options previously setup. */ -static -CURLcode sftp_perform(struct Curl_easy *data, - bool *connected, - bool *dophase_done) +static CURLcode sftp_perform(struct Curl_easy *data, + bool *connected, + bool *dophase_done) { struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN); CURLcode result = CURLE_OK; @@ -3064,34 +3048,34 @@ static CURLcode sftp_send(struct Curl_easy *data, int sockindex, #if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0) switch(sshc->sftp_send_state) { - case 0: - sftp_file_set_nonblocking(sshc->sftp_file); - if(sftp_aio_begin_write(sshc->sftp_file, mem, len, - &sshc->sftp_send_aio) == SSH_ERROR) { - return CURLE_SEND_ERROR; - } - sshc->sftp_send_state = 1; - FALLTHROUGH(); - case 1: - nwrite = sftp_aio_wait_write(&sshc->sftp_send_aio); - myssh_block2waitfor(conn, sshc, (nwrite == SSH_AGAIN) ? TRUE : FALSE); - if(nwrite == SSH_AGAIN) - return CURLE_AGAIN; - else if(nwrite < 0) - return CURLE_SEND_ERROR; - - /* - * sftp_aio_wait_write() would free sftp_send_aio and - * assign it NULL in all cases except when it returns - * SSH_AGAIN. - */ - - sshc->sftp_send_state = 0; - *pnwritten = (size_t)nwrite; - return CURLE_OK; - default: - /* we never reach here */ + case 0: + sftp_file_set_nonblocking(sshc->sftp_file); + if(sftp_aio_begin_write(sshc->sftp_file, mem, len, + &sshc->sftp_send_aio) == SSH_ERROR) { return CURLE_SEND_ERROR; + } + sshc->sftp_send_state = 1; + FALLTHROUGH(); + case 1: + nwrite = sftp_aio_wait_write(&sshc->sftp_send_aio); + myssh_block2waitfor(conn, sshc, (nwrite == SSH_AGAIN) ? TRUE : FALSE); + if(nwrite == SSH_AGAIN) + return CURLE_AGAIN; + else if(nwrite < 0) + return CURLE_SEND_ERROR; + + /* + * sftp_aio_wait_write() would free sftp_send_aio and + * assign it NULL in all cases except when it returns + * SSH_AGAIN. + */ + + sshc->sftp_send_state = 0; + *pnwritten = (size_t)nwrite; + return CURLE_OK; + default: + /* we never reach here */ + return CURLE_SEND_ERROR; } #else /* @@ -3143,54 +3127,53 @@ static CURLcode sftp_recv(struct Curl_easy *data, int sockindex, return CURLE_FAILED_INIT; switch(sshc->sftp_recv_state) { - case 0: + case 0: #if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0) - if(sftp_aio_begin_read(sshc->sftp_file, len, - &sshc->sftp_recv_aio) == SSH_ERROR) { - return CURLE_RECV_ERROR; - } + if(sftp_aio_begin_read(sshc->sftp_file, len, + &sshc->sftp_recv_aio) == SSH_ERROR) { + return CURLE_RECV_ERROR; + } #else - sshc->sftp_file_index = - sftp_async_read_begin(sshc->sftp_file, (uint32_t)len); - if(sshc->sftp_file_index < 0) - return CURLE_RECV_ERROR; + sshc->sftp_file_index = + sftp_async_read_begin(sshc->sftp_file, (uint32_t)len); + if(sshc->sftp_file_index < 0) + return CURLE_RECV_ERROR; #endif - FALLTHROUGH(); - case 1: - sshc->sftp_recv_state = 1; + FALLTHROUGH(); + case 1: + sshc->sftp_recv_state = 1; #if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0) - nread = sftp_aio_wait_read(&sshc->sftp_recv_aio, mem, len); + nread = sftp_aio_wait_read(&sshc->sftp_recv_aio, mem, len); #else - nread = sftp_async_read(sshc->sftp_file, mem, (uint32_t)len, - (uint32_t)sshc->sftp_file_index); + nread = sftp_async_read(sshc->sftp_file, mem, (uint32_t)len, + (uint32_t)sshc->sftp_file_index); #endif - myssh_block2waitfor(conn, sshc, (nread == SSH_AGAIN)); + myssh_block2waitfor(conn, sshc, (nread == SSH_AGAIN)); - if(nread == SSH_AGAIN) - return CURLE_AGAIN; - else if(nread < 0) - return CURLE_RECV_ERROR; + if(nread == SSH_AGAIN) + return CURLE_AGAIN; + else if(nread < 0) + return CURLE_RECV_ERROR; - /* - * sftp_aio_wait_read() would free sftp_recv_aio and - * assign it NULL in all cases except when it returns - * SSH_AGAIN. - */ + /* + * sftp_aio_wait_read() would free sftp_recv_aio and + * assign it NULL in all cases except when it returns + * SSH_AGAIN. + */ - sshc->sftp_recv_state = 0; - *pnread = (size_t)nread; - return CURLE_OK; + sshc->sftp_recv_state = 0; + *pnread = (size_t)nread; + return CURLE_OK; - default: - /* we never reach here */ - return CURLE_RECV_ERROR; + default: + /* we never reach here */ + return CURLE_RECV_ERROR; } } - CURLcode Curl_ssh_init(void) { if(ssh_init()) { @@ -3210,4 +3193,4 @@ void Curl_ssh_version(char *buffer, size_t buflen) (void)curl_msnprintf(buffer, buflen, "libssh/%s", ssh_version(0)); } -#endif /* USE_LIBSSH */ +#endif /* USE_LIBSSH */ diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index ce593d54874a..8701775d7d94 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -154,12 +154,12 @@ const struct Curl_handler Curl_handler_sftp = { PROTOPT_NOURLQUERY | PROTOPT_CONN_REUSE }; -static void -kbd_callback(const char *name, int name_len, const char *instruction, - int instruction_len, int num_prompts, - const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, - LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, - void **abstract) +static void kbd_callback(const char *name, int name_len, + const char *instruction, int instruction_len, + int num_prompts, + const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, + LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, + void **abstract) { struct Curl_easy *data = (struct Curl_easy *)*abstract; @@ -187,30 +187,30 @@ kbd_callback(const char *name, int name_len, const char *instruction, static CURLcode sftp_libssh2_error_to_CURLE(unsigned long err) { switch(err) { - case LIBSSH2_FX_OK: - return CURLE_OK; + case LIBSSH2_FX_OK: + return CURLE_OK; - case LIBSSH2_FX_NO_SUCH_FILE: - case LIBSSH2_FX_NO_SUCH_PATH: - return CURLE_REMOTE_FILE_NOT_FOUND; + case LIBSSH2_FX_NO_SUCH_FILE: + case LIBSSH2_FX_NO_SUCH_PATH: + return CURLE_REMOTE_FILE_NOT_FOUND; - case LIBSSH2_FX_PERMISSION_DENIED: - case LIBSSH2_FX_WRITE_PROTECT: - case LIBSSH2_FX_LOCK_CONFlICT: - return CURLE_REMOTE_ACCESS_DENIED; + case LIBSSH2_FX_PERMISSION_DENIED: + case LIBSSH2_FX_WRITE_PROTECT: + case LIBSSH2_FX_LOCK_CONFlICT: + return CURLE_REMOTE_ACCESS_DENIED; - case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM: - case LIBSSH2_FX_QUOTA_EXCEEDED: - return CURLE_REMOTE_DISK_FULL; + case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM: + case LIBSSH2_FX_QUOTA_EXCEEDED: + return CURLE_REMOTE_DISK_FULL; - case LIBSSH2_FX_FILE_ALREADY_EXISTS: - return CURLE_REMOTE_FILE_EXISTS; + case LIBSSH2_FX_FILE_ALREADY_EXISTS: + return CURLE_REMOTE_FILE_EXISTS; - case LIBSSH2_FX_DIR_NOT_EMPTY: - return CURLE_QUOTE_ERROR; + case LIBSSH2_FX_DIR_NOT_EMPTY: + return CURLE_QUOTE_ERROR; - default: - break; + default: + break; } return CURLE_SSH; @@ -219,39 +219,39 @@ static CURLcode sftp_libssh2_error_to_CURLE(unsigned long err) static CURLcode libssh2_session_error_to_CURLE(int err) { switch(err) { - /* Ordered by order of appearance in libssh2.h */ - case LIBSSH2_ERROR_NONE: - return CURLE_OK; + /* Ordered by order of appearance in libssh2.h */ + case LIBSSH2_ERROR_NONE: + return CURLE_OK; - /* This is the error returned by libssh2_scp_recv2 - * on unknown file */ - case LIBSSH2_ERROR_SCP_PROTOCOL: - return CURLE_REMOTE_FILE_NOT_FOUND; + /* This is the error returned by libssh2_scp_recv2 + * on unknown file */ + case LIBSSH2_ERROR_SCP_PROTOCOL: + return CURLE_REMOTE_FILE_NOT_FOUND; - case LIBSSH2_ERROR_SOCKET_NONE: - return CURLE_COULDNT_CONNECT; + case LIBSSH2_ERROR_SOCKET_NONE: + return CURLE_COULDNT_CONNECT; - case LIBSSH2_ERROR_ALLOC: - return CURLE_OUT_OF_MEMORY; + case LIBSSH2_ERROR_ALLOC: + return CURLE_OUT_OF_MEMORY; - case LIBSSH2_ERROR_SOCKET_SEND: - return CURLE_SEND_ERROR; + case LIBSSH2_ERROR_SOCKET_SEND: + return CURLE_SEND_ERROR; - case LIBSSH2_ERROR_HOSTKEY_INIT: - case LIBSSH2_ERROR_HOSTKEY_SIGN: - case LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED: - case LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED: - return CURLE_PEER_FAILED_VERIFICATION; + case LIBSSH2_ERROR_HOSTKEY_INIT: + case LIBSSH2_ERROR_HOSTKEY_SIGN: + case LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED: + case LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED: + return CURLE_PEER_FAILED_VERIFICATION; - case LIBSSH2_ERROR_PASSWORD_EXPIRED: - return CURLE_LOGIN_DENIED; + case LIBSSH2_ERROR_PASSWORD_EXPIRED: + return CURLE_LOGIN_DENIED; - case LIBSSH2_ERROR_SOCKET_TIMEOUT: - case LIBSSH2_ERROR_TIMEOUT: - return CURLE_OPERATION_TIMEDOUT; + case LIBSSH2_ERROR_SOCKET_TIMEOUT: + case LIBSSH2_ERROR_TIMEOUT: + return CURLE_OPERATION_TIMEDOUT; - case LIBSSH2_ERROR_EAGAIN: - return CURLE_AGAIN; + case LIBSSH2_ERROR_EAGAIN: + return CURLE_AGAIN; } return CURLE_SSH; @@ -283,7 +283,7 @@ static LIBSSH2_FREE_FUNC(my_libssh2_free) #if !defined(CURL_DISABLE_VERBOSE_STRINGS) static const char *myssh_statename(sshstate state) { - static const char *const names[] = { + static const char * const names[] = { "SSH_STOP", "SSH_INIT", "SSH_S_STARTUP", @@ -354,7 +354,7 @@ static const char *myssh_statename(sshstate state) #endif /* !CURL_DISABLE_VERBOSE_STRINGS */ -#define myssh_state(x,y,z) myssh_set_state(x,y,z) +#define myssh_state(x, y, z) myssh_set_state(x, y, z) /* * SSH State machine related code @@ -663,7 +663,7 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data, /* The fingerprint points to static storage (!), do not free() it. */ int i; for(i = 0; i < 16; i++) { - curl_msnprintf(&md5buffer[i*2], 3, "%02x", + curl_msnprintf(&md5buffer[i * 2], 3, "%02x", (unsigned char)fingerprint[i]); } @@ -703,7 +703,7 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data, rc = data->set.ssh_hostkeyfunc(data->set.ssh_hostkeyfunc_userp, (int)keytype, remotekey, keylen); Curl_set_in_callback(data, FALSE); - if(rc!= CURLKHMATCH_OK) { + if(rc != CURLKHMATCH_OK) { myssh_state(data, sshc, SSH_SESSION_FREE); return CURLE_PEER_FAILED_VERIFICATION; } @@ -1009,11 +1009,10 @@ static CURLcode sftp_quote(struct Curl_easy *data, return CURLE_QUOTE_ERROR; } -static CURLcode -sftp_upload_init(struct Curl_easy *data, - struct ssh_conn *sshc, - struct SSHPROTO *sshp, - bool *blockp) +static CURLcode sftp_upload_init(struct Curl_easy *data, + struct ssh_conn *sshc, + struct SSHPROTO *sshp, + bool *blockp) { unsigned long flags; @@ -1140,7 +1139,7 @@ sftp_upload_init(struct Curl_easy *data, } /* seekerr == CURL_SEEKFUNC_CANTSEEK (cannot seek to offset) */ do { - char scratch[4*1024]; + char scratch[4 * 1024]; size_t readthisamountnow = (data->state.resume_from - passed > (curl_off_t)sizeof(scratch)) ? @@ -1283,11 +1282,10 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, return 0; } -static CURLcode -sftp_quote_stat(struct Curl_easy *data, - struct ssh_conn *sshc, - struct SSHPROTO *sshp, - bool *blockp) +static CURLcode sftp_quote_stat(struct Curl_easy *data, + struct ssh_conn *sshc, + struct SSHPROTO *sshp, + bool *blockp) { char *cmd = sshc->quote_item->data; sshc->acceptfail = FALSE; @@ -1395,11 +1393,10 @@ sftp_quote_stat(struct Curl_easy *data, return CURLE_QUOTE_ERROR; } -static CURLcode -sftp_download_stat(struct Curl_easy *data, - struct ssh_conn *sshc, - struct SSHPROTO *sshp, - bool *blockp) +static CURLcode sftp_download_stat(struct Curl_easy *data, + struct ssh_conn *sshc, + struct SSHPROTO *sshp, + bool *blockp) { LIBSSH2_SFTP_ATTRIBUTES attrs; int rc = libssh2_sftp_stat_ex(sshc->sftp_session, sshp->path, @@ -1468,8 +1465,7 @@ sftp_download_stat(struct Curl_easy *data, /* Now store the number of bytes we are expected to download */ data->req.size = attrs.filesize - data->state.resume_from; data->req.maxdownload = attrs.filesize - data->state.resume_from; - Curl_pgrsSetDownloadSize(data, - attrs.filesize - data->state.resume_from); + Curl_pgrsSetDownloadSize(data, attrs.filesize - data->state.resume_from); libssh2_sftp_seek64(sshc->sftp_handle, (libssh2_uint64_t)data->state.resume_from); } @@ -1507,7 +1503,7 @@ static CURLcode sftp_readdir(struct Curl_easy *data, return result; } if(rc > 0) { - size_t readdir_len = (size_t) rc; + size_t readdir_len = (size_t)rc; sshp->readdir_filename[readdir_len] = '\0'; if(data->set.list_only) { @@ -1639,8 +1635,7 @@ static CURLcode ssh_state_authlist(struct Curl_easy *data, myssh_state(data, sshc, SSH_SESSION_FREE); return libssh2_session_error_to_CURLE(rc); } - infof(data, "SSH authentication methods available: %s", - sshc->authlist); + infof(data, "SSH authentication methods available: %s", sshc->authlist); myssh_state(data, sshc, SSH_AUTH_PKEY_INIT); return CURLE_OK; @@ -1679,8 +1674,7 @@ static CURLcode ssh_state_auth_pkey(struct Curl_easy *data, err_msg = unknown; } else { - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); } infof(data, "SSH public key authentication failed: %s", err_msg); myssh_state(data, sshc, SSH_AUTH_PASS_INIT); @@ -1742,8 +1736,8 @@ static CURLcode ssh_state_auth_agent_init(struct Curl_easy *data, struct ssh_conn *sshc) { int rc = 0; - if((data->set.ssh_auth_types & CURLSSH_AUTH_AGENT) - && (strstr(sshc->authlist, "publickey") != NULL)) { + if((data->set.ssh_auth_types & CURLSSH_AUTH_AGENT) && + (strstr(sshc->authlist, "publickey") != NULL)) { /* Connect to the ssh-agent */ /* The agent could be shared by a curl thread i believe @@ -1838,8 +1832,8 @@ static CURLcode ssh_state_auth_agent(struct Curl_easy *data, static CURLcode ssh_state_auth_key_init(struct Curl_easy *data, struct ssh_conn *sshc) { - if((data->set.ssh_auth_types & CURLSSH_AUTH_KEYBOARD) - && (strstr(sshc->authlist, "keyboard-interactive") != NULL)) { + if((data->set.ssh_auth_types & CURLSSH_AUTH_KEYBOARD) && + (strstr(sshc->authlist, "keyboard-interactive") != NULL)) { myssh_state(data, sshc, SSH_AUTH_KEY); } else { @@ -1913,8 +1907,7 @@ static CURLcode ssh_state_sftp_init(struct Curl_easy *data, LIBSSH2_ERROR_EAGAIN) return CURLE_AGAIN; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); failf(data, "Failure initializing sftp session: %s", err_msg); myssh_state(data, sshc, SSH_SESSION_FREE); return CURLE_FAILED_INIT; @@ -2384,8 +2377,7 @@ static CURLcode ssh_state_scp_download_init(struct Curl_easy *data, LIBSSH2_ERROR_EAGAIN) return CURLE_AGAIN; - ssh_err = (int)(libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0)); + ssh_err = libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); failf(data, "%s", err_msg); myssh_state(data, sshc, SSH_SCP_CHANNEL_FREE); return libssh2_session_error_to_CURLE(ssh_err); @@ -2415,8 +2407,7 @@ static CURLcode ssh_state_sftp_close(struct Curl_easy *data, if(rc < 0) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg); } sshc->sftp_handle = NULL; @@ -2454,8 +2445,7 @@ static CURLcode ssh_state_sftp_shutdown(struct Curl_easy *data, if(rc < 0) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, - NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg); } sshc->sftp_handle = NULL; @@ -2527,8 +2517,7 @@ static CURLcode ssh_state_scp_upload_init(struct Curl_easy *data, LIBSSH2_ERROR_EAGAIN) return CURLE_AGAIN; - ssh_err = (int)(libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0)); + ssh_err = libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); failf(data, "%s", err_msg); myssh_state(data, sshc, SSH_SCP_CHANNEL_FREE); result = libssh2_session_error_to_CURLE(ssh_err); @@ -2567,10 +2556,8 @@ static CURLcode ssh_state_session_disconnect(struct Curl_easy *data, if(rc < 0) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); - infof(data, "Failed to free libssh2 scp subsystem: %d %s", - rc, err_msg); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); + infof(data, "Failed to free libssh2 scp subsystem: %d %s", rc, err_msg); } sshc->ssh_channel = NULL; } @@ -2582,10 +2569,8 @@ static CURLcode ssh_state_session_disconnect(struct Curl_easy *data, if(rc < 0) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); - infof(data, "Failed to disconnect libssh2 session: %d %s", - rc, err_msg); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); + infof(data, "Failed to disconnect libssh2 session: %d %s", rc, err_msg); } } @@ -2750,8 +2735,7 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, } break; - case SSH_SFTP_FILETIME: - { + case SSH_SFTP_FILETIME: { LIBSSH2_SFTP_ATTRIBUTES attrs; int rc; @@ -2778,7 +2762,7 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, if(data->state.upload) myssh_state(data, sshc, SSH_SFTP_UPLOAD_INIT); else if(sshp) { - if(sshp->path[strlen(sshp->path)-1] == '/') + if(sshp->path[strlen(sshp->path) - 1] == '/') myssh_state(data, sshc, SSH_SFTP_READDIR_INIT); else myssh_state(data, sshc, SSH_SFTP_DOWNLOAD_INIT); @@ -3097,8 +3081,8 @@ static void ssh_block2waitfor(struct Curl_easy *data, dir = libssh2_session_block_directions(sshc->ssh_session); if(dir) { /* translate the libssh2 define bits into our own bit defines */ - sshc->waitfor = ((dir&LIBSSH2_SESSION_BLOCK_INBOUND) ? KEEP_RECV : 0) | - ((dir&LIBSSH2_SESSION_BLOCK_OUTBOUND) ? KEEP_SEND : 0); + sshc->waitfor = ((dir & LIBSSH2_SESSION_BLOCK_INBOUND) ? KEEP_RECV : 0) | + ((dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) ? KEEP_SEND : 0); } } if(!dir) @@ -3308,24 +3292,24 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done) { const char *crypto_str; switch(libssh2_crypto_engine()) { - case libssh2_gcrypt: - crypto_str = "libgcrypt"; - break; - case libssh2_mbedtls: - crypto_str = "mbedTLS"; - break; - case libssh2_openssl: - crypto_str = "openssl compatible"; - break; - case libssh2_os400qc3: - crypto_str = "OS400QC3"; - break; - case libssh2_wincng: - crypto_str = "WinCNG"; - break; - default: - crypto_str = NULL; - break; + case libssh2_gcrypt: + crypto_str = "libgcrypt"; + break; + case libssh2_mbedtls: + crypto_str = "mbedTLS"; + break; + case libssh2_openssl: + crypto_str = "openssl compatible"; + break; + case libssh2_os400qc3: + crypto_str = "OS400QC3"; + break; + case libssh2_wincng: + crypto_str = "WinCNG"; + break; + default: + crypto_str = NULL; + break; } if(crypto_str) infof(data, "libssh2 cryptography backend: %s", crypto_str); @@ -3476,10 +3460,9 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done) * the options previously setup. */ -static -CURLcode scp_perform(struct Curl_easy *data, - bool *connected, - bool *dophase_done) +static CURLcode scp_perform(struct Curl_easy *data, + bool *connected, + bool *dophase_done) { struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN); CURLcode result = CURLE_OK; @@ -3562,8 +3545,7 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data, rc = libssh2_agent_disconnect(sshc->ssh_agent); if((rc < 0) && data) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); infof(data, "Failed to disconnect from libssh2 agent: %d %s", rc, err_msg); } @@ -3583,8 +3565,7 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data, rc = libssh2_sftp_close(sshc->sftp_handle); if((rc < 0) && data) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, - NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg); } if(!block && (rc == LIBSSH2_ERROR_EAGAIN)) @@ -3597,10 +3578,8 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data, rc = libssh2_channel_free(sshc->ssh_channel); if((rc < 0) && data) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); - infof(data, "Failed to free libssh2 scp subsystem: %d %s", - rc, err_msg); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); + infof(data, "Failed to free libssh2 scp subsystem: %d %s", rc, err_msg); } if(!block && (rc == LIBSSH2_ERROR_EAGAIN)) return CURLE_AGAIN; @@ -3612,8 +3591,7 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data, rc = libssh2_sftp_shutdown(sshc->sftp_session); if((rc < 0) && data) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); infof(data, "Failed to stop libssh2 sftp subsystem: %d %s", rc, err_msg); } if(!block && (rc == LIBSSH2_ERROR_EAGAIN)) @@ -3626,8 +3604,7 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data, rc = libssh2_session_free(sshc->ssh_session); if((rc < 0) && data) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); infof(data, "Failed to free libssh2 session: %d %s", rc, err_msg); } if(!block && (rc == LIBSSH2_ERROR_EAGAIN)) @@ -3653,7 +3630,6 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data, return CURLE_OK; } - /* BLOCKING, but the function is using the state machine so the only reason this is still blocking is that the multi interface code has no support for disconnecting operations that takes a while */ @@ -3701,7 +3677,6 @@ static CURLcode ssh_done(struct Curl_easy *data, CURLcode status) return result; } - static CURLcode scp_done(struct Curl_easy *data, CURLcode status, bool premature) { @@ -3731,8 +3706,8 @@ static CURLcode scp_send(struct Curl_easy *data, int sockindex, return CURLE_FAILED_INIT; /* libssh2_channel_write() returns int! */ - nwritten = (ssize_t) libssh2_channel_write(sshc->ssh_channel, - (const char *)mem, len); + nwritten = (ssize_t)libssh2_channel_write(sshc->ssh_channel, + (const char *)mem, len); ssh_block2waitfor(data, sshc, (nwritten == LIBSSH2_ERROR_EAGAIN)); @@ -3761,7 +3736,7 @@ static CURLcode scp_recv(struct Curl_easy *data, int sockindex, return CURLE_FAILED_INIT; /* libssh2_channel_read() returns int */ - nread = (ssize_t) libssh2_channel_read(sshc->ssh_channel, mem, len); + nread = (ssize_t)libssh2_channel_read(sshc->ssh_channel, mem, len); ssh_block2waitfor(data, sshc, (nread == LIBSSH2_ERROR_EAGAIN)); if(nread == LIBSSH2_ERROR_EAGAIN) @@ -3787,10 +3762,9 @@ static CURLcode scp_recv(struct Curl_easy *data, int sockindex, * the options previously setup. */ -static -CURLcode sftp_perform(struct Curl_easy *data, - bool *connected, - bool *dophase_done) +static CURLcode sftp_perform(struct Curl_easy *data, + bool *connected, + bool *dophase_done) { struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN); CURLcode result = CURLE_OK; @@ -3850,7 +3824,6 @@ static CURLcode sftp_disconnect(struct Curl_easy *data, sshc_cleanup(sshc, data, TRUE); } return result; - } static CURLcode sftp_done(struct Curl_easy *data, CURLcode status, @@ -3934,65 +3907,65 @@ static CURLcode sftp_recv(struct Curl_easy *data, int sockindex, static const char *sftp_libssh2_strerror(unsigned long err) { switch(err) { - case LIBSSH2_FX_NO_SUCH_FILE: - return "No such file or directory"; + case LIBSSH2_FX_NO_SUCH_FILE: + return "No such file or directory"; - case LIBSSH2_FX_PERMISSION_DENIED: - return "Permission denied"; + case LIBSSH2_FX_PERMISSION_DENIED: + return "Permission denied"; - case LIBSSH2_FX_FAILURE: - return "Operation failed"; + case LIBSSH2_FX_FAILURE: + return "Operation failed"; - case LIBSSH2_FX_BAD_MESSAGE: - return "Bad message from SFTP server"; + case LIBSSH2_FX_BAD_MESSAGE: + return "Bad message from SFTP server"; - case LIBSSH2_FX_NO_CONNECTION: - return "Not connected to SFTP server"; + case LIBSSH2_FX_NO_CONNECTION: + return "Not connected to SFTP server"; - case LIBSSH2_FX_CONNECTION_LOST: - return "Connection to SFTP server lost"; + case LIBSSH2_FX_CONNECTION_LOST: + return "Connection to SFTP server lost"; - case LIBSSH2_FX_OP_UNSUPPORTED: - return "Operation not supported by SFTP server"; + case LIBSSH2_FX_OP_UNSUPPORTED: + return "Operation not supported by SFTP server"; - case LIBSSH2_FX_INVALID_HANDLE: - return "Invalid handle"; + case LIBSSH2_FX_INVALID_HANDLE: + return "Invalid handle"; - case LIBSSH2_FX_NO_SUCH_PATH: - return "No such file or directory"; + case LIBSSH2_FX_NO_SUCH_PATH: + return "No such file or directory"; - case LIBSSH2_FX_FILE_ALREADY_EXISTS: - return "File already exists"; + case LIBSSH2_FX_FILE_ALREADY_EXISTS: + return "File already exists"; - case LIBSSH2_FX_WRITE_PROTECT: - return "File is write protected"; + case LIBSSH2_FX_WRITE_PROTECT: + return "File is write protected"; - case LIBSSH2_FX_NO_MEDIA: - return "No media"; + case LIBSSH2_FX_NO_MEDIA: + return "No media"; - case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM: - return "Disk full"; + case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM: + return "Disk full"; - case LIBSSH2_FX_QUOTA_EXCEEDED: - return "User quota exceeded"; + case LIBSSH2_FX_QUOTA_EXCEEDED: + return "User quota exceeded"; - case LIBSSH2_FX_UNKNOWN_PRINCIPLE: - return "Unknown principle"; + case LIBSSH2_FX_UNKNOWN_PRINCIPLE: + return "Unknown principle"; - case LIBSSH2_FX_LOCK_CONFlICT: - return "File lock conflict"; + case LIBSSH2_FX_LOCK_CONFlICT: + return "File lock conflict"; - case LIBSSH2_FX_DIR_NOT_EMPTY: - return "Directory not empty"; + case LIBSSH2_FX_DIR_NOT_EMPTY: + return "Directory not empty"; - case LIBSSH2_FX_NOT_A_DIRECTORY: - return "Not a directory"; + case LIBSSH2_FX_NOT_A_DIRECTORY: + return "Not a directory"; - case LIBSSH2_FX_INVALID_FILENAME: - return "Invalid filename"; + case LIBSSH2_FX_INVALID_FILENAME: + return "Invalid filename"; - case LIBSSH2_FX_LINK_LOOP: - return "Link points to itself"; + case LIBSSH2_FX_LINK_LOOP: + return "Link points to itself"; } return "Unknown error in libssh2"; } diff --git a/lib/vssh/ssh.h b/lib/vssh/ssh.h index 92ae72a6a761..ad0875f19143 100644 --- a/lib/vssh/ssh.h +++ b/lib/vssh/ssh.h @@ -217,7 +217,7 @@ struct ssh_conn { #ifdef USE_LIBSSH #if LIBSSH_VERSION_INT < SSH_VERSION_INT(0, 9, 0) -# error "SCP/SFTP protocols require libssh 0.9.0 or later" +#error "SCP/SFTP protocols require libssh 0.9.0 or later" #endif #endif @@ -227,7 +227,7 @@ struct ssh_conn { non-configure platforms */ #if !defined(LIBSSH2_VERSION_NUM) || (LIBSSH2_VERSION_NUM < 0x010208) -# error "SCP/SFTP protocols require libssh2 1.2.8 or later" +#error "SCP/SFTP protocols require libssh2 1.2.8 or later" /* 1.2.8 was released on April 5 2011 */ #endif @@ -247,7 +247,7 @@ void Curl_ssh_attach(struct Curl_easy *data, #else /* for non-SSH builds */ #define Curl_ssh_cleanup() -#define Curl_ssh_attach(x,y) +#define Curl_ssh_attach(x, y) #define Curl_ssh_init() 0 #endif diff --git a/lib/vssh/vssh.c b/lib/vssh/vssh.c index a23f9e8e981f..bfc0a1eb3ab6 100644 --- a/lib/vssh/vssh.c +++ b/lib/vssh/vssh.c @@ -75,7 +75,7 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data, /* Copy a separating '/' if homedir does not end with one */ len = curlx_dyn_len(&npath); p = curlx_dyn_ptr(&npath); - if(len && (p[len-1] != '/')) + if(len && (p[len - 1] != '/')) copyfrom = 2; if(curlx_dyn_addn(&npath, &working_path[copyfrom], @@ -147,7 +147,6 @@ CURLcode Curl_get_pathname(const char **cpp, char **path, const char *homedir) if(!curlx_dyn_len(&out)) goto fail; - } else { struct Curl_str word; diff --git a/lib/vtls/apple.c b/lib/vtls/apple.c index 62bb9e3bd194..31108763a02a 100644 --- a/lib/vtls/apple.c +++ b/lib/vtls/apple.c @@ -207,8 +207,7 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf, #if defined(HAVE_BUILTIN_AVAILABLE) && defined(SUPPORTS_SecOCSP) if(ocsp_len > 0) { if(__builtin_available(macOS 10.9, iOS 7, tvOS 9, watchOS 2, *)) { - CFDataRef ocspdata = - CFDataCreate(NULL, ocsp_buf, (CFIndex)ocsp_len); + CFDataRef ocspdata = CFDataCreate(NULL, ocsp_buf, (CFIndex)ocsp_len); status = SecTrustSetOCSPResponse(trust, ocspdata); CFRelease(ocspdata); @@ -243,7 +242,7 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf, err_desc = curlx_malloc(size + 1); if(err_desc) { if(!CFStringGetCString(error_ref, err_desc, size, - kCFStringEncodingUTF8)) { + kCFStringEncodingUTF8)) { curlx_free(err_desc); err_desc = NULL; } diff --git a/lib/vtls/cipher_suite.c b/lib/vtls/cipher_suite.c index 23fb3a3c5d16..3726187d7fcc 100644 --- a/lib/vtls/cipher_suite.c +++ b/lib/vtls/cipher_suite.c @@ -547,8 +547,7 @@ static const struct cs_entry cs_list [] = { }; #define CS_LIST_LEN CURL_ARRAYSIZE(cs_list) -static int cs_str_to_zip(const char *cs_str, size_t cs_len, - uint8_t zip[6]) +static int cs_str_to_zip(const char *cs_str, size_t cs_len, uint8_t zip[6]) { uint8_t indexes[8] = {0}; const char *entry, *cur; @@ -568,7 +567,8 @@ static int cs_str_to_zip(const char *cs_str, size_t cs_len, /* determine the length of the part */ cur = nxt; - for(; nxt < end && *nxt != '\0' && *nxt != separator; nxt++); + for(; nxt < end && *nxt != '\0' && *nxt != separator; nxt++) + ; len = nxt - cur; /* lookup index for the part (skip empty string at 0) */ @@ -581,22 +581,21 @@ static int cs_str_to_zip(const char *cs_str, size_t cs_len, if(idx == CS_TXT_LEN) return -1; - indexes[i++] = (uint8_t) idx; + indexes[i++] = (uint8_t)idx; } while(nxt < end && *(nxt++) != '\0'); /* zip the 8 indexes into 48 bits */ - zip[0] = (uint8_t) (indexes[0] << 2 | (indexes[1] & 0x3F) >> 4); - zip[1] = (uint8_t) (indexes[1] << 4 | (indexes[2] & 0x3F) >> 2); - zip[2] = (uint8_t) (indexes[2] << 6 | (indexes[3] & 0x3F)); - zip[3] = (uint8_t) (indexes[4] << 2 | (indexes[5] & 0x3F) >> 4); - zip[4] = (uint8_t) (indexes[5] << 4 | (indexes[6] & 0x3F) >> 2); - zip[5] = (uint8_t) (indexes[6] << 6 | (indexes[7] & 0x3F)); + zip[0] = (uint8_t)(indexes[0] << 2 | (indexes[1] & 0x3F) >> 4); + zip[1] = (uint8_t)(indexes[1] << 4 | (indexes[2] & 0x3F) >> 2); + zip[2] = (uint8_t)(indexes[2] << 6 | (indexes[3] & 0x3F)); + zip[3] = (uint8_t)(indexes[4] << 2 | (indexes[5] & 0x3F) >> 4); + zip[4] = (uint8_t)(indexes[5] << 4 | (indexes[6] & 0x3F) >> 2); + zip[5] = (uint8_t)(indexes[6] << 6 | (indexes[7] & 0x3F)); return 0; } -static int cs_zip_to_str(const uint8_t zip[6], - char *buf, size_t buf_size) +static int cs_zip_to_str(const uint8_t zip[6], char *buf, size_t buf_size) { uint8_t indexes[8] = {0}; const char *entry; @@ -659,13 +658,12 @@ uint16_t Curl_cipher_suite_lookup_id(const char *cs_str, size_t cs_len) static bool cs_is_separator(char c) { switch(c) { - case ' ': - case '\t': - case ':': - case ',': - case ';': - return TRUE; - default:; + case ' ': + case '\t': + case ':': + case ',': + case ';': + return TRUE; } return FALSE; } @@ -673,10 +671,12 @@ static bool cs_is_separator(char c) uint16_t Curl_cipher_suite_walk_str(const char **str, const char **end) { /* move string pointer to first non-separator or end of string */ - for(; cs_is_separator(*str[0]); (*str)++); + for(; cs_is_separator(*str[0]); (*str)++) + ; /* move end pointer to next separator or end of string */ - for(*end = *str; *end[0] != '\0' && !cs_is_separator(*end[0]); (*end)++); + for(*end = *str; *end[0] != '\0' && !cs_is_separator(*end[0]); (*end)++) + ; return Curl_cipher_suite_lookup_id(*str, *end - *str); } diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c index c05ab8427b89..e0ba48422b22 100644 --- a/lib/vtls/gtls.c +++ b/lib/vtls/gtls.c @@ -66,7 +66,7 @@ #ifdef GTLSDEBUG static void tls_log_func(int level, const char *str) { - curl_mfprintf(stderr, "|<%d>| %s", level, str); + curl_mfprintf(stderr, "|<%d>| %s", level, str); } #endif @@ -131,8 +131,7 @@ static ssize_t gtls_pull(void *s, void *buf, size_t blen) } result = Curl_conn_cf_recv(cf->next, data, buf, blen, &nread); - CURL_TRC_CF(data, cf, "glts_pull(len=%zu) -> %d, %zd", - blen, result, nread); + CURL_TRC_CF(data, cf, "glts_pull(len=%zu) -> %d, %zd", blen, result, nread); backend->gtls.io_result = result; if(result) { /* !checksrc! disable ERRNOVAR 1 */ @@ -173,9 +172,7 @@ static void gtls_cleanup(void) } #ifndef CURL_DISABLE_VERBOSE_STRINGS -static void showtime(struct Curl_easy *data, - const char *text, - time_t stamp) +static void showtime(struct Curl_easy *data, const char *text, time_t stamp) { struct tm buffer; const struct tm *tm = &buffer; @@ -209,10 +206,10 @@ static gnutls_datum_t load_file(const char *file) f = curlx_fopen(file, "rb"); if(!f) return loaded_file; - if(fseek(f, 0, SEEK_END) != 0 - || (filelen = ftell(f)) < 0 - || fseek(f, 0, SEEK_SET) != 0 - || !(ptr = curlx_malloc((size_t)filelen))) + if(fseek(f, 0, SEEK_END) != 0 || + (filelen = ftell(f)) < 0 || + fseek(f, 0, SEEK_SET) != 0 || + !(ptr = curlx_malloc((size_t)filelen))) goto out; if(fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) { curlx_free(ptr); @@ -231,7 +228,6 @@ static void unload_file(gnutls_datum_t data) curlx_free(data.data); } - /* this function does an SSL/TLS (re-)handshake */ static CURLcode cf_gtls_handshake(struct Curl_cfilter *cf, struct Curl_easy *data) @@ -584,20 +580,20 @@ static bool gtls_shared_creds_different(struct Curl_cfilter *cf, return strcmp(sc->CAfile, conn_config->CAfile); } -static struct gtls_shared_creds* -gtls_get_cached_creds(struct Curl_cfilter *cf, struct Curl_easy *data) +static struct gtls_shared_creds *gtls_get_cached_creds(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct gtls_shared_creds *shared_creds; if(data->multi) { shared_creds = Curl_hash_pick(&data->multi->proto_hash, CURL_UNCONST(MPROTO_GTLS_X509_KEY), - sizeof(MPROTO_GTLS_X509_KEY)-1); - if(shared_creds && shared_creds->creds && - !gtls_shared_creds_expired(data, shared_creds) && - !gtls_shared_creds_different(cf, shared_creds)) { - return shared_creds; - } + sizeof(MPROTO_GTLS_X509_KEY) - 1); + if(shared_creds && shared_creds->creds && + !gtls_shared_creds_expired(data, shared_creds) && + !gtls_shared_creds_different(cf, shared_creds)) { + return shared_creds; + } } return NULL; } @@ -605,7 +601,7 @@ gtls_get_cached_creds(struct Curl_cfilter *cf, struct Curl_easy *data) static void gtls_shared_creds_hash_free(void *key, size_t key_len, void *p) { struct gtls_shared_creds *sc = p; - DEBUGASSERT(key_len == (sizeof(MPROTO_GTLS_X509_KEY)-1)); + DEBUGASSERT(key_len == (sizeof(MPROTO_GTLS_X509_KEY) - 1)); DEBUGASSERT(!memcmp(MPROTO_GTLS_X509_KEY, key, key_len)); (void)key; (void)key_len; @@ -635,9 +631,9 @@ static void gtls_set_cached_creds(struct Curl_cfilter *cf, return; if(!Curl_hash_add2(&data->multi->proto_hash, - CURL_UNCONST(MPROTO_GTLS_X509_KEY), - sizeof(MPROTO_GTLS_X509_KEY)-1, - sc, gtls_shared_creds_hash_free)) { + CURL_UNCONST(MPROTO_GTLS_X509_KEY), + sizeof(MPROTO_GTLS_X509_KEY) - 1, + sc, gtls_shared_creds_hash_free)) { Curl_gtls_shared_creds_free(&sc); /* down reference again */ return; } @@ -839,7 +835,7 @@ static CURLcode gtls_set_priority(struct Curl_cfilter *cf, if((conn_config->cipher_list[0] == '+') || (conn_config->cipher_list[0] == '-') || (conn_config->cipher_list[0] == '!')) { - /* add it to out own */ + /* add it to out own */ if(!curlx_dyn_len(&buf)) { /* not added yet */ result = curlx_dyn_add(&buf, priority); if(result) @@ -1106,8 +1102,8 @@ static CURLcode gtls_on_session_reuse(struct Curl_cfilter *cf, connssl->earlydata_state = ssl_earlydata_await; connssl->state = ssl_connection_deferred; result = Curl_alpn_set_negotiated(cf, data, connssl, - (const unsigned char *)scs->alpn, - scs->alpn ? strlen(scs->alpn) : 0); + (const unsigned char *)scs->alpn, + scs->alpn ? strlen(scs->alpn) : 0); *do_early_data = !result; } return result; @@ -1225,8 +1221,8 @@ CURLcode Curl_gtls_ctx_init(struct gtls_ctx *gctx, return result; } -static CURLcode -gtls_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode gtls_connect_step1(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct gtls_ssl_backend_data *backend = @@ -1333,8 +1329,7 @@ static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data, return result; } -void Curl_gtls_report_handshake(struct Curl_easy *data, - struct gtls_ctx *gctx) +void Curl_gtls_report_handshake(struct Curl_easy *data, struct gtls_ctx *gctx) { #ifndef CURL_DISABLE_VERBOSE_STRINGS if(Curl_trc_is_verbose(data)) { @@ -1580,8 +1575,7 @@ static CURLcode glts_apple_verify(struct Curl_cfilter *cf, CURLcode result; result = Curl_vtls_apple_verify(cf, data, peer, chain->num_certs, - gtls_chain_get_der, chain, - NULL, 0); + gtls_chain_get_der, chain, NULL, 0); *pverified = !result; if(*pverified) infof(data, " SSL certificate verified by Apple SecTrust."); @@ -1589,14 +1583,13 @@ static CURLcode glts_apple_verify(struct Curl_cfilter *cf, } #endif /* USE_APPLE_SECTRUST */ -CURLcode -Curl_gtls_verifyserver(struct Curl_cfilter *cf, - struct Curl_easy *data, - gnutls_session_t session, - struct ssl_primary_config *config, - struct ssl_config_data *ssl_config, - struct ssl_peer *peer, - const char *pinned_key) +CURLcode Curl_gtls_verifyserver(struct Curl_cfilter *cf, + struct Curl_easy *data, + gnutls_session_t session, + struct ssl_primary_config *config, + struct ssl_config_data *ssl_config, + struct ssl_peer *peer, + const char *pinned_key) { struct gtls_cert_chain chain; gnutls_x509_crt_t x509_cert = NULL, x509_issuer = NULL; @@ -1651,7 +1644,7 @@ Curl_gtls_verifyserver(struct Curl_cfilter *cf, goto out; for(i = 0; i < chain.num_certs; i++) { - const char *beg = (const char *) chain.certs[i].data; + const char *beg = (const char *)chain.certs[i].data; const char *end = beg + chain.certs[i].size; result = Curl_extract_certinfo(data, (int)i, beg, end); @@ -1897,7 +1890,7 @@ static CURLcode gtls_send_earlydata(struct Curl_cfilter *cf, { struct ssl_connect_data *connssl = cf->ctx; struct gtls_ssl_backend_data *backend = - (struct gtls_ssl_backend_data *)connssl->backend; + (struct gtls_ssl_backend_data *)connssl->backend; CURLcode result = CURLE_OK; const unsigned char *buf; size_t blen; @@ -1907,8 +1900,7 @@ static CURLcode gtls_send_earlydata(struct Curl_cfilter *cf, backend->gtls.io_result = CURLE_OK; while(Curl_bufq_peek(&connssl->earlydata, &buf, &blen)) { n = gnutls_record_send_early_data(backend->gtls.session, buf, blen); - CURL_TRC_CF(data, cf, "gtls_send_earlydata(len=%zu) -> %zd", - blen, n); + CURL_TRC_CF(data, cf, "gtls_send_earlydata(len=%zu) -> %zd", blen, n); if(n < 0) { if(n == GNUTLS_E_AGAIN) result = CURLE_AGAIN; @@ -1947,7 +1939,7 @@ static CURLcode gtls_connect_common(struct Curl_cfilter *cf, { struct ssl_connect_data *connssl = cf->ctx; struct gtls_ssl_backend_data *backend = - (struct gtls_ssl_backend_data *)connssl->backend; + (struct gtls_ssl_backend_data *)connssl->backend; CURLcode result = CURLE_OK; DEBUGASSERT(backend); @@ -2131,7 +2123,7 @@ static CURLcode gtls_shutdown(struct Curl_cfilter *cf, size_t i; DEBUGASSERT(backend); - /* If we have no handshaked connection or already shut down */ + /* If we have no handshaked connection or already shut down */ if(!backend->gtls.session || cf->shutdown || connssl->state != ssl_connection_complete) { *done = TRUE; diff --git a/lib/vtls/gtls.h b/lib/vtls/gtls.h index afbe51eb9cb8..4949eee2d211 100644 --- a/lib/vtls/gtls.h +++ b/lib/vtls/gtls.h @@ -119,8 +119,7 @@ CURLcode Curl_gtls_cache_session(struct Curl_cfilter *cf, size_t quic_tp_len); /* Report properties of a successful handshake */ -void Curl_gtls_report_handshake(struct Curl_easy *data, - struct gtls_ctx *gctx); +void Curl_gtls_report_handshake(struct Curl_easy *data, struct gtls_ctx *gctx); extern const struct Curl_ssl Curl_ssl_gnutls; diff --git a/lib/vtls/hostcheck.c b/lib/vtls/hostcheck.c index 672f473db42a..fbd460bc15b1 100644 --- a/lib/vtls/hostcheck.c +++ b/lib/vtls/hostcheck.c @@ -84,9 +84,9 @@ static bool hostmatch(const char *hostname, DEBUGASSERT(hostlen); /* normalize pattern and hostname by stripping off trailing dots */ - if(hostname[hostlen-1]=='.') + if(hostname[hostlen - 1] == '.') hostlen--; - if(pattern[patternlen-1]=='.') + if(pattern[patternlen - 1] == '.') patternlen--; if(strncmp(pattern, "*.", 2)) diff --git a/lib/vtls/keylog.c b/lib/vtls/keylog.c index 397bac1a366a..03dda01f8dec 100644 --- a/lib/vtls/keylog.c +++ b/lib/vtls/keylog.c @@ -38,8 +38,7 @@ /* The fp for the open SSLKEYLOGFILE, or NULL if not open */ static FILE *keylog_file_fp; -void -Curl_tls_keylog_open(void) +void Curl_tls_keylog_open(void) { char *keylog_file_name; @@ -63,8 +62,7 @@ Curl_tls_keylog_open(void) } } -void -Curl_tls_keylog_close(void) +void Curl_tls_keylog_close(void) { if(keylog_file_fp) { curlx_fclose(keylog_file_fp); @@ -72,14 +70,12 @@ Curl_tls_keylog_close(void) } } -bool -Curl_tls_keylog_enabled(void) +bool Curl_tls_keylog_enabled(void) { return keylog_file_fp != NULL; } -bool -Curl_tls_keylog_write_line(const char *line) +bool Curl_tls_keylog_write_line(const char *line) { /* The current maximum valid keylog line length LF and NUL is 195. */ size_t linelen; @@ -107,10 +103,9 @@ Curl_tls_keylog_write_line(const char *line) return TRUE; } -bool -Curl_tls_keylog_write(const char *label, - const unsigned char client_random[CLIENT_RANDOM_SIZE], - const unsigned char *secret, size_t secretlen) +bool Curl_tls_keylog_write(const char *label, + const unsigned char client_random[CLIENT_RANDOM_SIZE], + const unsigned char *secret, size_t secretlen) { size_t pos, i; unsigned char line[KEYLOG_LABEL_MAXLEN + 1 + 2 * CLIENT_RANDOM_SIZE + 1 + diff --git a/lib/vtls/mbedtls.c b/lib/vtls/mbedtls.c index 9e13ed4641d9..d33167037162 100644 --- a/lib/vtls/mbedtls.c +++ b/lib/vtls/mbedtls.c @@ -38,7 +38,7 @@ #include #if MBEDTLS_VERSION_NUMBER < 0x03020000 - #error "mbedTLS 3.2.0 or later required" +#error "mbedTLS 3.2.0 or later required" #endif #include #include @@ -77,7 +77,7 @@ /* ALPN for http2 */ #if defined(USE_HTTP2) && defined(MBEDTLS_SSL_ALPN) -# define HAS_ALPN_MBEDTLS +#define HAS_ALPN_MBEDTLS #endif struct mbed_ssl_backend_data { @@ -109,7 +109,7 @@ struct mbed_ssl_backend_data { #endif #ifndef MBEDTLS_ERROR_C -#define mbedtls_strerror(a,b,c) b[0] = 0 +#define mbedtls_strerror(a, b, c) b[0] = 0 #endif #if defined(CURL_MBEDTLS_DRBG) && defined(HAS_THREADING_SUPPORT) @@ -217,8 +217,7 @@ static int mbedtls_bio_cf_read(void *bio, unsigned char *buf, size_t blen) /* * profile */ -static const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_fr = -{ +static const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_fr = { /* Hashes from SHA-1 and above */ MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA1) | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_RIPEMD160) | @@ -307,9 +306,8 @@ mbed_set_ssl_version_min_max(struct Curl_easy *data, cipher suite present in other SSL implementations. Provide provisional support for specifying the cipher suite here. */ #ifdef MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 -static int -mbed_cipher_suite_get_str(uint16_t id, char *buf, size_t buf_size, - bool prefer_rfc) +static int mbed_cipher_suite_get_str(uint16_t id, char *buf, size_t buf_size, + bool prefer_rfc) { if(id == MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8) curl_msnprintf(buf, buf_size, "%s", "TLS_ECJPAKE_WITH_AES_128_CCM_8"); @@ -318,8 +316,7 @@ mbed_cipher_suite_get_str(uint16_t id, char *buf, size_t buf_size, return 0; } -static uint16_t -mbed_cipher_suite_walk_str(const char **str, const char **end) +static uint16_t mbed_cipher_suite_walk_str(const char **str, const char **end) { uint16_t id = Curl_cipher_suite_walk_str(str, end); size_t len = *end - *str; @@ -348,7 +345,8 @@ mbed_set_selected_ciphers(struct Curl_easy *data, const char *ptr, *end; supported = mbedtls_ssl_list_ciphersuites(); - for(i = 0; supported[i] != 0; i++); + for(i = 0; supported[i] != 0; i++) + ; supported_len = i; selected = curlx_malloc(sizeof(int) * (supported_len + 1)); @@ -361,7 +359,7 @@ mbed_set_selected_ciphers(struct Curl_easy *data, if(!ciphers13) { /* Add default TLSv1.3 ciphers to selection */ for(j = 0; j < supported_len; j++) { - uint16_t id = (uint16_t) supported[j]; + uint16_t id = (uint16_t)supported[j]; if(strncmp(mbedtls_ssl_get_ciphersuite_name(id), "TLS1-3", 6) != 0) continue; @@ -380,23 +378,25 @@ mbed_set_selected_ciphers(struct Curl_easy *data, /* Check if cipher is supported */ if(id) { - for(i = 0; i < supported_len && supported[i] != id; i++); + for(i = 0; i < supported_len && supported[i] != id; i++) + ; if(i == supported_len) id = 0; } if(!id) { if(ptr[0] != '\0') infof(data, "mbedTLS: unknown cipher in list: \"%.*s\"", - (int) (end - ptr), ptr); + (int)(end - ptr), ptr); continue; } /* No duplicates allowed (so selected cannot overflow) */ - for(i = 0; i < count && selected[i] != id; i++); + for(i = 0; i < count && selected[i] != id; i++) + ; if(i < count) { if(i >= default13_count) infof(data, "mbedTLS: duplicate cipher in list: \"%.*s\"", - (int) (end - ptr), ptr); + (int)(end - ptr), ptr); continue; } @@ -412,12 +412,13 @@ mbed_set_selected_ciphers(struct Curl_easy *data, if(!ciphers12) { /* Add default TLSv1.2 ciphers to selection */ for(j = 0; j < supported_len; j++) { - uint16_t id = (uint16_t) supported[j]; + uint16_t id = (uint16_t)supported[j]; if(strncmp(mbedtls_ssl_get_ciphersuite_name(id), "TLS1-3", 6) == 0) continue; /* No duplicates allowed (so selected cannot overflow) */ - for(i = 0; i < count && selected[i] != id; i++); + for(i = 0; i < count && selected[i] != id; i++) + ; if(i < count) continue; @@ -441,8 +442,8 @@ mbed_set_selected_ciphers(struct Curl_easy *data, return CURLE_OK; } -static void -mbed_dump_cert_info(struct Curl_easy *data, const mbedtls_x509_crt *crt) +static void mbed_dump_cert_info(struct Curl_easy *data, + const mbedtls_x509_crt *crt) { #if defined(CURL_DISABLE_VERBOSE_STRINGS) || defined(MBEDTLS_X509_REMOVE_INFO) (void)data, (void)crt; @@ -454,7 +455,7 @@ mbed_dump_cert_info(struct Curl_easy *data, const mbedtls_x509_crt *crt) infof(data, "Server certificate:"); for(p = buffer; *p; p += *p != '\0') { size_t s = strcspn(p, "\n"); - infof(data, "%.*s", (int) s, p); + infof(data, "%.*s", (int)s, p); p += s; } } @@ -465,8 +466,8 @@ mbed_dump_cert_info(struct Curl_easy *data, const mbedtls_x509_crt *crt) #endif } -static void -mbed_extract_certinfo(struct Curl_easy *data, const mbedtls_x509_crt *crt) +static void mbed_extract_certinfo(struct Curl_easy *data, + const mbedtls_x509_crt *crt) { CURLcode result; const mbedtls_x509_crt *cur; @@ -485,7 +486,7 @@ mbed_extract_certinfo(struct Curl_easy *data, const mbedtls_x509_crt *crt) result = Curl_ssl_init_certinfo(data, cert_count); for(i = 0, cur = crt; result == CURLE_OK && cur; ++i, cur = cur->next) { - const char *beg = (const char *) cur->raw.p; + const char *beg = (const char *)cur->raw.p; const char *end = beg + cur->raw.len; result = Curl_extract_certinfo(data, i, beg, end); } @@ -494,7 +495,7 @@ mbed_extract_certinfo(struct Curl_easy *data, const mbedtls_x509_crt *crt) static int mbed_verify_cb(void *ptr, mbedtls_x509_crt *crt, int depth, uint32_t *flags) { - struct Curl_cfilter *cf = (struct Curl_cfilter *) ptr; + struct Curl_cfilter *cf = (struct Curl_cfilter *)ptr; struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); struct Curl_easy *data = CF_DATA_CURRENT(cf); @@ -523,8 +524,8 @@ static int mbed_verify_cb(void *ptr, mbedtls_x509_crt *crt, return 0; } -static CURLcode -mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode mbed_connect_step1(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct mbed_ssl_backend_data *backend = @@ -959,8 +960,8 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_OK; } -static CURLcode -mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode mbed_connect_step2(struct Curl_cfilter *cf, + struct Curl_easy *data) { CURLcode result; int ret; @@ -1004,8 +1005,8 @@ mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) { char cipher_str[64]; uint16_t cipher_id; - cipher_id = (uint16_t) - mbedtls_ssl_get_ciphersuite_id_from_ssl(&backend->ssl); + cipher_id = + (uint16_t)mbedtls_ssl_get_ciphersuite_id_from_ssl(&backend->ssl); mbed_cipher_suite_get_str(cipher_id, cipher_str, sizeof(cipher_str), TRUE); infof(data, "mbedTLS: %s Handshake complete, cipher is %s", mbedtls_ssl_get_version(&backend->ssl), cipher_str); @@ -1084,8 +1085,8 @@ mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_OK; } -static CURLcode -mbed_new_session(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode mbed_new_session(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct mbed_ssl_backend_data *backend = @@ -1148,8 +1149,7 @@ mbed_new_session(struct Curl_cfilter *cf, struct Curl_easy *data) } static CURLcode mbed_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *mem, size_t len, - size_t *pnwritten) + const void *mem, size_t len, size_t *pnwritten) { struct ssl_connect_data *connssl = cf->ctx; struct mbed_ssl_backend_data *backend = @@ -1327,8 +1327,7 @@ static void mbedtls_close(struct Curl_cfilter *cf, struct Curl_easy *data) } static CURLcode mbed_recv(struct Curl_cfilter *cf, struct Curl_easy *data, - char *buf, size_t buffersize, - size_t *pnread) + char *buf, size_t buffersize, size_t *pnread) { struct ssl_connect_data *connssl = cf->ctx; struct mbed_ssl_backend_data *backend = diff --git a/lib/vtls/mbedtls_threadlock.c b/lib/vtls/mbedtls_threadlock.c index 89cc2b7d38df..0a74d60d37ae 100644 --- a/lib/vtls/mbedtls_threadlock.c +++ b/lib/vtls/mbedtls_threadlock.c @@ -24,9 +24,8 @@ ***************************************************************************/ #include "../curl_setup.h" -#if defined(USE_MBEDTLS) && \ - ((defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \ - defined(_WIN32)) +#if defined(USE_MBEDTLS) && \ + ((defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || defined(_WIN32)) #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) # include diff --git a/lib/vtls/mbedtls_threadlock.h b/lib/vtls/mbedtls_threadlock.h index 1855d4cc0187..55607e62504c 100644 --- a/lib/vtls/mbedtls_threadlock.h +++ b/lib/vtls/mbedtls_threadlock.h @@ -28,8 +28,7 @@ #ifdef USE_MBEDTLS -#if (defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \ - defined(_WIN32) +#if (defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || defined(_WIN32) int Curl_mbedtlsthreadlock_thread_setup(void); int Curl_mbedtlsthreadlock_thread_cleanup(void); diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index bdfe527acd83..a958698b5836 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -179,7 +179,7 @@ static void ossl_provider_cleanup(struct Curl_easy *data); #define OSSL_PACKAGE "BoringSSL" #elif defined(OPENSSL_IS_AWSLC) #define OSSL_PACKAGE "AWS-LC" -#elif defined(USE_NGTCP2) && defined(USE_NGHTTP3) && \ +#elif defined(USE_NGTCP2) && defined(USE_NGHTTP3) && \ !defined(OPENSSL_QUIC_API2) #define OSSL_PACKAGE "quictls" #else @@ -234,7 +234,7 @@ static CURLcode pubkey_show(struct Curl_easy *data, return push_certinfo(data, mem, namebuf, num); } -#define print_pubkey_BN(_type, _name, _num) \ +#define print_pubkey_BN(_type, _name, _num) \ pubkey_show(data, mem, _num, #_type, #_name, _name) static int asn1_object_dump(const ASN1_OBJECT *a, char *buf, size_t len) @@ -685,8 +685,7 @@ static void ossl_keylog_callback(const SSL *ssl, const char *line) * ossl_log_tls12_secret is called by libcurl to make the CLIENT_RANDOMs if the * OpenSSL being used does not have native support for doing that. */ -static void -ossl_log_tls12_secret(const SSL *ssl, bool *keylog_done) +static void ossl_log_tls12_secret(const SSL *ssl, bool *keylog_done) { const SSL_SESSION *session; unsigned char client_random[SSL3_RANDOM_SIZE]; @@ -791,8 +790,7 @@ static char *ossl_strerror(unsigned long error, char *buf, size_t size) return buf; } -static int passwd_callback(char *buf, int num, int encrypting, - void *password) +static int passwd_callback(char *buf, int num, int encrypting, void *password) { DEBUGASSERT(encrypting == 0); @@ -932,8 +930,7 @@ static int use_certificate_blob(SSL_CTX *ctx, const struct curl_blob *blob, } else if(type == SSL_FILETYPE_PEM) { /* ERR_R_PEM_LIB; */ - x = PEM_read_bio_X509(in, NULL, - passwd_callback, CURL_UNCONST(key_passwd)); + x = PEM_read_bio_X509(in, NULL, passwd_callback, CURL_UNCONST(key_passwd)); } else { ret = 0; @@ -979,9 +976,9 @@ static int use_privatekey_blob(SSL_CTX *ctx, const struct curl_blob *blob, return ret; } -static int -use_certificate_chain_blob(SSL_CTX *ctx, const struct curl_blob *blob, - const char *key_passwd) +static int use_certificate_chain_blob(SSL_CTX *ctx, + const struct curl_blob *blob, + const char *key_passwd) { int ret = 0; X509 *x = NULL; @@ -1011,8 +1008,7 @@ use_certificate_chain_blob(SSL_CTX *ctx, const struct curl_blob *blob, } while((ca = PEM_read_bio_X509(in, NULL, passwd_callback, - CURL_UNCONST(key_passwd))) - != NULL) { + CURL_UNCONST(key_passwd))) != NULL) { if(!SSL_CTX_add0_chain_cert(ctx, ca)) { X509_free(ca); @@ -1054,8 +1050,7 @@ static int enginecheck(struct Curl_easy *data, } if(data->state.engine) { - UI_METHOD *ui_method = - UI_create_method("curl user interface"); + UI_METHOD *ui_method = UI_create_method("curl user interface"); if(!ui_method) { failf(data, "unable to create " OSSL_PACKAGE " user-interface method"); return 0; @@ -1116,8 +1111,7 @@ static int providercheck(struct Curl_easy *data, EVP_PKEY *priv_key = NULL; OSSL_STORE_CTX *store = NULL; OSSL_STORE_INFO *info = NULL; - UI_METHOD *ui_method = - UI_create_method("curl user interface"); + UI_METHOD *ui_method = UI_create_method("curl user interface"); if(!ui_method) { failf(data, "unable to create " OSSL_PACKAGE " user-interface method"); return 0; @@ -1221,16 +1215,15 @@ static int engineload(struct Curl_easy *data, /* Load the certificate from the engine */ if(!ENGINE_ctrl_cmd(data->state.engine, cmd_name, 0, ¶ms, NULL, 1)) { - failf(data, "ssl engine cannot load client cert with id" - " '%s' [%s]", cert_file, + failf(data, "ssl engine cannot load client cert with id '%s' [%s]", + cert_file, ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer))); return 0; } if(!params.cert) { - failf(data, "ssl engine did not initialized the certificate " - "properly."); + failf(data, "ssl engine did not initialized the certificate properly."); return 0; } @@ -1352,8 +1345,7 @@ static int pkcs12load(struct Curl_easy *data, if(cert_blob) { cert_bio = BIO_new_mem_buf(cert_blob->data, (int)(cert_blob->len)); if(!cert_bio) { - failf(data, - "BIO_new_mem_buf NULL, " OSSL_PACKAGE " error %s", + failf(data, "BIO_new_mem_buf NULL, " OSSL_PACKAGE " error %s", ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer)) ); return 0; @@ -1362,8 +1354,7 @@ static int pkcs12load(struct Curl_easy *data, else { cert_bio = BIO_new(BIO_s_file()); if(!cert_bio) { - failf(data, - "BIO_new return NULL, " OSSL_PACKAGE " error %s", + failf(data, "BIO_new return NULL, " OSSL_PACKAGE " error %s", ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer)) ); return 0; @@ -1386,11 +1377,9 @@ static int pkcs12load(struct Curl_easy *data, } if(!PKCS12_parse(p12, key_passwd, &pri, &x509, &ca)) { - failf(data, - "could not parse PKCS12 file, check password, " OSSL_PACKAGE + failf(data, "could not parse PKCS12 file, check password, " OSSL_PACKAGE " error %s", - ossl_strerror(ERR_get_error(), error_buffer, - sizeof(error_buffer)) ); + ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer))); PKCS12_free(p12); return 0; } @@ -1398,17 +1387,14 @@ static int pkcs12load(struct Curl_easy *data, PKCS12_free(p12); if(SSL_CTX_use_certificate(ctx, x509) != 1) { - failf(data, - "could not load PKCS12 client certificate, " OSSL_PACKAGE + failf(data, "could not load PKCS12 client certificate, " OSSL_PACKAGE " error %s", - ossl_strerror(ERR_get_error(), error_buffer, - sizeof(error_buffer)) ); + ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer))); goto fail; } if(SSL_CTX_use_PrivateKey(ctx, pri) != 1) { - failf(data, "unable to use private key from PKCS12 file '%s'", - cert_file); + failf(data, "unable to use private key from PKCS12 file '%s'", cert_file); goto fail; } @@ -1500,7 +1486,7 @@ static CURLcode client_cert(struct Curl_easy *data, "(no key found, wrong passphrase, or wrong file format?)", (cert_blob ? "CURLOPT_SSLCERT_BLOB" : cert_file), ossl_strerror(ERR_get_error(), error_buffer, - sizeof(error_buffer)) ); + sizeof(error_buffer))); return CURLE_SSL_CERTPROBLEM; } break; @@ -1520,7 +1506,7 @@ static CURLcode client_cert(struct Curl_easy *data, "(no key found, wrong passphrase, or wrong file format?)", (cert_blob ? "CURLOPT_SSLCERT_BLOB" : cert_file), ossl_strerror(ERR_get_error(), error_buffer, - sizeof(error_buffer)) ); + sizeof(error_buffer))); return CURLE_SSL_CERTPROBLEM; } break; @@ -1850,20 +1836,17 @@ static CURLcode ossl_set_provider(struct Curl_easy *data, const char *iname) return CURLE_OK; } - data->state.provider = - OSSL_PROVIDER_try_load(data->state.libctx, name, 1); + data->state.provider = OSSL_PROVIDER_try_load(data->state.libctx, name, 1); if(!data->state.provider) { char error_buffer[256]; failf(data, "Failed to initialize provider: %s", - ossl_strerror(ERR_get_error(), error_buffer, - sizeof(error_buffer))); + ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer))); ossl_provider_cleanup(data); return CURLE_SSL_ENGINE_NOTFOUND; } /* load the base provider as well */ - data->state.baseprov = - OSSL_PROVIDER_try_load(data->state.libctx, "base", 1); + data->state.baseprov = OSSL_PROVIDER_try_load(data->state.libctx, "base", 1); if(!data->state.baseprov) { ossl_provider_cleanup(data); failf(data, "Failed to load base"); @@ -1875,7 +1858,6 @@ static CURLcode ossl_set_provider(struct Curl_easy *data, const char *iname) } #endif - static CURLcode ossl_shutdown(struct Curl_cfilter *cf, struct Curl_easy *data, bool send_shutdown, bool *done) @@ -2138,7 +2120,7 @@ static CURLcode ossl_verifyhost(struct Curl_easy *data, if(check->type == target) { /* get data and length */ const char *altptr = (const char *)ASN1_STRING_get0_data(check->d.ia5); - size_t altlen = (size_t) ASN1_STRING_length(check->d.ia5); + size_t altlen = (size_t)ASN1_STRING_length(check->d.ia5); switch(target) { case GEN_DNS: /* name/pattern comparison */ @@ -2166,8 +2148,7 @@ static CURLcode ossl_verifyhost(struct Curl_easy *data, our server IP address is */ if((altlen == addrlen) && !memcmp(altptr, &addr, altlen)) { matched = TRUE; - infof(data, - " subjectAltName: \"%s\" matches cert's IP address!", + infof(data, " subjectAltName: \"%s\" matches cert's IP address!", peer->dispname); } break; @@ -2242,8 +2223,7 @@ static CURLcode ossl_verifyhost(struct Curl_easy *data, /* error already detected, pass through */ ; else if(!cn) { - failf(data, - "SSL: unable to obtain common name from peer certificate"); + failf(data, "SSL: unable to obtain common name from peer certificate"); result = CURLE_PEER_FAILED_VERIFICATION; } else if(!Curl_cert_hostcheck((const char *)cn, cnlen, @@ -2780,7 +2760,7 @@ CURLcode Curl_ossl_add_session(struct Curl_cfilter *cf, */ static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) { - struct Curl_cfilter *cf = (struct Curl_cfilter*) SSL_get_app_data(ssl); + struct Curl_cfilter *cf = (struct Curl_cfilter *)SSL_get_app_data(ssl); if(cf) { struct Curl_easy *data = CF_DATA_CURRENT(cf); struct ssl_connect_data *connssl = cf->ctx; @@ -3181,7 +3161,7 @@ static CURLcode ossl_populate_x509_store(struct Curl_cfilter *cf, failf(data, "error loading CRL file: %s", ssl_crlfile); return CURLE_SSL_CRL_BADFILE; } - x509flags = X509_V_FLAG_CRL_CHECK|X509_V_FLAG_CRL_CHECK_ALL; + x509flags = X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL; infof(data, " CRLfile: %s", ssl_crlfile); } @@ -3210,7 +3190,7 @@ static CURLcode ossl_populate_x509_store(struct Curl_cfilter *cf, } /* key to use at `multi->proto_hash` */ -#define MPROTO_OSSL_X509_KEY "tls:ossl:x509:share" +#define MPROTO_OSSL_X509_KEY "tls:ossl:x509:share" struct ossl_x509_share { char *CAfile; /* CAfile path used to generate X509 store */ @@ -3222,7 +3202,7 @@ struct ossl_x509_share { static void oss_x509_share_free(void *key, size_t key_len, void *p) { struct ossl_x509_share *share = p; - DEBUGASSERT(key_len == (sizeof(MPROTO_OSSL_X509_KEY)-1)); + DEBUGASSERT(key_len == (sizeof(MPROTO_OSSL_X509_KEY) - 1)); DEBUGASSERT(!memcmp(MPROTO_OSSL_X509_KEY, key, key_len)); (void)key; (void)key_len; @@ -3233,9 +3213,8 @@ static void oss_x509_share_free(void *key, size_t key_len, void *p) curlx_free(share); } -static bool -ossl_cached_x509_store_expired(const struct Curl_easy *data, - const struct ossl_x509_share *mb) +static bool ossl_cached_x509_store_expired(const struct Curl_easy *data, + const struct ossl_x509_share *mb) { const struct ssl_general_config *cfg = &data->set.general_ssl; if(cfg->ca_cache_timeout < 0) @@ -3249,9 +3228,8 @@ ossl_cached_x509_store_expired(const struct Curl_easy *data, } } -static bool -ossl_cached_x509_store_different(struct Curl_cfilter *cf, - const struct ossl_x509_share *mb) +static bool ossl_cached_x509_store_different(struct Curl_cfilter *cf, + const struct ossl_x509_share *mb) { struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); if(!mb->CAfile || !conn_config->CAfile) @@ -3272,7 +3250,7 @@ static X509_STORE *ossl_get_cached_x509_store(struct Curl_cfilter *cf, *pempty = TRUE; share = multi ? Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_OSSL_X509_KEY), - sizeof(MPROTO_OSSL_X509_KEY)-1) : NULL; + sizeof(MPROTO_OSSL_X509_KEY) - 1) : NULL; if(share && share->store && !ossl_cached_x509_store_expired(data, share) && !ossl_cached_x509_store_different(cf, share)) { @@ -3297,7 +3275,7 @@ static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, return; share = Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_OSSL_X509_KEY), - sizeof(MPROTO_OSSL_X509_KEY)-1); + sizeof(MPROTO_OSSL_X509_KEY) - 1); if(!share) { share = curlx_calloc(1, sizeof(*share)); @@ -3305,7 +3283,7 @@ static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, return; if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_OSSL_X509_KEY), - sizeof(MPROTO_OSSL_X509_KEY)-1, + sizeof(MPROTO_OSSL_X509_KEY) - 1, share, oss_x509_share_free)) { curlx_free(share); return; @@ -3508,8 +3486,7 @@ static CURLcode ossl_init_ech(struct ossl_ctx *octx, if(data->set.tls_ech & CURLECH_HARD) return result; } - if(SSL_set1_ech_config_list(octx->ssl, ech_config, - ech_config_len) != 1) { + if(SSL_set1_ech_config_list(octx->ssl, ech_config, ech_config_len) != 1) { infof(data, "ECH: SSL_ECH_set1_ech_config_list failed"); if(data->set.tls_ech & CURLECH_HARD) { curlx_free(ech_config); @@ -3519,14 +3496,13 @@ static CURLcode ossl_init_ech(struct ossl_ctx *octx, curlx_free(ech_config); trying_ech_now = 1; # else - ech_config = (unsigned char *) data->set.str[STRING_ECH_CONFIG]; + ech_config = (unsigned char *)data->set.str[STRING_ECH_CONFIG]; if(!ech_config) { infof(data, "ECH: ECHConfig from command line empty"); return CURLE_SSL_CONNECT_ERROR; } ech_config_len = strlen(data->set.str[STRING_ECH_CONFIG]); - if(SSL_set1_ech_config_list(octx->ssl, ech_config, - ech_config_len) != 1) { + if(SSL_set1_ech_config_list(octx->ssl, ech_config, ech_config_len) != 1) { infof(data, "ECH: SSL_ECH_set1_ech_config_list failed"); if(data->set.tls_ech & CURLECH_HARD) return CURLE_SSL_CONNECT_ERROR; @@ -3584,16 +3560,16 @@ static CURLcode ossl_init_ech(struct ossl_ctx *octx, infof(data, "ECH: inner: '%s', outer: '%s'", peer->hostname ? peer->hostname : "NULL", outername); result = SSL_ech_set1_server_names(octx->ssl, - peer->hostname, outername, - 0 /* do send outer */); + peer->hostname, outername, + 0 /* do send outer */); if(result != 1) { infof(data, "ECH: rv failed to set server name(s) %d [ERROR]", result); return CURLE_SSL_CONNECT_ERROR; } } # endif /* HAVE_BORINGSSL_LIKE */ - if(trying_ech_now - && SSL_set_min_proto_version(octx->ssl, TLS1_3_VERSION) != 1) { + if(trying_ech_now && + SSL_set_min_proto_version(octx->ssl, TLS1_3_VERSION) != 1) { infof(data, "ECH: cannot force TLSv1.3 [ERROR]"); return CURLE_SSL_CONNECT_ERROR; } @@ -3602,7 +3578,6 @@ static CURLcode ossl_init_ech(struct ossl_ctx *octx, } #endif /* USE_ECH_OPENSSL */ - static CURLcode ossl_init_ssl(struct ossl_ctx *octx, struct Curl_cfilter *cf, struct Curl_easy *data, @@ -3706,7 +3681,6 @@ static CURLcode ossl_init_method(struct Curl_cfilter *cf, return *pmethod ? CURLE_OK : CURLE_SSL_CONNECT_ERROR; } - CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx, struct Curl_cfilter *cf, struct Curl_easy *data, @@ -3821,7 +3795,7 @@ CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx, /* "--tlsv" options mean TLS >= version */ case CURL_SSLVERSION_DEFAULT: - case CURL_SSLVERSION_TLSv1: /* TLS >= version 1.0 */ + case CURL_SSLVERSION_TLSv1: /* TLS >= version 1.0 */ case CURL_SSLVERSION_TLSv1_0: /* TLS >= version 1.0 */ case CURL_SSLVERSION_TLSv1_1: /* TLS >= version 1.1 */ case CURL_SSLVERSION_TLSv1_2: /* TLS >= version 1.2 */ @@ -4036,8 +4010,7 @@ static CURLcode ossl_on_session_reuse(struct Curl_cfilter *cf, return result; } -void Curl_ossl_report_handshake(struct Curl_easy *data, - struct ossl_ctx *octx) +void Curl_ossl_report_handshake(struct Curl_easy *data, struct ossl_ctx *octx) { #ifndef CURL_DISABLE_VERBOSE_STRINGS if(Curl_trc_is_verbose(data)) { @@ -4065,7 +4038,6 @@ void Curl_ossl_report_handshake(struct Curl_easy *data, (void)data; (void)octx; #endif /* CURL_DISABLE_VERBOSE_STRINGS */ - } static CURLcode ossl_connect_step1(struct Curl_cfilter *cf, @@ -4121,7 +4093,7 @@ static CURLcode ossl_connect_step1(struct Curl_cfilter *cf, #ifdef USE_ECH_OPENSSL /* If we have retry configs, then trace those out */ -static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL* ssl, +static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL *ssl, int reason) { CURLcode result = CURLE_OK; @@ -4247,7 +4219,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, else { /* untreated error */ sslerr_t errdetail; - char error_buffer[256]=""; + char error_buffer[256] = ""; CURLcode result; long lerr; int lib; @@ -4319,7 +4291,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, * the SO_ERROR is also lost. */ if(CURLE_SSL_CONNECT_ERROR == result && errdetail == 0) { - char extramsg[80]=""; + char extramsg[80] = ""; int sockerr = SOCKERRNO; if(sockerr && detail == SSL_ERROR_SYSCALL) @@ -4374,7 +4346,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, break; default: status = "unexpected status"; - infof(data, "ECH: unexpected status %d",rv); + infof(data, "ECH: unexpected status %d", rv); } infof(data, "ECH: result: status is %s, inner is %s, outer is %s", (status ? status : "NULL"), @@ -4418,7 +4390,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, * Heavily modified from: * https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning#OpenSSL */ -static CURLcode ossl_pkp_pin_peer_pubkey(struct Curl_easy *data, X509* cert, +static CURLcode ossl_pkp_pin_peer_pubkey(struct Curl_easy *data, X509 *cert, const char *pinnedpubkey) { /* Scratch */ @@ -4534,8 +4506,7 @@ static void infof_certstack(struct Curl_easy *data, const SSL *ssl) type_name = NULL; #endif - infof(data, - " Certificate level %d: " + infof(data, " Certificate level %d: " "Public key type %s%s (%d/%d Bits/secBits), signed using %s", cert_level, type_name ? type_name : "?", get_group_name == 0 ? "" : group_name_final, @@ -4553,7 +4524,7 @@ static CURLcode ossl_check_issuer(struct Curl_cfilter *cf, struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); X509 *issuer = NULL; BIO *fp = NULL; - char err_buf[256]=""; + char err_buf[256] = ""; bool verify_enabled = (conn_config->verifypeer || conn_config->verifyhost); CURLcode result = CURLE_OK; @@ -4671,12 +4642,12 @@ static CURLcode ossl_infof_cert(struct Curl_cfilter *cf, infof(data, " subject: %s", result ? "[NONE]" : curlx_dyn_ptr(&dname)); ASN1_TIME_print(mem, X509_get0_notBefore(server_cert)); - len = BIO_get_mem_data(mem, (char **) &buf); + len = BIO_get_mem_data(mem, (char **)&buf); infof(data, " start date: %.*s", (int)len, buf); (void)BIO_reset(mem); ASN1_TIME_print(mem, X509_get0_notAfter(server_cert)); - len = BIO_get_mem_data(mem, (char **) &buf); + len = BIO_get_mem_data(mem, (char **)&buf); infof(data, " expire date: %.*s", (int)len, buf); (void)BIO_reset(mem); @@ -5118,8 +5089,7 @@ static CURLcode ossl_send(struct Curl_cfilter *cf, result = CURLE_AGAIN; octx->blocked_ssl_write_len = memlen; goto out; - case SSL_ERROR_SYSCALL: - { + case SSL_ERROR_SYSCALL: { int sockerr = SOCKERRNO; if(octx->io_result == CURLE_AGAIN) { diff --git a/lib/vtls/openssl.h b/lib/vtls/openssl.h index 5b6f35396d91..ff8246b4fae3 100644 --- a/lib/vtls/openssl.h +++ b/lib/vtls/openssl.h @@ -150,8 +150,7 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, struct ssl_peer *peer); /* Report properties of a successful handshake */ -void Curl_ossl_report_handshake(struct Curl_easy *data, - struct ossl_ctx *octx); +void Curl_ossl_report_handshake(struct Curl_easy *data, struct ossl_ctx *octx); #endif /* USE_OPENSSL */ #endif /* HEADER_CURL_SSLUSE_H */ diff --git a/lib/vtls/rustls.c b/lib/vtls/rustls.c index 360a2454ac85..951b339b4346 100644 --- a/lib/vtls/rustls.c +++ b/lib/vtls/rustls.c @@ -42,8 +42,7 @@ #include "cipher_suite.h" #include "x509asn1.h" -struct rustls_ssl_backend_data -{ +struct rustls_ssl_backend_data { const struct rustls_client_config *config; struct rustls_connection *conn; size_t plain_out_buffered; @@ -58,17 +57,17 @@ static CURLcode map_error(const rustls_result r) return CURLE_PEER_FAILED_VERIFICATION; } switch(r) { - case RUSTLS_RESULT_OK: - return CURLE_OK; - case RUSTLS_RESULT_NULL_PARAMETER: - return CURLE_BAD_FUNCTION_ARGUMENT; - default: - return CURLE_RECV_ERROR; + case RUSTLS_RESULT_OK: + return CURLE_OK; + case RUSTLS_RESULT_NULL_PARAMETER: + return CURLE_BAD_FUNCTION_ARGUMENT; + default: + return CURLE_RECV_ERROR; } } -static void -rustls_failf(struct Curl_easy *data, const rustls_result rr, const char *msg) +static void rustls_failf(struct Curl_easy *data, const rustls_result rr, + const char *msg) { char errorbuf[STRERROR_LEN]; size_t errorlen; @@ -76,8 +75,8 @@ rustls_failf(struct Curl_easy *data, const rustls_result rr, const char *msg) failf(data, "%s: %.*s", msg, (int)errorlen, errorbuf); } -static bool -cr_data_pending(struct Curl_cfilter *cf, const struct Curl_easy *data) +static bool cr_data_pending(struct Curl_cfilter *cf, + const struct Curl_easy *data) { const struct ssl_connect_data *ctx = cf->ctx; struct rustls_ssl_backend_data *backend; @@ -93,11 +92,11 @@ struct io_ctx { struct Curl_easy *data; }; -static int -read_cb(void *userdata, uint8_t *buf, uintptr_t len, uintptr_t *out_n) +static int read_cb(void *userdata, uint8_t *buf, uintptr_t len, + uintptr_t *out_n) { const struct io_ctx *io_ctx = userdata; - struct ssl_connect_data *const connssl = io_ctx->cf->ctx; + struct ssl_connect_data * const connssl = io_ctx->cf->ctx; CURLcode result; int ret = 0; size_t nread; @@ -120,8 +119,8 @@ read_cb(void *userdata, uint8_t *buf, uintptr_t len, uintptr_t *out_n) return ret; } -static int -write_cb(void *userdata, const uint8_t *buf, uintptr_t len, uintptr_t *out_n) +static int write_cb(void *userdata, const uint8_t *buf, uintptr_t len, + uintptr_t *out_n) { const struct io_ctx *io_ctx = userdata; CURLcode result; @@ -146,8 +145,8 @@ write_cb(void *userdata, const uint8_t *buf, uintptr_t len, uintptr_t *out_n) static ssize_t tls_recv_more(struct Curl_cfilter *cf, struct Curl_easy *data, CURLcode *err) { - const struct ssl_connect_data *const connssl = cf->ctx; - struct rustls_ssl_backend_data *const backend = + const struct ssl_connect_data * const connssl = cf->ctx; + struct rustls_ssl_backend_data * const backend = (struct rustls_ssl_backend_data *)connssl->backend; struct io_ctx io_ctx; size_t tls_bytes_read = 0; @@ -186,12 +185,11 @@ static ssize_t tls_recv_more(struct Curl_cfilter *cf, * Filter receive method implementation. `plainbuf` and `plainlen` * are always not NULL/0. */ -static CURLcode -cr_recv(struct Curl_cfilter *cf, struct Curl_easy *data, - char *plainbuf, size_t plainlen, size_t *pnread) +static CURLcode cr_recv(struct Curl_cfilter *cf, struct Curl_easy *data, + char *plainbuf, size_t plainlen, size_t *pnread) { - const struct ssl_connect_data *const connssl = cf->ctx; - struct rustls_ssl_backend_data *const backend = + const struct ssl_connect_data * const connssl = cf->ctx; + struct rustls_ssl_backend_data * const backend = (struct rustls_ssl_backend_data *)connssl->backend; struct rustls_connection *rconn = NULL; CURLcode result = CURLE_OK; @@ -300,12 +298,12 @@ static CURLcode cr_flush_out(struct Curl_cfilter *cf, struct Curl_easy *data, * In that case, it will not read anything into Rustls' plaintext input buffer. * It will only drain Rustls' plaintext output buffer into the socket. */ -static CURLcode -cr_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *plainbuf, size_t plainlen, size_t *pnwritten) +static CURLcode cr_send(struct Curl_cfilter *cf, struct Curl_easy *data, + const void *plainbuf, size_t plainlen, + size_t *pnwritten) { - const struct ssl_connect_data *const connssl = cf->ctx; - struct rustls_ssl_backend_data *const backend = + const struct ssl_connect_data * const connssl = cf->ctx; + struct rustls_ssl_backend_data * const backend = (struct rustls_ssl_backend_data *)connssl->backend; struct rustls_connection *rconn = NULL; size_t plainwritten = 0; @@ -379,18 +377,15 @@ cr_send(struct Curl_cfilter *cf, struct Curl_easy *data, /* A server certificate verify callback for Rustls that always returns RUSTLS_RESULT_OK, or in other words disable certificate verification. */ -static uint32_t -cr_verify_none(void *userdata, - const rustls_verify_server_cert_params *params) +static uint32_t cr_verify_none(void *userdata, + const rustls_verify_server_cert_params *params) { (void)userdata; (void)params; return RUSTLS_RESULT_OK; } -static int -read_file_into(const char *filename, - struct dynbuf *out) +static int read_file_into(const char *filename, struct dynbuf *out) { FILE *f = curlx_fopen(filename, FOPEN_READTEXT); if(!f) { @@ -464,16 +459,17 @@ cr_get_selected_ciphers(struct Curl_easy *data, if(!id) { if(ptr[0] != '\0') infof(data, "rustls: unknown cipher in list: \"%.*s\"", - (int) (end - ptr), ptr); + (int)(end - ptr), ptr); continue; } /* No duplicates allowed (so selected cannot overflow) */ - for(i = 0; i < count && selected[i] != entry; i++); + for(i = 0; i < count && selected[i] != entry; i++) + ; if(i < count) { if(i >= default13_count) infof(data, "rustls: duplicate cipher in list: \"%.*s\"", - (int) (end - ptr), ptr); + (int)(end - ptr), ptr); continue; } @@ -494,7 +490,8 @@ cr_get_selected_ciphers(struct Curl_easy *data, continue; /* No duplicates allowed (so selected cannot overflow) */ - for(i = 0; i < count && selected[i] != entry; i++); + for(i = 0; i < count && selected[i] != entry; i++) + ; if(i < count) continue; @@ -505,10 +502,10 @@ cr_get_selected_ciphers(struct Curl_easy *data, *selected_size = count; } -static void -cr_keylog_log_cb(struct rustls_str label, - const uint8_t *client_random, size_t client_random_len, - const uint8_t *secret, size_t secret_len) +static void cr_keylog_log_cb(struct rustls_str label, + const uint8_t *client_random, + size_t client_random_len, const uint8_t *secret, + size_t secret_len) { char clabel[KEYLOG_LABEL_MAXLEN]; (void)client_random_len; @@ -528,12 +525,11 @@ init_config_builder(struct Curl_easy *data, const struct rustls_crypto_provider *custom_provider = NULL; uint16_t tls_versions[2] = { - RUSTLS_TLS_VERSION_TLSV1_2, - RUSTLS_TLS_VERSION_TLSV1_3, + RUSTLS_TLS_VERSION_TLSV1_2, + RUSTLS_TLS_VERSION_TLSV1_3, }; size_t tls_versions_len = 2; - size_t cipher_suites_len = - rustls_default_crypto_provider_ciphersuites_len(); + size_t cipher_suites_len = rustls_default_crypto_provider_ciphersuites_len(); CURLcode result = CURLE_OK; rustls_result rr; @@ -602,7 +598,7 @@ init_config_builder(struct Curl_easy *data, &custom_provider_builder); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, - "failed to create crypto provider builder from default"); + "failed to create crypto provider builder from default"); result = CURLE_SSL_CIPHER; goto cleanup; } @@ -614,13 +610,13 @@ init_config_builder(struct Curl_easy *data, cipher_suites_len); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, - "failed to set ciphersuites for crypto provider builder"); + "failed to set ciphersuites for crypto provider builder"); result = CURLE_SSL_CIPHER; goto cleanup; } - rr = rustls_crypto_provider_builder_build( - custom_provider_builder, &custom_provider); + rr = rustls_crypto_provider_builder_build(custom_provider_builder, + &custom_provider); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "failed to build custom crypto provider"); result = CURLE_SSL_CIPHER; @@ -628,9 +624,9 @@ init_config_builder(struct Curl_easy *data, } rr = rustls_client_config_builder_new_custom(custom_provider, - tls_versions, - tls_versions_len, - config_builder); + tls_versions, + tls_versions_len, + config_builder); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "failed to create client config builder"); result = CURLE_SSL_CIPHER; @@ -669,8 +665,7 @@ init_config_builder_alpn(struct Curl_easy *data, infof(data, VTLS_INFOF_ALPN_OFFER_1STR, proto.data); } -static CURLcode -init_config_builder_verifier_crl( +static CURLcode init_config_builder_verifier_crl( struct Curl_easy *data, const struct ssl_primary_config *conn_config, struct rustls_web_pki_server_cert_verifier_builder *builder) @@ -723,7 +718,6 @@ init_config_builder_verifier(struct Curl_easy *data, 1); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "failed to parse trusted certificates from blob"); - result = CURLE_SSL_CACERT_BADFILE; goto cleanup; } @@ -734,7 +728,6 @@ init_config_builder_verifier(struct Curl_easy *data, 1); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "failed to load trusted certificates"); - result = CURLE_SSL_CACERT_BADFILE; goto cleanup; } @@ -755,8 +748,8 @@ init_config_builder_verifier(struct Curl_easy *data, if(conn_config->CRLfile) { result = init_config_builder_verifier_crl(data, - conn_config, - verifier_builder); + conn_config, + verifier_builder); if(result) { goto cleanup; } @@ -789,8 +782,7 @@ init_config_builder_verifier(struct Curl_easy *data, return result; } -static CURLcode -init_config_builder_platform_verifier( +static CURLcode init_config_builder_platform_verifier( struct Curl_easy *data, struct rustls_client_config_builder *builder) { @@ -890,10 +882,8 @@ init_config_builder_client_auth(struct Curl_easy *data, rr = rustls_certified_key_keys_match(certified_key); if(rr != RUSTLS_RESULT_OK) { - rustls_failf(data, - rr, + rustls_failf(data, rr, "rustls: client certificate and keypair files do not match:"); - result = CURLE_SSL_CERTPROBLEM; goto cleanup; } @@ -1011,9 +1001,9 @@ init_config_builder_ech(struct Curl_easy *data, } #endif /* USE_ECH */ -static CURLcode -cr_init_backend(struct Curl_cfilter *cf, struct Curl_easy *data, - struct rustls_ssl_backend_data *const backend) +static CURLcode cr_init_backend(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct rustls_ssl_backend_data * const backend) { const struct ssl_connect_data *connssl = cf->ctx; const struct ssl_primary_config *conn_config = @@ -1091,9 +1081,7 @@ cr_init_backend(struct Curl_cfilter *cf, struct Curl_easy *data, return result; } - rr = rustls_client_config_builder_build( - config_builder, - &backend->config); + rr = rustls_client_config_builder_build(config_builder, &backend->config); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "failed to build client config"); return CURLE_SSL_CONNECT_ERROR; @@ -1116,11 +1104,11 @@ cr_init_backend(struct Curl_cfilter *cf, struct Curl_easy *data, return result; } -static void -cr_set_negotiated_alpn(struct Curl_cfilter *cf, struct Curl_easy *data, - const struct rustls_connection *rconn) +static void cr_set_negotiated_alpn(struct Curl_cfilter *cf, + struct Curl_easy *data, + const struct rustls_connection *rconn) { - struct ssl_connect_data *const connssl = cf->ctx; + struct ssl_connect_data * const connssl = cf->ctx; const uint8_t *protocol = NULL; size_t len = 0; @@ -1133,12 +1121,11 @@ cr_set_negotiated_alpn(struct Curl_cfilter *cf, struct Curl_easy *data, * This function will set `*done` to true once the handshake is complete. * This function never reads the value of `*done*`. */ -static CURLcode -cr_connect(struct Curl_cfilter *cf, - struct Curl_easy *data, bool *done) +static CURLcode cr_connect(struct Curl_cfilter *cf, struct Curl_easy *data, + bool *done) { - struct ssl_connect_data *const connssl = cf->ctx; - const struct rustls_ssl_backend_data *const backend = + struct ssl_connect_data * const connssl = cf->ctx; + const struct rustls_ssl_backend_data * const backend = (struct rustls_ssl_backend_data *)connssl->backend; const struct rustls_connection *rconn = NULL; CURLcode tmperr = CURLE_OK; @@ -1165,9 +1152,9 @@ cr_connect(struct Curl_cfilter *cf, /* Read/write data until the handshake is done or the socket would block. */ for(;;) { /* - * Connection has been established according to Rustls. Set send/recv - * handlers, and update the state machine. - */ + * Connection has been established according to Rustls. Set send/recv + * handlers, and update the state machine. + */ connssl->io_need = CURL_SSL_IO_NEED_NONE; if(!rustls_connection_is_handshaking(rconn)) { /* Rustls claims it is no longer handshaking *before* it has @@ -1186,8 +1173,7 @@ cr_connect(struct Curl_cfilter *cf, } /* REALLY Done with the handshake. */ { - const uint16_t proto = - rustls_connection_get_protocol_version(rconn); + const uint16_t proto = rustls_connection_get_protocol_version(rconn); const rustls_str ciphersuite_name = rustls_connection_get_negotiated_ciphersuite_name(rconn); const rustls_str kex_group_name = @@ -1297,9 +1283,7 @@ cr_connect(struct Curl_cfilter *cf, DEBUGASSERT(FALSE); } -static void * -cr_get_internals(struct ssl_connect_data *connssl, - CURLINFO info) +static void *cr_get_internals(struct ssl_connect_data *connssl, CURLINFO info) { struct rustls_ssl_backend_data *backend = (struct rustls_ssl_backend_data *)connssl->backend; @@ -1308,10 +1292,8 @@ cr_get_internals(struct ssl_connect_data *connssl, return backend->conn; } -static CURLcode -cr_shutdown(struct Curl_cfilter *cf, - struct Curl_easy *data, - const bool send_shutdown, bool *done) +static CURLcode cr_shutdown(struct Curl_cfilter *cf, struct Curl_easy *data, + const bool send_shutdown, bool *done) { struct ssl_connect_data *connssl = cf->ctx; struct rustls_ssl_backend_data *backend = @@ -1373,8 +1355,7 @@ cr_shutdown(struct Curl_cfilter *cf, return result; } -static void -cr_close(struct Curl_cfilter *cf, struct Curl_easy *data) +static void cr_close(struct Curl_cfilter *cf, struct Curl_easy *data) { const struct ssl_connect_data *connssl = cf->ctx; struct rustls_ssl_backend_data *backend = @@ -1398,13 +1379,12 @@ static size_t cr_version(char *buffer, size_t size) return curl_msnprintf(buffer, size, "%.*s", (int)ver.len, ver.data); } -static CURLcode -cr_random(struct Curl_easy *data, unsigned char *entropy, size_t length) +static CURLcode cr_random(struct Curl_easy *data, unsigned char *entropy, + size_t length) { rustls_result rresult = 0; (void)data; - rresult = - rustls_default_crypto_provider_random(entropy, length); + rresult = rustls_default_crypto_provider_random(entropy, length); return map_error(rresult); } diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c index 49a4516cdfc8..21314d16ecb3 100644 --- a/lib/vtls/schannel.c +++ b/lib/vtls/schannel.c @@ -34,7 +34,7 @@ #ifdef USE_SCHANNEL #ifndef USE_WINDOWS_SSPI -# error "cannot compile SCHANNEL support without SSPI." +#error "cannot compile SCHANNEL support without SSPI." #endif #include "schannel.h" @@ -67,7 +67,7 @@ */ #ifdef CURL_SCHANNEL_DEV_DEBUG #define SCH_DEV(x) x -#define SCH_DEV_SHOWBOOL(x) \ +#define SCH_DEV_SHOWBOOL(x) \ infof(data, "schannel: " #x " %s", (x) ? "TRUE" : "FALSE"); #else #define SCH_DEV(x) do { } while(0) @@ -159,10 +159,9 @@ static void InitSecBufferDesc(SecBufferDesc *desc, SecBuffer *BufArr, desc->cBuffers = NumArrElem; } -static CURLcode -schannel_set_ssl_version_min_max(DWORD *enabled_protocols, - struct Curl_cfilter *cf, - struct Curl_easy *data) +static CURLcode schannel_set_ssl_version_min_max(DWORD *enabled_protocols, + struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); long ssl_version = conn_config->version; @@ -222,7 +221,7 @@ struct algo { int id; }; -static const struct algo algs[]= { +static const struct algo algs[] = { CIPHEROPTION(CALG_MD2), CIPHEROPTION(CALG_MD4), CIPHEROPTION(CALG_MD5), @@ -330,8 +329,7 @@ static const struct algo algs[]= { {NULL, 0}, }; -static int -get_alg_id_by_name(const char *name) +static int get_alg_id_by_name(const char *name) { const char *nameEnd = strchr(name, ':'); size_t n = nameEnd ? (size_t)(nameEnd - name) : strlen(name); @@ -346,9 +344,8 @@ get_alg_id_by_name(const char *name) #define NUM_CIPHERS 47 /* There are 47 options listed above */ -static CURLcode -set_ssl_ciphers(SCHANNEL_CRED *schannel_cred, char *ciphers, - ALG_ID *algIds) +static CURLcode set_ssl_ciphers(SCHANNEL_CRED *schannel_cred, char *ciphers, + ALG_ID *algIds) { const char *startCur = ciphers; int algCount = 0; @@ -376,9 +373,8 @@ set_ssl_ciphers(SCHANNEL_CRED *schannel_cred, char *ciphers, } /* Function allocates memory for store_path only if CURLE_OK is returned */ -static CURLcode -get_cert_location(TCHAR *path, DWORD *store_name, TCHAR **store_path, - TCHAR **thumbprint) +static CURLcode get_cert_location(TCHAR *path, DWORD *store_name, + TCHAR **store_path, TCHAR **thumbprint) { TCHAR *sep; TCHAR *store_path_start; @@ -400,14 +396,11 @@ get_cert_location(TCHAR *path, DWORD *store_name, TCHAR **store_path, *store_name = CERT_SYSTEM_STORE_SERVICES; else if(_tcsncmp(path, TEXT("Users"), store_name_len) == 0) *store_name = CERT_SYSTEM_STORE_USERS; - else if(_tcsncmp(path, TEXT("CurrentUserGroupPolicy"), - store_name_len) == 0) + else if(_tcsncmp(path, TEXT("CurrentUserGroupPolicy"), store_name_len) == 0) *store_name = CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY; - else if(_tcsncmp(path, TEXT("LocalMachineGroupPolicy"), - store_name_len) == 0) + else if(_tcsncmp(path, TEXT("LocalMachineGroupPolicy"), store_name_len) == 0) *store_name = CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY; - else if(_tcsncmp(path, TEXT("LocalMachineEnterprise"), - store_name_len) == 0) + else if(_tcsncmp(path, TEXT("LocalMachineEnterprise"), store_name_len) == 0) *store_name = CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE; else return CURLE_SSL_CERTPROBLEM; @@ -431,9 +424,8 @@ get_cert_location(TCHAR *path, DWORD *store_name, TCHAR **store_path, return CURLE_OK; } -static CURLcode -schannel_acquire_credential_handle(struct Curl_cfilter *cf, - struct Curl_easy *data) +static CURLcode schannel_acquire_credential_handle(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); @@ -461,37 +453,36 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, if(ssl_config->no_revoke) { flags |= SCH_CRED_IGNORE_NO_REVOCATION_CHECK | - SCH_CRED_IGNORE_REVOCATION_OFFLINE; + SCH_CRED_IGNORE_REVOCATION_OFFLINE; DEBUGF(infof(data, "schannel: disabled server certificate revocation " - "checks")); + "checks")); } else if(ssl_config->revoke_best_effort) { flags |= SCH_CRED_IGNORE_NO_REVOCATION_CHECK | - SCH_CRED_IGNORE_REVOCATION_OFFLINE | SCH_CRED_REVOCATION_CHECK_CHAIN; + SCH_CRED_IGNORE_REVOCATION_OFFLINE | + SCH_CRED_REVOCATION_CHECK_CHAIN; DEBUGF(infof(data, "schannel: ignore revocation offline errors")); } else { flags |= SCH_CRED_REVOCATION_CHECK_CHAIN; - DEBUGF(infof(data, - "schannel: checking server certificate revocation")); + DEBUGF(infof(data, "schannel: checking server certificate revocation")); } } else { flags = SCH_CRED_MANUAL_CRED_VALIDATION | - SCH_CRED_IGNORE_NO_REVOCATION_CHECK | - SCH_CRED_IGNORE_REVOCATION_OFFLINE; - DEBUGF(infof(data, - "schannel: disabled server cert revocation checks")); + SCH_CRED_IGNORE_NO_REVOCATION_CHECK | + SCH_CRED_IGNORE_REVOCATION_OFFLINE; + DEBUGF(infof(data, "schannel: disabled server cert revocation checks")); } if(!conn_config->verifyhost) { flags |= SCH_CRED_NO_SERVERNAME_CHECK; DEBUGF(infof(data, "schannel: verifyhost setting prevents Schannel from " - "comparing the supplied target name with the subject " - "names in server certificates.")); + "comparing the supplied target name with the subject " + "names in server certificates.")); } if(!ssl_config->auto_client_cert) { @@ -508,8 +499,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, case CURL_SSLVERSION_TLSv1_0: case CURL_SSLVERSION_TLSv1_1: case CURL_SSLVERSION_TLSv1_2: - case CURL_SSLVERSION_TLSv1_3: - { + case CURL_SSLVERSION_TLSv1_3: { result = schannel_set_ssl_version_min_max(&enabled_protocols, cf, data); if(result) return result; @@ -550,7 +540,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, result = get_cert_location(cert_path, &cert_store_name, &cert_store_path, &cert_thumbprint_str); - if(result && (data->set.ssl.primary.clientcert[0]!='\0')) + if(result && (data->set.ssl.primary.clientcert[0] != '\0')) fInCert = curlx_fopen(data->set.ssl.primary.clientcert, "rb"); if(result && !fInCert) { @@ -579,7 +569,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, https://learn.microsoft.com/archive/msdn-technet-forums/3e7bc95f-b21a-4bcd-bd2c-7f996718cae5 */ CRYPT_DATA_BLOB datablob; - WCHAR* pszPassword; + WCHAR *pszPassword; size_t pwd_len = 0; int str_w_len = 0; int cert_find_flags; @@ -613,12 +603,12 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, } /* Convert key-pair data to the in-memory certificate store */ - datablob.pbData = (BYTE*)certdata; + datablob.pbData = (BYTE *)certdata; datablob.cbData = (DWORD)certsize; if(data->set.ssl.key_passwd) pwd_len = strlen(data->set.ssl.key_passwd); - pszPassword = (WCHAR*)curlx_malloc(sizeof(WCHAR)*(pwd_len + 1)); + pszPassword = (WCHAR *)curlx_malloc(sizeof(WCHAR) * (pwd_len + 1)); if(pszPassword) { if(pwd_len > 0) str_w_len = MultiByteToWideChar(CP_UTF8, @@ -854,8 +844,8 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, return CURLE_OK; } -static CURLcode -schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode schannel_connect_step1(struct Curl_cfilter *cf, + struct Curl_easy *data) { size_t written = 0; struct ssl_connect_data *connssl = cf->ctx; @@ -874,8 +864,7 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) CURLcode result; DEBUGASSERT(backend); - DEBUGF(infof(data, - "schannel: SSL/TLS connection with %s port %d (step 1/3)", + DEBUGF(infof(data, "schannel: SSL/TLS connection with %s port %d (step 1/3)", connssl->peer.hostname, connssl->peer.port)); if(curlx_verify_windows_version(5, 1, 0, PLATFORM_WINNT, @@ -899,7 +888,7 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) } else { failf(data, "schannel: this version of Windows is too old to support " - "certificate verification via CA bundle file."); + "certificate verification via CA bundle file."); return CURLE_SSL_CACERT_BADFILE; } } @@ -952,7 +941,7 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) int cur = 0; int list_start_index = 0; unsigned int *extension_len = NULL; - unsigned short* list_len = NULL; + unsigned short *list_len = NULL; struct alpn_proto_buf proto; /* The first four bytes will be an unsigned int indicating number @@ -968,7 +957,7 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) /* The next two bytes will be an unsigned short indicating the number of bytes used to list the preferred protocols. */ - list_len = (unsigned short*)(void *)(&alpn_buffer[cur]); + list_len = (unsigned short *)(void *)(&alpn_buffer[cur]); cur += (int)sizeof(unsigned short); list_start_index = cur; @@ -1006,8 +995,8 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) /* security request flags */ backend->req_flags = ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT | - ISC_REQ_CONFIDENTIALITY | ISC_REQ_ALLOCATE_MEMORY | - ISC_REQ_STREAM; + ISC_REQ_CONFIDENTIALITY | ISC_REQ_ALLOCATE_MEMORY | + ISC_REQ_STREAM; if(!ssl_config->auto_client_cert) { backend->req_flags |= ISC_REQ_USE_SUPPLIED_CREDS; @@ -1131,8 +1120,8 @@ static CURLcode schannel_error(struct Curl_easy *data, } } -static CURLcode -schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode schannel_connect_step2(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct schannel_ssl_backend_data *backend = @@ -1155,8 +1144,7 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) doread = (connssl->io_need & CURL_SSL_IO_NEED_SEND) ? FALSE : TRUE; connssl->io_need = CURL_SSL_IO_NEED_NONE; - DEBUGF(infof(data, - "schannel: SSL/TLS connection with %s port %d (step 2/3)", + DEBUGF(infof(data, "schannel: SSL/TLS connection with %s port %d (step 2/3)", connssl->peer.hostname, connssl->peer.port)); if(!backend->cred || !backend->ctxt) @@ -1361,7 +1349,8 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) if(backend->encdata_offset > inbuf[1].cbBuffer) { memmove(backend->encdata_buffer, (backend->encdata_buffer + backend->encdata_offset) - - inbuf[1].cbBuffer, inbuf[1].cbBuffer); + inbuf[1].cbBuffer, + inbuf[1].cbBuffer); backend->encdata_offset = inbuf[1].cbBuffer; if(sspi_status == SEC_I_CONTINUE_NEEDED) { doread = FALSE; @@ -1415,8 +1404,7 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_OK; } -static bool -valid_cert_encoding(const CERT_CONTEXT *cert_context) +static bool valid_cert_encoding(const CERT_CONTEXT *cert_context) { return (cert_context != NULL) && ((cert_context->dwCertEncodingType & X509_ASN_ENCODING) != 0) && @@ -1424,12 +1412,11 @@ valid_cert_encoding(const CERT_CONTEXT *cert_context) (cert_context->cbCertEncoded > 0); } -typedef bool(*Read_crt_func)(const CERT_CONTEXT *ccert_context, - bool reverse_order, void *arg); +typedef bool (*Read_crt_func)(const CERT_CONTEXT *ccert_context, + bool reverse_order, void *arg); -static void -traverse_cert_store(const CERT_CONTEXT *context, Read_crt_func func, - void *arg) +static void traverse_cert_store(const CERT_CONTEXT *context, + Read_crt_func func, void *arg) { const CERT_CONTEXT *current_context = NULL; bool should_continue = TRUE; @@ -1454,9 +1441,8 @@ traverse_cert_store(const CERT_CONTEXT *context, Read_crt_func func, CertFreeCertificateContext(current_context); } -static bool -cert_counter_callback(const CERT_CONTEXT *ccert_context, bool reverse_order, - void *certs_count) +static bool cert_counter_callback(const CERT_CONTEXT *ccert_context, + bool reverse_order, void *certs_count) { (void)reverse_order; if(valid_cert_encoding(ccert_context)) @@ -1466,22 +1452,20 @@ cert_counter_callback(const CERT_CONTEXT *ccert_context, bool reverse_order, return TRUE; } -struct Adder_args -{ +struct Adder_args { struct Curl_easy *data; CURLcode result; int idx; int certs_count; }; -static bool -add_cert_to_certinfo(const CERT_CONTEXT *ccert_context, bool reverse_order, - void *raw_arg) +static bool add_cert_to_certinfo(const CERT_CONTEXT *ccert_context, + bool reverse_order, void *raw_arg) { - struct Adder_args *args = (struct Adder_args*)raw_arg; + struct Adder_args *args = (struct Adder_args *)raw_arg; args->result = CURLE_OK; if(valid_cert_encoding(ccert_context)) { - const char *beg = (const char *) ccert_context->pbCertEncoded; + const char *beg = (const char *)ccert_context->pbCertEncoded; const char *end = beg + ccert_context->cbCertEncoded; int insert_index = reverse_order ? (args->certs_count - 1) - args->idx : args->idx; @@ -1511,8 +1495,8 @@ static void schannel_session_free(void *sessionid) } } -static CURLcode -schannel_connect_step3(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode schannel_connect_step3(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct schannel_ssl_backend_data *backend = @@ -1527,8 +1511,7 @@ schannel_connect_step3(struct Curl_cfilter *cf, struct Curl_easy *data) DEBUGASSERT(ssl_connect_3 == connssl->connecting_state); DEBUGASSERT(backend); - DEBUGF(infof(data, - "schannel: SSL/TLS connection with %s port %d (step 3/3)", + DEBUGF(infof(data, "schannel: SSL/TLS connection with %s port %d (step 3/3)", connssl->peer.hostname, connssl->peer.port)); if(!backend->cred) @@ -1886,9 +1869,8 @@ schannel_recv_renegotiate(struct Curl_cfilter *cf, struct Curl_easy *data, return result; } -static CURLcode -schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, size_t *pnwritten) +static CURLcode schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, + const void *buf, size_t len, size_t *pnwritten) { size_t data_len = 0; unsigned char *ptr = NULL; @@ -2018,7 +2000,7 @@ schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, else if(sspi_status == SEC_E_INSUFFICIENT_MEMORY) { result = CURLE_OUT_OF_MEMORY; } - else{ + else { result = CURLE_SEND_ERROR; } @@ -2032,9 +2014,8 @@ schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, return result; } -static CURLcode -schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, - char *buf, size_t len, size_t *pnread) +static CURLcode schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, + char *buf, size_t len, size_t *pnread) { size_t size = 0; size_t nread = 0; @@ -2170,7 +2151,7 @@ schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, /* https://learn.microsoft.com/windows/win32/api/sspi/nf-sspi-decryptmessage */ sspi_status = Curl_pSecFn->DecryptMessage(&backend->ctxt->ctxt_handle, - &inbuf_desc, 0, NULL); + &inbuf_desc, 0, NULL); /* check if everything went fine (server may want to renegotiate or shutdown the connection context) */ @@ -2231,7 +2212,8 @@ schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, buffer */ memmove(backend->encdata_buffer, (backend->encdata_buffer + backend->encdata_offset) - - inbuf[3].cbBuffer, inbuf[3].cbBuffer); + inbuf[3].cbBuffer, + inbuf[3].cbBuffer); backend->encdata_offset = inbuf[3].cbBuffer; } @@ -2761,7 +2743,7 @@ HCERTSTORE Curl_schannel_get_cached_cert_store(struct Curl_cfilter *cf, share = Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), - sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY)-1); + sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY) - 1); if(!share || !share->cert_store) { return NULL; } @@ -2809,7 +2791,7 @@ HCERTSTORE Curl_schannel_get_cached_cert_store(struct Curl_cfilter *cf, static void schannel_cert_share_free(void *key, size_t key_len, void *p) { struct schannel_cert_share *share = p; - DEBUGASSERT(key_len == (sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY)-1)); + DEBUGASSERT(key_len == (sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY) - 1)); DEBUGASSERT(!memcmp(MPROTO_SCHANNEL_CERT_SHARE_KEY, key, key_len)); (void)key; (void)key_len; @@ -2839,7 +2821,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, share = Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), - sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY)-1); + sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY) - 1); if(!share) { share = curlx_calloc(1, sizeof(*share)); if(!share) { @@ -2847,7 +2829,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, } if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), - sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY)-1, + sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY) - 1, share, schannel_cert_share_free)) { curlx_free(share); return FALSE; diff --git a/lib/vtls/schannel.h b/lib/vtls/schannel.h index 9d0bea221a9b..47017c5f5686 100644 --- a/lib/vtls/schannel.h +++ b/lib/vtls/schannel.h @@ -69,15 +69,14 @@ * (and only here). */ #if defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC) -# undef X509_NAME -# undef X509_CERT_PAIR -# undef X509_EXTENSIONS +#undef X509_NAME +#undef X509_CERT_PAIR +#undef X509_EXTENSIONS #endif extern const struct Curl_ssl Curl_ssl_schannel; -CURLcode Curl_verify_host(struct Curl_cfilter *cf, - struct Curl_easy *data); +CURLcode Curl_verify_host(struct Curl_cfilter *cf, struct Curl_easy *data); CURLcode Curl_verify_certificate(struct Curl_cfilter *cf, struct Curl_easy *data); diff --git a/lib/vtls/schannel_verify.c b/lib/vtls/schannel_verify.c index 4ff7b5d536a1..e1a3731457b8 100644 --- a/lib/vtls/schannel_verify.c +++ b/lib/vtls/schannel_verify.c @@ -33,7 +33,7 @@ #ifdef USE_SCHANNEL #ifndef USE_WINDOWS_SSPI -# error "cannot compile SCHANNEL support without SSPI." +#error "cannot compile SCHANNEL support without SSPI." #endif #include "schannel.h" @@ -157,8 +157,8 @@ static CURLcode add_certs_data_to_store(HCERTSTORE trust_store, const CERT_CONTEXT *cert_context = NULL; BOOL add_cert_result = FALSE; DWORD actual_content_type = 0; - DWORD cert_size = (DWORD) - ((end_cert_ptr + end_cert_len) - begin_cert_ptr); + DWORD cert_size = + (DWORD)((end_cert_ptr + end_cert_len) - begin_cert_ptr); cert_blob.pbData = (BYTE *)CURL_UNCONST(begin_cert_ptr); cert_blob.cbData = cert_size; @@ -238,13 +238,11 @@ static CURLcode add_certs_data_to_store(HCERTSTORE trust_store, if(result == CURLE_OK) { if(!num_certs) { - infof(data, - "schannel: did not add any certificates from CA file '%s'", + infof(data, "schannel: did not add any certificates from CA file '%s'", ca_file_text); } else { - infof(data, - "schannel: added %d certificate(s) from CA file '%s'", + infof(data, "schannel: added %d certificate(s) from CA file '%s'", num_certs, ca_file_text); } } @@ -266,9 +264,7 @@ static CURLcode add_certs_file_to_store(HCERTSTORE trust_store, ca_file_tstr = curlx_convert_UTF8_to_tchar(ca_file); if(!ca_file_tstr) { char buffer[WINAPI_ERROR_LEN]; - failf(data, - "schannel: invalid path name for CA file '%s': %s", - ca_file, + failf(data, "schannel: invalid path name for CA file '%s': %s", ca_file, curlx_winapi_strerror(GetLastError(), buffer, sizeof(buffer))); result = CURLE_SSL_CACERT_BADFILE; goto cleanup; @@ -288,9 +284,7 @@ static CURLcode add_certs_file_to_store(HCERTSTORE trust_store, NULL); if(ca_file_handle == INVALID_HANDLE_VALUE) { char buffer[WINAPI_ERROR_LEN]; - failf(data, - "schannel: failed to open CA file '%s': %s", - ca_file, + failf(data, "schannel: failed to open CA file '%s': %s", ca_file, curlx_winapi_strerror(GetLastError(), buffer, sizeof(buffer))); result = CURLE_SSL_CACERT_BADFILE; goto cleanup; @@ -298,8 +292,7 @@ static CURLcode add_certs_file_to_store(HCERTSTORE trust_store, if(!GetFileSizeEx(ca_file_handle, &file_size)) { char buffer[WINAPI_ERROR_LEN]; - failf(data, - "schannel: failed to determine size of CA file '%s': %s", + failf(data, "schannel: failed to determine size of CA file '%s': %s", ca_file, curlx_winapi_strerror(GetLastError(), buffer, sizeof(buffer))); result = CURLE_SSL_CACERT_BADFILE; @@ -307,8 +300,7 @@ static CURLcode add_certs_file_to_store(HCERTSTORE trust_store, } if(file_size.QuadPart > MAX_CAFILE_SIZE) { - failf(data, - "schannel: CA file exceeds max size of %u bytes", + failf(data, "schannel: CA file exceeds max size of %u bytes", MAX_CAFILE_SIZE); result = CURLE_SSL_CACERT_BADFILE; goto cleanup; @@ -328,9 +320,7 @@ static CURLcode add_certs_file_to_store(HCERTSTORE trust_store, if(!ReadFile(ca_file_handle, ca_file_buffer + total_bytes_read, bytes_to_read, &bytes_read, NULL)) { char buffer[WINAPI_ERROR_LEN]; - failf(data, - "schannel: failed to read from CA file '%s': %s", - ca_file, + failf(data, "schannel: failed to read from CA file '%s': %s", ca_file, curlx_winapi_strerror(GetLastError(), buffer, sizeof(buffer))); result = CURLE_SSL_CACERT_BADFILE; goto cleanup; @@ -455,12 +445,11 @@ static DWORD cert_get_name_string(struct Curl_easy *data, } /* -* Returns TRUE if the hostname is a numeric IPv4/IPv6 Address, -* and populates the buffer with IPv4/IPv6 info. -*/ + * Returns TRUE if the hostname is a numeric IPv4/IPv6 Address, + * and populates the buffer with IPv4/IPv6 info. + */ -static bool get_num_host_info(struct num_ip_data *ip_blob, - LPCSTR hostname) +static bool get_num_host_info(struct num_ip_data *ip_blob, LPCSTR hostname) { struct in_addr ia; struct in6_addr ia6; @@ -520,9 +509,8 @@ static bool get_alt_name_info(struct Curl_easy *data, &decode_para, alt_name_info, alt_name_info_size)) { - failf(data, - "schannel: CryptDecodeObjectEx() returned no alternate name " - "information."); + failf(data, "schannel: CryptDecodeObjectEx() returned no alternate name " + "information."); return result; } result = TRUE; @@ -530,8 +518,7 @@ static bool get_alt_name_info(struct Curl_easy *data, } /* Verify the server's hostname */ -CURLcode Curl_verify_host(struct Curl_cfilter *cf, - struct Curl_easy *data) +CURLcode Curl_verify_host(struct Curl_cfilter *cf, struct Curl_easy *data) { CURLcode result = CURLE_PEER_FAILED_VERIFICATION; struct ssl_connect_data *connssl = cf->ctx; @@ -545,7 +532,7 @@ CURLcode Curl_verify_host(struct Curl_cfilter *cf, DWORD actual_len = 0; PCERT_ALT_NAME_INFO alt_name_info = NULL; DWORD alt_name_info_size = 0; - struct num_ip_data ip_blob = { 0 }; + struct num_ip_data ip_blob = {0}; bool Win8_compat; struct num_ip_data *p = &ip_blob; DWORD i; @@ -840,7 +827,7 @@ CURLcode Curl_verify_certificate(struct Curl_cfilter *cf, * list URL, or when the list could not be downloaded because the * server is currently unreachable. */ dwTrustErrorMask &= ~(DWORD)(CERT_TRUST_REVOCATION_STATUS_UNKNOWN | - CERT_TRUST_IS_OFFLINE_REVOCATION); + CERT_TRUST_IS_OFFLINE_REVOCATION); } if(dwTrustErrorMask) { diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c index 6eb60e41cf99..e342953778b0 100644 --- a/lib/vtls/vtls.c +++ b/lib/vtls/vtls.c @@ -93,14 +93,13 @@ dest->var = NULL; \ } while(0) -#define CLONE_BLOB(var) \ - do { \ - if(blobdup(&dest->var, source->var)) \ - return FALSE; \ +#define CLONE_BLOB(var) \ + do { \ + if(blobdup(&dest->var, source->var)) \ + return FALSE; \ } while(0) -static CURLcode blobdup(struct curl_blob **dest, - struct curl_blob *src) +static CURLcode blobdup(struct curl_blob **dest, struct curl_blob *src) { DEBUGASSERT(dest); DEBUGASSERT(!*dest); @@ -149,8 +148,8 @@ static const struct alpn_spec ALPN_SPEC_H2_H11 = { #endif #if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_PROXY) -static const struct alpn_spec * -alpn_get_spec(http_majors allowed, bool use_alpn) +static const struct alpn_spec *alpn_get_spec(http_majors allowed, + bool use_alpn) { if(!use_alpn) return NULL; @@ -170,7 +169,6 @@ alpn_get_spec(http_majors allowed, bool use_alpn) #endif /* !CURL_DISABLE_HTTP || !CURL_DISABLE_PROXY */ #endif /* USE_SSL */ - void Curl_ssl_easy_config_init(struct Curl_easy *data) { /* @@ -185,10 +183,9 @@ void Curl_ssl_easy_config_init(struct Curl_easy *data) #endif } -static bool -match_ssl_primary_config(struct Curl_easy *data, - struct ssl_primary_config *c1, - struct ssl_primary_config *c2) +static bool match_ssl_primary_config(struct Curl_easy *data, + struct ssl_primary_config *c1, + struct ssl_primary_config *c2) { (void)data; if((c1->version == c2->version) && @@ -324,8 +321,7 @@ CURLcode Curl_ssl_easy_config_complete(struct Curl_easy *data) sslc->primary.cipher_list13 = data->set.str[STRING_SSL_CIPHER13_LIST]; sslc->primary.signature_algorithms = data->set.str[STRING_SSL_SIGNATURE_ALGORITHMS]; - sslc->primary.pinned_key = - data->set.str[STRING_SSL_PINNEDPUBLICKEY]; + sslc->primary.pinned_key = data->set.str[STRING_SSL_PINNEDPUBLICKEY]; sslc->primary.cert_blob = data->set.blobs[BLOB_CERT]; sslc->primary.ca_info_blob = data->set.blobs[BLOB_CAINFO]; sslc->primary.curves = data->set.str[STRING_SSL_EC_CURVES]; @@ -538,9 +534,9 @@ void Curl_ssl_close_all(struct Curl_easy *data) Curl_ssl->close_all(data); } -CURLcode Curl_ssl_adjust_pollset(struct Curl_cfilter *cf, - struct Curl_easy *data, - struct easy_pollset *ps) +CURLcode Curl_ssl_adjust_pollset(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct easy_pollset *ps) { struct ssl_connect_data *connssl = cf->ctx; @@ -628,7 +624,7 @@ CURLcode Curl_ssl_init_certinfo(struct Curl_easy *data, int num) Curl_ssl_free_certinfo(data); /* Allocate the required certificate information structures */ - table = curlx_calloc((size_t) num, sizeof(struct curl_slist *)); + table = curlx_calloc((size_t)num, sizeof(struct curl_slist *)); if(!table) return CURLE_OUT_OF_MEMORY; @@ -661,8 +657,7 @@ CURLcode Curl_ssl_push_certinfo_len(struct Curl_easy *data, curlx_dyn_addn(&build, value, valuelen)) return CURLE_OUT_OF_MEMORY; - nl = Curl_slist_append_nodup(ci->certinfo[certnum], - curlx_dyn_ptr(&build)); + nl = Curl_slist_append_nodup(ci->certinfo[certnum], curlx_dyn_ptr(&build)); if(!nl) { curlx_dyn_free(&build); curl_slist_free_all(ci->certinfo[certnum]); @@ -798,8 +793,8 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data, pinned_hash = pinnedpubkey; while(pinned_hash && - !strncmp(pinned_hash, "sha256//", (sizeof("sha256//")-1))) { - pinned_hash = pinned_hash + (sizeof("sha256//")-1); + !strncmp(pinned_hash, "sha256//", (sizeof("sha256//") - 1))) { + pinned_hash = pinned_hash + (sizeof("sha256//") - 1); end_pos = strchr(pinned_hash, ';'); pinned_hash_len = end_pos ? (size_t)(end_pos - pinned_hash) : strlen(pinned_hash); @@ -845,7 +840,7 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data, * if the size of our certificate is bigger than the file * size then it cannot match */ - size = curlx_sotouz((curl_off_t) filesize); + size = curlx_sotouz((curl_off_t)filesize); if(pubkeylen > size) goto end; @@ -1277,7 +1272,7 @@ CURLcode Curl_ssl_peer_init(struct ssl_peer *peer, /* not an IP address, normalize according to RCC 6066 ch. 3, * max len of SNI is 2^16-1, no trailing dot */ size_t len = strlen(peer->hostname); - if(len && (peer->hostname[len-1] == '.')) + if(len && (peer->hostname[len - 1] == '.')) len--; if(len < USHRT_MAX) { peer->sni = curlx_calloc(1, len + 1); @@ -1563,7 +1558,7 @@ static CURLcode ssl_cf_shutdown(struct Curl_cfilter *cf, *done = TRUE; /* If we have done the SSL handshake, shut down the connection cleanly */ if(cf->connected && (connssl->state == ssl_connection_complete) && - !cf->shutdown && Curl_ssl->shut_down) { + !cf->shutdown && Curl_ssl->shut_down) { struct cf_call_data save; CF_DATA_SAVE(save, cf, data); @@ -1781,7 +1776,7 @@ static CURLcode cf_ssl_proxy_create(struct Curl_cfilter **pcf, #ifdef USE_HTTP2 if(conn->http_proxy.proxytype == CURLPROXY_HTTPS2) { use_alpn = TRUE; - allowed = (CURL_HTTP_V1x|CURL_HTTP_V2x); + allowed = (CURL_HTTP_V1x | CURL_HTTP_V2x); } #endif @@ -1847,7 +1842,7 @@ static CURLcode vtls_shutdown_blocking(struct Curl_cfilter *cf, } result = connssl->ssl_impl->shut_down(cf, data, send_shutdown, done); - if(result ||*done) + if(result || *done) goto out; if(connssl->io_need) { @@ -2042,7 +2037,7 @@ CURLcode Curl_alpn_set_negotiated(struct Curl_cfilter *cf, if(proto && proto_len) { if(memchr(proto, '\0', proto_len)) { failf(data, "ALPN: server selected protocol contains NUL. " - "Refusing to continue."); + "Refusing to continue."); result = CURLE_SSL_CONNECT_ERROR; goto out; } diff --git a/lib/vtls/vtls.h b/lib/vtls/vtls.h index dbe13c59030b..b5b517f0b6fa 100644 --- a/lib/vtls/vtls.h +++ b/lib/vtls/vtls.h @@ -253,16 +253,16 @@ extern struct Curl_cftype Curl_cft_ssl_proxy; #define Curl_ssl_init() 1 #define Curl_ssl_cleanup() Curl_nop_stmt #define Curl_ssl_close_all(x) Curl_nop_stmt -#define Curl_ssl_set_engine(x,y) CURLE_NOT_BUILT_IN +#define Curl_ssl_set_engine(x, y) CURLE_NOT_BUILT_IN #define Curl_ssl_set_engine_default(x) CURLE_NOT_BUILT_IN #define Curl_ssl_engines_list(x) NULL #define Curl_ssl_free_certinfo(x) Curl_nop_stmt -#define Curl_ssl_random(x,y,z) ((void)x, CURLE_NOT_BUILT_IN) +#define Curl_ssl_random(x, y, z) ((void)x, CURLE_NOT_BUILT_IN) #define Curl_ssl_cert_status_request() FALSE -#define Curl_ssl_supports(a,b) FALSE -#define Curl_ssl_cfilter_add(a,b,c) CURLE_NOT_BUILT_IN -#define Curl_ssl_cfilter_remove(a,b,c) CURLE_OK -#define Curl_ssl_cf_get_config(a,b) NULL +#define Curl_ssl_supports(a, b) FALSE +#define Curl_ssl_cfilter_add(a, b, c) CURLE_NOT_BUILT_IN +#define Curl_ssl_cfilter_remove(a, b, c) CURLE_OK +#define Curl_ssl_cf_get_config(a, b) NULL #define Curl_ssl_cf_get_primary_config(a) NULL #endif diff --git a/lib/vtls/vtls_int.h b/lib/vtls/vtls_int.h index 8bf6c6c64be9..0a184f88c127 100644 --- a/lib/vtls/vtls_int.h +++ b/lib/vtls/vtls_int.h @@ -71,8 +71,7 @@ CURLcode Curl_alpn_set_negotiated(struct Curl_cfilter *cf, const unsigned char *proto, size_t proto_len); -bool Curl_alpn_contains_proto(const struct alpn_spec *spec, - const char *proto); +bool Curl_alpn_contains_proto(const struct alpn_spec *spec, const char *proto); /* enum for the nonblocking SSL connection state machine */ typedef enum { @@ -99,11 +98,11 @@ typedef enum { } ssl_earlydata_state; #define CURL_SSL_IO_NEED_NONE (0) -#define CURL_SSL_IO_NEED_RECV (1<<0) -#define CURL_SSL_IO_NEED_SEND (1<<1) +#define CURL_SSL_IO_NEED_RECV (1 << 0) +#define CURL_SSL_IO_NEED_SEND (1 << 1) /* Max earlydata payload we want to send */ -#define CURL_SSL_EARLY_MAX (64*1024) +#define CURL_SSL_EARLY_MAX (64 * 1024) /* Information in each SSL cfilter context: cf->ctx */ struct ssl_connect_data { @@ -130,11 +129,8 @@ struct ssl_connect_data { BIT(input_pending); /* data for SSL_read() may be available */ }; - #undef CF_CTX_CALL_DATA -#define CF_CTX_CALL_DATA(cf) \ - ((struct ssl_connect_data *)(cf)->ctx)->call_data - +#define CF_CTX_CALL_DATA(cf) ((struct ssl_connect_data *)(cf)->ctx)->call_data /* Definitions for SSL Implementations */ @@ -157,8 +153,7 @@ struct Curl_ssl { /* data_pending() shall return TRUE when it wants to get called again to drain internal buffers and deliver data instead of waiting for the socket to get readable */ - bool (*data_pending)(struct Curl_cfilter *cf, - const struct Curl_easy *data); + bool (*data_pending)(struct Curl_cfilter *cf, const struct Curl_easy *data); /* return 0 if a find random is filled in */ CURLcode (*random)(struct Curl_easy *data, unsigned char *entropy, @@ -181,7 +176,7 @@ struct Curl_ssl { struct curl_slist *(*engines_list)(struct Curl_easy *data); CURLcode (*sha256sum)(const unsigned char *input, size_t inputlen, - unsigned char *sha256sum, size_t sha256sumlen); + unsigned char *sha256sum, size_t sha256sumlen); CURLcode (*recv_plain)(struct Curl_cfilter *cf, struct Curl_easy *data, char *buf, size_t len, size_t *pnread); CURLcode (*send_plain)(struct Curl_cfilter *cf, struct Curl_easy *data, @@ -189,7 +184,6 @@ struct Curl_ssl { CURLcode (*get_channel_binding)(struct Curl_easy *data, int sockindex, struct dynbuf *binding); - }; extern const struct Curl_ssl *Curl_ssl; diff --git a/lib/vtls/vtls_scache.c b/lib/vtls/vtls_scache.c index 21dfe2eaa032..b968d8b8f36a 100644 --- a/lib/vtls/vtls_scache.c +++ b/lib/vtls/vtls_scache.c @@ -106,23 +106,21 @@ static void cf_ssl_scache_session_ldestroy(void *udata, void *obj) curlx_free(s); } -CURLcode -Curl_ssl_session_create(void *sdata, size_t sdata_len, - int ietf_tls_id, const char *alpn, - curl_off_t valid_until, size_t earlydata_max, - struct Curl_ssl_session **psession) +CURLcode Curl_ssl_session_create(void *sdata, size_t sdata_len, + int ietf_tls_id, const char *alpn, + curl_off_t valid_until, size_t earlydata_max, + struct Curl_ssl_session **psession) { return Curl_ssl_session_create2(sdata, sdata_len, ietf_tls_id, alpn, valid_until, earlydata_max, NULL, 0, psession); } -CURLcode -Curl_ssl_session_create2(void *sdata, size_t sdata_len, - int ietf_tls_id, const char *alpn, - curl_off_t valid_until, size_t earlydata_max, - unsigned char *quic_tp, size_t quic_tp_len, - struct Curl_ssl_session **psession) +CURLcode Curl_ssl_session_create2(void *sdata, size_t sdata_len, + int ietf_tls_id, const char *alpn, + curl_off_t valid_until, size_t earlydata_max, + unsigned char *quic_tp, size_t quic_tp_len, + struct Curl_ssl_session **psession) { struct Curl_ssl_session *s; @@ -322,7 +320,7 @@ CURLcode Curl_ssl_scache_create(size_t max_peers, } scache->magic = CURL_SCACHE_MAGIC; - scache->default_lifetime_secs = (24*60*60); /* 1 day */ + scache->default_lifetime_secs = (24 * 60 * 60); /* 1 day */ scache->peer_count = max_peers; scache->peers = peers; scache->age = 1; @@ -507,7 +505,7 @@ CURLcode Curl_ssl_peer_key_make(struct Curl_cfilter *cf, if(ssl->version || ssl->version_max) { r = curlx_dyn_addf(&buf, ":TLSVER-%d-%d", ssl->version, - (ssl->version_max >> 16)); + (ssl->version_max >> 16)); if(r) goto out; } @@ -616,19 +614,18 @@ static bool cf_ssl_scache_match_auth(struct Curl_ssl_scache_peer *peer, else if(!Curl_safecmp(peer->clientcert, conn_config->clientcert)) return FALSE; #ifdef USE_TLS_SRP - if(Curl_timestrcmp(peer->srp_username, conn_config->username) || - Curl_timestrcmp(peer->srp_password, conn_config->password)) - return FALSE; + if(Curl_timestrcmp(peer->srp_username, conn_config->username) || + Curl_timestrcmp(peer->srp_password, conn_config->password)) + return FALSE; #endif return TRUE; } -static CURLcode -cf_ssl_find_peer_by_key(struct Curl_easy *data, - struct Curl_ssl_scache *scache, - const char *ssl_peer_key, - struct ssl_primary_config *conn_config, - struct Curl_ssl_scache_peer **ppeer) +static CURLcode cf_ssl_find_peer_by_key(struct Curl_easy *data, + struct Curl_ssl_scache *scache, + const char *ssl_peer_key, + struct ssl_primary_config *conn_config, + struct Curl_ssl_scache_peer **ppeer) { size_t i, peer_key_len = 0; CURLcode result = CURLE_OK; @@ -718,12 +715,11 @@ cf_ssl_get_free_peer(struct Curl_ssl_scache *scache) return peer; } -static CURLcode -cf_ssl_add_peer(struct Curl_easy *data, - struct Curl_ssl_scache *scache, - const char *ssl_peer_key, - struct ssl_primary_config *conn_config, - struct Curl_ssl_scache_peer **ppeer) +static CURLcode cf_ssl_add_peer(struct Curl_easy *data, + struct Curl_ssl_scache *scache, + const char *ssl_peer_key, + struct ssl_primary_config *conn_config, + struct Curl_ssl_scache_peer **ppeer) { struct Curl_ssl_scache_peer *peer = NULL; CURLcode result = CURLE_OK; @@ -1000,7 +996,7 @@ void Curl_ssl_scache_remove_all(struct Curl_cfilter *cf, #ifdef USE_SSLS_EXPORT -#define CURL_SSL_TICKET_MAX (16*1024) +#define CURL_SSL_TICKET_MAX (16 * 1024) static CURLcode cf_ssl_scache_peer_set_hmac(struct Curl_ssl_scache_peer *peer) { diff --git a/lib/vtls/vtls_scache.h b/lib/vtls/vtls_scache.h index 445f21054937..67049462a859 100644 --- a/lib/vtls/vtls_scache.h +++ b/lib/vtls/vtls_scache.h @@ -37,8 +37,8 @@ struct ssl_peer; /* RFC 8446 (TLSv1.3) restrict lifetime to one week max, for * other, less secure versions, we restrict it to a day */ -#define CURL_SCACHE_MAX_13_LIFETIME_SEC (60*60*24*7) -#define CURL_SCACHE_MAX_12_LIFETIME_SEC (60*60*24) +#define CURL_SCACHE_MAX_13_LIFETIME_SEC (60 * 60 * 24 * 7) +#define CURL_SCACHE_MAX_12_LIFETIME_SEC (60 * 60 * 24) /* Create a session cache for up to max_peers endpoints with a total * of up to max_sessions SSL sessions per peer */ @@ -142,22 +142,18 @@ struct Curl_ssl_session { * in case this is not known. * @param psession on return the scached session instance created */ -CURLcode -Curl_ssl_session_create(void *sdata, size_t sdata_len, - int ietf_tls_id, const char *alpn, - curl_off_t valid_until, - size_t earlydata_max, - struct Curl_ssl_session **psession); +CURLcode Curl_ssl_session_create(void *sdata, size_t sdata_len, + int ietf_tls_id, const char *alpn, + curl_off_t valid_until, size_t earlydata_max, + struct Curl_ssl_session **psession); /* Variation of session creation with quic transport parameter bytes, * Takes ownership of `quic_tp` regardless of return code. */ -CURLcode -Curl_ssl_session_create2(void *sdata, size_t sdata_len, - int ietf_tls_id, const char *alpn, - curl_off_t valid_until, - size_t earlydata_max, - unsigned char *quic_tp, size_t quic_tp_len, - struct Curl_ssl_session **psession); +CURLcode Curl_ssl_session_create2(void *sdata, size_t sdata_len, + int ietf_tls_id, const char *alpn, + curl_off_t valid_until, size_t earlydata_max, + unsigned char *quic_tp, size_t quic_tp_len, + struct Curl_ssl_session **psession); /* Destroy a `session` instance. Can be called with NULL. * Does NOT need locking. */ diff --git a/lib/vtls/vtls_spack.c b/lib/vtls/vtls_spack.c index 070bb485a350..ac289f1b2f69 100644 --- a/lib/vtls/vtls_spack.c +++ b/lib/vtls/vtls_spack.c @@ -52,8 +52,8 @@ static CURLcode spack_enc8(struct dynbuf *buf, uint8_t b) return curlx_dyn_addn(buf, &b, 1); } -static CURLcode -spack_dec8(uint8_t *val, const uint8_t **src, const uint8_t *end) +static CURLcode spack_dec8(uint8_t *val, const uint8_t **src, + const uint8_t *end) { if(end - *src < 1) return CURLE_READ_ERROR; @@ -70,8 +70,8 @@ static CURLcode spack_enc16(struct dynbuf *buf, uint16_t val) return curlx_dyn_addn(buf, nval, sizeof(nval)); } -static CURLcode -spack_dec16(uint16_t *val, const uint8_t **src, const uint8_t *end) +static CURLcode spack_dec16(uint16_t *val, const uint8_t **src, + const uint8_t *end) { if(end - *src < 2) return CURLE_READ_ERROR; @@ -90,8 +90,8 @@ static CURLcode spack_enc32(struct dynbuf *buf, uint32_t val) return curlx_dyn_addn(buf, nval, sizeof(nval)); } -static CURLcode -spack_dec32(uint32_t *val, const uint8_t **src, const uint8_t *end) +static CURLcode spack_dec32(uint32_t *val, const uint8_t **src, + const uint8_t *end) { if(end - *src < 4) return CURLE_READ_ERROR; @@ -107,7 +107,7 @@ static CURLcode spack_enc64(struct dynbuf *buf, uint64_t val) nval[0] = (uint8_t)(val >> 56); nval[1] = (uint8_t)(val >> 48); nval[2] = (uint8_t)(val >> 40); - nval[3] = (uint8_t)(val >> 32); \ + nval[3] = (uint8_t)(val >> 32); nval[4] = (uint8_t)(val >> 24); nval[5] = (uint8_t)(val >> 16); nval[6] = (uint8_t)(val >> 8); @@ -115,8 +115,8 @@ static CURLcode spack_enc64(struct dynbuf *buf, uint64_t val) return curlx_dyn_addn(buf, nval, sizeof(nval)); } -static CURLcode -spack_dec64(uint64_t *val, const uint8_t **src, const uint8_t *end) +static CURLcode spack_dec64(uint64_t *val, const uint8_t **src, + const uint8_t *end) { if(end - *src < 8) return CURLE_READ_ERROR; @@ -141,8 +141,8 @@ static CURLcode spack_encstr16(struct dynbuf *buf, const char *s) return r; } -static CURLcode -spack_decstr16(char **val, const uint8_t **src, const uint8_t *end) +static CURLcode spack_decstr16(char **val, const uint8_t **src, + const uint8_t *end) { uint16_t slen; CURLcode r; @@ -158,8 +158,8 @@ spack_decstr16(char **val, const uint8_t **src, const uint8_t *end) return *val ? CURLE_OK : CURLE_OUT_OF_MEMORY; } -static CURLcode spack_encdata16(struct dynbuf *buf, - const uint8_t *data, size_t data_len) +static CURLcode spack_encdata16(struct dynbuf *buf, const uint8_t *data, + size_t data_len) { CURLcode r; if(data_len > UINT16_MAX) @@ -171,9 +171,8 @@ static CURLcode spack_encdata16(struct dynbuf *buf, return r; } -static CURLcode -spack_decdata16(uint8_t **val, size_t *val_len, - const uint8_t **src, const uint8_t *end) +static CURLcode spack_decdata16(uint8_t **val, size_t *val_len, + const uint8_t **src, const uint8_t *end) { uint16_t data_len; CURLcode r; diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c index eae17078fd35..62bf723efd33 100644 --- a/lib/vtls/wolfssl.c +++ b/lib/vtls/wolfssl.c @@ -127,9 +127,9 @@ static CURLcode wssl_connect(struct Curl_cfilter *cf, * (--enable-opensslextra or --enable-all). */ #if defined(HAVE_SECRET_CALLBACK) && defined(WOLFSSL_TLS13) -static int -wssl_tls13_secret_callback(SSL *ssl, int id, const unsigned char *secret, - int secretSz, void *ctx) +static int wssl_tls13_secret_callback(SSL *ssl, int id, + const unsigned char *secret, + int secretSz, void *ctx) { const char *label; unsigned char client_random[SSL3_RANDOM_SIZE]; @@ -309,8 +309,7 @@ static long wssl_bio_cf_ctrl(WOLFSSL_BIO *bio, int cmd, long num, void *ptr) return ret; } -static int wssl_bio_cf_out_write(WOLFSSL_BIO *bio, - const char *buf, int blen) +static int wssl_bio_cf_out_write(WOLFSSL_BIO *bio, const char *buf, int blen) { struct Curl_cfilter *cf = wolfSSL_BIO_get_data(bio); struct ssl_connect_data *connssl = cf->ctx; @@ -487,7 +486,7 @@ static int wssl_vtls_new_session_cb(WOLFSSL *ssl, WOLFSSL_SESSION *session) { struct Curl_cfilter *cf; - cf = (struct Curl_cfilter*)wolfSSL_get_app_data(ssl); + cf = (struct Curl_cfilter *)wolfSSL_get_app_data(ssl); DEBUGASSERT(cf != NULL); if(cf && session) { struct ssl_connect_data *connssl = cf->ctx; @@ -535,8 +534,8 @@ static CURLcode wssl_on_session_reuse(struct Curl_cfilter *cf, connssl->earlydata_state = ssl_earlydata_await; connssl->state = ssl_connection_deferred; result = Curl_alpn_set_negotiated(cf, data, connssl, - (const unsigned char *)scs->alpn, - scs->alpn ? strlen(scs->alpn) : 0); + (const unsigned char *)scs->alpn, + scs->alpn ? strlen(scs->alpn) : 0); *do_early_data = !result; } return result; @@ -640,7 +639,7 @@ static CURLcode wssl_populate_x509_store(struct Curl_cfilter *cf, } #else infof(data, "ignoring native CA option because wolfSSL was built without " - "native CA support"); + "native CA support"); #endif } #endif /* !NO_FILESYSTEM */ @@ -688,7 +687,7 @@ static CURLcode wssl_populate_x509_store(struct Curl_cfilter *cf, /* Just continue with a warning if no strict certificate verification is required. */ infof(data, "error setting certificate verify locations," - " continuing anyway:"); + " continuing anyway:"); } } else { @@ -707,15 +706,15 @@ static CURLcode wssl_populate_x509_store(struct Curl_cfilter *cf, #define MPROTO_WSSL_X509_KEY "tls:wssl:x509:share" struct wssl_x509_share { - char *CAfile; /* CAfile path used to generate X509 store */ + char *CAfile; /* CAfile path used to generate X509 store */ WOLFSSL_X509_STORE *store; /* cached X509 store or NULL if none */ - struct curltime time; /* when the cached store was created */ + struct curltime time; /* when the cached store was created */ }; static void wssl_x509_share_free(void *key, size_t key_len, void *p) { struct wssl_x509_share *share = p; - DEBUGASSERT(key_len == (sizeof(MPROTO_WSSL_X509_KEY)-1)); + DEBUGASSERT(key_len == (sizeof(MPROTO_WSSL_X509_KEY) - 1)); DEBUGASSERT(!memcmp(MPROTO_WSSL_X509_KEY, key, key_len)); (void)key; (void)key_len; @@ -726,9 +725,8 @@ static void wssl_x509_share_free(void *key, size_t key_len, void *p) curlx_free(share); } -static bool -wssl_cached_x509_store_expired(const struct Curl_easy *data, - const struct wssl_x509_share *mb) +static bool wssl_cached_x509_store_expired(const struct Curl_easy *data, + const struct wssl_x509_share *mb) { const struct ssl_general_config *cfg = &data->set.general_ssl; struct curltime now = curlx_now(); @@ -741,9 +739,8 @@ wssl_cached_x509_store_expired(const struct Curl_easy *data, return elapsed_ms >= timeout_ms; } -static bool -wssl_cached_x509_store_different(struct Curl_cfilter *cf, - const struct wssl_x509_share *mb) +static bool wssl_cached_x509_store_different(struct Curl_cfilter *cf, + const struct wssl_x509_share *mb) { struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); if(!mb->CAfile || !conn_config->CAfile) @@ -762,7 +759,7 @@ static WOLFSSL_X509_STORE *wssl_get_cached_x509_store(struct Curl_cfilter *cf, DEBUGASSERT(multi); share = multi ? Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_WSSL_X509_KEY), - sizeof(MPROTO_WSSL_X509_KEY)-1) : NULL; + sizeof(MPROTO_WSSL_X509_KEY) - 1) : NULL; if(share && share->store && !wssl_cached_x509_store_expired(data, share) && !wssl_cached_x509_store_different(cf, share)) { @@ -785,7 +782,7 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, return; share = Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_WSSL_X509_KEY), - sizeof(MPROTO_WSSL_X509_KEY)-1); + sizeof(MPROTO_WSSL_X509_KEY) - 1); if(!share) { share = curlx_calloc(1, sizeof(*share)); @@ -793,7 +790,7 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, return; if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_WSSL_X509_KEY), - sizeof(MPROTO_WSSL_X509_KEY)-1, + sizeof(MPROTO_WSSL_X509_KEY) - 1, share, wssl_x509_share_free)) { curlx_free(share); return; @@ -876,8 +873,7 @@ CURLcode Curl_wssl_setup_x509_store(struct Curl_cfilter *cf, } #ifdef WOLFSSL_TLS13 -static CURLcode -wssl_add_default_ciphers(bool tls13, struct dynbuf *buf) +static CURLcode wssl_add_default_ciphers(bool tls13, struct dynbuf *buf) { int i; char *str; @@ -905,8 +901,7 @@ wssl_add_default_ciphers(bool tls13, struct dynbuf *buf) /* 4.2.0 (2019) */ #if LIBWOLFSSL_VERSION_HEX < 0x04002000 || !defined(OPENSSL_EXTRA) -static int -wssl_legacy_CTX_set_min_proto_version(WOLFSSL_CTX* ctx, int version) +static int wssl_legacy_CTX_set_min_proto_version(WOLFSSL_CTX *ctx, int version) { int res; switch(version) { @@ -933,8 +928,8 @@ wssl_legacy_CTX_set_min_proto_version(WOLFSSL_CTX* ctx, int version) } return res; } -static int -wssl_legacy_CTX_set_max_proto_version(WOLFSSL_CTX* ctx, int version) + +static int wssl_legacy_CTX_set_max_proto_version(WOLFSSL_CTX *ctx, int version) { (void)ctx, (void)version; return WOLFSSL_NOT_IMPLEMENTED; @@ -1106,7 +1101,6 @@ static CURLcode ssl_version(struct Curl_easy *data, return CURLE_OK; } - #define QUIC_GROUPS "P-256:P-384:P-521" CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, @@ -1121,7 +1115,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, { struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data); struct ssl_primary_config *conn_config; - WOLFSSL_METHOD* req_method = NULL; + WOLFSSL_METHOD *req_method = NULL; struct alpn_spec alpns; char *curves; #ifdef WOLFSSL_HAVE_KYBER @@ -1357,8 +1351,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, /* Ensure the Client Random is preserved. */ wolfSSL_KeepArrays(wctx->ssl); #if defined(HAVE_SECRET_CALLBACK) && defined(WOLFSSL_TLS13) - wolfSSL_set_tls13_secret_cb(wctx->ssl, - wssl_tls13_secret_callback, NULL); + wolfSSL_set_tls13_secret_cb(wctx->ssl, wssl_tls13_secret_callback, NULL); #endif } #endif /* OPENSSL_EXTRA */ @@ -1383,15 +1376,15 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, if(data->set.tls_ech == CURLECH_GREASE) { infof(data, "ECH: GREASE is done by default by wolfSSL: no need to ask"); } - if(data->set.tls_ech & CURLECH_CLA_CFG - && data->set.str[STRING_ECH_CONFIG]) { + if(data->set.tls_ech & CURLECH_CLA_CFG && + data->set.str[STRING_ECH_CONFIG]) { char *b64val = data->set.str[STRING_ECH_CONFIG]; word32 b64len = 0; - b64len = (word32) strlen(b64val); - if(b64len - && wolfSSL_SetEchConfigsBase64(wctx->ssl, b64val, b64len) - != WOLFSSL_SUCCESS) { + b64len = (word32)strlen(b64val); + if(b64len && + wolfSSL_SetEchConfigsBase64(wctx->ssl, + b64val, b64len) != WOLFSSL_SUCCESS) { if(data->set.tls_ech & CURLECH_HARD) { result = CURLE_SSL_CONNECT_ERROR; goto out; @@ -1424,8 +1417,8 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, size_t elen = rinfo->echconfiglist_len; infof(data, "ECH: ECHConfig from DoH HTTPS RR"); - if(wolfSSL_SetEchConfigs(wctx->ssl, ecl, (word32) elen) != - WOLFSSL_SUCCESS) { + if(wolfSSL_SetEchConfigs(wctx->ssl, ecl, (word32)elen) != + WOLFSSL_SUCCESS) { infof(data, "ECH: wolfSSL_SetEchConfigs failed"); if(data->set.tls_ech & CURLECH_HARD) { result = CURLE_SSL_CONNECT_ERROR; @@ -1476,8 +1469,8 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, * This function loads all the client/CA certificates and CRLs. Setup the TLS * layer and do all necessary magic. */ -static CURLcode -wssl_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode wssl_connect_step1(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct wssl_ctx *wssl = (struct wssl_ctx *)connssl->backend; @@ -1542,9 +1535,7 @@ wssl_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_OK; } - -static char *wssl_strerror(unsigned long error, char *buf, - unsigned long size) +static char *wssl_strerror(unsigned long error, char *buf, unsigned long size) { DEBUGASSERT(size > 40); *buf = '\0'; @@ -1665,8 +1656,7 @@ static CURLcode wssl_send_earlydata(struct Curl_cfilter *cf, } #endif /* WOLFSSL_EARLY_DATA */ -static CURLcode wssl_handshake(struct Curl_cfilter *cf, - struct Curl_easy *data) +static CURLcode wssl_handshake(struct Curl_cfilter *cf, struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct wssl_ctx *wssl = (struct wssl_ctx *)connssl->backend; @@ -1735,7 +1725,7 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, conn_config->verifyhost && !connssl->peer.sni) { /* we have an IP address as hostname. */ - WOLFSSL_X509* cert = wolfSSL_get_peer_certificate(wssl->ssl); + WOLFSSL_X509 *cert = wolfSSL_get_peer_certificate(wssl->ssl); if(!cert) { failf(data, "unable to get peer certificate"); return CURLE_PEER_FAILED_VERIFICATION; @@ -1789,11 +1779,11 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, } else if(wssl->io_result) { switch(wssl->io_result) { - case CURLE_SEND_ERROR: - case CURLE_RECV_ERROR: - return CURLE_SSL_CONNECT_ERROR; - default: - return wssl->io_result; + case CURLE_SEND_ERROR: + case CURLE_RECV_ERROR: + return CURLE_SSL_CONNECT_ERROR; + default: + return wssl->io_result; } } #ifdef USE_ECH_WOLFSSL @@ -1804,8 +1794,7 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, int rv = 0; /* this currently does not produce the retry_configs */ - rv = wolfSSL_GetEchConfigs(wssl->ssl, echConfigs, - &echConfigsLen); + rv = wolfSSL_GetEchConfigs(wssl->ssl, echConfigs, &echConfigsLen); if(rv != WOLFSSL_SUCCESS) { infof(data, "Failed to get ECHConfigs"); } @@ -2087,7 +2076,6 @@ size_t Curl_wssl_version(char *buffer, size_t size) #endif } - static int wssl_init(void) { int ret; @@ -2101,7 +2089,6 @@ static int wssl_init(void) return ret; } - static void wssl_cleanup(void) { wssl_bio_cf_free_methods(); @@ -2111,7 +2098,6 @@ static void wssl_cleanup(void) #endif } - static bool wssl_data_pending(struct Curl_cfilter *cf, const struct Curl_easy *data) { @@ -2128,15 +2114,14 @@ static bool wssl_data_pending(struct Curl_cfilter *cf, return FALSE; } -void Curl_wssl_report_handshake(struct Curl_easy *data, - struct wssl_ctx *wssl) +void Curl_wssl_report_handshake(struct Curl_easy *data, struct wssl_ctx *wssl) { #if (LIBWOLFSSL_VERSION_HEX >= 0x03009010) - infof(data, "SSL connection using %s / %s", - wolfSSL_get_version(wssl->ssl), - wolfSSL_get_cipher_name(wssl->ssl)); + infof(data, "SSL connection using %s / %s", + wolfSSL_get_version(wssl->ssl), + wolfSSL_get_cipher_name(wssl->ssl)); #else - infof(data, "SSL connected"); + infof(data, "SSL connected"); #endif } diff --git a/lib/vtls/wolfssl.h b/lib/vtls/wolfssl.h index 7ff4cfb88178..5e3c9e2c5dd6 100644 --- a/lib/vtls/wolfssl.h +++ b/lib/vtls/wolfssl.h @@ -41,9 +41,9 @@ extern const struct Curl_ssl Curl_ssl_wolfssl; struct wssl_ctx { struct WOLFSSL_CTX *ssl_ctx; - struct WOLFSSL *ssl; - CURLcode io_result; /* result of last BIO cfilter operation */ - CURLcode hs_result; /* result of handshake */ + struct WOLFSSL *ssl; + CURLcode io_result; /* result of last BIO cfilter operation */ + CURLcode hs_result; /* result of handshake */ int io_send_blocked_len; /* length of last BIO write that EAGAIN-ed */ BIT(x509_store_setup); /* x509 store has been set up */ BIT(shutting_down); /* TLS is being shut down */ @@ -88,8 +88,7 @@ CURLcode Curl_wssl_verify_pinned(struct Curl_cfilter *cf, struct Curl_easy *data, struct wssl_ctx *wssl); -void Curl_wssl_report_handshake(struct Curl_easy *data, - struct wssl_ctx *wssl); +void Curl_wssl_report_handshake(struct Curl_easy *data, struct wssl_ctx *wssl); #endif /* USE_WOLFSSL */ #endif /* HEADER_CURL_WOLFSSL_H */ diff --git a/lib/vtls/x509asn1.c b/lib/vtls/x509asn1.c index fcc0d0e1daf2..f63a9fcb9928 100644 --- a/lib/vtls/x509asn1.c +++ b/lib/vtls/x509asn1.c @@ -192,7 +192,7 @@ static const char *getASN1Element_(struct Curl_asn1Element *elem, /* Process header byte. */ elem->header = beg; - b = (unsigned char) *beg++; + b = (unsigned char)*beg++; elem->constructed = (b & 0x20) != 0; elem->eclass = (b >> 6) & 3; b &= 0x1F; @@ -203,7 +203,7 @@ static const char *getASN1Element_(struct Curl_asn1Element *elem, /* Process length. */ if(beg >= end) return NULL; - b = (unsigned char) *beg++; + b = (unsigned char)*beg++; if(!(b & 0x80)) len = b; else if(!(b &= 0x7F)) { @@ -284,7 +284,7 @@ static CURLcode bool2str(struct dynbuf *store, { if(end - beg != 1) return CURLE_BAD_FUNCTION_ARGUMENT; - return curlx_dyn_add(store, *beg ? "TRUE": "FALSE"); + return curlx_dyn_add(store, *beg ? "TRUE" : "FALSE"); } /* @@ -298,13 +298,12 @@ static CURLcode octet2str(struct dynbuf *store, CURLcode result = CURLE_OK; while(!result && beg < end) - result = curlx_dyn_addf(store, "%02x:", (unsigned char) *beg++); + result = curlx_dyn_addf(store, "%02x:", (unsigned char)*beg++); return result; } -static CURLcode bit2str(struct dynbuf *store, - const char *beg, const char *end) +static CURLcode bit2str(struct dynbuf *store, const char *beg, const char *end) { /* Convert an ASN.1 bit string to a printable string. */ @@ -318,8 +317,7 @@ static CURLcode bit2str(struct dynbuf *store, * * Returns error. */ -static CURLcode int2str(struct dynbuf *store, - const char *beg, const char *end) +static CURLcode int2str(struct dynbuf *store, const char *beg, const char *end) { unsigned int val = 0; size_t n = end - beg; @@ -335,7 +333,7 @@ static CURLcode int2str(struct dynbuf *store, val = ~val; do - val = (val << 8) | *(const unsigned char *) beg++; + val = (val << 8) | *(const unsigned char *)beg++; while(beg < end); return curlx_dyn_addf(store, "%s%x", val >= 10 ? "0x" : "", val); } @@ -348,8 +346,8 @@ static CURLcode int2str(struct dynbuf *store, * * Returns error. */ -static CURLcode -utf8asn1str(struct dynbuf *to, int type, const char *from, const char *end) +static CURLcode utf8asn1str(struct dynbuf *to, int type, const char *from, + const char *end) { size_t inlength = end - from; int size = 1; @@ -390,14 +388,14 @@ utf8asn1str(struct dynbuf *to, int type, const char *from, const char *end) switch(size) { case 4: - wc = (wc << 8) | *(const unsigned char *) from++; - wc = (wc << 8) | *(const unsigned char *) from++; + wc = (wc << 8) | *(const unsigned char *)from++; + wc = (wc << 8) | *(const unsigned char *)from++; FALLTHROUGH(); case 2: - wc = (wc << 8) | *(const unsigned char *) from++; + wc = (wc << 8) | *(const unsigned char *)from++; FALLTHROUGH(); default: /* case 1: */ - wc = (wc << 8) | *(const unsigned char *) from++; + wc = (wc << 8) | *(const unsigned char *)from++; } if(wc >= 0x00000080) { if(wc >= 0x00000800) { @@ -406,19 +404,19 @@ utf8asn1str(struct dynbuf *to, int type, const char *from, const char *end) /* Invalid char. size for target encoding. */ return CURLE_WEIRD_SERVER_REPLY; } - buf[3] = (char) (0x80 | (wc & 0x3F)); + buf[3] = (char)(0x80 | (wc & 0x3F)); wc = (wc >> 6) | 0x00010000; charsize++; } - buf[2] = (char) (0x80 | (wc & 0x3F)); + buf[2] = (char)(0x80 | (wc & 0x3F)); wc = (wc >> 6) | 0x00000800; charsize++; } - buf[1] = (char) (0x80 | (wc & 0x3F)); + buf[1] = (char)(0x80 | (wc & 0x3F)); wc = (wc >> 6) | 0x000000C0; charsize++; } - buf[0] = (char) wc; + buf[0] = (char)wc; result = curlx_dyn_addn(to, buf, charsize); } } @@ -438,7 +436,7 @@ static CURLcode encodeOID(struct dynbuf *store, CURLcode result = CURLE_OK; /* Process the first two numbers. */ - y = *(const unsigned char *) beg++; + y = *(const unsigned char *)beg++; x = y / 40; y -= x * 40; @@ -452,7 +450,7 @@ static CURLcode encodeOID(struct dynbuf *store, do { if(x & 0xFF000000) return CURLE_OK; - y = *(const unsigned char *) beg++; + y = *(const unsigned char *)beg++; x = (x << 7) | (y & 0x7F); } while(y & 0x80); result = curlx_dyn_addf(store, ".%u", x); @@ -973,8 +971,8 @@ static CURLcode do_pubkey_field(struct Curl_easy *data, int certnum, } /* return 0 on success, 1 on error */ -static int do_pubkey(struct Curl_easy *data, int certnum, - const char *algo, struct Curl_asn1Element *param, +static int do_pubkey(struct Curl_easy *data, int certnum, const char *algo, + struct Curl_asn1Element *param, struct Curl_asn1Element *pubkey) { struct Curl_asn1Element elem; @@ -1019,7 +1017,7 @@ static int do_pubkey(struct Curl_easy *data, int certnum, len = ((elem.end - q) * 8); if(len) { unsigned int i; - for(i = *(const unsigned char *) q; !(i & 0x80); i <<= 1) + for(i = *(const unsigned char *)q; !(i & 0x80); i <<= 1) len--; } if(len > 32) @@ -1078,8 +1076,7 @@ static int do_pubkey(struct Curl_easy *data, int certnum, * Convert an ASN.1 distinguished name into a printable string. * Return error. */ -static CURLcode DNtostr(struct dynbuf *store, - struct Curl_asn1Element *dn) +static CURLcode DNtostr(struct dynbuf *store, struct Curl_asn1Element *dn) { return encodeDN(store, dn); } @@ -1135,7 +1132,7 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data, /* Version (always fits in less than 32 bits). */ version = 0; for(ptr = cert.version.beg; ptr < cert.version.end; ptr++) - version = (version << 8) | *(const unsigned char *) ptr; + version = (version << 8) | *(const unsigned char *)ptr; if(data->set.ssl.certinfo) { result = curlx_dyn_addf(&out, "%x", version); if(result) @@ -1163,8 +1160,7 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data, if(result) goto done; if(data->set.ssl.certinfo) { - result = ssl_push_certinfo_dyn(data, certnum, "Signature Algorithm", - &out); + result = ssl_push_certinfo_dyn(data, certnum, "Signature Algorithm", &out); if(result) goto done; } From 47a1ab2ebecb21485c0e955316d90511e80a3c43 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 29 Nov 2025 22:37:26 +0100 Subject: [PATCH 125/140] lib: fix formatting nits (part 1) From `lib/a*` to `lib/cs*`. Closes #19764 --- lib/altsvc.c | 1 - lib/altsvc.h | 2 +- lib/amigaos.c | 12 ++-- lib/arpa_telnet.h | 12 ++-- lib/asyn-ares.c | 22 +++---- lib/asyn-base.c | 8 +-- lib/asyn-thrdd.c | 15 ++--- lib/asyn.h | 20 +++--- lib/bufq.c | 3 +- lib/bufq.h | 2 +- lib/bufref.c | 2 +- lib/bufref.h | 1 - lib/cf-h1-proxy.c | 40 ++++++------ lib/cf-h1-proxy.h | 1 - lib/cf-h2-proxy.c | 159 +++++++++++++++++++++++----------------------- lib/cf-haproxy.c | 8 +-- lib/cf-ip-happy.c | 90 +++++++++++++------------- lib/cf-socket.c | 117 +++++++++++++++++----------------- lib/cf-socket.h | 2 +- lib/cfilters.c | 19 +++--- lib/cfilters.h | 55 ++++++++-------- lib/conncache.c | 18 ++---- lib/conncache.h | 3 +- lib/connect.c | 64 +++++++++---------- lib/connect.h | 12 ++-- lib/cookie.c | 61 ++++++++---------- lib/cookie.h | 40 ++++++------ lib/cshutdn.c | 20 ++---- 28 files changed, 377 insertions(+), 432 deletions(-) diff --git a/lib/altsvc.c b/lib/altsvc.c index 84f6c1b44547..cbaf4b4d85f9 100644 --- a/lib/altsvc.c +++ b/lib/altsvc.c @@ -64,7 +64,6 @@ const char *Curl_alpnid2str(enum alpnid id) } } - static void altsvc_free(struct altsvc *as) { curlx_free(as->src.host); diff --git a/lib/altsvc.h b/lib/altsvc.h index 831cd097436a..d370b4e4b195 100644 --- a/lib/altsvc.h +++ b/lib/altsvc.h @@ -68,7 +68,7 @@ bool Curl_altsvc_lookup(struct altsvcinfo *asi, const int versions); /* CURLALTSVC_H* bits */ #else /* disabled */ -#define Curl_altsvc_save(a,b,c) +#define Curl_altsvc_save(a, b, c) #define Curl_altsvc_cleanup(x) #endif /* !CURL_DISABLE_HTTP && !CURL_DISABLE_ALTSVC */ #endif /* HEADER_CURL_ALTSVC_H */ diff --git a/lib/amigaos.c b/lib/amigaos.c index e4b678d54185..d32ee5e7902f 100644 --- a/lib/amigaos.c +++ b/lib/amigaos.c @@ -120,8 +120,7 @@ void Curl_amiga_cleanup(void) * allocates memory also. */ -struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, - int port) +struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, int port) { struct Curl_addrinfo *ai = NULL; struct hostent *h; @@ -144,7 +143,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, } } else { - #ifdef CURLRES_THREADED +#ifdef CURLRES_THREADED /* gethostbyname() is not thread safe, so we need to reopen bsdsocket * on the thread's context */ @@ -160,13 +159,13 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, } CloseLibrary(base); } - #else +#else /* not using threaded resolver - safe to use this as-is */ h = gethostbyname(hostname); if(h) { ai = Curl_he2ai(h, port); } - #endif +#endif } return ai; @@ -219,8 +218,7 @@ CURLcode Curl_amiga_init(void) } if(SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (ULONG)&errno, - SBTM_SETVAL(SBTC_LOGTAGPTR), (ULONG)"curl", - TAG_DONE)) { + SBTM_SETVAL(SBTC_LOGTAGPTR), (ULONG)"curl", TAG_DONE)) { CURL_AMIGA_REQUEST("SocketBaseTags ERROR"); return CURLE_FAILED_INIT; } diff --git a/lib/arpa_telnet.h b/lib/arpa_telnet.h index 055aa98b1096..daf2487fc616 100644 --- a/lib/arpa_telnet.h +++ b/lib/arpa_telnet.h @@ -43,8 +43,7 @@ /* * The telnet options represented as strings */ -static const char * const telnetoptions[]= -{ +static const char * const telnetoptions[] = { "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", "NAOCRD", "NAOHTS", @@ -86,8 +85,7 @@ static const char * const telnetoptions[]= /* * Then those numbers represented as strings: */ -static const char * const telnetcmds[]= -{ +static const char * const telnetcmds[] = { "EOF", "SUSP", "ABORT", "EOR", "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", "EL", "GA", "SB", @@ -103,11 +101,11 @@ static const char * const telnetcmds[]= #define CURL_TELQUAL_INFO 2 #define CURL_TELQUAL_NAME 3 -#define CURL_TELCMD_OK(x) ( ((unsigned int)(x) >= CURL_TELCMD_MINIMUM) && \ - ((unsigned int)(x) <= CURL_TELCMD_MAXIMUM) ) +#define CURL_TELCMD_OK(x) (((unsigned int)(x) >= CURL_TELCMD_MINIMUM) && \ + ((unsigned int)(x) <= CURL_TELCMD_MAXIMUM)) #ifndef CURL_DISABLE_VERBOSE_STRINGS -#define CURL_TELCMD(x) telnetcmds[(x)-CURL_TELCMD_MINIMUM] +#define CURL_TELCMD(x) telnetcmds[(x) - CURL_TELCMD_MINIMUM] #else #define CURL_TELCMD(x) "" #endif diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index e3ba512b77ff..ce4f866be6d2 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -140,7 +140,6 @@ void Curl_async_global_cleanup(void) #endif } - static void sock_state_cb(void *data, ares_socket_t socket_fd, int readable, int writable) { @@ -309,12 +308,12 @@ CURLcode Curl_async_is_resolved(struct Curl_easy *data, /* Now that we have checked for any last minute results above, see if there are any responses still pending when the EXPIRE_HAPPY_EYEBALLS_DNS timer expires. */ - if(ares->num_pending + if(ares->num_pending && /* This is only set to non-zero if the timer was started. */ - && (ares->happy_eyeballs_dns_time.tv_sec - || ares->happy_eyeballs_dns_time.tv_usec) - && (curlx_timediff_ms(curlx_now(), ares->happy_eyeballs_dns_time) - >= HAPPY_EYEBALLS_DNS_TIMEOUT)) { + (ares->happy_eyeballs_dns_time.tv_sec || + ares->happy_eyeballs_dns_time.tv_usec) && + (curlx_timediff_ms(curlx_now(), ares->happy_eyeballs_dns_time) >= + HAPPY_EYEBALLS_DNS_TIMEOUT)) { /* Remember that the EXPIRE_HAPPY_EYEBALLS_DNS timer is no longer running. */ memset(&ares->happy_eyeballs_dns_time, 0, @@ -418,8 +417,8 @@ CURLcode Curl_async_await(struct Curl_easy *data, itimeout_ms = (int)timeout_ms; #endif - max_timeout.tv_sec = itimeout_ms/1000; - max_timeout.tv_usec = (itimeout_ms%1000)*1000; + max_timeout.tv_sec = itimeout_ms / 1000; + max_timeout.tv_usec = (itimeout_ms % 1000) * 1000; real_timeout = ares_timeout(ares->channel, &max_timeout, &time_buf); @@ -427,7 +426,7 @@ CURLcode Curl_async_await(struct Curl_easy *data, second is left, otherwise just use 1000ms to make sure the progress callback gets called frequent enough */ if(!real_timeout->tv_sec) - call_timeout_ms = (timediff_t)(real_timeout->tv_usec/1000); + call_timeout_ms = (timediff_t)(real_timeout->tv_usec / 1000); else call_timeout_ms = 1000; @@ -518,7 +517,7 @@ static void async_ares_hostbyname_cb(void *user_data, if(ARES_SUCCESS == status) { ares->ares_status = status; /* one success overrules any error */ async_addr_concat(&ares->temp_ai, - Curl_he2ai(hostent, data->state.async.port)); + Curl_he2ai(hostent, data->state.async.port)); } else if(ares->ares_status != ARES_SUCCESS) { /* no success so far, remember last error */ @@ -586,8 +585,7 @@ static void async_ares_hostbyname_cb(void *user_data, c-ares retry cycle each request is. */ ares->happy_eyeballs_dns_time = curlx_now(); - Curl_expire(data, HAPPY_EYEBALLS_DNS_TIMEOUT, - EXPIRE_HAPPY_EYEBALLS_DNS); + Curl_expire(data, HAPPY_EYEBALLS_DNS_TIMEOUT, EXPIRE_HAPPY_EYEBALLS_DNS); } } diff --git a/lib/asyn-base.c b/lib/asyn-base.c index 6338a3fc6e25..5358fcb8fa54 100644 --- a/lib/asyn-base.c +++ b/lib/asyn-base.c @@ -59,7 +59,6 @@ **********************************************************************/ #ifdef CURLRES_ASYNCH - #ifdef USE_ARES #if ARES_VERSION < 0x010600 @@ -122,8 +121,7 @@ CURLcode Curl_ares_pollset(struct Curl_easy *data, * * return number of sockets it worked on, or -1 on error */ -int Curl_ares_perform(ares_channel channel, - timediff_t timeout_ms) +int Curl_ares_perform(ares_channel channel, timediff_t timeout_ms) { int nfds; int bitmask; @@ -142,11 +140,11 @@ int Curl_ares_perform(ares_channel channel, pfd[i].revents = 0; if(ARES_GETSOCK_READABLE(bitmask, i)) { pfd[i].fd = socks[i]; - pfd[i].events |= POLLRDNORM|POLLIN; + pfd[i].events |= POLLRDNORM | POLLIN; } if(ARES_GETSOCK_WRITABLE(bitmask, i)) { pfd[i].fd = socks[i]; - pfd[i].events |= POLLWRNORM|POLLOUT; + pfd[i].events |= POLLWRNORM | POLLOUT; } if(pfd[i].events) num++; diff --git a/lib/asyn-thrdd.c b/lib/asyn-thrdd.c index 6c2e02fd1871..e5bf0629d38f 100644 --- a/lib/asyn-thrdd.c +++ b/lib/asyn-thrdd.c @@ -45,13 +45,13 @@ #endif #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) -# include +#include #endif #ifdef HAVE_GETADDRINFO -# define RESOLVER_ENOMEM EAI_MEMORY /* = WSA_NOT_ENOUGH_MEMORY on Windows */ +#define RESOLVER_ENOMEM EAI_MEMORY /* = WSA_NOT_ENOUGH_MEMORY on Windows */ #else -# define RESOLVER_ENOMEM SOCKENOMEM +#define RESOLVER_ENOMEM SOCKENOMEM #endif #include "urldata.h" @@ -245,7 +245,6 @@ static CURL_THREAD_RETURN_T CURL_STDCALL getaddrinfo_thread(void *arg) } } #endif - } addr_ctx_unlink(&addr_ctx, NULL); @@ -486,8 +485,8 @@ static void async_thrdd_shutdown(struct Curl_easy *data) Curl_mutex_acquire(&addr_ctx->mutx); #ifndef CURL_DISABLE_SOCKETPAIR - if(!addr_ctx->do_abort) - Curl_multi_will_close(data, addr_ctx->sock_pair[0]); + if(!addr_ctx->do_abort) + Curl_multi_will_close(data, addr_ctx->sock_pair[0]); #endif addr_ctx->do_abort = TRUE; done = addr_ctx->thrd_done; @@ -703,7 +702,7 @@ CURLcode Curl_async_pollset(struct Curl_easy *data, struct easy_pollset *ps) if(!thrd_done) { #ifndef CURL_DISABLE_SOCKETPAIR - /* return read fd to client for polling the DNS resolution status */ + /* return read fd to client for polling the DNS resolution status */ result = Curl_pollset_add_in(data, ps, thrdd->addr->sock_pair[0]); #else timediff_t milli; @@ -711,7 +710,7 @@ CURLcode Curl_async_pollset(struct Curl_easy *data, struct easy_pollset *ps) if(ms < 3) milli = 0; else if(ms <= 50) - milli = ms/3; + milli = ms / 3; else if(ms <= 250) milli = 50; else diff --git a/lib/asyn.h b/lib/asyn.h index 8da7dd9720cc..e5e472e247db 100644 --- a/lib/asyn.h +++ b/lib/asyn.h @@ -129,19 +129,18 @@ CURLcode Curl_ares_pollset(struct Curl_easy *data, ares_channel channel, struct easy_pollset *ps); -int Curl_ares_perform(ares_channel channel, - timediff_t timeout_ms); +int Curl_ares_perform(ares_channel channel, timediff_t timeout_ms); #endif #ifdef CURLRES_ARES /* async resolving implementation using c-ares alone */ struct async_ares_ctx { ares_channel channel; - int num_pending; /* number of outstanding c-ares requests */ + int num_pending; /* number of outstanding c-ares requests */ struct Curl_addrinfo *temp_ai; /* intermediary result while fetching c-ares parts */ - int ares_status; /* ARES_SUCCESS, ARES_ENOTFOUND, etc. */ - CURLcode result; /* CURLE_OK or error handling response */ + int ares_status; /* ARES_SUCCESS, ARES_ENOTFOUND, etc. */ + CURLcode result; /* CURLE_OK or error handling response */ #ifndef HAVE_CARES_GETADDRINFO struct curltime happy_eyeballs_dns_time; /* when this timer started, or 0 */ #endif @@ -223,11 +222,11 @@ struct doh_probes; #else /* CURLRES_ASYNCH */ /* convert these functions if an asynch resolver is not used */ -#define Curl_async_get_impl(x,y) (*(y) = NULL, CURLE_OK) -#define Curl_async_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST -#define Curl_async_await(x,y) CURLE_COULDNT_RESOLVE_HOST -#define Curl_async_global_init() CURLE_OK -#define Curl_async_global_cleanup() Curl_nop_stmt +#define Curl_async_get_impl(x, y) (*(y) = NULL, CURLE_OK) +#define Curl_async_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST +#define Curl_async_await(x, y) CURLE_COULDNT_RESOLVE_HOST +#define Curl_async_global_init() CURLE_OK +#define Curl_async_global_cleanup() Curl_nop_stmt #endif /* !CURLRES_ASYNCH */ @@ -270,6 +269,5 @@ void Curl_async_destroy(struct Curl_easy *data); #define Curl_async_destroy(x) Curl_nop_stmt #endif /* USE_CURL_ASYNC */ - /********** end of generic resolver interface functions *****************/ #endif /* HEADER_CURL_ASYN_H */ diff --git a/lib/bufq.c b/lib/bufq.c index 5a77fc52d4b3..6eeeeb35d432 100644 --- a/lib/bufq.c +++ b/lib/bufq.c @@ -143,7 +143,6 @@ static void chunk_list_free(struct buf_chunk **anchor) } } - void Curl_bufcp_init(struct bufc_pool *pool, size_t chunk_size, size_t spare_max) { @@ -330,7 +329,7 @@ static void prune_head(struct bufq *q) --q->chunk_count; } else if((q->chunk_count > q->max_chunks) || - (q->opts & BUFQ_OPT_NO_SPARES)) { + (q->opts & BUFQ_OPT_NO_SPARES)) { /* SOFT_LIMIT allowed us more than max. free spares until * we are at max again. Or free them if we are configured * to not use spares. */ diff --git a/lib/bufq.h b/lib/bufq.h index 9557e5d33bba..112388a6bf47 100644 --- a/lib/bufq.h +++ b/lib/bufq.h @@ -38,7 +38,7 @@ struct buf_chunk { size_t r_offset; /* first unread bytes */ size_t w_offset; /* one after last written byte */ union { - uint8_t data[1]; /* the buffer for `dlen` bytes */ + uint8_t data[1]; /* the buffer for `dlen` bytes */ void *dummy; /* alignment */ } x; }; diff --git a/lib/bufref.c b/lib/bufref.c index d5181a5da662..643fe5d2e08c 100644 --- a/lib/bufref.c +++ b/lib/bufref.c @@ -76,7 +76,7 @@ void Curl_bufref_set(struct bufref *br, const void *ptr, size_t len, DEBUGASSERT(len <= CURL_MAX_INPUT_LENGTH); Curl_bufref_free(br); - br->ptr = (const unsigned char *) ptr; + br->ptr = (const unsigned char *)ptr; br->len = len; br->dtor = dtor; } diff --git a/lib/bufref.h b/lib/bufref.h index dd424f18f556..f80011fde5ec 100644 --- a/lib/bufref.h +++ b/lib/bufref.h @@ -36,7 +36,6 @@ struct bufref { #endif }; - void Curl_bufref_init(struct bufref *br); void Curl_bufref_set(struct bufref *br, const void *ptr, size_t len, void (*dtor)(void *)); diff --git a/lib/cf-h1-proxy.c b/lib/cf-h1-proxy.c index 84ba3d6193fa..19c63a12b049 100644 --- a/lib/cf-h1-proxy.c +++ b/lib/cf-h1-proxy.c @@ -48,12 +48,12 @@ typedef enum { - H1_TUNNEL_INIT, /* init/default/no tunnel state */ - H1_TUNNEL_CONNECT, /* CONNECT request is being send */ - H1_TUNNEL_RECEIVE, /* CONNECT answer is being received */ - H1_TUNNEL_RESPONSE, /* CONNECT response received completely */ - H1_TUNNEL_ESTABLISHED, - H1_TUNNEL_FAILED + H1_TUNNEL_INIT, /* init/default/no tunnel state */ + H1_TUNNEL_CONNECT, /* CONNECT request is being send */ + H1_TUNNEL_RECEIVE, /* CONNECT answer is being received */ + H1_TUNNEL_RESPONSE, /* CONNECT response received completely */ + H1_TUNNEL_ESTABLISHED, + H1_TUNNEL_FAILED } h1_tunnel_state; /* struct for HTTP CONNECT tunneling */ @@ -74,7 +74,6 @@ struct h1_tunnel_state { BIT(close_connection); }; - static bool tunnel_is_established(struct h1_tunnel_state *ts) { return ts && (ts->tunnel_state == H1_TUNNEL_ESTABLISHED); @@ -209,9 +208,9 @@ static CURLcode start_CONNECT(struct Curl_cfilter *cf, int http_minor; CURLcode result; - /* This only happens if we have looped here due to authentication - reasons, and we do not really use the newly cloned URL here - then. Just free it. */ + /* This only happens if we have looped here due to authentication + reasons, and we do not really use the newly cloned URL here + then. Just free it. */ Curl_safefree(data->req.newurl); result = Curl_http_proxy_create_CONNECT(&req, cf, data, 1); @@ -281,10 +280,8 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf, struct SingleRequest *k = &data->req; (void)cf; - if((checkprefix("WWW-Authenticate:", header) && - (401 == k->httpcode)) || - (checkprefix("Proxy-authenticate:", header) && - (407 == k->httpcode))) { + if((checkprefix("WWW-Authenticate:", header) && (401 == k->httpcode)) || + (checkprefix("Proxy-authenticate:", header) && (407 == k->httpcode))) { bool proxy = (k->httpcode == 407); char *auth = Curl_copy_header_value(header); @@ -300,7 +297,7 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf, return result; } else if(checkprefix("Content-Length:", header)) { - if(k->httpcode/100 == 2) { + if(k->httpcode / 100 == 2) { /* A client MUST ignore any Content-Length or Transfer-Encoding header fields received in a successful response to CONNECT. "Successful" described as: 2xx (Successful). RFC 7231 4.3.6 */ @@ -319,7 +316,7 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf, STRCONST("Connection:"), STRCONST("close"))) ts->close_connection = TRUE; else if(checkprefix("Transfer-Encoding:", header)) { - if(k->httpcode/100 == 2) { + if(k->httpcode / 100 == 2) { /* A client MUST ignore any Content-Length or Transfer-Encoding header fields received in a successful response to CONNECT. "Successful" described as: 2xx (Successful). RFC 7231 4.3.6 */ @@ -493,8 +490,8 @@ static CURLcode recv_CONNECT_resp(struct Curl_cfilter *cf, ts->keepon = KEEPON_DONE; } - DEBUGASSERT(ts->keepon == KEEPON_IGNORE - || ts->keepon == KEEPON_DONE); + DEBUGASSERT(ts->keepon == KEEPON_IGNORE || + ts->keepon == KEEPON_DONE); continue; } @@ -508,7 +505,7 @@ static CURLcode recv_CONNECT_resp(struct Curl_cfilter *cf, if(error) result = CURLE_RECV_ERROR; *done = (ts->keepon == KEEPON_DONE); - if(!result && *done && data->info.httpproxycode/100 != 2) { + if(!result && *done && data->info.httpproxycode / 100 != 2) { /* Deal with the possibly already received authenticate headers. 'newurl' is set to a new URL if we must loop. */ result = Curl_http_auth_act(data); @@ -603,7 +600,7 @@ static CURLcode H1_CONNECT(struct Curl_cfilter *cf, } while(data->req.newurl); DEBUGASSERT(ts->tunnel_state == H1_TUNNEL_RESPONSE); - if(data->info.httpproxycode/100 != 2) { + if(data->info.httpproxycode / 100 != 2) { /* a non-2xx response and we have no next URL to try. */ Curl_safefree(data->req.newurl); h1_tunnel_go_state(cf, ts, H1_TUNNEL_FAILED, data); @@ -716,10 +713,9 @@ static void cf_h1_proxy_close(struct Curl_cfilter *cf, } } - struct Curl_cftype Curl_cft_h1_proxy = { "H1-PROXY", - CF_TYPE_IP_CONNECT|CF_TYPE_PROXY, + CF_TYPE_IP_CONNECT | CF_TYPE_PROXY, 0, cf_h1_proxy_destroy, cf_h1_proxy_connect, diff --git a/lib/cf-h1-proxy.h b/lib/cf-h1-proxy.h index ac5bed0b2bc7..ded55db9df31 100644 --- a/lib/cf-h1-proxy.h +++ b/lib/cf-h1-proxy.h @@ -33,7 +33,6 @@ CURLcode Curl_cf_h1_proxy_insert_after(struct Curl_cfilter *cf, extern struct Curl_cftype Curl_cft_h1_proxy; - #endif /* !CURL_DISABLE_PROXY && !CURL_DISABLE_HTTP */ #endif /* HEADER_CURL_H1_PROXY_H */ diff --git a/lib/cf-h2-proxy.c b/lib/cf-h2-proxy.c index 7066db3b4c4a..fb2586d1d0e5 100644 --- a/lib/cf-h2-proxy.c +++ b/lib/cf-h2-proxy.c @@ -45,12 +45,12 @@ #include "curlx/warnless.h" #include "cf-h2-proxy.h" -#define PROXY_H2_CHUNK_SIZE (16*1024) +#define PROXY_H2_CHUNK_SIZE (16 * 1024) #define PROXY_HTTP2_HUGE_WINDOW_SIZE (100 * 1024 * 1024) #define H2_TUNNEL_WINDOW_SIZE (10 * 1024 * 1024) -#define PROXY_H2_NW_RECV_CHUNKS (H2_TUNNEL_WINDOW_SIZE / PROXY_H2_CHUNK_SIZE) +#define PROXY_H2_NW_RECV_CHUNKS (H2_TUNNEL_WINDOW_SIZE / PROXY_H2_CHUNK_SIZE) #define PROXY_H2_NW_SEND_CHUNKS 1 #define H2_TUNNEL_RECV_CHUNKS (H2_TUNNEL_WINDOW_SIZE / PROXY_H2_CHUNK_SIZE) @@ -58,11 +58,11 @@ typedef enum { - H2_TUNNEL_INIT, /* init/default/no tunnel state */ - H2_TUNNEL_CONNECT, /* CONNECT request is being send */ - H2_TUNNEL_RESPONSE, /* CONNECT response received completely */ - H2_TUNNEL_ESTABLISHED, - H2_TUNNEL_FAILED + H2_TUNNEL_INIT, /* init/default/no tunnel state */ + H2_TUNNEL_CONNECT, /* CONNECT request is being send */ + H2_TUNNEL_RESPONSE, /* CONNECT response received completely */ + H2_TUNNEL_ESTABLISHED, + H2_TUNNEL_FAILED } h2_tunnel_state; struct tunnel_stream { @@ -94,7 +94,7 @@ static CURLcode tunnel_stream_init(struct Curl_cfilter *cf, Curl_http_proxy_get_destination(cf, &hostname, &port, &ipv6_ip); /* host:port with IPv6 support */ - ts->authority = curl_maprintf("%s%s%s:%d", ipv6_ip ? "[":"", hostname, + ts->authority = curl_maprintf("%s%s%s:%d", ipv6_ip ? "[" : "", hostname, ipv6_ip ? "]" : "", port); if(!ts->authority) return CURLE_OUT_OF_MEMORY; @@ -184,8 +184,7 @@ struct cf_h2_proxy_ctx { /* How to access `call_data` from a cf_h2 filter */ #undef CF_CTX_CALL_DATA -#define CF_CTX_CALL_DATA(cf) \ - ((struct cf_h2_proxy_ctx *)(cf)->ctx)->call_data +#define CF_CTX_CALL_DATA(cf) ((struct cf_h2_proxy_ctx *)(cf)->ctx)->call_data static void cf_h2_proxy_ctx_clear(struct cf_h2_proxy_ctx *ctx) { @@ -542,70 +541,70 @@ static int proxy_h2_fr_print(const nghttp2_frame *frame, char *buffer, size_t blen) { switch(frame->hd.type) { - case NGHTTP2_DATA: { - return curl_msnprintf(buffer, blen, - "FRAME[DATA, len=%d, eos=%d, padlen=%d]", - (int)frame->hd.length, - !!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM), - (int)frame->data.padlen); + case NGHTTP2_DATA: { + return curl_msnprintf(buffer, blen, + "FRAME[DATA, len=%d, eos=%d, padlen=%d]", + (int)frame->hd.length, + !!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM), + (int)frame->data.padlen); + } + case NGHTTP2_HEADERS: { + return curl_msnprintf(buffer, blen, + "FRAME[HEADERS, len=%d, hend=%d, eos=%d]", + (int)frame->hd.length, + !!(frame->hd.flags & NGHTTP2_FLAG_END_HEADERS), + !!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM)); + } + case NGHTTP2_PRIORITY: { + return curl_msnprintf(buffer, blen, + "FRAME[PRIORITY, len=%d, flags=%d]", + (int)frame->hd.length, frame->hd.flags); + } + case NGHTTP2_RST_STREAM: { + return curl_msnprintf(buffer, blen, + "FRAME[RST_STREAM, len=%d, flags=%d, error=%u]", + (int)frame->hd.length, frame->hd.flags, + frame->rst_stream.error_code); + } + case NGHTTP2_SETTINGS: { + if(frame->hd.flags & NGHTTP2_FLAG_ACK) { + return curl_msnprintf(buffer, blen, "FRAME[SETTINGS, ack=1]"); } - case NGHTTP2_HEADERS: { - return curl_msnprintf(buffer, blen, - "FRAME[HEADERS, len=%d, hend=%d, eos=%d]", - (int)frame->hd.length, - !!(frame->hd.flags & NGHTTP2_FLAG_END_HEADERS), - !!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM)); - } - case NGHTTP2_PRIORITY: { - return curl_msnprintf(buffer, blen, - "FRAME[PRIORITY, len=%d, flags=%d]", - (int)frame->hd.length, frame->hd.flags); - } - case NGHTTP2_RST_STREAM: { - return curl_msnprintf(buffer, blen, - "FRAME[RST_STREAM, len=%d, flags=%d, error=%u]", - (int)frame->hd.length, frame->hd.flags, - frame->rst_stream.error_code); - } - case NGHTTP2_SETTINGS: { - if(frame->hd.flags & NGHTTP2_FLAG_ACK) { - return curl_msnprintf(buffer, blen, "FRAME[SETTINGS, ack=1]"); - } - return curl_msnprintf(buffer, blen, - "FRAME[SETTINGS, len=%d]", (int)frame->hd.length); - } - case NGHTTP2_PUSH_PROMISE: - return curl_msnprintf(buffer, blen, - "FRAME[PUSH_PROMISE, len=%d, hend=%d]", - (int)frame->hd.length, - !!(frame->hd.flags & NGHTTP2_FLAG_END_HEADERS)); - case NGHTTP2_PING: - return curl_msnprintf(buffer, blen, - "FRAME[PING, len=%d, ack=%d]", - (int)frame->hd.length, - frame->hd.flags & NGHTTP2_FLAG_ACK); - case NGHTTP2_GOAWAY: { - char scratch[128]; - size_t s_len = CURL_ARRAYSIZE(scratch); - size_t len = (frame->goaway.opaque_data_len < s_len) ? - frame->goaway.opaque_data_len : s_len-1; - if(len) - memcpy(scratch, frame->goaway.opaque_data, len); - scratch[len] = '\0'; - return curl_msnprintf(buffer, blen, - "FRAME[GOAWAY, error=%d, reason='%s', " - "last_stream=%d]", frame->goaway.error_code, - scratch, frame->goaway.last_stream_id); - } - case NGHTTP2_WINDOW_UPDATE: { - return curl_msnprintf(buffer, blen, - "FRAME[WINDOW_UPDATE, incr=%d]", - frame->window_update.window_size_increment); - } - default: - return curl_msnprintf(buffer, blen, "FRAME[%d, len=%d, flags=%d]", - frame->hd.type, (int)frame->hd.length, - frame->hd.flags); + return curl_msnprintf(buffer, blen, + "FRAME[SETTINGS, len=%d]", (int)frame->hd.length); + } + case NGHTTP2_PUSH_PROMISE: + return curl_msnprintf(buffer, blen, + "FRAME[PUSH_PROMISE, len=%d, hend=%d]", + (int)frame->hd.length, + !!(frame->hd.flags & NGHTTP2_FLAG_END_HEADERS)); + case NGHTTP2_PING: + return curl_msnprintf(buffer, blen, + "FRAME[PING, len=%d, ack=%d]", + (int)frame->hd.length, + frame->hd.flags & NGHTTP2_FLAG_ACK); + case NGHTTP2_GOAWAY: { + char scratch[128]; + size_t s_len = CURL_ARRAYSIZE(scratch); + size_t len = (frame->goaway.opaque_data_len < s_len) ? + frame->goaway.opaque_data_len : s_len-1; + if(len) + memcpy(scratch, frame->goaway.opaque_data, len); + scratch[len] = '\0'; + return curl_msnprintf(buffer, blen, + "FRAME[GOAWAY, error=%d, reason='%s', " + "last_stream=%d]", frame->goaway.error_code, + scratch, frame->goaway.last_stream_id); + } + case NGHTTP2_WINDOW_UPDATE: { + return curl_msnprintf(buffer, blen, + "FRAME[WINDOW_UPDATE, incr=%d]", + frame->window_update.window_size_increment); + } + default: + return curl_msnprintf(buffer, blen, "FRAME[%d, len=%d, flags=%d]", + frame->hd.type, (int)frame->hd.length, + frame->hd.flags); } } @@ -621,7 +620,7 @@ static int proxy_h2_on_frame_send(nghttp2_session *session, if(data && Curl_trc_cf_is_verbose(cf, data)) { char buffer[256]; int len; - len = proxy_h2_fr_print(frame, buffer, sizeof(buffer)-1); + len = proxy_h2_fr_print(frame, buffer, sizeof(buffer) - 1); buffer[len] = 0; CURL_TRC_CF(data, cf, "[%d] -> %s", frame->hd.stream_id, buffer); } @@ -644,9 +643,9 @@ static int proxy_h2_on_frame_recv(nghttp2_session *session, if(Curl_trc_cf_is_verbose(cf, data)) { char buffer[256]; int len; - len = proxy_h2_fr_print(frame, buffer, sizeof(buffer)-1); + len = proxy_h2_fr_print(frame, buffer, sizeof(buffer) - 1); buffer[len] = 0; - CURL_TRC_CF(data, cf, "[%d] <- %s",frame->hd.stream_id, buffer); + CURL_TRC_CF(data, cf, "[%d] <- %s", frame->hd.stream_id, buffer); } #endif /* !CURL_DISABLE_VERBOSE_STRINGS */ @@ -962,7 +961,7 @@ static CURLcode inspect_response(struct Curl_cfilter *cf, (void)cf; DEBUGASSERT(ts->resp); - if(ts->resp->status/100 == 2) { + if(ts->resp->status / 100 == 2) { infof(data, "CONNECT tunnel established, response %d", ts->resp->status); h2_tunnel_go_state(cf, ts, H2_TUNNEL_ESTABLISHED, data); return CURLE_OK; @@ -1220,7 +1219,7 @@ static CURLcode cf_h2_proxy_adjust_pollset(struct Curl_cfilter *cf, c_exhaust = !nghttp2_session_get_remote_window_size(ctx->h2); s_exhaust = ctx->tunnel.stream_id >= 0 && !nghttp2_session_get_stream_remote_window_size( - ctx->h2, ctx->tunnel.stream_id); + ctx->h2, ctx->tunnel.stream_id); want_recv = (want_recv || c_exhaust || s_exhaust); want_send = (!s_exhaust && want_send) || (!c_exhaust && nghttp2_session_want_write(ctx->h2)) || @@ -1414,7 +1413,7 @@ static CURLcode cf_h2_proxy_send(struct Curl_cfilter *cf, "h2 windows %d-%d (stream-conn), buffers %zu-%zu (stream-conn)", ctx->tunnel.stream_id, len, result, *pnwritten, nghttp2_session_get_stream_remote_window_size( - ctx->h2, ctx->tunnel.stream_id), + ctx->h2, ctx->tunnel.stream_id), nghttp2_session_get_remote_window_size(ctx->h2), Curl_bufq_len(&ctx->tunnel.sendbuf), Curl_bufq_len(&ctx->outbufq)); @@ -1566,7 +1565,7 @@ static CURLcode cf_h2_proxy_cntrl(struct Curl_cfilter *cf, struct Curl_cftype Curl_cft_h2_proxy = { "H2-PROXY", - CF_TYPE_IP_CONNECT|CF_TYPE_PROXY, + CF_TYPE_IP_CONNECT | CF_TYPE_PROXY, CURL_LOG_LVL_NONE, cf_h2_proxy_destroy, cf_h2_proxy_connect, diff --git a/lib/cf-haproxy.c b/lib/cf-haproxy.c index a1793c0071ec..5ceef5190a37 100644 --- a/lib/cf-haproxy.c +++ b/lib/cf-haproxy.c @@ -36,9 +36,9 @@ typedef enum { - HAPROXY_INIT, /* init/default/no tunnel state */ - HAPROXY_SEND, /* data_out being sent */ - HAPROXY_DONE /* all work done */ + HAPROXY_INIT, /* init/default/no tunnel state */ + HAPROXY_SEND, /* data_out being sent */ + HAPROXY_DONE /* all work done */ } haproxy_state; struct cf_haproxy_ctx { @@ -61,7 +61,7 @@ static void cf_haproxy_ctx_free(struct cf_haproxy_ctx *ctx) } } -static CURLcode cf_haproxy_date_out_set(struct Curl_cfilter*cf, +static CURLcode cf_haproxy_date_out_set(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_haproxy_ctx *ctx = cf->ctx; diff --git a/lib/cf-ip-happy.c b/lib/cf-ip-happy.c index 8901db02c283..72ac59b7d90b 100644 --- a/lib/cf-ip-happy.c +++ b/lib/cf-ip-happy.c @@ -108,7 +108,6 @@ void Curl_debug_set_transport_provider(uint8_t transport, } #endif /* UNITTESTS */ - struct cf_ai_iter { const struct Curl_addrinfo *head; const struct Curl_addrinfo *last; @@ -423,9 +422,9 @@ static CURLcode cf_ip_ballers_run(struct cf_ip_ballers *bs, int ai_family = 0; #ifdef USE_IPV6 if((bs->last_attempt_ai_family == AF_INET) || - !cf_ai_iter_has_more(&bs->addr_iter)) { - addr = cf_ai_iter_next(&bs->ipv6_iter); - ai_family = bs->ipv6_iter.ai_family; + !cf_ai_iter_has_more(&bs->addr_iter)) { + addr = cf_ai_iter_next(&bs->ipv6_iter); + ai_family = bs->ipv6_iter.ai_family; } #endif if(!addr) { @@ -629,7 +628,6 @@ struct cf_ip_happy_ctx { struct curltime started; }; - static CURLcode is_connected(struct Curl_cfilter *cf, struct Curl_easy *data, bool *connected) @@ -774,50 +772,50 @@ static CURLcode cf_ip_happy_connect(struct Curl_cfilter *cf, *done = FALSE; switch(ctx->state) { - case SCFST_INIT: - DEBUGASSERT(CURL_SOCKET_BAD == Curl_conn_cf_get_socket(cf, data)); - DEBUGASSERT(!cf->connected); - result = start_connect(cf, data); - if(result) - return result; - ctx->state = SCFST_WAITING; - FALLTHROUGH(); - case SCFST_WAITING: - result = is_connected(cf, data, done); - if(!result && *done) { - DEBUGASSERT(ctx->ballers.winner); - DEBUGASSERT(ctx->ballers.winner->cf); - DEBUGASSERT(ctx->ballers.winner->cf->connected); - /* we have a winner. Install and activate it. - * close/free all others. */ - ctx->state = SCFST_DONE; - cf->connected = TRUE; - cf->next = ctx->ballers.winner->cf; - ctx->ballers.winner->cf = NULL; - cf_ip_happy_ctx_clear(cf, data); - Curl_expire_done(data, EXPIRE_HAPPY_EYEBALLS); - - if(cf->conn->handler->protocol & PROTO_FAMILY_SSH) - Curl_pgrsTime(data, TIMER_APPCONNECT); /* we are connected already */ + case SCFST_INIT: + DEBUGASSERT(CURL_SOCKET_BAD == Curl_conn_cf_get_socket(cf, data)); + DEBUGASSERT(!cf->connected); + result = start_connect(cf, data); + if(result) + return result; + ctx->state = SCFST_WAITING; + FALLTHROUGH(); + case SCFST_WAITING: + result = is_connected(cf, data, done); + if(!result && *done) { + DEBUGASSERT(ctx->ballers.winner); + DEBUGASSERT(ctx->ballers.winner->cf); + DEBUGASSERT(ctx->ballers.winner->cf->connected); + /* we have a winner. Install and activate it. + * close/free all others. */ + ctx->state = SCFST_DONE; + cf->connected = TRUE; + cf->next = ctx->ballers.winner->cf; + ctx->ballers.winner->cf = NULL; + cf_ip_happy_ctx_clear(cf, data); + Curl_expire_done(data, EXPIRE_HAPPY_EYEBALLS); + + if(cf->conn->handler->protocol & PROTO_FAMILY_SSH) + Curl_pgrsTime(data, TIMER_APPCONNECT); /* we are connected already */ #ifndef CURL_DISABLE_VERBOSE_STRINGS - if(Curl_trc_cf_is_verbose(cf, data)) { - struct ip_quadruple ipquad; - bool is_ipv6; - if(!Curl_conn_cf_get_ip_info(cf->next, data, &is_ipv6, &ipquad)) { - const char *host; - int port; - Curl_conn_get_current_host(data, cf->sockindex, &host, &port); - CURL_TRC_CF(data, cf, "Connected to %s (%s) port %u", - host, ipquad.remote_ip, ipquad.remote_port); - } + if(Curl_trc_cf_is_verbose(cf, data)) { + struct ip_quadruple ipquad; + bool is_ipv6; + if(!Curl_conn_cf_get_ip_info(cf->next, data, &is_ipv6, &ipquad)) { + const char *host; + int port; + Curl_conn_get_current_host(data, cf->sockindex, &host, &port); + CURL_TRC_CF(data, cf, "Connected to %s (%s) port %u", + host, ipquad.remote_ip, ipquad.remote_port); } -#endif - data->info.numconnects++; /* to track the # of connections made */ } - break; - case SCFST_DONE: - *done = TRUE; - break; +#endif + data->info.numconnects++; /* to track the # of connections made */ + } + break; + case SCFST_DONE: + *done = TRUE; + break; } return result; } diff --git a/lib/cf-socket.c b/lib/cf-socket.c index 3172aee5b9c9..a12995941610 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -96,7 +96,7 @@ static void set_ipv6_v6only(curl_socket_t sockfd, int on) (void)setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)); } #else -#define set_ipv6_v6only(x,y) +#define set_ipv6_v6only(x, y) #endif static void tcpnodelay(struct Curl_cfilter *cf, @@ -104,7 +104,7 @@ static void tcpnodelay(struct Curl_cfilter *cf, curl_socket_t sockfd) { #if defined(TCP_NODELAY) && defined(CURL_TCP_NODELAY_SUPPORTED) - curl_socklen_t onoff = (curl_socklen_t) 1; + curl_socklen_t onoff = (curl_socklen_t)1; int level = IPPROTO_TCP; char buffer[STRERROR_LEN]; @@ -142,7 +142,7 @@ static void nosigpipe(struct Curl_cfilter *cf, } } #else -#define nosigpipe(x,y,z) Curl_nop_stmt +#define nosigpipe(x, y, z) Curl_nop_stmt #endif #if defined(USE_WINSOCK) || \ @@ -156,10 +156,9 @@ static void nosigpipe(struct Curl_cfilter *cf, #define KEEPALIVE_FACTOR(x) #endif -static void -tcpkeepalive(struct Curl_cfilter *cf, - struct Curl_easy *data, - curl_socket_t sockfd) +static void tcpkeepalive(struct Curl_cfilter *cf, + struct Curl_easy *data, + curl_socket_t sockfd) { int optval = data->set.tcp_keepalive ? 1 : 0; @@ -202,7 +201,7 @@ tcpkeepalive(struct Curl_cfilter *cf, { /* Offered by mingw-w64 and MS SDK. Latter only when targeting Win7+. */ #ifndef SIO_KEEPALIVE_VALS -#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4) +#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR, 4) struct tcp_keepalive { u_long onoff; u_long keepalivetime; @@ -342,15 +341,15 @@ static CURLcode socket_open(struct Curl_easy *data, DEBUGASSERT(data); DEBUGASSERT(data->conn); if(data->set.fopensocket) { - /* - * If the opensocket callback is set, all the destination address - * information is passed to the callback. Depending on this information the - * callback may opt to abort the connection, this is indicated returning - * CURL_SOCKET_BAD; otherwise it will return a not-connected socket. When - * the callback returns a valid socket the destination address information - * might have been changed and this 'new' address will actually be used - * here to connect. - */ + /* + * If the opensocket callback is set, all the destination address + * information is passed to the callback. Depending on this information the + * callback may opt to abort the connection, this is indicated returning + * CURL_SOCKET_BAD; otherwise it will return a not-connected socket. When + * the callback returns a valid socket the destination address information + * might have been changed and this 'new' address will actually be used + * here to connect. + */ Curl_set_in_callback(data, TRUE); *sockfd = data->set.fopensocket(data->set.opensocket_client, CURLSOCKTYPE_IPCXN, @@ -600,7 +599,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn, if(!iface && !host && !port) /* no local kind of binding was requested */ return CURLE_OK; - else if(iface && (strlen(iface) >= 255) ) + else if(iface && (strlen(iface) >= 255)) return CURLE_BAD_FUNCTION_ARGUMENT; memset(&sa, 0, sizeof(struct Curl_sockaddr_storage)); @@ -640,33 +639,33 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn, /* Discover IP from input device, then bind to it */ if2ip_result = Curl_if2ip(af, #ifdef USE_IPV6 - scope, conn->scope_id, + scope, conn->scope_id, #endif - iface, myhost, sizeof(myhost)); + iface, myhost, sizeof(myhost)); } switch(if2ip_result) { - case IF2IP_NOT_FOUND: - if(iface_input && !host_input) { - /* Do not fall back to treating it as a hostname */ - char buffer[STRERROR_LEN]; - data->state.os_errno = error = SOCKERRNO; - failf(data, "Could not bind to interface '%s' with errno %d: %s", - iface, error, curlx_strerror(error, buffer, sizeof(buffer))); - return CURLE_INTERFACE_FAILED; - } - break; - case IF2IP_AF_NOT_SUPPORTED: - /* Signal the caller to try another address family if available */ - return CURLE_UNSUPPORTED_PROTOCOL; - case IF2IP_FOUND: - /* - * We now have the numerical IP address in the 'myhost' buffer - */ - host = myhost; - infof(data, "Local Interface %s is ip %s using address family %i", - iface, host, af); - done = 1; - break; + case IF2IP_NOT_FOUND: + if(iface_input && !host_input) { + /* Do not fall back to treating it as a hostname */ + char buffer[STRERROR_LEN]; + data->state.os_errno = error = SOCKERRNO; + failf(data, "Could not bind to interface '%s' with errno %d: %s", + iface, error, curlx_strerror(error, buffer, sizeof(buffer))); + return CURLE_INTERFACE_FAILED; + } + break; + case IF2IP_AF_NOT_SUPPORTED: + /* Signal the caller to try another address family if available */ + return CURLE_UNSUPPORTED_PROTOCOL; + case IF2IP_FOUND: + /* + * We now have the numerical IP address in the 'myhost' buffer + */ + host = myhost; + infof(data, "Local Interface %s is ip %s using address family %i", + iface, host, af); + done = 1; + break; } if(!iface_input || host_input) { /* @@ -728,7 +727,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn, present, is known to be numeric */ curl_off_t scope_id; if(curlx_str_number((const char **)CURL_UNCONST(&scope_ptr), - &scope_id, UINT_MAX)) + &scope_id, UINT_MAX)) return CURLE_UNSUPPORTED_PROTOCOL; si6->sin6_scope_id = (unsigned int)scope_id; } @@ -921,7 +920,7 @@ struct cf_socket_ctx { int wblock_percent; /* percent of writes doing EAGAIN */ int wpartial_percent; /* percent of bytes written in send */ int rblock_percent; /* percent of reads doing EAGAIN */ - size_t recv_max; /* max enforced read size */ + size_t recv_max; /* max enforced read size */ #endif BIT(got_first_byte); /* if first byte was received */ BIT(listening); /* socket is listening */ @@ -1043,12 +1042,12 @@ static void set_local_ip(struct Curl_cfilter *cf, curl_socklen_t slen = sizeof(struct Curl_sockaddr_storage); memset(&ssloc, 0, sizeof(ssloc)); - if(getsockname(ctx->sock, (struct sockaddr*) &ssloc, &slen)) { + if(getsockname(ctx->sock, (struct sockaddr *)&ssloc, &slen)) { int error = SOCKERRNO; infof(data, "getsockname() failed with errno %d: %s", error, curlx_strerror(error, buffer, sizeof(buffer))); } - else if(!Curl_addr2string((struct sockaddr*)&ssloc, slen, + else if(!Curl_addr2string((struct sockaddr *)&ssloc, slen, ctx->ip.local_ip, &ctx->ip.local_port)) { infof(data, "ssloc inet_ntop() failed with errno %d: %s", errno, curlx_strerror(errno, buffer, sizeof(buffer))); @@ -1123,8 +1122,8 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf, infof(data, " Trying %s:%d...", ctx->ip.remote_ip, ctx->ip.remote_port); #ifdef USE_IPV6 - is_tcp = (ctx->addr.family == AF_INET - || ctx->addr.family == AF_INET6) && + is_tcp = (ctx->addr.family == AF_INET || + ctx->addr.family == AF_INET6) && ctx->addr.socktype == SOCK_STREAM; #else is_tcp = (ctx->addr.family == AF_INET) && @@ -1320,8 +1319,7 @@ static CURLcode cf_tcp_connect(struct Curl_cfilter *cf, rc = SOCKET_WRITABLE(ctx->sock, 0); if(rc == 0) { /* no connection yet */ - CURL_TRC_CF(data, cf, "not connected yet on fd=%" FMT_SOCKET_T, - ctx->sock); + CURL_TRC_CF(data, cf, "not connected yet on fd=%" FMT_SOCKET_T, ctx->sock); return CURLE_OK; } else if(rc == CURL_CSELECT_OUT || cf->conn->bits.tcp_fastopen) { @@ -1411,7 +1409,7 @@ static void win_update_sndbuf_size(struct cf_socket_ctx *ctx) if(curlx_timediff_ms(n, ctx->last_sndbuf_query_at) > 1000) { if(!WSAIoctl(ctx->sock, SIO_IDEAL_SEND_BACKLOG_QUERY, 0, 0, - &ideal, sizeof(ideal), &ideallen, 0, 0) && + &ideal, sizeof(ideal), &ideallen, 0, 0) && ideal != ctx->sndbuf_size && !setsockopt(ctx->sock, SOL_SOCKET, SO_SNDBUF, (const char *)&ideal, sizeof(ideal))) { @@ -1443,7 +1441,7 @@ static CURLcode cf_socket_send(struct Curl_cfilter *cf, struct Curl_easy *data, if(ctx->wblock_percent > 0) { unsigned char c = 0; Curl_rand_bytes(data, FALSE, &c, 1); - if(c >= ((100-ctx->wblock_percent)*256/100)) { + if(c >= ((100 - ctx->wblock_percent) * 256 / 100)) { CURL_TRC_CF(data, cf, "send(len=%zu) SIMULATE EWOULDBLOCK", orig_len); cf->conn->sock[cf->sockindex] = fdsave; return CURLE_AGAIN; @@ -1520,7 +1518,7 @@ static CURLcode cf_socket_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(cf->cft != &Curl_cft_udp && ctx->rblock_percent > 0) { unsigned char c = 0; Curl_rand(data, &c, 1); - if(c >= ((100-ctx->rblock_percent)*256/100)) { + if(c >= ((100 - ctx->rblock_percent) * 256 / 100)) { CURL_TRC_CF(data, cf, "recv(len=%zu) SIMULATE EWOULDBLOCK", len); return CURLE_AGAIN; } @@ -1634,7 +1632,7 @@ static bool cf_socket_conn_is_alive(struct Curl_cfilter *cf, /* Check with 0 timeout if there are any events pending on the socket */ pfd[0].fd = ctx->sock; - pfd[0].events = POLLRDNORM|POLLIN|POLLRDBAND|POLLPRI; + pfd[0].events = POLLRDNORM | POLLIN | POLLRDBAND | POLLPRI; pfd[0].revents = 0; r = Curl_poll(pfd, 1, 0); @@ -1646,7 +1644,7 @@ static bool cf_socket_conn_is_alive(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "is_alive: poll timeout, assume alive"); return TRUE; } - else if(pfd[0].revents & (POLLERR|POLLHUP|POLLPRI|POLLNVAL)) { + else if(pfd[0].revents & (POLLERR | POLLHUP | POLLPRI | POLLNVAL)) { CURL_TRC_CF(data, cf, "is_alive: err/hup/etc events, assume dead"); return FALSE; } @@ -1814,7 +1812,6 @@ static void linux_quic_gro(struct cf_socket_ctx *ctx) #define linux_quic_gro(x) #endif - static CURLcode cf_udp_setup_quic(struct Curl_cfilter *cf, struct Curl_easy *data) { @@ -2035,13 +2032,13 @@ static void cf_tcp_set_accepted_remote_ip(struct Curl_cfilter *cf, ctx->ip.remote_port = 0; plen = sizeof(ssrem); memset(&ssrem, 0, plen); - if(getpeername(ctx->sock, (struct sockaddr*) &ssrem, &plen)) { + if(getpeername(ctx->sock, (struct sockaddr *)&ssrem, &plen)) { int error = SOCKERRNO; failf(data, "getpeername() failed with errno %d: %s", error, curlx_strerror(error, buffer, sizeof(buffer))); return; } - if(!Curl_addr2string((struct sockaddr*)&ssrem, plen, + if(!Curl_addr2string((struct sockaddr *)&ssrem, plen, ctx->ip.remote_ip, &ctx->ip.remote_port)) { failf(data, "ssrem inet_ntop() failed with errno %d: %s", errno, curlx_strerror(errno, buffer, sizeof(buffer))); @@ -2111,10 +2108,10 @@ static CURLcode cf_tcp_accept_connect(struct Curl_cfilter *cf, size = sizeof(add); #ifdef HAVE_ACCEPT4 - s_accepted = CURL_ACCEPT4(ctx->sock, (struct sockaddr *) &add, &size, + s_accepted = CURL_ACCEPT4(ctx->sock, (struct sockaddr *)&add, &size, SOCK_NONBLOCK | SOCK_CLOEXEC); #else - s_accepted = CURL_ACCEPT(ctx->sock, (struct sockaddr *) &add, &size); + s_accepted = CURL_ACCEPT(ctx->sock, (struct sockaddr *)&add, &size); #endif if(CURL_SOCKET_BAD == s_accepted) { diff --git a/lib/cf-socket.h b/lib/cf-socket.h index 432b0870451d..e5f69c60f46f 100644 --- a/lib/cf-socket.h +++ b/lib/cf-socket.h @@ -57,7 +57,7 @@ struct Curl_sockaddr_ex { /* * Parse interface option, and return the interface name and the host part. -*/ + */ CURLcode Curl_parse_interface(const char *input, char **dev, char **iface, char **host); diff --git a/lib/cfilters.c b/lib/cfilters.c index dd4cb5210acc..f51da8521aff 100644 --- a/lib/cfilters.c +++ b/lib/cfilters.c @@ -511,8 +511,7 @@ CURLcode Curl_conn_connect(struct Curl_easy *data, goto out; } else if(result) { - CURL_TRC_CF(data, cf, "Curl_conn_connect(), filter returned %d", - result); + CURL_TRC_CF(data, cf, "Curl_conn_connect(), filter returned %d", result); conn_report_connect_stats(cf, data); goto out; } @@ -653,7 +652,7 @@ bool Curl_conn_is_multiplex(struct connectdata *conn, int sockindex) for(; cf; cf = cf->next) { if(cf->cft->flags & CF_TYPE_MULTIPLEX) return TRUE; - if(cf->cft->flags & (CF_TYPE_IP_CONNECT|CF_TYPE_SSL)) + if(cf->cft->flags & (CF_TYPE_IP_CONNECT | CF_TYPE_SSL)) return FALSE; } return FALSE; @@ -691,7 +690,7 @@ unsigned char Curl_conn_http_version(struct Curl_easy *data, v = (unsigned char)value; break; } - if(cf->cft->flags & (CF_TYPE_IP_CONNECT|CF_TYPE_SSL)) + if(cf->cft->flags & (CF_TYPE_IP_CONNECT | CF_TYPE_SSL)) break; } return (unsigned char)(result ? 0 : v); @@ -803,9 +802,9 @@ void Curl_conn_get_current_host(struct Curl_easy *data, int sockindex, cf = CONN_SOCK_IDX_VALID(sockindex) ? data->conn->cfilter[sockindex] : NULL; /* Find the "lowest" tunneling proxy filter that has not connected yet. */ while(cf && !cf->connected) { - if((cf->cft->flags & (CF_TYPE_IP_CONNECT|CF_TYPE_PROXY)) == - (CF_TYPE_IP_CONNECT|CF_TYPE_PROXY)) - cf_proxy = cf; + if((cf->cft->flags & (CF_TYPE_IP_CONNECT | CF_TYPE_PROXY)) == + (CF_TYPE_IP_CONNECT | CF_TYPE_PROXY)) + cf_proxy = cf; cf = cf->next; } /* cf_proxy (!= NULL) is not connected yet. It is talking @@ -945,8 +944,7 @@ static CURLcode cf_cntrl_all(struct connectdata *conn, CURLcode Curl_conn_ev_data_setup(struct Curl_easy *data) { - return cf_cntrl_all(data->conn, data, FALSE, - CF_CTRL_DATA_SETUP, 0, NULL); + return cf_cntrl_all(data->conn, data, FALSE, CF_CTRL_DATA_SETUP, 0, NULL); } CURLcode Curl_conn_flush(struct Curl_easy *data, int sockindex) @@ -1100,8 +1098,7 @@ CURLcode Curl_conn_send(struct Curl_easy *data, int sockindex, return CURLE_BAD_FUNCTION_ARGUMENT; #ifdef DEBUGBUILD if(write_len) { - /* Allow debug builds to override this logic to force short sends - */ + /* Allow debug builds to override this logic to force short sends */ const char *p = getenv("CURL_SMALLSENDS"); if(p) { curl_off_t altsize; diff --git a/lib/cfilters.h b/lib/cfilters.h index a3bd97a9f166..73b9cb03e034 100644 --- a/lib/cfilters.h +++ b/lib/cfilters.h @@ -116,16 +116,16 @@ typedef CURLcode Curl_cft_conn_keep_alive(struct Curl_cfilter *cf, * "ignored" meaning return values are ignored and the event is distributed * to all filters in the chain. Overall result is always CURLE_OK. */ -/* data event arg1 arg2 return */ -#define CF_CTRL_DATA_SETUP 4 /* 0 NULL first fail */ -/* unused now 5 */ -#define CF_CTRL_DATA_PAUSE 6 /* on/off NULL first fail */ -#define CF_CTRL_DATA_DONE 7 /* premature NULL ignored */ -#define CF_CTRL_DATA_DONE_SEND 8 /* 0 NULL ignored */ +/* data event arg1 arg2 return */ +#define CF_CTRL_DATA_SETUP 4 /* 0 NULL first fail */ +/* unused now 5 */ +#define CF_CTRL_DATA_PAUSE 6 /* on/off NULL first fail */ +#define CF_CTRL_DATA_DONE 7 /* premature NULL ignored */ +#define CF_CTRL_DATA_DONE_SEND 8 /* 0 NULL ignored */ /* update conn info at connection and data */ -#define CF_CTRL_CONN_INFO_UPDATE (256+0) /* 0 NULL ignored */ -#define CF_CTRL_FORGET_SOCKET (256+1) /* 0 NULL ignored */ -#define CF_CTRL_FLUSH (256+2) /* 0 NULL first fail */ +#define CF_CTRL_CONN_INFO_UPDATE (256 + 0) /* 0 NULL ignored */ +#define CF_CTRL_FORGET_SOCKET (256 + 1) /* 0 NULL ignored */ +#define CF_CTRL_FLUSH (256 + 2) /* 0 NULL first fail */ /** * Handle event/control for the filter. @@ -135,7 +135,6 @@ typedef CURLcode Curl_cft_cntrl(struct Curl_cfilter *cf, struct Curl_easy *data, int event, int arg1, void *arg2); - /** * Queries to ask via a `Curl_cft_query *query` method on a cfilter chain. * - MAX_CONCURRENT: the maximum number of parallel transfers the filter @@ -210,21 +209,21 @@ typedef CURLcode Curl_cft_query(struct Curl_cfilter *cf, /* A connection filter type, e.g. specific implementation. */ struct Curl_cftype { - const char *name; /* name of the filter type */ - int flags; /* flags of filter type */ - int log_level; /* log level for such filters */ - Curl_cft_destroy_this *destroy; /* destroy resources of this cf */ - Curl_cft_connect *do_connect; /* establish connection */ - Curl_cft_close *do_close; /* close conn */ - Curl_cft_shutdown *do_shutdown; /* shutdown conn */ + const char *name; /* name of the filter type */ + int flags; /* flags of filter type */ + int log_level; /* log level for such filters */ + Curl_cft_destroy_this *destroy; /* destroy resources of this cf */ + Curl_cft_connect *do_connect; /* establish connection */ + Curl_cft_close *do_close; /* close conn */ + Curl_cft_shutdown *do_shutdown; /* shutdown conn */ Curl_cft_adjust_pollset *adjust_pollset; /* adjust transfer poll set */ - Curl_cft_data_pending *has_data_pending;/* conn has data pending */ - Curl_cft_send *do_send; /* send data */ - Curl_cft_recv *do_recv; /* receive data */ - Curl_cft_cntrl *cntrl; /* events/control */ - Curl_cft_conn_is_alive *is_alive; /* FALSE if conn is dead, Jim! */ - Curl_cft_conn_keep_alive *keep_alive; /* try to keep it alive */ - Curl_cft_query *query; /* query filter chain */ + Curl_cft_data_pending *has_data_pending; /* conn has data pending */ + Curl_cft_send *do_send; /* send data */ + Curl_cft_recv *do_recv; /* receive data */ + Curl_cft_cntrl *cntrl; /* events/control */ + Curl_cft_conn_is_alive *is_alive; /* FALSE if conn is dead, Jim! */ + Curl_cft_conn_keep_alive *keep_alive; /* try to keep it alive */ + Curl_cft_query *query; /* query filter chain */ }; /* A connection filter instance, e.g. registered at a connection */ @@ -426,7 +425,7 @@ const char *Curl_conn_get_alpn_negotiated(struct Curl_easy *data, /** * Close the filter chain at `sockindex` for connection `data->conn`. - * Filters remain in place and may be connected again afterwards. + * Filters remain in place and may be connected again afterwards. */ void Curl_conn_close(struct Curl_easy *data, int sockindex); @@ -622,7 +621,6 @@ CURLcode Curl_conn_send(struct Curl_easy *data, int sockindex, const void *buf, size_t blen, bool eos, size_t *pnwritten); - /** * Types and macros used to keep the current easy handle in filter calls, * allowing for nested invocations. See #10336. @@ -654,7 +652,7 @@ struct cf_call_data { * a member in the cfilter's `ctx`. * * #define CF_CTX_CALL_DATA(cf) -> struct cf_call_data instance -*/ + */ #ifdef DEBUGBUILD @@ -688,7 +686,6 @@ struct cf_call_data { #endif /* !DEBUGBUILD */ -#define CF_DATA_CURRENT(cf) \ - ((cf)? (CF_CTX_CALL_DATA(cf).data) : NULL) +#define CF_DATA_CURRENT(cf) ((cf) ? (CF_CTX_CALL_DATA(cf).data) : NULL) #endif /* HEADER_CURL_CFILTERS_H */ diff --git a/lib/conncache.c b/lib/conncache.c index 7f38a1875790..c7a52b69f69a 100644 --- a/lib/conncache.c +++ b/lib/conncache.c @@ -59,7 +59,7 @@ } \ } while(0) -#define CPOOL_UNLOCK(c,d) \ +#define CPOOL_UNLOCK(c,d) \ do { \ if((c)) { \ DEBUGASSERT((c)->locked); \ @@ -161,7 +161,6 @@ static struct connectdata *cpool_get_first(struct cpool *cpool) return NULL; } - static struct cpool_bundle *cpool_find_bundle(struct cpool *cpool, struct connectdata *conn) { @@ -178,7 +177,6 @@ static void cpool_remove_bundle(struct cpool *cpool, Curl_hash_delete(&cpool->dest2bundle, bundle->dest, bundle->dest_len); } - static void cpool_remove_conn(struct cpool *cpool, struct connectdata *conn) { @@ -260,8 +258,8 @@ void Curl_cpool_xfer_init(struct Curl_easy *data) } } -static struct cpool_bundle * -cpool_add_bundle(struct cpool *cpool, struct connectdata *conn) +static struct cpool_bundle *cpool_add_bundle(struct cpool *cpool, + struct connectdata *conn) { struct cpool_bundle *bundle; @@ -341,7 +339,6 @@ static struct connectdata *cpool_get_oldest_idle(struct cpool *cpool) return oldest_idle; } - int Curl_cpool_check_limits(struct Curl_easy *data, struct connectdata *conn) { @@ -386,10 +383,10 @@ int Curl_cpool_check_limits(struct Curl_easy *data, if(!oldest_idle) break; /* disconnect the old conn and continue */ - CURL_TRC_M(data, "Discarding connection #%" - FMT_OFF_T " from %zu to reach destination " - "limit of %zu", oldest_idle->connection_id, - Curl_llist_count(&bundle->conns), dest_limit); + CURL_TRC_M(data, "Discarding connection #%" FMT_OFF_T + " from %zu to reach destination limit of %zu", + oldest_idle->connection_id, + Curl_llist_count(&bundle->conns), dest_limit); Curl_conn_terminate(cpool->idata, oldest_idle, FALSE); /* in case the bundle was destroyed in disconnect, look it up again */ @@ -704,7 +701,6 @@ void Curl_conn_terminate(struct Curl_easy *data, CPOOL_UNLOCK(cpool, data); } - struct cpool_reaper_ctx { struct curltime now; }; diff --git a/lib/conncache.h b/lib/conncache.h index a5f133344fd4..5761ee9b4464 100644 --- a/lib/conncache.h +++ b/lib/conncache.h @@ -49,7 +49,7 @@ void Curl_conn_terminate(struct Curl_easy *data, bool aborted); struct cpool { - /* the pooled connections, bundled per destination */ + /* the pooled connections, bundled per destination */ struct Curl_hash dest2bundle; size_t num_conn; curl_off_t next_connection_id; @@ -166,5 +166,4 @@ void Curl_cpool_do_locked(struct Curl_easy *data, /* Close all unused connections, prevent reuse of existing ones. */ void Curl_cpool_nw_changed(struct Curl_easy *data); - #endif /* HEADER_CURL_CONNCACHE_H */ diff --git a/lib/connect.c b/lib/connect.c index 72a27fae1cd9..748cf53a29ae 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -247,36 +247,35 @@ bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen, #endif switch(sa->sa_family) { - case AF_INET: - si = (struct sockaddr_in *)(void *) sa; - if(curlx_inet_ntop(sa->sa_family, &si->sin_addr, addr, MAX_IPADR_LEN)) { - *port = ntohs(si->sin_port); - return TRUE; - } - break; + case AF_INET: + si = (struct sockaddr_in *)(void *)sa; + if(curlx_inet_ntop(sa->sa_family, &si->sin_addr, addr, MAX_IPADR_LEN)) { + *port = ntohs(si->sin_port); + return TRUE; + } + break; #ifdef USE_IPV6 - case AF_INET6: - si6 = (struct sockaddr_in6 *)(void *) sa; - if(curlx_inet_ntop(sa->sa_family, &si6->sin6_addr, addr, - MAX_IPADR_LEN)) { - *port = ntohs(si6->sin6_port); - return TRUE; - } - break; + case AF_INET6: + si6 = (struct sockaddr_in6 *)(void *)sa; + if(curlx_inet_ntop(sa->sa_family, &si6->sin6_addr, addr, MAX_IPADR_LEN)) { + *port = ntohs(si6->sin6_port); + return TRUE; + } + break; #endif #if (defined(HAVE_SYS_UN_H) || defined(WIN32_SOCKADDR_UN)) && defined(AF_UNIX) - case AF_UNIX: - if(salen > (curl_socklen_t)sizeof(CURL_SA_FAMILY_T)) { - su = (struct sockaddr_un*)sa; - curl_msnprintf(addr, MAX_IPADR_LEN, "%s", su->sun_path); - } - else - addr[0] = 0; /* socket with no name */ - *port = 0; - return TRUE; + case AF_UNIX: + if(salen > (curl_socklen_t)sizeof(CURL_SA_FAMILY_T)) { + su = (struct sockaddr_un *)sa; + curl_msnprintf(addr, MAX_IPADR_LEN, "%s", su->sun_path); + } + else + addr[0] = 0; /* socket with no name */ + *port = 0; + return TRUE; #endif - default: - break; + default: + break; } addr[0] = '\0'; @@ -338,7 +337,7 @@ void Curl_conncontrol(struct connectdata *conn, #endif is_multiplex = Curl_conn_is_multiplex(conn, FIRSTSOCKET); closeit = (ctrl == CONNCTRL_CONNECTION) || - ((ctrl == CONNCTRL_STREAM) && !is_multiplex); + ((ctrl == CONNCTRL_STREAM) && !is_multiplex); if((ctrl == CONNCTRL_STREAM) && is_multiplex) ; /* stream signal on multiplex conn never affects close state */ else if((bit)closeit != conn->bits.close) { @@ -409,8 +408,8 @@ static CURLcode cf_setup_connect(struct Curl_cfilter *cf, if(ctx->state < CF_SETUP_CNNCT_HTTP_PROXY && cf->conn->bits.httpproxy) { #ifdef USE_SSL - if(IS_HTTPS_PROXY(cf->conn->http_proxy.proxytype) - && !Curl_conn_is_ssl(cf->conn, cf->sockindex)) { + if(IS_HTTPS_PROXY(cf->conn->http_proxy.proxytype) && + !Curl_conn_is_ssl(cf->conn, cf->sockindex)) { result = Curl_cf_ssl_proxy_insert_after(cf, data); if(result) return result; @@ -450,9 +449,9 @@ static CURLcode cf_setup_connect(struct Curl_cfilter *cf, if(ctx->state < CF_SETUP_CNNCT_SSL) { #ifdef USE_SSL - if((ctx->ssl_mode == CURL_CF_SSL_ENABLE - || (ctx->ssl_mode != CURL_CF_SSL_DISABLE - && cf->conn->handler->flags & PROTOPT_SSL)) /* we want SSL */ + if((ctx->ssl_mode == CURL_CF_SSL_ENABLE || + (ctx->ssl_mode != CURL_CF_SSL_DISABLE && + cf->conn->handler->flags & PROTOPT_SSL)) /* we want SSL */ && !Curl_conn_is_ssl(cf->conn, cf->sockindex)) { /* it is missing */ result = Curl_cf_ssl_insert_after(cf, data); if(result) @@ -494,7 +493,6 @@ static void cf_setup_destroy(struct Curl_cfilter *cf, struct Curl_easy *data) Curl_safefree(ctx); } - struct Curl_cftype Curl_cft_setup = { "SETUP", 0, diff --git a/lib/connect.h b/lib/connect.h index 9060591dcec6..7d1c9c908991 100644 --- a/lib/connect.h +++ b/lib/connect.h @@ -100,13 +100,13 @@ void Curl_conncontrol(struct connectdata *conn, ); #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) -#define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM, y) -#define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION, y) -#define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP, y) +#define streamclose(x, y) Curl_conncontrol(x, CONNCTRL_STREAM, y) +#define connclose(x, y) Curl_conncontrol(x, CONNCTRL_CONNECTION, y) +#define connkeep(x, y) Curl_conncontrol(x, CONNCTRL_KEEP, y) #else /* if !DEBUGBUILD || CURL_DISABLE_VERBOSE_STRINGS */ -#define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM) -#define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION) -#define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP) +#define streamclose(x, y) Curl_conncontrol(x, CONNCTRL_STREAM) +#define connclose(x, y) Curl_conncontrol(x, CONNCTRL_CONNECTION) +#define connkeep(x, y) Curl_conncontrol(x, CONNCTRL_KEEP) #endif CURLcode Curl_cf_setup_insert_after(struct Curl_cfilter *cf_at, diff --git a/lib/cookie.c b/lib/cookie.c index 250c7390ce12..81a57942b245 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -45,7 +45,7 @@ static void strstore(char **str, const char *newstr, size_t len); /* number of seconds in 400 days */ -#define COOKIES_MAXAGE (400*24*3600) +#define COOKIES_MAXAGE (400 * 24 * 3600) /* Make sure cookies never expire further away in time than 400 days into the future. (from RFC6265bis draft-19) @@ -59,7 +59,7 @@ static void cap_expires(time_t now, struct Cookie *co) timediff_t cap = now + COOKIES_MAXAGE; if(co->expires > cap) { cap += 30; - co->expires = (cap/60)*60; + co->expires = (cap / 60) * 60; } } } @@ -84,7 +84,7 @@ static bool cookie_tailmatch(const char *cookie_domain, return FALSE; if(!curl_strnequal(cookie_domain, - hostname + hostname_len-cookie_domain_len, + hostname + hostname_len - cookie_domain_len, cookie_domain_len)) return FALSE; @@ -428,8 +428,8 @@ parse_cookie_header(struct Curl_easy *data, * combination of name + contents. Chrome and Firefox support 4095 or * 4096 bytes combo */ - if(curlx_strlen(&name) >= (MAX_NAME-1) || - curlx_strlen(&val) >= (MAX_NAME-1) || + if(curlx_strlen(&name) >= (MAX_NAME - 1) || + curlx_strlen(&val) >= (MAX_NAME - 1) || ((curlx_strlen(&name) + curlx_strlen(&val)) > MAX_NAME)) { infof(data, "oversized cookie dropped, name/val %zu + %zu bytes", curlx_strlen(&name), curlx_strlen(&val)); @@ -530,11 +530,11 @@ parse_cookie_header(struct Curl_easy *data, is_ip = Curl_host_is_ipnum(domain ? domain : curlx_str(&val)); - if(!domain - || (is_ip && !strncmp(curlx_str(&val), domain, - curlx_strlen(&val)) && - (curlx_strlen(&val) == strlen(domain))) - || (!is_ip && cookie_tailmatch(curlx_str(&val), + if(!domain || + (is_ip && + !strncmp(curlx_str(&val), domain, curlx_strlen(&val)) && + (curlx_strlen(&val) == strlen(domain))) || + (!is_ip && cookie_tailmatch(curlx_str(&val), curlx_strlen(&val), domain))) { strstore(&co->domain, curlx_str(&val), curlx_strlen(&val)); if(!co->domain) @@ -689,7 +689,7 @@ parse_netscape(struct Cookie *co, co->httponly = TRUE; } - if(lineptr[0]=='#') + if(lineptr[0] == '#') /* do not even try the comments */ return CURLE_OK; @@ -704,7 +704,7 @@ parse_netscape(struct Cookie *co, next = (ptr[len] == '\t' ? &ptr[len + 1] : NULL); switch(fields) { case 0: - if(ptr[0]=='.') { /* skip preceding dots */ + if(ptr[0] == '.') { /* skip preceding dots */ ptr++; len--; } @@ -792,10 +792,9 @@ parse_netscape(struct Cookie *co, return CURLE_OK; } -static bool -is_public_suffix(struct Curl_easy *data, - struct Cookie *co, - const char *domain) +static bool is_public_suffix(struct Curl_easy *data, + struct Cookie *co, + const char *domain) { #ifdef USE_LIBPSL /* @@ -899,7 +898,7 @@ static bool replace_existing(struct Curl_easy *data, if(clist->domain && co->domain) { if(curl_strequal(clist->domain, co->domain) && - (clist->tailmatch == co->tailmatch)) + (clist->tailmatch == co->tailmatch)) /* The domains are identical */ replace_old = TRUE; } @@ -1059,7 +1058,6 @@ Curl_cookie_add(struct Curl_easy *data, return result; } - /* * Curl_cookie_init() * @@ -1195,7 +1193,6 @@ CURLcode Curl_cookie_loadfiles(struct Curl_easy *data) return result; } - /* * cookie_sort * @@ -1291,8 +1288,7 @@ CURLcode Curl_cookie_getlist(struct Curl_easy *data, /* at first, remove expired cookies */ remove_expired(ci); - for(n = Curl_llist_head(&ci->cookielist[myhash]); - n; n = Curl_node_next(n)) { + for(n = Curl_llist_head(&ci->cookielist[myhash]); n; n = Curl_node_next(n)) { struct Cookie *co = Curl_node_elem(n); /* if the cookie requires we are secure we must only continue if we are! */ @@ -1302,7 +1298,7 @@ CURLcode Curl_cookie_getlist(struct Curl_easy *data, if(!co->domain || (co->tailmatch && !is_ip && cookie_tailmatch(co->domain, strlen(co->domain), host)) || - ((!co->tailmatch || is_ip) && curl_strequal(host, co->domain)) ) { + ((!co->tailmatch || is_ip) && curl_strequal(host, co->domain))) { /* * the right part of the host matches the domain stuff in the * cookie data @@ -1312,7 +1308,7 @@ CURLcode Curl_cookie_getlist(struct Curl_easy *data, * now check the left part of the path with the cookies path * requirement */ - if(!co->spath || pathmatch(co->spath, path) ) { + if(!co->spath || pathmatch(co->spath, path)) { /* * This is a match and we add it to the return-linked-list @@ -1445,14 +1441,14 @@ void Curl_cookie_cleanup(struct CookieInfo *ci) static char *get_netscape_format(const struct Cookie *co) { return curl_maprintf( - "%s" /* httponly preamble */ - "%s%s\t" /* domain */ - "%s\t" /* tailmatch */ - "%s\t" /* path */ - "%s\t" /* secure */ - "%" FMT_OFF_T "\t" /* expires */ - "%s\t" /* name */ - "%s", /* value */ + "%s" /* httponly preamble */ + "%s%s\t" /* domain */ + "%s\t" /* tailmatch */ + "%s\t" /* path */ + "%s\t" /* secure */ + "%" FMT_OFF_T "\t" /* expires */ + "%s\t" /* name */ + "%s", /* value */ co->httponly ? "#HttpOnly_" : "", /* * Make sure all domains are prefixed with a dot if they allow @@ -1522,8 +1518,7 @@ static CURLcode cookie_output(struct Curl_easy *data, /* only sort the cookies with a domain property */ for(i = 0; i < COOKIE_HASH_SIZE; i++) { - for(n = Curl_llist_head(&ci->cookielist[i]); n; - n = Curl_node_next(n)) { + for(n = Curl_llist_head(&ci->cookielist[i]); n; n = Curl_node_next(n)) { struct Cookie *co = Curl_node_elem(n); if(!co->domain) continue; diff --git a/lib/cookie.h b/lib/cookie.h index e1be698cf49a..5e9f5f7823ce 100644 --- a/lib/cookie.h +++ b/lib/cookie.h @@ -30,29 +30,29 @@ #include "llist.h" struct Cookie { - struct Curl_llist_node node; /* for the main cookie list */ + struct Curl_llist_node node; /* for the main cookie list */ struct Curl_llist_node getnode; /* for getlist */ - char *name; /* = value */ - char *value; /* name = */ - char *path; /* path = which is in Set-Cookie: */ - char *spath; /* sanitized cookie path */ - char *domain; /* domain = */ - curl_off_t expires; /* expires = */ - unsigned int creationtime; /* time when the cookie was written */ - BIT(tailmatch); /* tail-match the domain name */ - BIT(secure); /* the 'secure' keyword was used */ - BIT(livecookie); /* updated from a server, not a stored file */ - BIT(httponly); /* the httponly directive is present */ - BIT(prefix_secure); /* secure prefix is set */ - BIT(prefix_host); /* host prefix is set */ + char *name; /* = value */ + char *value; /* name = */ + char *path; /* path = which is in Set-Cookie: */ + char *spath; /* sanitized cookie path */ + char *domain; /* domain = */ + curl_off_t expires; /* expires = */ + unsigned int creationtime; /* time when the cookie was written */ + BIT(tailmatch); /* tail-match the domain name */ + BIT(secure); /* the 'secure' keyword was used */ + BIT(livecookie); /* updated from server, not a stored file */ + BIT(httponly); /* the httponly directive is present */ + BIT(prefix_secure); /* secure prefix is set */ + BIT(prefix_host); /* host prefix is set */ }; /* * Available cookie prefixes, as defined in * draft-ietf-httpbis-rfc6265bis-02 */ -#define COOKIE_PREFIX__SECURE (1<<0) -#define COOKIE_PREFIX__HOST (1<<1) +#define COOKIE_PREFIX__SECURE (1 << 0) +#define COOKIE_PREFIX__HOST (1 << 1) #define COOKIE_HASH_SIZE 63 @@ -60,9 +60,9 @@ struct CookieInfo { /* linked lists of cookies we know of */ struct Curl_llist cookielist[COOKIE_HASH_SIZE]; curl_off_t next_expiration; /* the next time at which expiration happens */ - unsigned int numcookies; /* number of cookies in the "jar" */ - unsigned int lastct; /* last creation-time used in the jar */ - BIT(running); /* state info, for cookie adding information */ + unsigned int numcookies; /* number of cookies in the "jar" */ + unsigned int lastct; /* last creation-time used in the jar */ + BIT(running); /* state info, for cookie adding information */ BIT(newsession); /* new session, discard session cookies on load */ }; @@ -130,7 +130,7 @@ void Curl_cookie_clearsess(struct CookieInfo *cookies); #define Curl_cookie_init() NULL #define Curl_cookie_run(x) Curl_nop_stmt #define Curl_cookie_cleanup(x) Curl_nop_stmt -#define Curl_flush_cookies(x,y) Curl_nop_stmt +#define Curl_flush_cookies(x, y) Curl_nop_stmt #else void Curl_flush_cookies(struct Curl_easy *data, bool cleanup); void Curl_cookie_cleanup(struct CookieInfo *c); diff --git a/lib/cshutdn.c b/lib/cshutdn.c index 0a4ab416473f..26c8f9c0dd41 100644 --- a/lib/cshutdn.c +++ b/lib/cshutdn.c @@ -119,7 +119,6 @@ void Curl_cshutdn_run_once(struct Curl_easy *data, Curl_detach_connection(data); } - void Curl_cshutdn_terminate(struct Curl_easy *data, struct connectdata *conn, bool do_shutdown) @@ -227,7 +226,6 @@ static CURLcode cshutdn_wait(struct cshutdn *cshutdn, return result; } - static void cshutdn_perform(struct cshutdn *cshutdn, struct Curl_easy *data) { @@ -270,7 +268,6 @@ static void cshutdn_perform(struct cshutdn *cshutdn, Curl_expire_ex(data, nowp, next_expire_ms, EXPIRE_SHUTDOWN); } - static void cshutdn_terminate_all(struct cshutdn *cshutdn, struct Curl_easy *data, int timeout_ms) @@ -301,7 +298,7 @@ static void cshutdn_terminate_all(struct cshutdn *cshutdn, spent_ms = curlx_timediff_ms(curlx_now(), started); if(spent_ms >= (timediff_t)timeout_ms) { CURL_TRC_M(data, "[SHUTDOWN] shutdown finished, %s", - (timeout_ms > 0) ? "timeout" : "best effort done"); + (timeout_ms > 0) ? "timeout" : "best effort done"); break; } @@ -325,7 +322,6 @@ static void cshutdn_terminate_all(struct cshutdn *cshutdn, sigpipe_restore(&pipe_st); } - int Curl_cshutdn_init(struct cshutdn *cshutdn, struct Curl_multi *multi) { @@ -336,7 +332,6 @@ int Curl_cshutdn_init(struct cshutdn *cshutdn, return 0; /* good */ } - void Curl_cshutdn_destroy(struct cshutdn *cshutdn, struct Curl_easy *data) { @@ -388,7 +383,6 @@ size_t Curl_cshutdn_dest_count(struct Curl_easy *data, return 0; } - static CURLMcode cshutdn_update_ev(struct cshutdn *cshutdn, struct Curl_easy *data, struct connectdata *conn) @@ -404,7 +398,6 @@ static CURLMcode cshutdn_update_ev(struct cshutdn *cshutdn, return mresult; } - void Curl_cshutdn_add(struct cshutdn *cshutdn, struct connectdata *conn, size_t conns_in_pool) @@ -436,7 +429,6 @@ void Curl_cshutdn_add(struct cshutdn *cshutdn, conn->connection_id, Curl_llist_count(&cshutdn->list)); } - static void cshutdn_multi_socket(struct cshutdn *cshutdn, struct Curl_easy *data, curl_socket_t s) @@ -461,7 +453,6 @@ static void cshutdn_multi_socket(struct cshutdn *cshutdn, } } - void Curl_cshutdn_perform(struct cshutdn *cshutdn, struct Curl_easy *data, curl_socket_t s) @@ -483,8 +474,7 @@ void Curl_cshutdn_setfds(struct cshutdn *cshutdn, struct easy_pollset ps; Curl_pollset_init(&ps); - for(e = Curl_llist_head(&cshutdn->list); e; - e = Curl_node_next(e)) { + for(e = Curl_llist_head(&cshutdn->list); e; e = Curl_node_next(e)) { unsigned int i; struct connectdata *conn = Curl_node_elem(e); CURLcode result; @@ -535,8 +525,7 @@ unsigned int Curl_cshutdn_add_waitfds(struct cshutdn *cshutdn, CURLcode result; Curl_pollset_init(&ps); - for(e = Curl_llist_head(&cshutdn->list); e; - e = Curl_node_next(e)) { + for(e = Curl_llist_head(&cshutdn->list); e; e = Curl_node_next(e)) { conn = Curl_node_elem(e); Curl_pollset_reset(&ps); Curl_attach_connection(data, conn); @@ -563,8 +552,7 @@ CURLcode Curl_cshutdn_add_pollfds(struct cshutdn *cshutdn, struct connectdata *conn; Curl_pollset_init(&ps); - for(e = Curl_llist_head(&cshutdn->list); e; - e = Curl_node_next(e)) { + for(e = Curl_llist_head(&cshutdn->list); e; e = Curl_node_next(e)) { conn = Curl_node_elem(e); Curl_pollset_reset(&ps); Curl_attach_connection(data, conn); From 6d156bc05f6d96a84a5c6a464dee638870e92094 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 30 Nov 2025 01:26:56 +0100 Subject: [PATCH 126/140] tests/data: replace Perl `&&` with `and` for XML-compliance Bringing down non-XML-compliant files to 50 (from 58). Follow-up to 7f3731ce142c1d74023abad183cc8ce0fd527fab #19595 Closes #19765 --- tests/data/test1506 | 3 +-- tests/data/test1510 | 3 +-- tests/data/test1512 | 3 +-- tests/data/test1542 | 3 +-- tests/data/test2402 | 3 +-- tests/data/test2404 | 3 +-- tests/data/test2502 | 3 +-- tests/data/test96 | 3 +-- 8 files changed, 8 insertions(+), 16 deletions(-) diff --git a/tests/data/test1506 b/tests/data/test1506 index cd7654a0d8bc..677d16773c22 100644 --- a/tests/data/test1506 +++ b/tests/data/test1506 @@ -4,7 +4,6 @@ HTTP multi verbose logs -notxml @@ -93,7 +92,7 @@ Accept: */* * Connection #3 to host server4.example.com:%HTTPPORT left intact -$_ = '' if(($_ !~ /left intact/) && ($_ !~ /Closing connection/)) +$_ = '' if(($_ !~ /left intact/) and ($_ !~ /Closing connection/)) diff --git a/tests/data/test1510 b/tests/data/test1510 index febe7d76ea30..7a688c81a23a 100644 --- a/tests/data/test1510 +++ b/tests/data/test1510 @@ -4,7 +4,6 @@ HTTP verbose logs flaky -notxml @@ -90,7 +89,7 @@ Accept: */* * Connection #3 to host server4.example.com:%HTTPPORT left intact -$_ = '' if(($_ !~ /left intact/) && ($_ !~ /Closing connection/)) +$_ = '' if(($_ !~ /left intact/) and ($_ !~ /Closing connection/)) diff --git a/tests/data/test1512 b/tests/data/test1512 index 3798d7325b4c..74547cdd2867 100644 --- a/tests/data/test1512 +++ b/tests/data/test1512 @@ -3,7 +3,6 @@ HTTP GLOBAL DNS CACHE -notxml @@ -75,7 +74,7 @@ Accept: */* ^Host:.* -$_ = '' if(($_ !~ /left intact/) && ($_ !~ /Closing connection/)) +$_ = '' if(($_ !~ /left intact/) and ($_ !~ /Closing connection/)) diff --git a/tests/data/test1542 b/tests/data/test1542 index 044fe518a467..41cf01432475 100644 --- a/tests/data/test1542 +++ b/tests/data/test1542 @@ -6,7 +6,6 @@ connection reuse persistent connection CURLOPT_MAXLIFETIME_CONN verbose logs -notxml @@ -66,7 +65,7 @@ Accept: */* == Info: Connection #1 to host %HOSTIP:%HTTPPORT left intact -$_ = '' if(($_ !~ /left intact/) && ($_ !~ /(closing|shutting down) connection #\d+/)) +$_ = '' if(($_ !~ /left intact/) and ($_ !~ /(closing|shutting down) connection #\d+/)) diff --git a/tests/data/test2402 b/tests/data/test2402 index ba3fcc85b451..5dc357f58fcd 100644 --- a/tests/data/test2402 +++ b/tests/data/test2402 @@ -5,7 +5,6 @@ HTTP HTTP/2 multi verbose logs -notxml @@ -104,7 +103,7 @@ Via: 2 nghttpx * Connection #0 to host localhost:%HTTP2TLSPORT left intact -$_ = '' if(($_ !~ /left intact/) && ($_ !~ /Closing connection/)) +$_ = '' if(($_ !~ /left intact/) and ($_ !~ /Closing connection/)) diff --git a/tests/data/test2404 b/tests/data/test2404 index 5034a15c3ca6..3dbb726be9a3 100644 --- a/tests/data/test2404 +++ b/tests/data/test2404 @@ -5,7 +5,6 @@ HTTP HTTP/2 multi verbose logs -notxml @@ -104,7 +103,7 @@ Via: 2 nghttpx * Connection #0 to host localhost:%HTTP2TLSPORT left intact -$_ = '' if(($_ !~ /left intact/) && ($_ !~ /Closing connection/)) +$_ = '' if(($_ !~ /left intact/) and ($_ !~ /Closing connection/)) diff --git a/tests/data/test2502 b/tests/data/test2502 index ac6cd3cf588c..c76b0418744d 100644 --- a/tests/data/test2502 +++ b/tests/data/test2502 @@ -5,7 +5,6 @@ HTTP HTTP/3 multi verbose logs -notxml @@ -99,7 +98,7 @@ Via: 3 nghttpx == Info: Connection #0 to host localhost:%HTTP3PORT left intact -$_ = '' if(($_ !~ /left intact/) && ($_ !~ /Closing connection/)) +$_ = '' if(($_ !~ /left intact/) and ($_ !~ /Closing connection/)) Maximum allocated: 1800000 diff --git a/tests/data/test96 b/tests/data/test96 index de4b7c18ad3f..a99114a3b3fb 100644 --- a/tests/data/test96 +++ b/tests/data/test96 @@ -2,7 +2,6 @@ TrackMemory -notxml @@ -37,7 +36,7 @@ MEM tool_cfgable.c MEM tool_cfgable.c -$_ = '' if((($_ !~ /tool_paramhlp/) && ($_ !~ /tool_cfgable/)) || ($_ =~ /free\(\(nil\)\)/)) +$_ = '' if((($_ !~ /tool_paramhlp/) and ($_ !~ /tool_cfgable/)) || ($_ =~ /free\(\(nil\)\)/)) s/:\d+.*// s:^(MEM )(.*/)(.*):$1$3: From 2d2d70b6e568f229d140264361a219851de1fd56 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 30 Nov 2025 01:45:57 +0100 Subject: [PATCH 127/140] test613.pl: integrate mtime check for test 1445, 1446 Move check logic from postchecks to `test613.pl`. To make these test data files XML-compliant. Also to avoid POSIX/bash-shellisms in postcheck. Closes #19766 --- tests/data/test1445 | 4 +--- tests/data/test1446 | 7 +------ tests/libtest/test613.pl | 9 ++++++++- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/data/test1445 b/tests/data/test1445 index 705162be2d37..08c12c9647a8 100644 --- a/tests/data/test1445 +++ b/tests/data/test1445 @@ -3,7 +3,6 @@ FILE --remote-time -notxml @@ -29,8 +28,7 @@ file://localhost%FILE_PWD/%LOGDIR/test%TESTNUMBER.dir/plainfile.txt --remote-tim # Verify data after the test has been "shot" -%PERL %SRCDIR/libtest/test613.pl postprocess %PWD/%LOGDIR/test%TESTNUMBER.dir && \ -%PERL -e 'exit((stat("%LOGDIR/curl%TESTNUMBER.out"))[9] != 946728000)' +%PERL %SRCDIR/libtest/test613.pl postprocess %PWD/%LOGDIR/test%TESTNUMBER.dir %LOGDIR/curl%TESTNUMBER.out 946728000 diff --git a/tests/data/test1446 b/tests/data/test1446 index 448eefbc1f5a..aa87ce11e193 100644 --- a/tests/data/test1446 +++ b/tests/data/test1446 @@ -3,16 +3,13 @@ SFTP --remote-time -notxml -# # Server-side -# # Client-side @@ -29,12 +26,10 @@ SFTP with --remote-time -# # Verify data after the test has been "shot" -%PERL %SRCDIR/libtest/test613.pl postprocess %PWD/%LOGDIR/test%TESTNUMBER.dir && \ -%PERL -e 'exit((stat("%LOGDIR/curl%TESTNUMBER.out"))[9] != 978264000)' +%PERL %SRCDIR/libtest/test613.pl postprocess %PWD/%LOGDIR/test%TESTNUMBER.dir %LOGDIR/curl%TESTNUMBER.out 978264000 diff --git a/tests/libtest/test613.pl b/tests/libtest/test613.pl index 88c0e4968256..3cccb6ed7f71 100755 --- a/tests/libtest/test613.pl +++ b/tests/libtest/test613.pl @@ -83,7 +83,6 @@ sub errout { } elsif($ARGV[0] eq "postprocess") { my $dirname = $ARGV[1]; - my $logfile = $ARGV[2]; # Clean up the test directory if($^O eq 'cygwin') { @@ -97,6 +96,14 @@ sub errout { rmdir $dirname || die "$!"; + if($#ARGV >= 3) { # Verify mtime if requested + my $checkfile = $ARGV[2]; + my $expected_mtime = int($ARGV[3]); + my $mtime = (stat($checkfile))[9]; + exit ($mtime != $expected_mtime); + } + + my $logfile = $ARGV[2]; if($logfile && -s $logfile) { # Process the directory file to remove all information that # could be inconsistent from one test run to the next (e.g. From 0180af248119d373b74b6906c5adac71d4b6cdfe Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 30 Nov 2025 02:57:39 +0100 Subject: [PATCH 128/140] tests/data: add `%PERL` to postcheck commands where missing To avoid potentially executing a different Perl than used by the rest of the build and tests. Also to be more portable by not relying on shebang support, though these particular tests require POSIX shell anyway. Closes #19767 --- tests/data/test1013 | 2 +- tests/data/test1014 | 2 +- tests/data/test1022 | 2 +- tests/data/test1023 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/data/test1013 b/tests/data/test1013 index aee2bfbefb3a..ef7cd958aa7e 100644 --- a/tests/data/test1013 +++ b/tests/data/test1013 @@ -25,7 +25,7 @@ Compare curl --version with curl-config --protocols # Verify data after the test has been "shot" -%SRCDIR/libtest/test%TESTNUMBER.pl ../curl-config %LOGDIR/stdout%TESTNUMBER protocols +%PERL %SRCDIR/libtest/test%TESTNUMBER.pl ../curl-config %LOGDIR/stdout%TESTNUMBER protocols 0 diff --git a/tests/data/test1014 b/tests/data/test1014 index 7dce0d8e1542..72289bc4ad32 100644 --- a/tests/data/test1014 +++ b/tests/data/test1014 @@ -25,7 +25,7 @@ Compare curl --version with curl-config --features # Verify data after the test has been "shot" -%SRCDIR/libtest/test1013.pl ../curl-config %LOGDIR/stdout%TESTNUMBER features > %LOGDIR/result%TESTNUMBER +%PERL %SRCDIR/libtest/test1013.pl ../curl-config %LOGDIR/stdout%TESTNUMBER features > %LOGDIR/result%TESTNUMBER 0 diff --git a/tests/data/test1022 b/tests/data/test1022 index 888c9ea1024c..b3b6bc04a2d6 100644 --- a/tests/data/test1022 +++ b/tests/data/test1022 @@ -25,7 +25,7 @@ Compare curl --version with curl-config --version # Verify data after the test has been "shot" -%SRCDIR/libtest/test%TESTNUMBER.pl ../curl-config %LOGDIR/stdout%TESTNUMBER version +%PERL %SRCDIR/libtest/test%TESTNUMBER.pl ../curl-config %LOGDIR/stdout%TESTNUMBER version 0 diff --git a/tests/data/test1023 b/tests/data/test1023 index 40fb11f81ed2..6e55d235e82d 100644 --- a/tests/data/test1023 +++ b/tests/data/test1023 @@ -25,7 +25,7 @@ Compare curl --version with curl-config --vernum # Verify data after the test has been "shot" -%SRCDIR/libtest/test1022.pl ../curl-config %LOGDIR/stdout%TESTNUMBER vernum +%PERL %SRCDIR/libtest/test1022.pl ../curl-config %LOGDIR/stdout%TESTNUMBER vernum 0 From fdf9937cef62755f67e7d622d6fdd296eb542009 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 30 Nov 2025 12:34:02 +0100 Subject: [PATCH 129/140] rtmp: stop redefining `setsockopt` system symbol on Windows Before this patch it added Windows-specific casts. In unity builds this also affected other source files. `setsockopt()` is called without special casts in other places in the code, and passing a non-const char ptr to a const char ptr arg also should work. Basic compile test with mingw-w64 confirms. In case of issues, a cast to `curl_socklen_t` can be used, or do the special case in an `#if` branch. Also: merge Windows-specific guards for `SET_RCVTIMEO()`. Follow-up to 639d052e4499c663a578d940713e40cd466268fa #3155 Follow-up to 04cb15ae9dc0e863487ee55de2226cf5033311c0 Closes #19768 --- lib/curl_rtmp.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/curl_rtmp.c b/lib/curl_rtmp.c index b2dd937008a5..6f9e7c37b4b8 100644 --- a/lib/curl_rtmp.c +++ b/lib/curl_rtmp.c @@ -37,10 +37,7 @@ #include #include -#if defined(_WIN32) && !defined(USE_LWIPSOCK) -#define setsockopt(a,b,c,d,e) (setsockopt)(a,b,c,(const char *)d,(int)e) -#define SET_RCVTIMEO(tv,s) int tv = s*1000 -#elif defined(LWIP_SO_SNDRCVTIMEO_NONSTANDARD) +#if defined(USE_WINSOCK) || defined(LWIP_SO_SNDRCVTIMEO_NONSTANDARD) #define SET_RCVTIMEO(tv,s) int tv = s*1000 #else #define SET_RCVTIMEO(tv,s) struct timeval tv = {s,0} From 003689c3d37510f7073d203ed94c882c19653fac Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 30 Nov 2025 12:52:46 +0100 Subject: [PATCH 130/140] cf-socket: drop feature check for `IPV6_V6ONLY` on Windows The macro is present in all supported Windows toolchains. It's present in mingw-w64 v3+, and in MS SDK 6.0A+ (maybe earlier). Also: - restrict this logic to `USE_WINSOCK` (was: `_WIN32`), to exclude alternate socket libraries (i.e. lwIP). lwIP supports `IPV6_V6ONLY` since its 2.0.0 (2016-11-10) release and it's disabled by default, unlike in Winsock. Ref: https://github.com/lwip-tcpip/lwip/commit/e65202f8257e55b09e6309b1aa405b5e6a017f0d - delete interim setter function/dummy macro `set_ipv6_v6only()`. Follow-up to a28f5f68b965119d9dd1ab6c2a2ccc66c6ed5d1f #18010 Follow-up to ca3f6decb927a4c3eb4c10fba09848b626a526d6 #10975 Closes #19769 --- lib/cf-socket.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/cf-socket.c b/lib/cf-socket.c index a12995941610..0e431976c915 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -83,22 +83,6 @@ #include "curlx/strparse.h" -#if defined(USE_IPV6) && defined(IPV6_V6ONLY) && defined(_WIN32) -/* It makes support for IPv4-mapped IPv6 addresses. - * Linux kernel, NetBSD, FreeBSD and Darwin: default is off; - * Windows Vista and later: default is on; - * DragonFly BSD: acts like off, and dummy setting; - * OpenBSD and earlier Windows: unsupported. - * Linux: controlled by /proc/sys/net/ipv6/bindv6only. - */ -static void set_ipv6_v6only(curl_socket_t sockfd, int on) -{ - (void)setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)); -} -#else -#define set_ipv6_v6only(x, y) -#endif - static void tcpnodelay(struct Curl_cfilter *cf, struct Curl_easy *data, curl_socket_t sockfd) @@ -1114,7 +1098,18 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf, #ifdef USE_IPV6 if(ctx->addr.family == AF_INET6) { - set_ipv6_v6only(ctx->sock, 0); +#ifdef USE_WINSOCK + /* Turn on support for IPv4-mapped IPv6 addresses. + * Linux kernel, NetBSD, FreeBSD, Darwin, lwIP: default is off; + * Windows Vista and later: default is on; + * DragonFly BSD: acts like off, and dummy setting; + * OpenBSD and earlier Windows: unsupported. + * Linux: controlled by /proc/sys/net/ipv6/bindv6only. + */ + int on = 0; + (void)setsockopt(ctx->sock, IPPROTO_IPV6, IPV6_V6ONLY, + (void *)&on, sizeof(on)); +#endif infof(data, " Trying [%s]:%d...", ctx->ip.remote_ip, ctx->ip.remote_port); } else From 815bf7664999cb733438c9dd54bbbd8f1737679e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 30 Nov 2025 17:16:03 +0100 Subject: [PATCH 131/140] autotools: delete idle `AM_CFLAGS`, `AM_LDFLAGS` variables Closes #19771 --- lib/Makefile.am | 9 +++------ src/Makefile.am | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/Makefile.am b/lib/Makefile.am index 784b7f35d61e..2645872ebf77 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -63,8 +63,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/include \ # Prevent LIBS from being used for all link targets LIBS = $(BLANK_AT_MAKETIME) -AM_LDFLAGS = -AM_CFLAGS = if DEBUGBUILD AM_CPPFLAGS += -DDEBUGBUILD endif @@ -136,12 +134,11 @@ libcurl_la_CFLAGS_EXTRA += $(CFLAG_CURL_SYMBOL_HIDING) endif libcurl_la_CPPFLAGS = $(AM_CPPFLAGS) $(libcurl_la_CPPFLAGS_EXTRA) -libcurl_la_LDFLAGS = $(AM_LDFLAGS) $(libcurl_la_LDFLAGS_EXTRA) $(CURL_LDFLAGS_LIB) $(LIBCURL_PC_LIBS_PRIVATE) -libcurl_la_CFLAGS = $(AM_CFLAGS) $(libcurl_la_CFLAGS_EXTRA) +libcurl_la_LDFLAGS = $(libcurl_la_LDFLAGS_EXTRA) $(CURL_LDFLAGS_LIB) $(LIBCURL_PC_LIBS_PRIVATE) +libcurl_la_CFLAGS = $(libcurl_la_CFLAGS_EXTRA) libcurlu_la_CPPFLAGS = $(AM_CPPFLAGS) -DCURL_STATICLIB -DUNITTESTS -libcurlu_la_LDFLAGS = $(AM_LDFLAGS) -static $(LIBCURL_PC_LIBS_PRIVATE) -libcurlu_la_CFLAGS = $(AM_CFLAGS) +libcurlu_la_LDFLAGS = -static $(LIBCURL_PC_LIBS_PRIVATE) CHECKSRC = $(CS_$(V)) CS_0 = @echo " RUN " $@; diff --git a/src/Makefile.am b/src/Makefile.am index c1bcf273597e..169a64f71391 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -61,7 +61,6 @@ if CURLDEBUG AM_CPPFLAGS += -DCURLDEBUG endif -AM_LDFLAGS = if USE_UNICODE UNICODEFLAG = -municode endif @@ -94,7 +93,7 @@ curl_SOURCES += $(CURL_RCFILES) $(CURL_RCFILES): tool_version.h endif -curl_LDFLAGS = $(AM_LDFLAGS) $(CURL_LDFLAGS_BIN) $(UNICODEFLAG) +curl_LDFLAGS = $(CURL_LDFLAGS_BIN) $(UNICODEFLAG) # This might hold -Werror CFLAGS += @CURL_CFLAG_EXTRAS@ From 4e8d5da7eeaa83c9d2e5cc62fb92231cf75d3c94 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 30 Nov 2025 17:31:24 +0100 Subject: [PATCH 132/140] vtls: drop interim ECH feature macros (OpenSSL, wolfSSL) Use the macros set by autotools and cmake, to simplify. Closes #19772 --- lib/vtls/openssl.c | 24 ++++++++++-------------- lib/vtls/wolfssl.c | 12 ++++-------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index a958698b5836..67466e6e41d5 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -86,11 +86,7 @@ #include #include -#ifdef HAVE_SSL_SET1_ECH_CONFIG_LIST -#define USE_ECH_OPENSSL -#endif - -#if defined(USE_ECH_OPENSSL) && !defined(HAVE_BORINGSSL_LIKE) +#if defined(HAVE_SSL_SET1_ECH_CONFIG_LIST) && !defined(HAVE_BORINGSSL_LIKE) #include #endif @@ -3447,7 +3443,7 @@ ossl_init_session_and_alpns(struct ossl_ctx *octx, return CURLE_OK; } -#ifdef USE_ECH_OPENSSL +#ifdef HAVE_SSL_SET1_ECH_CONFIG_LIST static CURLcode ossl_init_ech(struct ossl_ctx *octx, struct Curl_cfilter *cf, struct Curl_easy *data, @@ -3576,7 +3572,7 @@ static CURLcode ossl_init_ech(struct ossl_ctx *octx, return CURLE_OK; } -#endif /* USE_ECH_OPENSSL */ +#endif /* HAVE_SSL_SET1_ECH_CONFIG_LIST */ static CURLcode ossl_init_ssl(struct ossl_ctx *octx, struct Curl_cfilter *cf, @@ -3611,13 +3607,13 @@ static CURLcode ossl_init_ssl(struct ossl_ctx *octx, } } -#ifdef USE_ECH_OPENSSL +#ifdef HAVE_SSL_SET1_ECH_CONFIG_LIST { CURLcode result = ossl_init_ech(octx, cf, data, peer); if(result) return result; } -#endif /* USE_ECH_OPENSSL */ +#endif /* HAVE_SSL_SET1_ECH_CONFIG_LIST */ return ossl_init_session_and_alpns(octx, cf, data, peer, alpns_requested, sess_reuse_cb); @@ -4091,7 +4087,7 @@ static CURLcode ossl_connect_step1(struct Curl_cfilter *cf, return CURLE_OK; } -#ifdef USE_ECH_OPENSSL +#ifdef HAVE_SSL_SET1_ECH_CONFIG_LIST /* If we have retry configs, then trace those out */ static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL *ssl, int reason) @@ -4262,7 +4258,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, ossl_strerror(errdetail, error_buffer, sizeof(error_buffer))); } #endif -#ifdef USE_ECH_OPENSSL +#ifdef HAVE_SSL_SET1_ECH_CONFIG_LIST else if((lib == ERR_LIB_SSL) && # ifndef HAVE_BORINGSSL_LIKE (reason == SSL_R_ECH_REQUIRED)) { @@ -4309,7 +4305,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, connssl->connecting_state = ssl_connect_3; Curl_ossl_report_handshake(data, octx); -#if defined(USE_ECH_OPENSSL) && !defined(HAVE_BORINGSSL_LIKE) +#if defined(HAVE_SSL_SET1_ECH_CONFIG_LIST) && !defined(HAVE_BORINGSSL_LIKE) if(ECH_ENABLED(data)) { char *inner = NULL, *outer = NULL; const char *status = NULL; @@ -4367,7 +4363,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, else { infof(data, "ECH: result: status is not attempted"); } -#endif /* USE_ECH_OPENSSL && !HAVE_BORINGSSL_LIKE */ +#endif /* HAVE_SSL_SET1_ECH_CONFIG_LIST && !HAVE_BORINGSSL_LIKE */ #ifdef HAS_ALPN_OPENSSL /* Sets data and len to negotiated protocol, len is 0 if no protocol was @@ -5435,7 +5431,7 @@ const struct Curl_ssl Curl_ssl_openssl = { #ifdef HAVE_SSL_CTX_SET1_SIGALGS SSLSUPP_SIGNATURE_ALGORITHMS | #endif -#ifdef USE_ECH_OPENSSL +#ifdef HAVE_SSL_SET1_ECH_CONFIG_LIST SSLSUPP_ECH | #endif SSLSUPP_CA_CACHE | diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c index 62bf723efd33..cfefeb9320c7 100644 --- a/lib/vtls/wolfssl.c +++ b/lib/vtls/wolfssl.c @@ -75,10 +75,6 @@ #include #include "wolfssl.h" -#ifdef HAVE_WOLFSSL_CTX_GENERATEECHCONFIG -#define USE_ECH_WOLFSSL -#endif - /* KEEP_PEER_CERT is a product of the presence of build time symbol OPENSSL_EXTRA without NO_CERTS, depending on the version. KEEP_PEER_CERT is in wolfSSL's settings.h, and the latter two are build time symbols in @@ -1364,7 +1360,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, } #endif /* HAVE_SECURE_RENEGOTIATION */ -#ifdef USE_ECH_WOLFSSL +#ifdef HAVE_WOLFSSL_CTX_GENERATEECHCONFIG if(ECH_ENABLED(data)) { int trying_ech_now = 0; @@ -1449,7 +1445,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, } } -#endif /* USE_ECH_WOLFSSL */ +#endif /* HAVE_WOLFSSL_CTX_GENERATEECHCONFIG */ result = CURLE_OK; @@ -1786,7 +1782,7 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, struct Curl_easy *data) return wssl->io_result; } } -#ifdef USE_ECH_WOLFSSL +#ifdef HAVE_WOLFSSL_CTX_GENERATEECHCONFIG else if(detail == -1) { /* try access a retry_config ECHConfigList for tracing */ byte echConfigs[1000]; @@ -2282,7 +2278,7 @@ const struct Curl_ssl Curl_ssl_wolfssl = { #endif SSLSUPP_CA_PATH | SSLSUPP_CAINFO_BLOB | -#ifdef USE_ECH_WOLFSSL +#ifdef HAVE_WOLFSSL_CTX_GENERATEECHCONFIG SSLSUPP_ECH | #endif SSLSUPP_SSL_CTX | From f553bff6ee719cf04402b28305e911458b5b6d36 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 30 Nov 2025 23:27:06 +0100 Subject: [PATCH 133/140] cmakelint: also lint CMake `.in` files, fix a long line ``` CMakeConfigurableFile.in cmake_uninstall.cmake.in curl-config.cmake.in ``` Follow-up to 16f073ef49f94412000218c9f6ad04e3fd7e4d01 #16973 Closes #19773 --- CMake/curl-config.cmake.in | 3 ++- scripts/cmakelint.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMake/curl-config.cmake.in b/CMake/curl-config.cmake.in index c4e9f59e863b..33d540da27c8 100644 --- a/CMake/curl-config.cmake.in +++ b/CMake/curl-config.cmake.in @@ -23,7 +23,8 @@ ########################################################################### @PACKAGE_INIT@ -option(CURL_USE_PKGCONFIG "Enable pkg-config to detect @PROJECT_NAME@ dependencies. Default: @CURL_USE_PKGCONFIG@" "@CURL_USE_PKGCONFIG@") +option(CURL_USE_PKGCONFIG "Enable pkg-config to detect @PROJECT_NAME@ dependencies. Default: @CURL_USE_PKGCONFIG@" + "@CURL_USE_PKGCONFIG@") include(CMakeFindDependencyMacro) diff --git a/scripts/cmakelint.sh b/scripts/cmakelint.sh index 325a07b5e6cb..1e1cc592ed3f 100755 --- a/scripts/cmakelint.sh +++ b/scripts/cmakelint.sh @@ -52,7 +52,7 @@ cd "$(dirname "$0")"/.. # strip off the leading ./ to make the grep regexes work properly find . -type f | sed 's@^\./@@' fi -} | grep -E '(^CMake|/CMake|\.cmake$)' | grep -v -E '(\.h\.cmake|\.in|\.c)$' \ +} | grep -E '(^CMake|/CMake|\.cmake$)' | grep -v -E '(\.h\.cmake|\.c)$' \ | xargs \ cmake-lint \ --suppress-decorations \ From 7799d15eef302cdc3fdbbe1dec5c43df2048ec9e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 1 Dec 2025 00:34:33 +0100 Subject: [PATCH 134/140] cmake: fix `ws2_32` reference in `curl-config.cmake` Follow-up to 16f073ef49f94412000218c9f6ad04e3fd7e4d01 #16973 Follow-up to 554dfa556886c3d7425f6690f3fc408128bf4744 #17927 Closes #19775 --- CMake/curl-config.cmake.in | 2 +- CMakeLists.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CMake/curl-config.cmake.in b/CMake/curl-config.cmake.in index 33d540da27c8..525f2d3dbeb3 100644 --- a/CMake/curl-config.cmake.in +++ b/CMake/curl-config.cmake.in @@ -133,7 +133,7 @@ set(CMAKE_MODULE_PATH ${_curl_cmake_module_path_save}) if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND WIN32 AND NOT TARGET CURL::win32_winsock) add_library(CURL::win32_winsock INTERFACE IMPORTED) - set_target_properties(CURL::win32_winsock PROPERTIES INTERFACE_LINK_LIBRARIES "@_win32_winsock@") + set_target_properties(CURL::win32_winsock PROPERTIES INTERFACE_LINK_LIBRARIES "ws2_32") endif() include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") diff --git a/CMakeLists.txt b/CMakeLists.txt index 2af1679c993f..5bcf0b6a631a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2340,7 +2340,6 @@ if(NOT CURL_DISABLE_INSTALL) # USE_RUSTLS # USE_WIN32_LDAP CURL_DISABLE_LDAP # USE_WOLFSSL - # _win32_winsock configure_package_config_file("CMake/curl-config.cmake.in" "${_project_config}" INSTALL_DESTINATION ${_install_cmake_dir} From bf58ca6e8f5f518c1f4b4acab03acb1b60e25c00 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 1 Dec 2025 01:17:41 +0100 Subject: [PATCH 135/140] cmake: narrow scope of custom `CMAKE_MODULE_PATH` in `curl-config.cmake` Set it only while using local Find modules, leave it as-is while using system ones. Follow-up to 16f073ef49f94412000218c9f6ad04e3fd7e4d01 #16973 Cherry-picked from #19776 --- CMake/curl-config.cmake.in | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CMake/curl-config.cmake.in b/CMake/curl-config.cmake.in index 525f2d3dbeb3..97c60d3a8d4d 100644 --- a/CMake/curl-config.cmake.in +++ b/CMake/curl-config.cmake.in @@ -28,10 +28,6 @@ option(CURL_USE_PKGCONFIG "Enable pkg-config to detect @PROJECT_NAME@ dependenci include(CMakeFindDependencyMacro) -set(_curl_cmake_module_path_save ${CMAKE_MODULE_PATH}) -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH}) - -set(_libs "") if("@USE_OPENSSL@") if("@OPENSSL_VERSION_MAJOR@") find_dependency(OpenSSL "@OPENSSL_VERSION_MAJOR@") @@ -42,6 +38,12 @@ endif() if("@HAVE_LIBZ@") find_dependency(ZLIB "@ZLIB_VERSION_MAJOR@") endif() + +set(_curl_cmake_module_path_save ${CMAKE_MODULE_PATH}) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH}) + +set(_libs "") + if("@HAVE_BROTLI@") find_dependency(Brotli) list(APPEND _libs CURL::brotli) From 41931f1659f485ba60cfb4da0b4479bfb0fd8a8e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 30 Nov 2025 23:35:25 +0100 Subject: [PATCH 136/140] imap: make sure Curl_pgrsSetDownloadSize() does not overflow Follow-up to c1e3a760b. The previous update missed an addition that also can wrap and cause confusion. Fixing this by calling Curl_pgrsSetDownloadSize() after the overflow check. Reported-by: Deniz Parlak Closes #19774 --- lib/imap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/imap.c b/lib/imap.c index d093e46d33ab..9d58bec4ec81 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -1214,8 +1214,6 @@ static CURLcode imap_state_listsearch_resp(struct Curl_easy *data, /* This is a literal response, setup to receive the body data */ infof(data, "Found %" FMT_OFF_T " bytes to download", size); - /* Progress size includes both header line and literal body */ - Curl_pgrsSetDownloadSize(data, size + len); /* First write the header line */ result = Curl_client_write(data, CLIENTWRITE_BODY, line, len); @@ -1268,6 +1266,9 @@ static CURLcode imap_state_listsearch_resp(struct Curl_easy *data, else size += len; + /* Progress size includes both header line and literal body */ + Curl_pgrsSetDownloadSize(data, size); + if(data->req.bytecount == size) /* All data already transferred (header + literal body) */ Curl_xfer_setup_nop(data); From cffc91284475e78a7d9b0538b9db329fe3249f63 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 1 Dec 2025 09:26:28 +0100 Subject: [PATCH 137/140] url: fix return code for OOM in parse_proxy() Closes #19779 --- lib/url.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/url.c b/lib/url.c index b4c33236cd67..84909f037238 100644 --- a/lib/url.c +++ b/lib/url.c @@ -2250,11 +2250,15 @@ static CURLcode parse_proxy(struct Curl_easy *data, /* Is there a username and password given in this proxy url? */ uc = curl_url_get(uhp, CURLUPART_USER, &proxyuser, CURLU_URLDECODE); - if(uc && (uc != CURLUE_NO_USER)) + if(uc && (uc != CURLUE_NO_USER)) { + result = Curl_uc_to_curlcode(uc); goto error; + } uc = curl_url_get(uhp, CURLUPART_PASSWORD, &proxypasswd, CURLU_URLDECODE); - if(uc && (uc != CURLUE_NO_PASSWORD)) + if(uc && (uc != CURLUE_NO_PASSWORD)) { + result = Curl_uc_to_curlcode(uc); goto error; + } if(proxyuser || proxypasswd) { curlx_free(proxyinfo->user); From 729316a9e4aed66c3ca90435e2c7f4052dac32f9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 1 Dec 2025 10:24:32 +0100 Subject: [PATCH 138/140] http: handle oom error from Curl_input_digest() Closes #19780 --- lib/http.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/http.c b/lib/http.c index f09d96ee0607..5e2b8f9ac013 100644 --- a/lib/http.c +++ b/lib/http.c @@ -976,6 +976,8 @@ static CURLcode auth_digest(struct Curl_easy *data, * Digest */ result = Curl_input_digest(data, proxy, auth); if(result) { + if(result == CURLE_OUT_OF_MEMORY) + return result; infof(data, "Digest authentication problem, ignoring."); data->state.authproblem = TRUE; } From dabfae84f0f2626974c109c979a21bcaad357450 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 1 Dec 2025 01:53:25 +0100 Subject: [PATCH 139/140] cmake: namespace all local variables in `curl-config.cmake` Also: - apply it to the local copy of this code in `lib/CMakeLists.txt`. - replace 'CURL' with `@PROJECT_NAME@` in a message. Closes #19777 --- CMake/curl-config.cmake.in | 86 +++++++++++++++++++------------------- lib/CMakeLists.txt | 16 +++---- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/CMake/curl-config.cmake.in b/CMake/curl-config.cmake.in index 97c60d3a8d4d..7ae026d8f8c6 100644 --- a/CMake/curl-config.cmake.in +++ b/CMake/curl-config.cmake.in @@ -42,93 +42,93 @@ endif() set(_curl_cmake_module_path_save ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH}) -set(_libs "") +set(_curl_libs "") if("@HAVE_BROTLI@") find_dependency(Brotli) - list(APPEND _libs CURL::brotli) + list(APPEND _curl_libs CURL::brotli) endif() if("@USE_ARES@") find_dependency(Cares) - list(APPEND _libs CURL::cares) + list(APPEND _curl_libs CURL::cares) endif() if("@HAVE_GSSAPI@") find_dependency(GSS) - list(APPEND _libs CURL::gss) + list(APPEND _curl_libs CURL::gss) endif() if("@USE_BACKTRACE@") find_dependency(Libbacktrace) - list(APPEND _libs CURL::libbacktrace) + list(APPEND _curl_libs CURL::libbacktrace) endif() if("@USE_GSASL@") find_dependency(Libgsasl) - list(APPEND _libs CURL::libgsasl) + list(APPEND _curl_libs CURL::libgsasl) endif() if(NOT "@USE_WIN32_LDAP@" AND NOT "@CURL_DISABLE_LDAP@") find_dependency(LDAP) - list(APPEND _libs CURL::ldap) + list(APPEND _curl_libs CURL::ldap) endif() if("@HAVE_LIBIDN2@") find_dependency(Libidn2) - list(APPEND _libs CURL::libidn2) + list(APPEND _curl_libs CURL::libidn2) endif() if("@USE_LIBPSL@") find_dependency(Libpsl) - list(APPEND _libs CURL::libpsl) + list(APPEND _curl_libs CURL::libpsl) endif() if("@USE_LIBRTMP@") find_dependency(Librtmp) - list(APPEND _libs CURL::librtmp) + list(APPEND _curl_libs CURL::librtmp) endif() if("@USE_LIBSSH@") find_dependency(Libssh) - list(APPEND _libs CURL::libssh) + list(APPEND _curl_libs CURL::libssh) endif() if("@USE_LIBSSH2@") find_dependency(Libssh2) - list(APPEND _libs CURL::libssh2) + list(APPEND _curl_libs CURL::libssh2) endif() if("@USE_LIBUV@") find_dependency(Libuv) - list(APPEND _libs CURL::libuv) + list(APPEND _curl_libs CURL::libuv) endif() if("@USE_MBEDTLS@") find_dependency(MbedTLS) - list(APPEND _libs CURL::mbedtls) + list(APPEND _curl_libs CURL::mbedtls) endif() if("@USE_NGHTTP2@") find_dependency(NGHTTP2) - list(APPEND _libs CURL::nghttp2) + list(APPEND _curl_libs CURL::nghttp2) endif() if("@USE_NGHTTP3@") find_dependency(NGHTTP3) - list(APPEND _libs CURL::nghttp3) + list(APPEND _curl_libs CURL::nghttp3) endif() if("@USE_NGTCP2@") find_dependency(NGTCP2) - list(APPEND _libs CURL::ngtcp2) + list(APPEND _curl_libs CURL::ngtcp2) endif() if("@USE_GNUTLS@") find_dependency(GnuTLS) - list(APPEND _libs CURL::gnutls) + list(APPEND _curl_libs CURL::gnutls) find_dependency(Nettle) - list(APPEND _libs CURL::nettle) + list(APPEND _curl_libs CURL::nettle) endif() if("@USE_QUICHE@") find_dependency(Quiche) - list(APPEND _libs CURL::quiche) + list(APPEND _curl_libs CURL::quiche) endif() if("@USE_RUSTLS@") find_dependency(Rustls) - list(APPEND _libs CURL::rustls) + list(APPEND _curl_libs CURL::rustls) endif() if("@USE_WOLFSSL@") find_dependency(WolfSSL) - list(APPEND _libs CURL::wolfssl) + list(APPEND _curl_libs CURL::wolfssl) endif() if("@HAVE_ZSTD@") find_dependency(Zstd) - list(APPEND _libs CURL::zstd) + list(APPEND _curl_libs CURL::zstd) endif() set(CMAKE_MODULE_PATH ${_curl_cmake_module_path_save}) @@ -155,16 +155,16 @@ if(TARGET @PROJECT_NAME@::@LIB_STATIC@) if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17) cmake_policy(GET CMP0099 _has_CMP0099) # https://cmake.org/cmake/help/latest/policy/CMP0099.html endif() - if(NOT _has_CMP0099 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.13 AND _libs) - set(_libdirs "") - foreach(_lib IN LISTS _libs) - get_target_property(_libdir "${_lib}" INTERFACE_LINK_DIRECTORIES) - if(_libdir) - list(APPEND _libdirs "${_libdir}") + if(NOT _has_CMP0099 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.13 AND _curl_libs) + set(_curl_libdirs "") + foreach(_curl_lib IN LISTS _curl_libs) + get_target_property(_curl_libdir "${_curl_lib}" INTERFACE_LINK_DIRECTORIES) + if(_curl_libdir) + list(APPEND _curl_libdirs "${_curl_libdir}") endif() endforeach() - if(_libdirs) - target_link_directories(@PROJECT_NAME@::@LIB_STATIC@ INTERFACE ${_libdirs}) + if(_curl_libdirs) + target_link_directories(@PROJECT_NAME@::@LIB_STATIC@ INTERFACE ${_curl_libdirs}) endif() endif() endif() @@ -178,25 +178,25 @@ set_and_check(CURL_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@") set(CURL_SUPPORTED_PROTOCOLS "@CURL_SUPPORTED_PROTOCOLS_LIST@") set(CURL_SUPPORTED_FEATURES "@CURL_SUPPORTED_FEATURES_LIST@") -foreach(_item IN LISTS CURL_SUPPORTED_PROTOCOLS CURL_SUPPORTED_FEATURES) - set(CURL_SUPPORTS_${_item} TRUE) +foreach(_curl_item IN LISTS CURL_SUPPORTED_PROTOCOLS CURL_SUPPORTED_FEATURES) + set(CURL_SUPPORTS_${_curl_item} TRUE) endforeach() -set(_missing_req "") -foreach(_item IN LISTS CURL_FIND_COMPONENTS) - if(CURL_SUPPORTS_${_item}) - set(CURL_${_item}_FOUND TRUE) - elseif(CURL_FIND_REQUIRED_${_item}) - list(APPEND _missing_req ${_item}) +set(_curl_missing_req "") +foreach(_curl_item IN LISTS CURL_FIND_COMPONENTS) + if(CURL_SUPPORTS_${_curl_item}) + set(CURL_${_curl_item}_FOUND TRUE) + elseif(CURL_FIND_REQUIRED_${_curl_item}) + list(APPEND _curl_missing_req ${_curl_item}) endif() endforeach() -if(_missing_req) - string(REPLACE ";" " " _missing_req "${_missing_req}") +if(_curl_missing_req) + string(REPLACE ";" " " _curl_missing_req "${_curl_missing_req}") if(CURL_FIND_REQUIRED) - message(FATAL_ERROR "CURL: missing required components: ${_missing_req}") + message(FATAL_ERROR "@PROJECT_NAME@: missing required components: ${_curl_missing_req}") endif() - unset(_missing_req) + unset(_curl_missing_req) endif() check_required_components("@PROJECT_NAME@") diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 5ce288a0a897..b9b175a24d06 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -181,17 +181,17 @@ if(BUILD_STATIC_LIBS) cmake_policy(GET CMP0099 _has_CMP0099) # https://cmake.org/cmake/help/latest/policy/CMP0099.html endif() if(NOT _has_CMP0099 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.13 AND CURL_LIBS) - set(_libdirs "") - foreach(_lib IN LISTS CURL_LIBS) - if(TARGET "${_lib}") - get_target_property(_libdir "${_lib}" INTERFACE_LINK_DIRECTORIES) - if(_libdir) - list(APPEND _libdirs "${_libdir}") + set(_curl_libdirs "") + foreach(_curl_lib IN LISTS CURL_LIBS) + if(TARGET "${_curl_lib}") + get_target_property(_curl_libdir "${_curl_lib}" INTERFACE_LINK_DIRECTORIES) + if(_curl_libdir) + list(APPEND _curl_libdirs "${_curl_libdir}") endif() endif() endforeach() - if(_libdirs) - target_link_directories(${LIB_STATIC} INTERFACE ${_libdirs}) + if(_curl_libdirs) + target_link_directories(${LIB_STATIC} INTERFACE ${_curl_libdirs}) endif() endif() endif() From 4aed2dcc897b383b8bb9ae3bf2d7a2246ebccfcd Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 29 Nov 2025 15:23:58 +0100 Subject: [PATCH 140/140] krb5: fix detecting channel binding feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the already detected `gssapi/gssapi_krb5.h` MIT Kerberos header to pull in `gssapi_ext.h`, which in turn sets `GSS_C_CHANNEL_BOUND_FLAG` if supported. Channel binding is present in MIT Kerberos 1.19+. Also: - lib: de-duplicate GSS-API header includes. - vauth: de-duplicate `urldata.h` includes. - drop interim feature macro in favor of the native GSS one. Assisted-by: Max Faxälv Reported-by: Max Faxälv Bug: https://github.com/curl/curl/pull/19164#issuecomment-3551687025 Follow-up to 8616e5aada9c78fb611c60d913c999c8e78c14ba #19164 Closes #19603 Closes #19760 --- lib/curl_gssapi.h | 5 ----- lib/http_negotiate.c | 6 +++--- lib/urldata.h | 11 +++++------ lib/vauth/cleartext.c | 1 - lib/vauth/cram.c | 1 - lib/vauth/digest.c | 1 - lib/vauth/digest_sspi.c | 1 - lib/vauth/gsasl.c | 1 - lib/vauth/krb5_gssapi.c | 1 - lib/vauth/krb5_sspi.c | 1 - lib/vauth/ntlm.c | 4 +--- lib/vauth/ntlm_sspi.c | 1 - lib/vauth/oauth2.c | 1 - lib/vauth/spnego_gssapi.c | 5 ++--- lib/vauth/spnego_sspi.c | 1 - lib/vauth/vauth.c | 1 - lib/vauth/vauth.h | 15 ++------------- lib/version.c | 12 ------------ 18 files changed, 13 insertions(+), 56 deletions(-) diff --git a/lib/curl_gssapi.h b/lib/curl_gssapi.h index 1a2bbabdf516..6df7e059d325 100644 --- a/lib/curl_gssapi.h +++ b/lib/curl_gssapi.h @@ -28,11 +28,6 @@ #include "urldata.h" #ifdef HAVE_GSSAPI - -#ifdef GSS_C_CHANNEL_BOUND_FLAG /* MIT Kerberos 1.19+, missing from GNU GSS */ -#define CURL_GSSAPI_HAS_CHANNEL_BINDING -#endif - extern gss_OID_desc Curl_spnego_mech_oid; extern gss_OID_desc Curl_krb5_mech_oid; diff --git a/lib/http_negotiate.c b/lib/http_negotiate.c index fc80f80fa350..f31e59c2ca6d 100644 --- a/lib/http_negotiate.c +++ b/lib/http_negotiate.c @@ -120,7 +120,7 @@ CURLcode Curl_input_negotiate(struct Curl_easy *data, struct connectdata *conn, neg_ctx->sslContext = conn->sslContext; #endif /* Check if the connection is using SSL and get the channel binding data */ -#ifdef CURL_GSSAPI_HAS_CHANNEL_BINDING +#ifdef GSS_C_CHANNEL_BOUND_FLAG #ifdef USE_SSL curlx_dyn_init(&neg_ctx->channel_binding_data, SSL_CB_MAX_SIZE + 1); if(Curl_conn_is_ssl(conn, FIRSTSOCKET)) { @@ -134,13 +134,13 @@ CURLcode Curl_input_negotiate(struct Curl_easy *data, struct connectdata *conn, #else curlx_dyn_init(&neg_ctx->channel_binding_data, 1); #endif /* USE_SSL */ -#endif /* CURL_GSSAPI_HAS_CHANNEL_BINDING */ +#endif /* GSS_C_CHANNEL_BOUND_FLAG */ /* Initialize the security context and decode our challenge */ result = Curl_auth_decode_spnego_message(data, userp, passwdp, service, host, header, neg_ctx); -#ifdef CURL_GSSAPI_HAS_CHANNEL_BINDING +#ifdef GSS_C_CHANNEL_BOUND_FLAG curlx_dyn_free(&neg_ctx->channel_binding_data); #endif diff --git a/lib/urldata.h b/lib/urldata.h index 561db56ecd8a..1c91099d153d 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -191,12 +191,11 @@ typedef CURLcode (Curl_recv)(struct Curl_easy *data, /* transfer */ #ifdef HAVE_GSSAPI # ifdef HAVE_GSSGNU # include -# else -# ifdef HAVE_GSSAPI_H -# include -# else -# include -# endif +# elif defined(HAVE_GSSAPI_H) +# include +# else /* MIT Kerberos */ +# include +# include /* for GSS_C_CHANNEL_BOUND_FLAG, in 1.19+ */ # endif #endif diff --git a/lib/vauth/cleartext.c b/lib/vauth/cleartext.c index 862310111e66..c0e59fd273b9 100644 --- a/lib/vauth/cleartext.c +++ b/lib/vauth/cleartext.c @@ -32,7 +32,6 @@ (!defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP)) #include -#include "../urldata.h" #include "vauth.h" #include "../curlx/warnless.h" diff --git a/lib/vauth/cram.c b/lib/vauth/cram.c index 9bc5544a64fa..6a39a400ee3c 100644 --- a/lib/vauth/cram.c +++ b/lib/vauth/cram.c @@ -29,7 +29,6 @@ #ifndef CURL_DISABLE_DIGEST_AUTH #include -#include "../urldata.h" #include "vauth.h" #include "../curl_hmac.h" diff --git a/lib/vauth/digest.c b/lib/vauth/digest.c index c5fea6739449..8bcfc7ed6c9c 100644 --- a/lib/vauth/digest.c +++ b/lib/vauth/digest.c @@ -33,7 +33,6 @@ #include "vauth.h" #include "digest.h" -#include "../urldata.h" #include "../curlx/base64.h" #include "../curl_hmac.h" #include "../curl_md5.h" diff --git a/lib/vauth/digest_sspi.c b/lib/vauth/digest_sspi.c index 550810acda18..fc2c1393750f 100644 --- a/lib/vauth/digest_sspi.c +++ b/lib/vauth/digest_sspi.c @@ -33,7 +33,6 @@ #include "vauth.h" #include "digest.h" -#include "../urldata.h" #include "../curlx/warnless.h" #include "../curlx/multibyte.h" #include "../sendf.h" diff --git a/lib/vauth/gsasl.c b/lib/vauth/gsasl.c index 8330a4bd7155..3888622dbffa 100644 --- a/lib/vauth/gsasl.c +++ b/lib/vauth/gsasl.c @@ -31,7 +31,6 @@ #include #include "vauth.h" -#include "../urldata.h" #include "../sendf.h" #include diff --git a/lib/vauth/krb5_gssapi.c b/lib/vauth/krb5_gssapi.c index 1590949d681a..7ba21a394184 100644 --- a/lib/vauth/krb5_gssapi.c +++ b/lib/vauth/krb5_gssapi.c @@ -33,7 +33,6 @@ #include "vauth.h" #include "../curl_sasl.h" -#include "../urldata.h" #include "../curl_gssapi.h" #include "../sendf.h" diff --git a/lib/vauth/krb5_sspi.c b/lib/vauth/krb5_sspi.c index 2f82345b98c7..7317af809ad5 100644 --- a/lib/vauth/krb5_sspi.c +++ b/lib/vauth/krb5_sspi.c @@ -31,7 +31,6 @@ #include #include "vauth.h" -#include "../urldata.h" #include "../curlx/warnless.h" #include "../curlx/multibyte.h" #include "../sendf.h" diff --git a/lib/vauth/ntlm.c b/lib/vauth/ntlm.c index e5eb1de5ef8b..e47135337acd 100644 --- a/lib/vauth/ntlm.c +++ b/lib/vauth/ntlm.c @@ -35,7 +35,7 @@ #define DEBUG_ME 0 -#include "../urldata.h" +#include "vauth.h" #include "../sendf.h" #include "../curl_ntlm_core.h" #include "../curl_gethostname.h" @@ -44,8 +44,6 @@ #include "../rand.h" #include "../vtls/vtls.h" #include "../strdup.h" - -#include "vauth.h" #include "../curl_endian.h" /* NTLM buffer fixed size, large enough for long user + host + domain */ diff --git a/lib/vauth/ntlm_sspi.c b/lib/vauth/ntlm_sspi.c index bab319671c48..561de27dc36c 100644 --- a/lib/vauth/ntlm_sspi.c +++ b/lib/vauth/ntlm_sspi.c @@ -29,7 +29,6 @@ #include #include "vauth.h" -#include "../urldata.h" #include "../curl_ntlm_core.h" #include "../curlx/warnless.h" #include "../curlx/multibyte.h" diff --git a/lib/vauth/oauth2.c b/lib/vauth/oauth2.c index 3b4d4164f094..c9122debffa9 100644 --- a/lib/vauth/oauth2.c +++ b/lib/vauth/oauth2.c @@ -31,7 +31,6 @@ (!defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP)) #include -#include "../urldata.h" #include "vauth.h" #include "../curlx/warnless.h" diff --git a/lib/vauth/spnego_gssapi.c b/lib/vauth/spnego_gssapi.c index f956f2c03e81..3a24e8860a80 100644 --- a/lib/vauth/spnego_gssapi.c +++ b/lib/vauth/spnego_gssapi.c @@ -31,7 +31,6 @@ #include #include "vauth.h" -#include "../urldata.h" #include "../curlx/base64.h" #include "../curl_gssapi.h" #include "../curlx/warnless.h" @@ -92,7 +91,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER; gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER; gss_channel_bindings_t chan_bindings = GSS_C_NO_CHANNEL_BINDINGS; -#ifdef CURL_GSSAPI_HAS_CHANNEL_BINDING +#ifdef GSS_C_CHANNEL_BOUND_FLAG struct gss_channel_bindings_struct chan; #endif @@ -155,7 +154,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, } /* Set channel binding data if available */ -#ifdef CURL_GSSAPI_HAS_CHANNEL_BINDING +#ifdef GSS_C_CHANNEL_BOUND_FLAG if(curlx_dyn_len(&nego->channel_binding_data)) { memset(&chan, 0, sizeof(struct gss_channel_bindings_struct)); chan.application_data.length = curlx_dyn_len(&nego->channel_binding_data); diff --git a/lib/vauth/spnego_sspi.c b/lib/vauth/spnego_sspi.c index 2b0504f630f8..2a6548b6d4d9 100644 --- a/lib/vauth/spnego_sspi.c +++ b/lib/vauth/spnego_sspi.c @@ -31,7 +31,6 @@ #include #include "vauth.h" -#include "../urldata.h" #include "../curlx/base64.h" #include "../curlx/warnless.h" #include "../curlx/multibyte.h" diff --git a/lib/vauth/vauth.c b/lib/vauth/vauth.c index 4ca6cef7c8fe..9b87bd2c6757 100644 --- a/lib/vauth/vauth.c +++ b/lib/vauth/vauth.c @@ -28,7 +28,6 @@ #include "vauth.h" #include "../strdup.h" -#include "../urldata.h" #include "../curlx/multibyte.h" #include "../url.h" diff --git a/lib/vauth/vauth.h b/lib/vauth/vauth.h index 51b9f41c1b04..4c98d9b1c11c 100644 --- a/lib/vauth/vauth.h +++ b/lib/vauth/vauth.h @@ -28,6 +28,7 @@ #include "../bufref.h" #include "../curlx/dynbuf.h" +#include "../urldata.h" struct Curl_easy; struct connectdata; @@ -233,18 +234,6 @@ CURLcode Curl_auth_create_xoauth_bearer_message(const char *user, #ifdef USE_KERBEROS5 -#ifdef HAVE_GSSAPI -# ifdef HAVE_GSSGNU -# include -# else -# ifdef HAVE_GSSAPI_H -# include -# else -# include -# endif -# endif -#endif - /* meta key for storing KRB5 meta at connection */ #define CURL_META_KRB5_CONN "meta:auth:krb5:conn" @@ -310,7 +299,7 @@ struct negotiatedata { gss_ctx_id_t context; gss_name_t spn; gss_buffer_desc output_token; -#ifdef CURL_GSSAPI_HAS_CHANNEL_BINDING +#ifdef GSS_C_CHANNEL_BOUND_FLAG struct dynbuf channel_binding_data; #endif #else diff --git a/lib/version.c b/lib/version.c index f02b92fedfc7..49c15ffcdec9 100644 --- a/lib/version.c +++ b/lib/version.c @@ -77,18 +77,6 @@ #include #endif -#ifdef HAVE_GSSAPI -# ifdef HAVE_GSSGNU -# include -# else -# ifdef HAVE_GSSAPI_H -# include -# else -# include -# endif -# endif -#endif - #ifdef USE_OPENLDAP #include #endif