Commit Graph

3302 Commits

Author SHA1 Message Date
Viktor Szakats
0417d323c9
src: fix formatting nits
Closes #19823
2025-12-03 20:50:18 +01:00
Daniel Stenberg
a2ebae61ca
tool_urlglob: acknowledge OOM in peek_ipv6
Previously, an OOM error would just imply not an IPv6 address.

Closes #19784
2025-12-01 14:44:41 +01:00
Viktor Szakats
815bf76649
autotools: delete idle AM_CFLAGS, AM_LDFLAGS variables
Closes #19771
2025-11-30 22:27:25 +01:00
Daniel Stenberg
0eed8b7330
tool_operatate: return error for OOM in append2query
Closes #19763
2025-11-30 10:37:41 +01:00
Viktor Szakats
16f073ef49
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::<dependency>`. 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 e86542038d #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
2025-11-29 01:41:40 +01:00
Viktor Szakats
193cb00ce9
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 b12da22db1 #18866
Follow-up to db98daab05 #18844
Follow-up to 4deea9396b #18814
Follow-up to 9678ff5b1b #18776
Follow-up to 10bac43b87 #18774
Follow-up to 20142f5d06 #18634
Follow-up to bf7375ecc5 #18503
Follow-up to 9863599d69 #18502
Follow-up to 3bb5e58c10 #17827

Closes #19626
2025-11-28 10:44:26 +01:00
Stefan Eissing
bbb929112b
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
2025-11-27 14:35:01 +01:00
Stefan Eissing
94ce87c391
types: remove curl_int64_t/curl_uint64_t
These types and the definitions surrounding them are no longer needed.

Closes #19706
2025-11-26 13:53:53 +01:00
Yedaya Katsman
fc09a2da4a
tool: log when loading .curlrc in verbose mode
Inspired by @vszakats in
https://github.com/curl/curl/pull/19631#issuecomment-3560803674

Closes #19663
2025-11-25 16:06:27 +01:00
Viktor Szakats
62683ad3f4
curlx: replace sprintf with snprintf
To avoid using a deprecated function on Windows.

Also: de-dupe `SNPRINTF` definition in curlx.

Closes #19681
2025-11-25 11:11:06 +01:00
Daniel Stenberg
6069c340b4
tool_doswin: clear pointer when thread takes ownership
Attempt to address #19675
Closes #19689
2025-11-25 10:59:37 +01:00
Daniel Stenberg
039fb84cb4
tool_writeout: bail out proper on OOM
Closes #19667
2025-11-24 13:32:51 +01:00
Daniel Stenberg
f13f320dee
tool_msgs: make voutf() use stack instead of heap
For printf()ing the message to show.

Closes #19651
2025-11-23 12:52:00 +01:00
Daniel Stenberg
36b9987acb
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
2025-11-22 22:22:41 +01:00
Daniel Stenberg
4ebef2f0d9
tool_operate: fix case of ignoring return code in single_transfer
When glob_url() returns error, stop.

Closes #19649
2025-11-22 22:21:43 +01:00
x2018
3561f2c7bf
lib: cleanup some whitespace nits
Closes #19588
2025-11-21 11:25:59 +01:00
Viktor Szakats
fd23d9505c
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 c255d2fdcb #19602

Closes #19629
2025-11-21 04:30:44 +01:00
Daniel Stenberg
5f273fdddf
tool_urlglob: clean up used memory on errors better
Previously it had to realloc the pattern array to store the last entry
even when that last entry triggered an error and could be only half
filled in.

Also cleaned up for readability and better reallocs for sets.

Reported-by: letshack9707 on hackerone
Closes #19614
2025-11-20 22:34:34 +01:00
Viktor Szakats
7e8f36bf8e
cmake: honor CURL_DISABLE_INSTALL and CURL_ENABLE_EXPORT_TARGET in lib and src
Based on existing code and commit history it appears
`CURL_DISABLE_INSTALL` means to prevent calling `install()`;
`CURL_ENABLE_EXPORT_TARGET` means to prevent calling `export()` and
`install()`s with `EXPORT` in them.

Fix them to also apply to the lib and src directories in that vain:
- lib: honor `CURL_DISABLE_INSTALL`
- src: honor `CURL_DISABLE_INSTALL`
- src: honor `CURL_ENABLE_EXPORT_TARGET`

https://cmake.org/cmake/help/v4.2/command/install.html
https://cmake.org/cmake/help/v4.2/command/export.html

- `CURL_DISABLE_INSTALL` follow-up to:
  aace27b096 #12287
- `CURL_ENABLE_EXPORT_TARGET` follow-up to:
  8698825106 #9638
  643ec29645 #7060

Closes #19144
2025-11-20 00:23:08 +01:00
Viktor Szakats
3d80d37cf0
curlx: add and use curlx_freopen()
To complement the existing `curlx_fopen()` internal API.
It's used by the curl's `--stderr` option.

`curlx_freopen()` adds two features to the bare `freopen()`:
- tracing for debug-enabled builds.
- Unicode and long-filename support for Windows builds.

In effect this adds long-filename and enables Unicode support for
the `--stderr <filename>` curl command-line option on Windows.

Also add to checksrc.

Follow-up to 2f17a9b654 #10673

Closes #19598
2025-11-19 22:04:53 +01:00
Viktor Szakats
47b8e1dbd3
tidy-up: move CURL_UNCONST() out from macro curl_unicodefree()
To stop applying it where not needed (most uses) and make it visible
where it's actually used (5 uses).

Follow-up to f4e23950c7 #16142

Closes #19606
2025-11-19 15:48:21 +01:00
Daniel Stenberg
abe6ea0531
curlinfo: add "ssl-sessions" as a feature to show
To allow tests depend on it
2025-11-19 12:58:24 +01:00
Daniel Stenberg
c255d2fdcb
tool_cfgable: free ssl-sessions at exit
Also free the memory correctly in tool_ssls_load

Closes #19602
2025-11-19 12:58:15 +01:00
Daniel Stenberg
88024c6d39
tool_getparam: verify that a file exists for some options
Passing the option as-is to libcurl is fine, but checking that the file
exists allows the tool to better provide a helpful message.

This now done for the following options:

  --cacert, --crlfile, --knownhosts, --netrc-file, --proxy-cacert amd
  --proxy-crlfile

Bonus: bail out properly on OOM errors in the --cert parser.

Reported-by: Wesley Moore
Fixes #19583
Closes #19585
2025-11-18 11:37:08 +01:00
boingball
a41cea7d67
AmigaOS: increase minimum stack size for tool_main
In testing, the older stack size of 16384 was causing curl to crash on
heavy TLS loads

Closes #19578
2025-11-18 07:54:11 +01:00
Viktor Szakats
1e1ec7f6c2
badwords: add more contractions, fix fallouts
Also fix hits in autotools scripts (not to enforce).

Closes #19576
2025-11-17 19:29:15 +01:00
Viktor Szakats
554dfa5568
build: drop Windows CE / CeGCC support
Windows CE support was limited to successful builds with ming32ce
(a toolchain that hasn't seen an update since 2009, using an ancient gcc
version and "old mingw"-style SDK headers, that curl deprecated earlier).
Builds with MSVC were broken for a long time. mingw32ce builds were never
actually tested and runtime and unlikely to work due to missing stubs.
Windows CE toolchains also miss to comply with C89. Paired with lack of
demand and support for the platform, curl deprecated it earlier.

This patch removes support from the codebase to ease maintaining Windows
codepaths.

Follow-up to f98c0ba834 #17924
Follow-up to 8491e6574c #17379
Follow-up to 2a292c3984 #15975

Closes #17927
2025-11-15 15:35:23 +01:00
Viktor Szakats
2dc71ba8bf
badwords: check indented lines in source code, fix fallouts
- badwords.pl: add `-a` option to check all lines in source code files.
  Before this patch indented lines were skipped (to avoid Markdown code
  fences.)
- GHA/checksrc: use `-a` when verifying the source code.
- GHA/checksrc: disable `So` and `But` rules for source code.
- GHA/checksrc: add docs/examples to the verified sources.
- badwords.txt: delete 4 duplicates.
- badwords.txt: group and sort contractions.
- badwords.txt: allow ` url = `, `DIR`, `<file name`.

Closes #19536
2025-11-15 13:25:02 +01:00
Viktor Szakats
af4c789e00
badwords: fix two exceptions and drop them
Also:
- extend `dir` rule to exclude C assignments.

Closes #19532
2025-11-14 17:32:04 +01:00
Daniel Stenberg
3fc31c4ee2
config2setopts: bail out if curl_url_get() returns OOM
Closes #19518
2025-11-14 09:39:42 +01:00
Daniel Stenberg
e3e0559ed2
config2setopts: exit if curl_url_set() fails on OOM
An error case that previously did not properly return error.

Closes #19517
2025-11-13 22:57:08 +01:00
Daniel Stenberg
0afb52a0cd
code: minor indent fixes before closing braces
Closes #19512
2025-11-13 17:27:40 +01:00
Daniel Stenberg
75955c0851
tool_operate: exit on curl_share_setopt errors
Continuing when one of these has failed is fragile and error-prone.

Closes #19513
2025-11-13 17:24:40 +01:00
Viktor Szakats
6384e2aca0
checksrc: disallow atoi and atol globally
No longer used in core and test code.

Also: allowlist in docs/examples.

Closes #19508
2025-11-13 14:28:25 +01:00
Stefan Eissing
78a610cb83
lib: rename curlx_timediff to curlx_timeleft_ms
Rename `Curl_timeleft()` to `Curl_timeleft_ms()` to make the units in
the returned `timediff_t` clear. (We used to always have ms there, but
with QUIC started to sometimes calc ns as well).

Rename some assigned vars without `_ms` suffix for clarity as well.

Closes #19486
2025-11-13 13:12:58 +01:00
Daniel Stenberg
207721165e
src/checksrc: ban atoi use 2025-11-12 10:27:54 +01:00
Daniel Stenberg
4bb6a5d50f
tool_operate: use curlx_str_number intead of atoi
For consistency. This instance is for debug-only code and is not
important.

Closes #19480
2025-11-12 10:27:48 +01:00
Viktor Szakats
4841e4290d
badwords: re-sync with curl-www, fix issues found
Also:
- replace `manpage` with `man page`, add to `badwords.txt`.
- badwords.pl: import `-w` feature from curl-www, syncing the two
  scripts fully.
- badwords.txt: import missing items from curl-www, syncing the two
  files fully.
- pyspelling.words: drop `cURL` allowed word.

Closes #19468
2025-11-12 00:53:44 +01:00
Daniel Stenberg
40b1724f58
tool: consider (some) curl_easy_setopt errors fatal
Instead of happily ignoring return codes.

Calls that allocate data, like duplicating strings, can fail because of
lack of memory which could then leave the option unset and curl would
unknowingly continue (if the memory shortage was momentary).

Closes #19385
2025-11-07 11:12:34 +01:00
Daniel Stenberg
8e93a74a73
tool_paramhlp: refuse --proto remove all protocols
curl is for transfers so disabling all protocols has to be a mistake.
Previously it would allow this to get set (even if curl_easy_setopt()
returns an error for it) and then let libcurl return error instead.

Updated 1474 accordingly.

Closes #19388
2025-11-06 23:42:47 +01:00
x2018
69622ff37d
tool_help: add checks to avoid unsigned wrap around
Closes #19377
2025-11-06 15:37:53 +01:00
Stefan Eissing
f12a81de4f
curl: fix progress meter in parallel mode
With `check_finished()` triggered by notifications now, the
`progress_meter()` was no longer called at regular intervals.

Move `progress_meter()` out of `check_finished()` into the perform loop
and event callbacks.

Closes #19383
2025-11-06 13:37:57 +01:00
Daniel Stenberg
66a66c596b
tool_operate: remove redundant condition
And avoid an early return.

Pointed out by CodeSonar

Closes #19381
2025-11-06 11:39:52 +01:00
Daniel Stenberg
56129718b8
tool_ipfs: check return codes better
Closes #19382
2025-11-06 11:38:54 +01:00
x2018
dd71f61ea2
lib: cleanup for some typos about spaces and code style
Closes #19370
2025-11-05 14:07:28 +01:00
x2018
11683f121d
tool_ipfs: check the return value of curl_url_get for gwpath
Closes #19358
2025-11-04 14:13:00 +01:00
Daniel Stenberg
1afc4bb768
tool/var: explain how the null termination byte is there
Closes #19287
2025-10-30 20:22:37 +01:00
Jay Satiro
0ba006601f tool_operate: move the checks that skip ca cert detection
- Move the checks into the function that needs them, cacertpaths().

Prior to this change the caller made the determination whether to skip
calling cacertpaths for cert detection. However for posterity it is
better to have the checks in cacertpaths since other code could call it.

Closes https://github.com/curl/curl/pull/19148
2025-10-29 02:46:43 -04:00
Dalei
e51966d9df
tool_cfgable: remove superfluous free calls
Fixes #19213
Closes #19214
2025-10-24 11:05:43 +02:00
Daniel Stenberg
9e198618de
tool_parsecfg: detect and error on recursive --config use
The config file parser now has a maximum level of inclusions allowed (5)
to detect and prevent recursive inclusions of itself leading to badness.

Bonus: clean up return code handling from the config parser.

Test 774 verifies
Closes #19168
2025-10-21 10:11:43 +02:00