From 4f0e530c77641fdec9719399001c2318160a87ce Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 31 Jul 2025 08:37:13 +0200 Subject: [PATCH] tidy-up: formatting Closes #18373 --- docs/examples/block_ip.c | 4 +- lib/curl_setup.h | 2 +- lib/socks.c | 2 +- lib/vtls/openssl.c | 94 +++++++++++++++++----------------------- lib/vtls/schannel.c | 8 ++-- src/tool_doswin.c | 12 ++--- tests/CMakeLists.txt | 4 +- tests/devtest.pl | 6 +-- tests/ech_tests.sh | 18 +++----- tests/globalconfig.pm | 4 +- tests/testutil.pm | 2 +- 11 files changed, 68 insertions(+), 88 deletions(-) diff --git a/docs/examples/block_ip.c b/docs/examples/block_ip.c index a6609d3428..181cd8270d 100644 --- a/docs/examples/block_ip.c +++ b/docs/examples/block_ip.c @@ -254,7 +254,7 @@ static curl_socket_t opensocket(void *clientp, struct connection_filter *filter = (struct connection_filter *)clientp; #ifdef AF_INET6 int mapped = !filter->ipv6_v6only && - is_ipv4_mapped_ipv6_address(address->family, cinaddr); + is_ipv4_mapped_ipv6_address(address->family, cinaddr); #endif for(ip = filter->list; ip; ip = ip->next) { @@ -281,7 +281,7 @@ static curl_socket_t opensocket(void *clientp, char buf[128] = {0}; inet_ntop(address->family, cinaddr, buf, sizeof(buf)); fprintf(stderr, - "* Rejecting IP %s due to missing whitelist entry.\n", buf); + "* Rejecting IP %s due to missing whitelist entry.\n", buf); } return CURL_SOCKET_BAD; } diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 0a6591db83..12108e6df1 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -385,7 +385,7 @@ * performing this task will result in a synthesized IPv6 address. */ #if defined(__APPLE__) && !defined(USE_ARES) -#define USE_RESOLVE_ON_IPS 1 +# define USE_RESOLVE_ON_IPS 1 # if TARGET_OS_MAC && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && \ defined(USE_IPV6) # define CURL_MACOS_CALL_COPYPROXIES 1 diff --git a/lib/socks.c b/lib/socks.c index 8084489c98..fc6c9730f8 100644 --- a/lib/socks.c +++ b/lib/socks.c @@ -1006,7 +1006,7 @@ CONNECT_REQ_SEND: ATYP: o IP v4 address: X'01', BND.ADDR = 4 byte - o domain name: X'03', BND.ADDR = [ 1 byte length, string ] + o domain name: X'03', BND.ADDR = [ 1 byte length, string ] o IP v6 address: X'04', BND.ADDR = 16 byte */ diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index a3e3c29cf5..53bd5199d3 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -104,12 +104,12 @@ #endif #ifdef LIBRESSL_VERSION_NUMBER -# /* As of LibreSSL 2.0.0-4.0.0: OPENSSL_VERSION_NUMBER == 0x20000000L */ -# if LIBRESSL_VERSION_NUMBER < 0x2090100fL /* 2019-04-13 */ -# error "LibreSSL 2.9.1 or later required" -# endif +/* As of LibreSSL 2.0.0-4.0.0: OPENSSL_VERSION_NUMBER == 0x20000000L */ +# if LIBRESSL_VERSION_NUMBER < 0x2090100fL /* 2019-04-13 */ +# error "LibreSSL 2.9.1 or later required" +# endif #elif OPENSSL_VERSION_NUMBER < 0x1000201fL /* 2015-03-19 */ -# error "OpenSSL 1.0.2a or later required" +# error "OpenSSL 1.0.2a or later required" #endif #if defined(HAVE_OPENSSL3) && !defined(OPENSSL_NO_UI_CONSOLE) @@ -121,10 +121,9 @@ static void ossl_provider_cleanup(struct Curl_easy *data); #endif -#if (OPENSSL_VERSION_NUMBER >= 0x10100000L && \ - !defined(LIBRESSL_VERSION_NUMBER) && \ - !defined(OPENSSL_IS_BORINGSSL)) - #define HAVE_SSL_CTX_SET_DEFAULT_READ_BUFFER_LEN 1 +#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \ + !defined(LIBRESSL_VERSION_NUMBER) && !defined(OPENSSL_IS_BORINGSSL) +#define HAVE_SSL_CTX_SET_DEFAULT_READ_BUFFER_LEN 1 #endif #include "../curlx/warnless.h" @@ -185,10 +184,10 @@ static void ossl_provider_cleanup(struct Curl_easy *data); (defined(LIBRESSL_VERSION_NUMBER) && \ LIBRESSL_VERSION_NUMBER >= 0x3040100fL)) && \ !defined(OPENSSL_IS_BORINGSSL) - #define HAVE_SSL_CTX_SET_CIPHERSUITES - #ifndef OPENSSL_IS_AWSLC - #define HAVE_SSL_CTX_SET_POST_HANDSHAKE_AUTH - #endif +# define HAVE_SSL_CTX_SET_CIPHERSUITES +# ifndef OPENSSL_IS_AWSLC +# define HAVE_SSL_CTX_SET_POST_HANDSHAKE_AUTH +# endif #endif /* Whether SSL_CTX_set1_sigalgs_list is available @@ -196,9 +195,8 @@ static void ossl_provider_cleanup(struct Curl_easy *data); * BoringSSL: supported since 0.20240913.0 (commit 826ce15) * LibreSSL: no */ -#if (OPENSSL_VERSION_NUMBER >= 0x10002000L && \ - !defined(LIBRESSL_VERSION_NUMBER)) - #define HAVE_SSL_CTX_SET1_SIGALGS +#if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(LIBRESSL_VERSION_NUMBER) +#define HAVE_SSL_CTX_SET1_SIGALGS #endif #ifdef LIBRESSL_VERSION_NUMBER @@ -207,8 +205,8 @@ 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) && \ - !defined(OPENSSL_QUIC_API2)) +#elif defined(USE_NGTCP2) && defined(USE_NGHTTP3) && \ + !defined(OPENSSL_QUIC_API2) #define OSSL_PACKAGE "quictls" #else #define OSSL_PACKAGE "OpenSSL" @@ -223,7 +221,7 @@ typedef unsigned long sslerr_t; #endif #define ossl_valsize_t numcert_t -#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) +#if OPENSSL_VERSION_NUMBER >= 0x10100000L /* up2date versions of OpenSSL maintain reasonably secure defaults without * breaking compatibility, so it is better not to override the defaults in curl */ @@ -242,7 +240,7 @@ typedef unsigned long sslerr_t; #endif #endif -#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) +#if OPENSSL_VERSION_NUMBER >= 0x10100000L #define HAVE_RANDOM_INIT_BY_DEFAULT 1 #endif @@ -251,7 +249,7 @@ typedef unsigned long sslerr_t; * X509_STORE between connections. The API is: * * `X509_STORE_up_ref` -- Introduced: OpenSSL 1.1.0. */ -#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) /* OpenSSL >= 1.1.0 */ +#if OPENSSL_VERSION_NUMBER >= 0x10100000L /* OpenSSL >= 1.1.0 */ #define HAVE_SSL_X509_STORE_SHARE #endif @@ -322,8 +320,7 @@ static CURLcode X509V3_ext(struct Curl_easy *data, { int i; CURLcode result = CURLE_OK; -#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \ - !defined(LIBRESSL_VERSION_NUMBER) +#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) const STACK_OF(X509_EXTENSION) *exts = extsarg; #else STACK_OF(X509_EXTENSION) *exts = CURL_UNCONST(extsarg); @@ -1255,8 +1252,7 @@ static int enginecheck(struct Curl_easy *data, UI_METHOD *ui_method = UI_create_method(OSSL_UI_METHOD_CAST("curl user interface")); if(!ui_method) { - failf(data, "unable do create " OSSL_PACKAGE - " user-interface method"); + failf(data, "unable do create " OSSL_PACKAGE " user-interface method"); return 0; } UI_method_set_opener(ui_method, UI_method_get_opener(UI_OpenSSL())); @@ -1318,8 +1314,7 @@ static int providercheck(struct Curl_easy *data, UI_METHOD *ui_method = UI_create_method(OSSL_UI_METHOD_CAST("curl user interface")); if(!ui_method) { - failf(data, "unable do create " OSSL_PACKAGE - " user-interface method"); + failf(data, "unable do create " OSSL_PACKAGE " user-interface method"); return 0; } UI_method_set_opener(ui_method, UI_method_get_opener(UI_OpenSSL())); @@ -1547,8 +1542,7 @@ static int pkcs12load(struct Curl_easy *data, 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", + "BIO_new_mem_buf NULL, " OSSL_PACKAGE " error %s", ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer)) ); return 0; @@ -1558,8 +1552,7 @@ static int pkcs12load(struct Curl_easy *data, cert_bio = BIO_new(BIO_s_file()); if(!cert_bio) { failf(data, - "BIO_new return NULL, " OSSL_PACKAGE - " error %s", + "BIO_new return NULL, " OSSL_PACKAGE " error %s", ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer)) ); return 0; @@ -2872,7 +2865,7 @@ static void ossl_trace(int direction, int ssl_ver, int content_type, # define HAS_ALPN_OPENSSL #endif -#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) /* 1.1.0 */ +#if OPENSSL_VERSION_NUMBER >= 0x10100000L /* 1.1.0 */ static CURLcode ossl_set_ssl_version_min_max(struct Curl_cfilter *cf, SSL_CTX *ctx) { @@ -2970,7 +2963,7 @@ typedef unsigned long ctx_option_t; typedef long ctx_option_t; #endif -#if (OPENSSL_VERSION_NUMBER < 0x10100000L) /* 1.1.0 */ +#if OPENSSL_VERSION_NUMBER < 0x10100000L /* 1.1.0 */ static CURLcode ossl_set_ssl_version_min_max_legacy(ctx_option_t *ctx_options, struct Curl_cfilter *cf, @@ -3923,7 +3916,7 @@ static CURLcode ossl_init_ssl(struct ossl_ctx *octx, if(result) return result; } -#endif /* USE_ECH_OPENSSL */ +#endif /* USE_ECH_OPENSSL */ return ossl_init_session_and_alpns(octx, cf, data, peer, alpns_requested, sess_reuse_cb); @@ -3951,11 +3944,11 @@ static CURLcode ossl_init_method(struct Curl_cfilter *cf, case CURL_SSLVERSION_TLSv1_2: case CURL_SSLVERSION_TLSv1_3: /* it will be handled later with the context options */ - #if (OPENSSL_VERSION_NUMBER >= 0x10100000L) +#if OPENSSL_VERSION_NUMBER >= 0x10100000L *pmethod = TLS_client_method(); - #else +#else *pmethod = SSLv23_client_method(); - #endif +#endif break; case CURL_SSLVERSION_SSLv2: failf(data, "No SSLv2 support"); @@ -4118,7 +4111,7 @@ CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx, ctx_options |= SSL_OP_NO_SSLv2; ctx_options |= SSL_OP_NO_SSLv3; -#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) /* 1.1.0 */ +#if OPENSSL_VERSION_NUMBER >= 0x10100000L /* 1.1.0 */ result = ossl_set_ssl_version_min_max(cf, octx->ssl_ctx); #else result = ossl_set_ssl_version_min_max_legacy(&ctx_options, cf, data); @@ -4338,7 +4331,7 @@ void Curl_ossl_report_handshake(struct Curl_easy *data, #ifdef HAVE_OPENSSL3 SSL_get_peer_signature_type_nid(octx->ssl, &psigtype_nid); -#if (OPENSSL_VERSION_NUMBER >= 0x30200000L) +#if OPENSSL_VERSION_NUMBER >= 0x30200000L negotiated_group_name = SSL_get0_group_name(octx->ssl); #else negotiated_group_name = @@ -4629,8 +4622,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, connssl->connecting_state = ssl_connect_3; Curl_ossl_report_handshake(data, octx); -#ifdef USE_ECH_OPENSSL -# ifndef HAVE_BORINGSSL_LIKE +#if defined(USE_ECH_OPENSSL) && !defined(HAVE_BORINGSSL_LIKE) if(ECH_ENABLED(data)) { char *inner = NULL, *outer = NULL; const char *status = NULL; @@ -4688,8 +4680,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, else { infof(data, "ECH: result: status is not attempted"); } -# endif /* !HAVE_BORINGSSL_LIKE */ -#endif /* USE_ECH_OPENSSL */ +#endif /* USE_ECH_OPENSSL && !HAVE_BORINGSSL_LIKE */ #ifdef HAS_ALPN_OPENSSL /* Sets data and len to negotiated protocol, len is 0 if no protocol was @@ -4766,7 +4757,7 @@ static CURLcode ossl_pkp_pin_peer_pubkey(struct Curl_easy *data, X509* cert, return result; } -#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && \ +#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \ !(defined(LIBRESSL_VERSION_NUMBER) && \ LIBRESSL_VERSION_NUMBER < 0x3060000fL) && \ !defined(HAVE_BORINGSSL_LIKE) && !defined(CURL_DISABLE_VERBOSE_STRINGS) @@ -4859,8 +4850,7 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, if(!mem) { failf(data, - "BIO_new return NULL, " OSSL_PACKAGE - " error %s", + "BIO_new return NULL, " OSSL_PACKAGE " error %s", ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer)) ); return CURLE_OUT_OF_MEMORY; @@ -4936,8 +4926,7 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, (int)conn_config->issuercert_blob->len); if(!fp) { failf(data, - "BIO_new_mem_buf NULL, " OSSL_PACKAGE - " error %s", + "BIO_new_mem_buf NULL, " OSSL_PACKAGE " error %s", ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer)) ); X509_free(octx->server_cert); @@ -4949,8 +4938,7 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, fp = BIO_new(BIO_s_file()); if(!fp) { failf(data, - "BIO_new return NULL, " OSSL_PACKAGE - " error %s", + "BIO_new return NULL, " OSSL_PACKAGE " error %s", ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer)) ); X509_free(octx->server_cert); @@ -5558,15 +5546,13 @@ size_t Curl_ossl_version(char *buffer, size_t size) #elif defined(OPENSSL_IS_BORINGSSL) #ifdef CURL_BORINGSSL_VERSION return msnprintf(buffer, size, "%s/%s", - OSSL_PACKAGE, - CURL_BORINGSSL_VERSION); + OSSL_PACKAGE, CURL_BORINGSSL_VERSION); #else return msnprintf(buffer, size, OSSL_PACKAGE); #endif #elif defined(OPENSSL_IS_AWSLC) return msnprintf(buffer, size, "%s/%s", - OSSL_PACKAGE, - AWSLC_VERSION_NUMBER_STRING); + OSSL_PACKAGE, AWSLC_VERSION_NUMBER_STRING); #elif defined(OPENSSL_VERSION_STRING) /* OpenSSL 3+ */ return msnprintf(buffer, size, "%s/%s", OSSL_PACKAGE, OpenSSL_version(OPENSSL_VERSION_STRING)); diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c index 4fd424a43c..7fb4cb1fde 100644 --- a/lib/vtls/schannel.c +++ b/lib/vtls/schannel.c @@ -1184,8 +1184,8 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) if(doread) { /* read encrypted handshake data from socket */ result = Curl_conn_cf_recv(cf->next, data, - (char *) (backend->encdata_buffer + - backend->encdata_offset), + (char *)(backend->encdata_buffer + + backend->encdata_offset), backend->encdata_length - backend->encdata_offset, &nread); @@ -1715,7 +1715,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 *)malloc(data_len); if(!ptr) { return CURLE_OUT_OF_MEMORY; } @@ -1736,7 +1736,7 @@ schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, /* https://msdn.microsoft.com/en-us/library/windows/desktop/aa375390.aspx */ sspi_status = Curl_pSecFn->EncryptMessage(&backend->ctxt->ctxt_handle, 0, - &outbuf_desc, 0); + &outbuf_desc, 0); /* check if the message was encrypted */ if(sspi_status == SEC_E_OK) { diff --git a/src/tool_doswin.c b/src/tool_doswin.c index 23233bc2d1..bff8573d7c 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -765,7 +765,7 @@ static DWORD WINAPI win_stdin_thread_func(void *thread_data) int clientAddrLen = sizeof(clientAddr); curl_socket_t socket_w = accept(tdata->socket_l, (SOCKADDR*)&clientAddr, - &clientAddrLen); + &clientAddrLen); if(socket_w == CURL_SOCKET_BAD) { errorf("accept error: %08lx", GetLastError()); @@ -919,11 +919,11 @@ curl_socket_t win32_stdin_read_thread(void) if(rc != 1) { if(socket_r != CURL_SOCKET_BAD && tdata) { if(GetStdHandle(STD_INPUT_HANDLE) == (HANDLE)socket_r && - tdata->stdin_handle) { - /* restore STDIN */ - SetStdHandle(STD_INPUT_HANDLE, tdata->stdin_handle); - tdata->stdin_handle = NULL; - } + tdata->stdin_handle) { + /* restore STDIN */ + SetStdHandle(STD_INPUT_HANDLE, tdata->stdin_handle); + tdata->stdin_handle = NULL; + } sclose(socket_r); socket_r = CURL_SOCKET_BAD; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 657d9fe09a..8bfca21ca6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -74,8 +74,8 @@ function(curl_add_runtests _targetname _test_flags) COMMAND ${_setenv} "${PERL_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/runtests.pl" - ${_test_flags_list} - "\$TFLAGS" + ${_test_flags_list} + "\$TFLAGS" DEPENDS "${_depends}" VERBATIM USES_TERMINAL ) diff --git a/tests/devtest.pl b/tests/devtest.pl index 168e00ec94..0bfc71b07a 100755 --- a/tests/devtest.pl +++ b/tests/devtest.pl @@ -54,14 +54,14 @@ use servers qw( protoport serverfortest stopservers -); + ); use runner qw( readtestkeywords singletest_preprocess -); + ); use testutil qw( setlogfunc -); + ); use getpart; diff --git a/tests/ech_tests.sh b/tests/ech_tests.sh index 9912929ff3..9123bbc096 100755 --- a/tests/ech_tests.sh +++ b/tests/ech_tests.sh @@ -120,18 +120,15 @@ declare -A neither_targets=( DEFPORT=443 -function whenisitagain() -{ +function whenisitagain() { /bin/date -u +%Y%m%d-%H%M%S } -function fileage() -{ +function fileage() { echo $(($(date +%s) - $(date +%s -r "$1"))) } -function hostport2host() -{ +function hostport2host() { case $1 in *:*) host=${1%:*} port=${1##*:};; *) host=$1 port=$DEFPORT;; @@ -139,8 +136,7 @@ function hostport2host() echo "$host" } -function hostport2port() -{ +function hostport2port() { case $1 in *:*) host=${1%:*} port=${1##*:};; *) host=$1 port=$DEFPORT;; @@ -148,8 +144,7 @@ function hostport2port() echo "$port" } -function cli_test() -{ +function cli_test() { # 1st param is target URL turl=$1 # 2nd param is 0 if we expect curl to not work or 1 if we expect it @@ -191,8 +186,7 @@ function cli_test() rm -f "$TMPF" } -function get_ech_configlist() -{ +function get_ech_configlist() { domain=$1 ecl=$(dig +short https "$domain" | grep "ech=" | sed -e 's/^.*ech=//' | sed -e 's/ .*//') echo "$ecl" diff --git a/tests/globalconfig.pm b/tests/globalconfig.pm index 6ea605a219..de9abab34c 100644 --- a/tests/globalconfig.pm +++ b/tests/globalconfig.pm @@ -78,11 +78,11 @@ BEGIN { use pathhelp qw( exe_ext dirsepadd -); + ); use Cwd qw(getcwd); use testutil qw( shell_quote -); + ); use File::Spec; diff --git a/tests/testutil.pm b/tests/testutil.pm index d1cf0c6b34..e84cc45fde 100644 --- a/tests/testutil.pm +++ b/tests/testutil.pm @@ -58,7 +58,7 @@ use globalconfig qw( $torture $verbose $dev_null -); + ); my $logfunc; # optional reference to function for logging my @logmessages; # array holding logged messages -- 2.47.3