Commit graph

7799 commits

Author SHA1 Message Date
Viktor Szakats
69e8278149
servers: fix to reverse SA_RESTART option for sigaction() on modern codepath
Historically servers used the deprecated `siginterrupt()` function to
configure restart behavior on specific signals. It accepts a flag, where
1 means to remove the `SA_RESTART` option, and 0 means to enable it.

In year 2021 3fb6e5a010 introduced the
modern alternative to the codebase, replacing `siginterrupt()` with
`sigaction()`. After this patch, supporting, modern, systems reacted on
the same flag, but, by accident, set the `SA_RESTART` bit when flag is
1, and did not set it when 0. This reversed the previous behavior, and
the one still used on the `siginterrupt()` legacy codepath.

Fix it by revesring the `SA_RESTART` logic for the `sigaction()`
codepath, syncing it with the pre-existing behavior.

I find it odd this did not cause any perceivable issue for 5 years, even
though it's the active one in most Unix envs.

Spotted by GitHub Code Quality, though suggesting to fix
`siginterrupt()` calls. But looking into the history, those were correct
all along.

Refs:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/siginterrupt.html
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaction.html
https://www.man7.org/linux/man-pages/man3/siginterrupt.3.html
https://www.man7.org/linux/man-pages/man2/sigaction.2.html

Follow-up to 3fb6e5a010 #6529

Closes #22037
2026-08-04 17:36:14 +02:00
Daniel Stenberg
7acf124614
url: rename Curl_init_do => Curl_init_transfer
And correct some comments

Closes #22474
2026-08-04 09:08:53 +02:00
Daniel Stenberg
56457f838c
test557: test curl_mv*printf() functions
These functions were previously untested in the test suite. This is just
a set of basic invokes to make sure they work. The core of these
functions is identical and is tested already.

  - curl_mvfprintf
  - curl_mvprintf
  - curl_mvsnprintf
  - curl_mvsprintf
  - curl_mvaprintf

Closes #22472
2026-08-03 16:24:06 +02:00
Daniel Stenberg
1f860394e6
lib1560: add CURLU_NO_GUESS_SCHEME tests
Closes #22469
2026-08-03 14:00:11 +02:00
Daniel Stenberg
a2b178d378
tests: convert unit test 1396 and 1398 into libtests
They were previously unit tests but used only public library functions.

Closes #22471
2026-08-03 13:55:53 +02:00
Viktor Szakats
c59b06c99c
sshserver.pl: bump an sshd config to use its modern name
Ref: ee9c0da803

Closes #22460
2026-08-02 11:47:46 +02:00
dependabot[bot]
d2ea63b17c
GHA: bump GitHub Actions and pips
- update `actions/checkout` from 7.0.0 to 7.0.1
- update `actions/labeler` from 6.1.0 to 7.0.0
- update `github/codeql-action/analyze` from 4.36.2 to 4.37.3
- update `github/codeql-action/init` from 4.36.2 to 4.37.3

- update `cryptography` from 48.0.1 to 49.0.0
- update `filelock` from 3.29.0 to 3.32.0
- update `impacket` from 0.13.0 to 0.13.1
- update `pytest` from 9.0.3 to 9.1.1
- update `websockets` from 16.0 to 16.1.1

Closes #22458
Closes #22459
2026-08-02 00:02:10 +02:00
Daniel Stenberg
5eb2f0757e
curl: help category cleanups
- add 'mqtt' as a category
- add more protocol categories to several options
- make --data worded better to also cover MQTT

Closes #22447
2026-07-30 16:17:55 +02:00
Viktor Szakats
b84838073c
tidy-up: minor code fixes and improvements
- schannel: drop redundant parentheses.
- os400sys: drop redundant includes.
  Follow-up to ebc5212dac #22374
- pytest: replace `()` with `[]` to match rest of tests.
- libtests: constify some local pointers.
- libtests: drop redundant `(long)` casts.
- lib650: use `CURL_CSTRLEN()`.
  Follow-up to 59dc2bbe07 #22424

Closes #22444
2026-07-30 12:00:22 +02:00
Viktor Szakats
c4013cdb85
tidy-up: comments, messages, formatting
- 'null-terminate', sync casing.
- add an `#endif` comment.
- avoid a few instances of 'will'.
- configure: 'aws' -> 'aws-sigv4', where missing.
- unfold/fold lines.
- update memzero/strzero comments.
- uppercase 'CRLF'.

Closes #22443
2026-07-30 11:26:22 +02:00
Viktor Szakats
ddb22d12c2
lib5004: fix memleak on OOM, check all slist append results (httpsig)
Detected by torture tests:
```
test 5004...[HTTP RFC 9421 B.2.6: Ed25519 POST with headers (RFC test vector)]
 105 functions found, but only fail 25 (23.81%)
** MEMORY FAILURE
Leak detected: memory still allocated: 99 bytes
At 6000022c9408, there is 36 bytes.
 allocated by /Users/runner/work/curl/curl/lib/slist.c:87
At 6000039c8e78, there is 31 bytes.
 allocated by /Users/runner/work/curl/curl/lib/slist.c:87
At 6000037dd688, there is 16 bytes.
 allocated by /Users/runner/work/curl/curl/lib/slist.c:62
At 6000037dd628, there is 16 bytes.
 allocated by /Users/runner/work/curl/curl/lib/slist.c:62
LIMIT /Users/runner/work/curl/curl/lib/slist.c:62 malloc reached memlimit
 5004: torture FAILED: function number 10 in test.
```
Ref: https://github.com/curl/curl/actions/runs/30497660391/job/90730128599?pr=22437#step:16:2331

Also:
- enable HTTPSIG in torture tests.
- NULL check all `curl_slist_append()` results.
- apply a NULL check to sibling test 5000 also.

Co-authored-by: Daniel Stenberg
Follow-up to a55731050e #22386 #21239

Closes #22437
2026-07-30 10:39:01 +02:00
Daniel Stenberg
57cae40ae5
sws: log the exact closing reason better, to help debugging tests
Closes #22431
2026-07-29 23:59:00 +02:00
Dan Fandrich
9743720ab9 tests: fix cert comparison with old cryptography
The fallback path for cryptography < 42 was broken by commit e13362c2
that caused a comparison between offset-naive and offset-aware
datetimes. Use the positional form of tz in datetime.now() everywhere.

Ref: #22396

Pointed out by Codex Security
Closes #22426
2026-07-29 13:56:49 -07:00
Stefan Eissing
3974491c97
websocket: pause writing and meta data fix
When writing a decoded chunk of websocket data, always flush the writer
chain so that buffered data gets delivered before the ws meta data gets
updated.

Add client writer flags CURL_CW_FLAG_BLOWUP for writer types that may
significantly enlarge write sizes. This flag causes the pause writer to
be added and shrinks the write chunk sizes. We do not want that for
content decoders like WS that do not change the size.

Add test_20_13 to check that large frames are paused/unpaused correctly
with the matching meta data.

Fixes #22413
Reported-by: Hendrik Hübner
Closes #22416
2026-07-29 13:35:50 +02:00
Viktor Szakats
59dc2bbe07
tidy-up: use CURL_CSTRLEN() macro on more static strings
Follow-up to e1450d8fda #22406

Closes #22424
2026-07-29 00:19:37 +02:00
Viktor Szakats
ca96fd5190
scorecard: fix max_upload init value in ul_parallel()
"In `ul_parallel`, `max_parallel` is computed using
`self._download_parallel` instead of `self._upload_parallel`. This
causes the upload parallelism to incorrectly follow the download
parallel setting. It should use `self._upload_parallel` to be consistent
with how `uploads()` computes `max_parallel`."

Reported by GitHub Code Quality

Follow-up to 30ef79ed93 #17295

Closes #22421
2026-07-28 22:22:50 +02:00
Viktor Szakats
387b4c5e4c
dnsd: fix bounds check in read_https_alpn_part()
"The check `i > 256` permits `i == 256` to pass through. When `i` is
then cast to `uint8_t` in `blob_add(b, (uint8_t)i)`, the value wraps to
0, silently encoding a zero-length ALPN entry instead of rejecting it.
The condition should be `i > 255` (or equivalently `i >= 256`) to
correctly reject any length that does not fit in a single byte."

Reported by GitHub Code Quality

Follow-up to 86f1e5b3f6 #21299

Closes #22420
2026-07-28 22:22:50 +02:00
Dan Fandrich
3de2777421 tests: target Python 3.8 as the minimum Python version
This version is already two releases out of support, but is "only" 7
years old so is probably still being used in the real world. Document
this version along with some other testing dependencies.  Remove code
support for earlier versions. Disable ruff checks that need a newer
version.
2026-07-28 08:52:01 -07:00
Dan Fandrich
e13362c20a tests: address mutable class vars and naive datetime in Python code
Mark Python mutable class variables with ClassVar, to denote that the
danger this can cause has been considered.  Since any change made to
these in any object affects all other objects, this can cause locality
errors. However, as used in the test suite, they are are never modified
and so they are annotated as being intended.

Always set a timezone in datetime objects, as mixing naive and
timezone-aware object can cause errors.

These fix ruff rules DTZ005, RUF012.
2026-07-28 08:52:01 -07:00
Dan Fandrich
b151a0bb90 tests: use simpler constructions in Python code
* call super() without arguments
* mark an unused variable as such
* simplify by using dict getter for default values
* use writelines() when possible
* use dedent to simplify some text formatting
* avoid items() on dict in a loop when unnecessary
* replace most Python format() calls with f-strings
* use capture_output in subprocess.run

This fixes ruff rules FLY002, FURB122, PERF102, RUF059, SIM401, UP008,
UP022, UP030.
2026-07-28 08:52:01 -07:00
Dan Fandrich
3901c16933 tests: simplify by removing unneeded Python code
* combine separate if statements
* remove an unneeded encode() call
* remove unneeded returns
* simplify code when returning early

This fixes ruff rules SIM102, SIM114, UP012, PLR1711.
2026-07-28 08:52:01 -07:00
Dan Fandrich
4eb691e89c tests: change whitespace and comments in Python test code
* remove an unneeded ruff warning disable
* remove coding: utf-8 from Python code; PEP 3120 makes UTF-8 the
  default encoding
* remove unusable shebang lines from Python code
* remove empty print strings
* disable warnings when file objects are stored; these instances can't
  be handled with context managers
* use more consistent whitespace in Python code, fixing flake8 warnings
* set the executable bit on scorecard.py, making it easier to run

These fix ruff rules EXE001, FURB105, UP009, SIM115.
2026-07-28 08:52:01 -07:00
Dan Fandrich
c39193a589 tests: improve exception handling in Python test code
* Explicitly set "check" in subprocess.run() to raise an exception
  automatically, where it was done manually before
* Use contextlib.suppress to ignore exceptions
* Use custom exceptions for test errors for clarity and flexibility.
* Replace IOError with OSError

This fixes ruff rules BLE001, PLW1510, S110, TRY201, TRY203, TRY002,
UP024.
2026-07-28 08:52:01 -07:00
Viktor Szakats
e1450d8fda
tidy-up: use more static, sizeof(), char[], double-const
- make `const` data `static`, where missing and possible.
- replace `strlen()` on literal or const strings with `sizeof()`.
  While the latter is optimized by popular C compiler, e.g. MSVC only
  does it with `/O2`.
- replace magic numbers with `sizeof()`, where missing.
- introduce `CURL_CSTRLEN()` macro for `sizeof(char[]) - 1`.
- use `CURL_CSTRLEN()` macro.
- move `const` before integer types, where missing.
- replace `char *var` with `var[]`, where missing and possible.
- use double const, where missing.
  `static const char *` -> `static const char * const`.
- lib1514: constify pointers.
- unit3205: drop redundant cast, avoid another one.
- unit1666: map `OID()` macro to identical `STRCONST()`.

Closes #22406
2026-07-28 13:53:11 +02:00
Daniel Stenberg
573a6ec16b
urlapi: improved return codes
- add CURLUE_BACKSLASH that can be returned when a backslash was used
  where a forward one probably was intended.

- make CURLUE_NO_HOST higher priority than port number errors for URLs
  without hostname. Like in "http://::1"

- shortened some URL parser error strings

Extend test 1560 to verify.

Reported-by: kit-ty-kate on github
Fixes #22337
Closes #22408
2026-07-28 13:37:28 +02:00
Daniel Stenberg
c7328740ec
lib2405: adjust for non-threaded builds
- Attempt to fix the flakiness set in 9726fc8259
- Reduce macro use

Closes #22414
2026-07-28 13:30:26 +02:00
Matthew John Cheetham
a8881e5e1d spnego: block NTLM fallback in SPNEGO negotiation
- Switch the Windows SSPI identity struct to SEC_WINNT_AUTH_IDENTITY_EX
  to use !ntlm in PackageList to prevent NTLM from being offered.

- For GSS filter out NTLMSSP OID, and restrict via gss_set_neg_mechs()
  to prevent NTLM from being offered.

- Extend the GSS-API debug stub layer to support the NTLM blocking logic
  without a real Kerberos environment.

- Update test 2057 to check that negotiate auth is silently skipped with
  no Authorization header when only NTLM stub credentials are available.

- Add SPNEGO NTLM blocking test 2093 which verifies that Kerberos
  credentials still succeed when NTLM is blocked within SPNEGO.

- Suppress tests valgrind leak for MIT krb5 gss_display_status, since
  the leak is in the library and not in curl.

To suppress the tests valgrind leak, the wildcard '...' bridges over an
anonymous frame inside libgssapi_krb5.so that valgrind reports as '???'.

Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
Aided-by: Johannes Schindelin

Closes https://github.com/curl/curl/pull/21315
Closes https://github.com/curl/curl/pull/22410
2026-07-27 17:28:52 -04:00
Stefan Eissing
4eb4b0d080
vquic: use ngtcp2 v1.25.0 new close2 callback
Forward only the app error code from the receiving side to the h3 layer.

This only takes effect when building against ngtcp2 v1.25.0 or higher.

Fixes #22270

Closes #22356
2026-07-27 11:36:56 +02:00
Viktor Szakats
f9dc57a149
pytest: update two H3 tests for nghttp3 1.18.0+
Fixing:
```
FAILED ../../tests/http/test_02_download.py::TestDownload::test_02_36_looong_urls[65536-h3] -
  AssertionError: expected exit code 0, got 56
FAILED ../../tests/http/test_14_auth.py::TestAuth::test_14_05_basic_large_pw[h3] -
  AssertionError: expected exit code 0, got 56
```
Ref: https://github.com/curl/curl/actions/runs/30207198835/job/89807247058?pr=22400

Refs:
https://github.com/ngtcp2/nghttp3/pull/539
a587264544

Bug: https://github.com/curl/curl/pull/22397#issuecomment-5084927935

Closes #22402
2026-07-27 10:16:43 +02:00
Viktor Szakats
6f39c854c8
runtests: fix mode="warn" tests passing unconditionally, fix test 1752
Fix test 1712 to pass curl C by setting `COLUMNS` to the highest
accepted value, and adjust expected results. To avoid envs with varying
lengths of `LOGDIR` affect the outcome.

Apply the same fix to test 459, though it wasn't affected in curl CI.

Also sync up test 433 `COLUMNS` value with these two tests for
consistency.

Ref: #22381
Follow-up to 8e3a2a64d1 #20666

Closes #22388
2026-07-26 22:50:50 +02:00
Daniel Stenberg
acf4498381
http: fix httpsig with auth-redir
Do not let unrelated credentials from a redirected URL bypass the
cross-host auth boundary

Verified by test 5023 to 5025

Follow-up to a55731050e

Closes #22395
2026-07-26 22:45:30 +02:00
Viktor Szakats
b2a5369e70
runtests: allow comments in setenv section, merge sections in test433
Closes #22389
2026-07-26 16:43:18 +02:00
Daniel Stenberg
9bcc64c39b
curl: make --httpsig-key take a key OR a file name for key
Verified by test 5022

Closes #22392
2026-07-25 22:10:30 +02:00
Sameeh Jubran
a55731050e
httpsig: add RFC 9421 HTTP Message Signatures support
Add support for signing outgoing HTTP requests per RFC 9421 using
Ed25519 or HMAC-SHA256 algorithms.

New libcurl options:
 - CURLOPT_HTTPSIG: signing algorithm ("ed25519" or "hmac-sha256")
 - CURLOPT_HTTPSIG_KEY: path to hex-encoded key file
 - CURLOPT_HTTPSIG_KEYID: key identifier for Signature-Input
 - CURLOPT_HTTPSIG_HEADERS: space-separated components to sign

New CLI flags: --httpsig, --httpsig-key, --httpsig-keyid,
--httpsig-headers

The crypto layer follows the sha256.c multi-backend pattern with
implementations for OpenSSL (EVP_DigestSign) and wolfSSL
(wc_ed25519_sign_msg). HMAC-SHA256 uses the existing Curl_hmacit()
infrastructure which works on all backends.

Verified by test 5000 to 5021

Assisted-by: Daniel Stenberg
Signed-off-by: Sameeh Jubran <sameeh@wolfssl.com>
Closes #22386
Closes #21239
2026-07-25 16:25:37 +02:00
Viktor Szakats
ebc5212dac
tidy-up: drop redundant includes
`sys/types.h` and `sys/socket.h` (non-Win32). They are included via
`curl/curl.h` and `curl_setup.h`.

This drops `HAVE_SYS_TYPES_H` guards from the codebase. It's safe
because `sys/types.h` (POSIX) is already required unconditionally by
`curl/curl.h`. It remains used in feature checks by both autotools and
cmake; to be reviewed in a future step.

Closes #22374
2026-07-25 11:37:12 +02:00
Stefan Eissing
e093c67f1c
connect: connection close tweaks
- connclose/streamclose/connkeep() remove description string that was
  never used anywhere. Add trace statements where reasons for closing
  were not already traced and maybe not obvious.
- multi_remove_handle: only lookup former connection in pool when
  transfer is set to connect only
- test1554: adapt expectations now that pool is less often locked

Closes #22379
2026-07-24 22:59:46 +02:00
Stefan Eissing
a954d87f0b
httpsrr: DoH with HTTPS, fix response handling
Fix handling of DoH response that only asks for HTTPS records.

Add test 2117 for checking that a HTTPS-RR resolve is processed,
even though the actual answer is invalid.

Closes #22372
2026-07-24 22:58:51 +02:00
Graham Campbell
c8860532dd tests: fix the FTP check for unexpected RST
- In vsftpd ignore unrelated RST by matching tcpdump RSTs to the data
  connection port pair.

Prior to this change an unrelated RST on a recycled ephemeral port
could cause test failure.

Closes https://github.com/curl/curl/pull/22305
2026-07-24 04:31:09 -04:00
Stefan Eissing
545cdd4b50
asyn-thrdd: retry link-local ipv6 if missing scope id
When the threaded resolver gets AAAA results that carry a link-local
address without scope-id, it now re-queues a query with AF_UNSPEC and
strips ipv4 addresses from that result. Whatever the resulting addresses
and scope-ids are, this becomes the result of the resolve.

Fixes #22330
Reported-by: Bartel Sielski
Closes #22368
2026-07-23 22:26:43 +02:00
Alhuda Khan
489a4c1b48
ctype: exclude control bytes from ISPRINT and ISGRAPH
Closes #22371
2026-07-23 22:25:06 +02:00
Viktor Szakats
8734b08883
tidy-up: miscellaneous
- CMake/CurlTests.c: sync indent with rest of file and most of code.
- cmake: sync term in `_CURL_PREFILL` description with rest of code.
- curl_setup.h: document function relying on `_CRT_SECURE_NO_WARNINGS`.
- tests/http/scorecard.py: typo in message.
- 'Quiche' -> 'quiche'.
- fix comment and formatting nits.

Closes #22378
2026-07-23 14:19:23 +02:00
Viktor Szakats
0ada20387c
tidy-up: fix Perl syntax and formatting nits
Closes #22376
2026-07-23 12:56:18 +02:00
Viktor Szakats
3a0c600a1e
tidy-up: fix comment indentation
Closes #22373
2026-07-23 12:01:40 +02:00
Viktor Szakats
41b4a91123
scripts: replace/extend -- with --end-of-options in git commands
It makes these scripts require Git 2.24.0+ (2019-11-04).

Refs:
https://git-scm.com/docs/gitcli
https://nesbitt.io/2026/07/21/end-of-options.html
19e8789b23

Closes #22369
2026-07-22 21:14:52 +02:00
Viktor Szakats
6bff85be68
tool_xattr: add support for Windows alternate data stream
Requires a supported filesystem, i.e. NTFS.

Example:
```console
> curl.exe https://curl.se/index.html --output test.txt --xattr --referer https://curl.se/
> cat < test.txt:Zone.Identifier

[ZoneTransfer]
HostUrl=https://curl.se/index.html
ReferrerUrl=https://curl.se/
```

Where newlines are CLRF, `ReferrerUrl` is set when using `--referer`
option.

Also:
- test688: make it test `--referer`.
- document `user.xdg.referrer.url` in `--xattr` man page.

Refs:
https://en.wikipedia.org/wiki/Mark_of_the_Web
https://en.wikipedia.org/wiki/NTFS#Alternate_data_stream_(ADS)
https://learn.microsoft.com/en-us/windows/win32/fileio/file-streams
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/c54dec26-1551-4d3a-a0ea-4fa40f848eb3

Ref: #22345

Closes #22354
2026-07-22 12:27:39 +02:00
Stefan Eissing
0c4eebb3fa
test: adjust test_06_13 for 0100::/64 being blackholed
Fixes #22344
Reported-by: Carlos Henrique Lima Melara
Closes #22355
2026-07-21 23:52:35 +02:00
Alb3e3
c221469032
urlapi: preserve empty markers in relative URLs
Verified in test 1560

Closes #22298
2026-07-21 23:38:55 +02:00
Graham Campbell
4dc236a109
thrdpool: retry failed thread starts while items wait
Verified in test 3306

Closes #22303
2026-07-21 23:35:18 +02:00
Stefan Eissing
dfc01ea2a3
hardening: add API guards
Add call stacks to easy and multi instances. Record ongoing API calls
and callback invocations there to detect recursion and not allowed
invocations.

Define enums for easy, multi and callbacks in `api.h`. In `api.c` define
properties for these functions:

- can they recurse
- is the easy/multi handle destroyed during the call or should it be
  good afterwards
- is the call allowed when a multi event callback is ongoing
- is the call allowed when a notification callback is ongoing

Entering a guard
- checks that passed CURL*/CURLM* are GOOD on entering
- checks that easy handle's `mid` is correct and it is known
  for it in the multi.
- checks that call properties are obeyed (recursion, callback checks)
- checks that passed CURL*/CURLM* are GOOD on leaving, unless call is
  known to kill it

Checks for ongoing callbacks inspect the whole call stack and catches
nested invocations (which our current flags can not).

Call stacks in easy/multi handle are fixed size and will deny recursion
when the limit is reached. The current limits are 7 for easy and 15 for
multi now.

Removes:
- multi->in_callback, check is done via call stack
- multi->in_ntfy_cb, check is done via call stack

The overhead in my tests seems minimal, if noticeable at all.

Closes #22237
2026-07-21 23:22:24 +02:00
Stefan Eissing
7ad33fe56f
cf-dns: resolve on filter demand
Use separate dns cache entries for addresses (A+AAAA) and HTTPS-RR
results. That makes also "negative" results independent of each other.
Dns cache entries, once in use, can no longer be modified safely, as
concurrent use would require each access then to be done under lock. By
using separate entries, we can update a HTTPS entry without needing to
duplicate an existing address entry for the same host+port.

Connection filters can now ask for DNS resolves. This works at any time
during connection setup and while connect is going on.
`Curl_conn_dns_add_addr_resolve()` and
`Curl_conn_dns_add_https_resolve()` are used for that. They check if the
resolve is already ongoing, can be added to a resolve not started yet
or, as last resort, create a new filter instance and add it to the
connection (it's easier to add more filters than making the same filter
handle multiple resolves. Since DNS filters are removed once the
connection is established, there is no later penalty).

HTTPS-RR queries are added by the `HTTPS-CONNECT`, `SSL` and `QUIC`
filters. The latter will only do that when ECH is configured and
supported. That means we trigger HTTPS-RR queries only when the results
matter.

Add test_22_06 for ALPN influenced via HTTPS-RR when tunneling through a
proxy. This did not work before.

Adjust test2100 to use https: as the previous http: URL no longer
triggers HTTPS-RR resolves.

Closes #22216
2026-07-21 23:18:53 +02:00