Commit Graph

35949 Commits

Author SHA1 Message Date
Stefan Eissing
0b40db0489
libssh2: fix freeing of resources in disconnect
ssh's disconnect assumed that the session to the server could be shut
down successfully during disconnect. When this failed, e.g. timed out,
memory was leaked.

Closes #16656
2025-03-10 22:52:42 +01:00
Viktor Szakats
f4e23950c7
build: enable -Wcast-qual, fix or silence compiler warnings
The issues found fell into these categories, with the applied fixes:

- const was accidentally stripped.
  Adjust code to not cast or cast with const.

- const/volatile missing from arguments, local variables.
  Constify arguments or variables, adjust/delete casts. Small code
  changes in a few places.

- const must be stripped because an API dependency requires it.
  Strip `const` with `CURL_UNCONST()` macro to silence the warning out
  of our control. These happen at API boundaries. Sometimes they depend
  on dependency version, which this patch handles as necessary. Also
  enable const support for the zlib API, using `ZLIB_CONST`. Supported
  by zlib 1.2.5.2 and newer.

- const must be stripped because a curl API requires it.
  Strip `const` with `CURL_UNCONST()` macro to silence the warning out
  of our immediate control. For example we promise to send a non-const
  argument to a callback, though the data is const internally.

- other cases where we may avoid const stripping by code changes.
  Also silenced with `CURL_UNCONST()`.

- there are 3 places where `CURL_UNCONST()` is cast again to const.
  To silence this type of warning:
  ```
  lib/vquic/curl_osslq.c:1015:29: error: to be safe all intermediate
    pointers in cast from 'unsigned char **' to 'const unsigned char **'
    must be 'const' qualified [-Werror=cast-qual]
  lib/cf-socket.c:734:32: error: to be safe all intermediate pointers in
    cast from 'char **' to 'const char **' must be 'const' qualified
    [-Werror=cast-qual]
  ```
  There may be a better solution, but I couldn't find it.

These cases are handled in separate subcommits, but without further
markup.

If you see a `-Wcast-qual` warning in curl, we appreciate your report
about it.

Closes #16142
2025-03-10 22:30:15 +01:00
Viktor Szakats
8b1b5cd4d2
DISABLED: add 313 for sectransp (move from GHA/macos)
Closes #16660
2025-03-10 20:58:06 +01:00
Viktor Szakats
57218d5327
tidy-up: replace Curl_safefree with free before re-assignment
Also drop `NULL` assignments after `Curl_safefree()`.

Closes #16640
2025-03-10 20:58:05 +01:00
Jay Satiro
9b523773b8 libssh: fix scp large file upload for 32-bit size_t systems
- Use ssh_scp_push_file64 instead of ssh_scp_push_file.

The former uses uint64_t for file size and the latter uses size_t which
may be 32-bit.

Ref: https://github.com/curl/curl/pull/16194

Closes https://github.com/curl/curl/pull/16641
2025-03-10 13:20:19 -04:00
Daniel Stenberg
19d6415273
urlapi: treat 0 alone as decimal number in IPv4 address
Not as a broken octcal. Regression from b4538ec522

Extended test 1560 to verify this behavior.

Reported-by: Carlos Henrique Lima Melara

Closes #16652
2025-03-10 17:10:23 +01:00
Viktor Szakats
bad5e71331
tidy-up: whitespace, tests/server Makefile.inc, timeval in VS project
- VS projects: drop unused `timediff`.
  (used by curltool library, but this build method doesn't build that.)
- tests/server/sws: reflow an `if` for greppability.
- tests/server/Makefile.inc: indent, format
- tests/server/Makefile.inc: merge `USEFUL` and `UTIL` lists.

Closes #16651
2025-03-10 14:19:49 +01:00
Daniel Stenberg
75acda70aa
hostip: don't use alarm() for DoH resolves
When built to use the synch resolver and DoH is used for a transfer, do
not use alarm() for timeout since DoH resolving is not blocking.

Closes #16649
2025-03-10 13:17:18 +01:00
Daniel Stenberg
3c2948e0a6
lib: clear up CURLRES_ASYNCH vs USE_CURL_ASYNC use
CURLRES_ASYNCH - is for when built to use an async name resolver; threaded or
c-ares

USE_CURL_ASYNC - is for when built to use either an async name resolver OR DoH

Reported-by: Lars Karlitski
Fixes #16645
Closes #16648
2025-03-10 13:15:20 +01:00
Daniel Stenberg
aa8d1d648e
socks: remove bad assert from do_SOCKS5()
It verified the auth bits wrongly. We don't need this assert anymore
since the input is verified in *setopt().

Bug: https://issues.oss-fuzz.com/issues/401869346

Closes #16650
2025-03-10 13:13:59 +01:00
Daniel Stenberg
06ae0eceb9
STRPARSE: amend with recently added functions
Closes #16647
2025-03-10 12:18:48 +01:00
Daniel Stenberg
09a5b2f2de
lib: rename curlx_strtoofft to Curl_str_numblanks()
The function is no longer used via the curlx shortcut.

Remove the strtoofft.[ch] files.

Closes #16642
2025-03-10 10:39:20 +01:00
Christian Schmitz
fc04eca8f8
easy: fix warning about possible comma misuse
Closes #16644
2025-03-10 10:38:04 +01:00
Daniel Stenberg
5fdf30b4dd
configure: call the blocking resolver "blocking", not "default"
On most systems the default is actually the threaded resolver.

Closes #16646
2025-03-10 10:34:28 +01:00
Daniel Stenberg
f8e7a4df94
mprintf: switch three number parsers to use strparse
Also add more const char pointers and reduced the scope for some
variables.

Closes #16628
2025-03-10 09:01:04 +01:00
Daniel Stenberg
8dca3b0656
src: replace strto[u][ld] with curlx_str_ parsers
- Better error handling (no errno mess), better limit checks.

- Also removed all uses of curlx_strtoofft()

Closes #16634
2025-03-10 08:09:41 +01:00
Viktor Szakats
f3b599a7e2
GHA/windows: enable H3 in GnuTLS MinGW job
Closes #16635
2025-03-10 01:13:17 +01:00
Viktor Szakats
30739b4d36
libssh2: fix memory leak in SSH_SFTP_REALPATH state
Seen in MSVC libssh2 CI job:
```
test 0615...[SFTP put remote failure]
test 0616...[SFTP retrieval of empty file]
test 0618...[SFTP retrieval of two files]
test 0620...[SFTP retrieval of missing file followed by good file]
test 0622...[SFTP put failure]
test 0637...[SFTP retrieval with invalid X- range]
test 0640...[SFTP --head retrieval]
  ** MEMORY FAILURE
  Leak detected: memory still allocated: 22 bytes
  At 2ae5b8a7ab8, there's 22 bytes.
   allocated by D:/a/curl/curl/lib/vssh/libssh2.c:2006
```
https://github.com/curl/curl/actions/runs/13752652590/job/38455575042?pr=16636#step:14:3907
https://github.com/curl/curl/actions/runs/13752879003/job/38456075461
https://github.com/curl/curl/actions/runs/13753706458/job/38457888479

Bug: https://github.com/curl/curl/pull/16636#issuecomment-2709086838
Co-authored-by: Daniel Stenberg

Closes #16639
2025-03-10 01:13:05 +01:00
Viktor Szakats
61d30615e4
runtests: fix SSH server not starting in cases, re-ignore failing vcpkg CI jobs
Replace `Cwd::abs_path()` with `File::Spec->rel2abs()`. The former
requires the file to exist, but in some cases, it's missing.

Seen in MSVC vcpkg jobs using Chocolatey OpenSSH v8.0.0.1 ending up with
`$path=/d/a/curl/curl/bld/tests/log/3/server/ssh_server.pid`, which does
not exist while converting to an absolute path (the path is already
absolute, but the conversion is done unconditionally):
```
Use of uninitialized value in subroutine entry at D:/a/curl/curl/tests/pathhelp.pm line 128.
can't convert empty path at D:/a/curl/curl/tests/pathhelp.pm line 128.
```
Ref: https://github.com/curl/curl/actions/runs/13747741797/job/38444844173#step:14:1233 (master)
Ref: https://github.com/curl/curl/actions/runs/13751862952/job/38453816737#step:14:3185 (trace)

Also ignore 3 new libssh2 jobs failing due to memleak.

Partial revert of 1bd5ac998b #16570

Closes #16636
2025-03-09 23:28:07 +01:00
Viktor Szakats
5681628e2d
tests/server: sync wait_ms() with the libcurl implementation
It contains a series of bugfixes and updates applied to libcurl's
`Curl_wait_ms()` over the years, but missed from the copy in
`tests/server/util.c`:
- d65321f939,
  52e822173a,
  5912da253b
- 4a8f459837
- 1ad49feb71

It fixes `wait_ms()` to check for, and return `SOCKERRNO`. Fixing error
handling on Windows.

Also:
- tests/server: change callers to check `SOCKERRNO`.
- `wait_ms()`: fix to check for the correct error code on Windows.
  Pending for `Curl_wait_ms()`: #16621.
- `Curl_wait_ms()`: tidy-up `Sleep()` argument cast (nit).
- lib/curl_trc: drop an unused header.

Closes #16627
2025-03-09 12:04:30 +01:00
Samuel Henrique
454762d5ca
tests/servers.pm: remove unused variable 'portrange'
Its usage was dropped at 4efa0b5749
(https://github.com/curl/curl/pull/11220)

Grepping the tests folder for "portrange" returns only this as a result.

Closes #16632
2025-03-09 11:56:00 +01:00
Viktor Szakats
7e282e18a5
lib2302: fix crash due to stack overflow on MSVC and clang Windows
It fixes test 2302, 2303, 2307 with MSVC and clang on Windows.
GCC Windows builds were not affected.

Failure was caused by stack overflow due to a 1MB+ sized test struct on
stack. Replace it with dynamic allocation.

Also unignore affected tests in GHA/windows.

As seen under WINE with llvm-mingw:
```
$ wine64 libtests.exe lib2302 ws://127.0.0.1:59964/2302 > stdout2302 2> stderr2302
Test: lib2302
URL: ws://127.0.0.1:59964/2302
wine: Unhandled stack overflow at address 000000014007486A (thread 0024), starting debugger...
Unhandled exception: stack overflow in 64-bit code (0x000000014007486a).
```

Ref: #16629 (discovery)
Ref: 1bd5ac998b #16570

Closes #16630
2025-03-09 11:53:12 +01:00
Viktor Szakats
66313cc036
GHA/windows: add GnuTLS job, drop default OpenSSL for Cygwin/MSYS2 jobs
To allow selecting the TLS backend(s) for each individual job.

Closes #16629
2025-03-09 03:30:42 +01:00
Viktor Szakats
e86f99824c
GHA/windows: re-add GnuTLS for vcpkg, improve perf by building examples less
The GnuTLS MSVC/vcpkg build doesn't actually work on Windows. Let's
restore the build itself, to keep it fit for more testing. With disabled
tests (and examples) to keep it fast and not add to flakiness.

Also:
- enable GnuTLS in the MultiSSL job.
- limit building examples to one normal and one UWP job. It saves
  6 x 1-1.5 minutes. Coverage remains the same, because example builds
  only depend on the toolchain / target, not on the actual features
  (except IPv6, but that's enabled for all.)

Closes #16623
2025-03-08 23:49:10 +01:00
Daniel Stenberg
74a2f2661d
RELEASE-NOTES: synced 2025-03-08 22:32:44 +01:00
Samuel Henrique
3c1a88fdf7
test1022: add support for rc releases
Fix the following test failure:
 curl-config: illegal value

Closes #16626
2025-03-08 22:15:34 +01:00
Viktor Szakats
2fc8f7a3f7
gtls: fix uninitialized variable
Fix uninitialized variable (warning by MSVC):
```
lib\vtls\gtls.c(1207,1): error C2220: the following warning is treated as an error
lib\vtls\gtls.c(1207,1): warning C4701: potentially uninitialized local variable 'result' used
```
Ref: https://github.com/curl/curl/actions/runs/13733139148/job/38413553053#step:9:31

Closes #16625
2025-03-08 13:24:24 +01:00
renovate[bot]
8f700cf5f9
GHA: update dependency cloudflare/quiche to v0.23.4
Closes #16618
2025-03-08 12:19:12 +01:00
Daniel Stenberg
124c2bed2a
RELEASE-PROCEDURE.md: explain release candidates
Closes #16622
2025-03-08 10:49:46 +01:00
Viktor Szakats
4bca9eb581
curl_setup_once: stop redefining ENAMETOOLONG to winsock2 error code
The only user is error display code following an `mkdir()` call. In this
case the redefinition didn't cause an issue, but was unnecessary.

Follow-up to d69425ed7d #16615
Closes #16620
2025-03-08 04:30:54 +01:00
Viktor Szakats
d69425ed7d
curl_setup_once: drop E* macro redefines unused (with winsock2)
These were not used in curl sources at all.

Except `EDQUOT` which was used after `mkdir()` in `src/tool_dirhie.c`
for error display. It should not be redefined to a winsock2 error.
This makes the "exceeded your quota" error correctly appear on Windows,
if detected, after operations that create directories.

After this patch there remain 14 `E*` macro redefines on Windows,
down from 40 before this patch.

Bug: https://github.com/curl/curl/pull/16553#issuecomment-2704679377
Ref: #16612
Ref: #16605
Closes #16615
2025-03-08 01:53:49 +01:00
Viktor Szakats
abf80aae38
tests/server: fix to check against winsock2 error codes on Windows
Windows's winsock2 returns socket errors via `WSAGetLastError()` and
not via `errno` like most systems out there. This was covered by
switching to the `SOCKERRNO` curl macro earlier. But, on Windows the
returned socket error codes have different values than the standard
POSIX errno values. Existing code was using the POSIX values for all
these checks. Meaning they never actually matched on Windows.

This patch defines a set of `SOCKERRNO` constants that map to the
correct socket error values for Windows and other platforms.

The reverse issue exists in core curl code, which redefines POSIX errno
values to winsock2 ones, breaking non-socket uses on Windows.

Cherry-picked from #15000
Follow-up to adcfd4fb3e #16553
Bug: https://github.com/curl/curl/pull/16553#issuecomment-2704679377

Closes #16612
2025-03-08 01:53:48 +01:00
Viktor Szakats
25f8486f26
zlib: bump minimum to 1.2.5.2 (was: 1.2.0.4)
1.2.5.2 was released on 2011-12-18. (vs. 1.2.0.4 on 2003-08-10)

It allows to:
- use `Z_BLOCK` unconditionally.
- use `inflateReset2()` to replace `inflateEnd()` + `inflateInit2()`
  and save a memory allocation.
- use `Z_CONST` and `z_const` (in a future commit).

Suggested-by: Dan Fandrich
Ref: https://github.com/curl/curl/pull/16142#discussion_r1985449743

Closes #16616
2025-03-08 00:39:04 +01:00
Stefan Eissing
646ffb591a
quiche: do not iterate over multi handles
Quiche needs to find easy handles to events. Do this by iterating
over the filters stream hash and lookup the easy handle on a match.

This O(+streams-in-filter) vs O(all easy handles), at least once
we fix the multi lookup to use a hash.

Closes #16607
2025-03-07 23:36:17 +01:00
Daniel Stenberg
906aa04d9b
tool_parsecfg: make my_get_line() skip empty and blanks-only lines
Closes #16613
2025-03-07 23:34:36 +01:00
Daniel Stenberg
36a831b868
setopt: illegal CURLOPT_SOCKS5_AUTH should return error
The check was just wrong before.

Regression introduced in 30da1f5974

Bug: https://issues.oss-fuzz.com/issues/401430844
Closes #16617
2025-03-07 23:32:31 +01:00
Viktor Szakats
27d24690a4
GHA/windows: msys/mingw improvements
- enable zstd in Cygwin and MSYS jobs.
- dl-mingw: use Ninja in the 9.5.0 (winlibs-mingw) job.
  The download package is shipping with it. Saves 15s build time.
  Keep testing GNU Makefiles with the two mingw-builds jobs.
- dl-mingw: split `env` prop to `env` and `ver` to aid integrating with
  MSYS2.
- dl-mingw: install MSYS2 with options to make it quick (<20s).
  It allows to use MSYS2 dependency packages with the downloaded
  toolchains. It also makes configuration cleaner. Install libpsl.
- dl-mingw: enable mbedTLS in the 7.3.0 job.
  (OpenSSL took a long time to install, wolfSSL misses features.)

Assisted-by: Jeremy Drake

Closes #16429
2025-03-07 15:54:59 +01:00
Viktor Szakats
a7c8d2f9bc
vtls: fix compiler warnings seen with gcc 7.3.0 and mbedTLS
Seen with downloaded mingw 7.3.0 when built against MSYS2 mbedTLS 3.6.2:
```
lib/vtls/cipher_suite.c: In function 'cs_zip_to_str':
lib/vtls/cipher_suite.c:789:16: error: conversion to 'uint8_t {aka unsigned char}' from 'int' may alter its value [-Werror=conversion]
   indexes[1] = ((zip[0] << 4) & 0x3F) | zip[1] >> 4;
                ^
lib/vtls/cipher_suite.c:790:16: error: conversion to 'uint8_t {aka unsigned char}' from 'int' may alter its value [-Werror=conversion]
   indexes[2] = ((zip[1] << 2) & 0x3F) | zip[2] >> 6;
                ^
lib/vtls/cipher_suite.c:793:16: error: conversion to 'uint8_t {aka unsigned char}' from 'int' may alter its value [-Werror=conversion]
   indexes[5] = ((zip[3] << 4) & 0x3F) | zip[4] >> 4;
                ^
lib/vtls/cipher_suite.c:794:16: error: conversion to 'uint8_t {aka unsigned char}' from 'int' may alter its value [-Werror=conversion]
   indexes[6] = ((zip[4] << 2) & 0x3F) | zip[5] >> 6;
                ^
```
Ref: https://github.com/curl/curl/actions/runs/13719756989/job/38372409927?pr=16429#step:10:21

Cherry-picked from #16429
Closes #16614
2025-03-07 15:43:00 +01:00
Stefan Eissing
469c037fcf
openssl-quic: do not iterate over multi handles
Iterate over the filters stream hash instead, lookup easy handles
at the multi when needed.

This also limits to pollset array sizes to the number of streams
on the connection and not the total number of transfers in the multi.

Closes #16611
2025-03-07 14:54:25 +01:00
Viktor Szakats
7cc4a23ee4
GHA/windows: ignore flaky 2310 with MSVC again
Follow-up to 1bd5ac998b #16570
2025-03-07 14:28:27 +01:00
Viktor Szakats
bc55b435af
tests/server: round of tidy-ups (part 2)
General tidy-ups, to identify and reduce duplications and potential
issues, while also making the server modules compile as a single binary.

- ensure unique symbols and no shadowing across server sources, by
  renaming variables.
- move globals common to multiple servers into shared `util` module.
- drop constants with a single use.
- undef macro before re-using them across server sources.
- move common functions into shared `util` module.
- drop redundant static declarations.
- disable IPv6 code when built without IPv6.
- start syncing the 3 almost identical copies of `sockdaemon` function.
- drop unused `timeval.h` header.
- drop `poll()` from `wait_ms()`, for macOS, following an earlier core
  update.
  Follow-up to c72cefea0f #15096

Follow-up to 9213e4e497 #16525
Cherry-picked from #15000
Closes #16609
2025-03-07 13:48:07 +01:00
Viktor Szakats
07f99b72d5
wolfssl: fix unused variable warning
E.g. when building against msys2-mingw wolfssl:
https://packages.msys2.org/base/mingw-w64-wolfssl

```
lib/vtls/wolfssl.c: In function 'wssl_verify_pinned':
lib/vtls/wolfssl.c:1534:20: error: unused variable 'wssl' [-Werror=unused-variable]
   struct wssl_ctx *wssl = (struct wssl_ctx *)connssl->backend;
                    ^~~~
```
Ref: https://github.com/curl/curl/actions/runs/13713131802/job/38353245932#step:10:78

Building with the MSYS2 wolfssl is broken due to further issues.

Closes #16608
2025-03-07 13:48:07 +01:00
Viktor Szakats
0ead361904
cmake: CURL_LIBDIRS improvements (upstreamed from vcpkg)
Apply downstream patches from the vcpkg project:

- cmake: remove duplicates from `CURL_LIBDIRS`.

- cmake: set `CURL_LIBDIRS` as `INTERFACE_LINK_DIRECTORIES` for static
  libcurl.
  To support CMake <3.13, change downstream patch from:
  ```cmake
  target_link_directories(${LIB_STATIC} INTERFACE ${CURL_LIBDIRS})
  ```
  to:
  ```cmake
  set_target_properties(${LIB_STATIC} PROPERTIES [...] INTERFACE_LINK_DIRECTORIES "${CURL_LIBDIRS}")
  ```

Co-authored-by: Kai Pastor
Ref: https://github.com/microsoft/vcpkg/pull/43819

Closes #16610
2025-03-07 13:48:07 +01:00
Viktor Szakats
3b501976a9
build: cmake multi-pkg-config detection improvements (brotli, ldap, mbedtls)
Apply downstream patch from the vcpkg project:

- cmake/FindBrotli: streamline detecting multiple pkg-config modules.
  Add `libbrotlicommon` to `Requires.private` in `libcurl.pc`.

Apply the above idea to the rest of multi-module dependencies:

- cmake/FindMbedTLS: streamline detecting multiple pkg-config modules
  Add `mbedx509`, `mbedcrypto` to `Requires.private` in `libcurl.pc`.

- cmake/FindLDAP: streamline detecting multiple pkg-config modules

And sync these changes with autotools, and add `libbrotlicommon`,
`mbedx509`, `mbedcrypto` to `Requires.private`.

Co-authored-by: Kai Pastor
Ref: https://github.com/microsoft/vcpkg/pull/43819

Closes #16479
2025-03-07 13:48:07 +01:00
Daniel Stenberg
f4831daa9b
url: call protocol handler's disconnect in Curl_conn_free
For the case when the connection struct is all setup, the protocol
handler allocates data in its setup_connection function, but the
connection struct is discarded again before used further because a
connection reuse is prefered. Then the handler's disconnect function was
not previously called, which then would lead to a memory leak.

I added test case 698 that reproduces the leak and the fix.

Reported-by: Philippe Antoine
Closes #16604
2025-03-07 11:16:24 +01:00
Stefan Eissing
0d1e43af8d
ngtcp2: do not iterate over multi handles
There was on place left iterating over `multi->process` list which was
unnecessary. Remove that.

Closes #16606
2025-03-07 11:14:37 +01:00
Daniel Stenberg
1503555836
src: cleanup ISBLANK vs ISSPACE
- use ISBLANK() where only spaces and tabs should match
- change while(x && ISBLANK(X)) => while(ISBLANK(x))

Closes #16589
2025-03-07 08:58:46 +01:00
Viktor Szakats
9147903366
GHA/macos: add initial pytest support
Add support for running pytest in GHA/macos jobs.

Experimental, with caveats:
- slow.
- `httpd` often fails to start.
- 10-15 tests (depending on C compiler) fail consistently:
  02_20, 02_33, 02_34, 03_01, 03_03, 05_04, 07_42.
- Homebrew build of vsftpd misses TLS support.
- `nghttpx` temporarily disabled for pytest.

You can test pytest by adding `install_steps: pytest` to a job.

Closes #16518
2025-03-07 02:19:28 +01:00
Daniel Stenberg
4e8d621bd8
setopt: setting PROXYUSERPWD after PROXYUSERNAME/PASSWORD is fine
Prevent the previous memory leak. Adjusted test 590 to reproduce the
problem then verify the fix.

Fixes #16599
Reported-by: Catena cyber
Closes #16601
2025-03-07 00:08:53 +01:00
Harry Sintonen
f1662ae97b
doh: improve HTTPS RR svcparams parsing
Fixed a heap read overflow when parsing the HTTP RR svcparams. Also the
code failed to enforce the requirements of SvcParamKey order specified
in section 2.2 of the RFC 9460.

Closes #16598
2025-03-07 00:06:17 +01:00