Commit Graph

2562 Commits

Author SHA1 Message Date
Viktor Szakats
1d5b7b7009
Makefile.m32: add CURL_RC and CURL_STRIP variables [ci skip]
They allow to override the hardcoded values for the `windres` and `strip`
tools, complementing the existing set of `CURL_{CC,AR,RANLIB}` variables.

`CURL_RC` comes handy when using LLVM tools with `CROSSPREFIX=llvm-` and
`CURL_CC=clang` set on current latest debian:unstable or earlier, where
`llvm-windres` is missing, and a `CURL_RC=<triplet>-windres` fixes it.
Hopefully this will be fixed in the llvm package. FWIW `llvm-windres`
does exist in Homebrew llvm, MSYS2 llvm and llvm-mingw.

Reviewed-by: Daniel Stenberg
Closes #9132
2022-07-10 22:28:14 +00:00
xkernel
d123f0e590
tool_operate: better cleanup of easy handle in exit path
Closes #9114
2022-07-10 18:23:03 +02:00
Daniel Stenberg
bf7e887b24
tool_getparam: repair cleanarg
Regression since 9e5669f.

Make sure the "cleaning" of command line arguments is done on the
original argv[] pointers. As a bonus, it also exits better on out of
memory error.

Reported-by: Litter White
Fixes #9128
Closes #9130
2022-07-10 15:49:14 +02:00
Viktor Szakats
190caa9ce2
Makefile.m32: add NGTCP2_LIBS option [ci skip]
Makefile.m32's ngtcp2 has its two libs hardwired for OpenSSL.
Add `NGTCP2_LIBS` envvar to override them with a custom list,
making it possible to use BoringSSL, or any other backend.

Closes #9109
2022-07-06 09:22:42 +00:00
Daniel Stenberg
127d04aadf
curl: proto2num: make sure obuf is inited
Detected by Coverity. CID 1507052.

Closes #9096
2022-07-04 14:38:35 +02:00
Viktor Szakats
8ef0f35a04
makefile.m32: add support for custom ARCH [ci skip]
When building curl for target platform other than x64 and x86, it is now
possible to pass `ARCH=custom`, that will omit all hardcoded logic for
setting up CFLAGS/LDFLAGS/RCFLAGS for these platforms, and let these be
customized via `CURL_CFLAG_EXTRAS`, `CURL_LDFLAG_EXTRAS`, and a newly
added one for the resource compiler: `CURL_RCFLAG_EXTRAS`.

This makes it possible to use `makefile.m32` to build for ARM64 for
example.

Reviewed-by: Daniel Stenberg
Closes #9092
2022-07-04 10:26:30 +00:00
Viktor Szakats
76172511e7
windows: improve random source
- Use the Windows API to seed the fallback random generator.

  This ensures to always have a random seed, even when libcurl is built
  with a vtls backend lacking a random generator API, such as rustls
  (experimental), GSKit and certain mbedTLS builds, or, when libcurl is
  built without a TLS backend. We reuse the Windows-specific random
  function from the Schannel backend.

- Implement support for `BCryptGenRandom()` [1] on Windows, as a
  replacement for the deprecated `CryptGenRandom()` [2] function.

  It is used as the secure random generator for Schannel, and also to
  provide entropy for libcurl's fallback random generator. The new
  function is supported on Vista and newer via its `bcrypt.dll`. It is
  used automatically when building for supported versions. It also works
  in UWP apps (the old function did not).

- Clear entropy buffer before calling the Windows random generator.

  This avoids using arbitrary application memory as entropy (with
  `CryptGenRandom()`) and makes sure to return in a predictable state
  when an API call fails.

[1] https://docs.microsoft.com/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom
[2] https://docs.microsoft.com/windows/win32/api/wincrypt/nf-wincrypt-cryptgenrandom

Closes #9027
2022-07-04 09:38:24 +00:00
Daniel Stenberg
e6f8445ede
setopt: add CURLOPT_PROTOCOLS_STR and CURLOPT_REDIR_PROTOCOLS_STR
... as replacements for deprecated CURLOPT_PROTOCOLS and
CURLOPT_REDIR_PROTOCOLS as these new ones do not risk running into the
32 bit limit the old ones are facing.

CURLINFO_PROTCOOL is now deprecated.

The curl tool is updated to use the new options.

Added test 1597 to verify the libcurl protocol parser.

Closes #8992
2022-07-04 08:35:09 +02:00
Daniel Stenberg
0defae2fe5
tool_progress: avoid division by zero in parallel progress meter
Reported-by: Brian Carpenter
Fixes #9082
Closes #9083
2022-07-02 00:45:58 +02:00
Daniel Stenberg
f57f96dedc
curl: output warning when a cookie is dropped due to size
Dropped from the request, that is.

Closes #9064
2022-06-29 08:48:03 +02:00
Viktor Szakats
6c501cb624
Makefile.m32: stop forcing XP target with ipv6 enabled [ci skip]
Since this [1] commit in 2011, `_WIN32_WINNT` was set fixed to Windows
XP when the `-ipv6` option is selected. Maybe this was added to support
pre-XP Windows versions (?). These days libcurl builds fine for both XP
and post-XP versions with IPv6 support enabled. The relevance of pre-XP
version is also low by now. Other build methods also do not impose such
limitation for a similar configuration. So, drop this hard-wired
`_WIN32_WINNT` limit from `Makefile.m32`, thus building for the default
Windows version set by the compiler. This is Vista for recent MinGW
versions.

Old behaviour can be restored by setting this envvar:
export CURL_CFLAG_EXTRAS=-D_WIN32_WINNT=0x0501

[1] 98a61d8e2e

Closes #9035
2022-06-22 00:06:48 +00:00
Viktor Szakats
a94d6fe706
version: rename threadsafe-init to threadsafe
Referring to Daniel's article [1], making the init function thread-safe
was the last bit to make libcurl thread-safe as a whole. So the name of
the feature may as well be the more concise 'threadsafe', also telling
the story that libcurl is now fully thread-safe, not just its init
function. Chances are high that libcurl wants to remain so in the
future, so there is little likelihood of ever needing any other distinct
`threadsafe-<name>` feature flags.

For consistency we also shorten `CURL_VERSION_THREADSAFE_INIT` to
`CURL_VERSION_THREADSAFE`, update its description and reference libcurl's
thread safety documentation.

[1]: https://daniel.haxx.se/blog/2022/06/08/making-libcurl-init-more-thread-safe/

Reviewed-by: Daniel Stenberg
Reviewed-by: Jay Satiro
Closes #8989
2022-06-13 18:59:45 +00:00
max.mehl
ad9bc5976d
copyright: make repository REUSE compliant
Add licensing and copyright information for all files in this repository. This
either happens in the file itself as a comment header or in the file
`.reuse/dep5`.

This commit also adds a Github workflow to check pull requests and adapts
copyright.pl to the changes.

Closes #8869
2022-06-13 09:13:00 +02:00
Daniel Stenberg
95f5aae9ad
test390: verify --parallel
Closes #8985
2022-06-10 09:05:25 +02:00
Thomas Guillem
2ed1012564
curl_version_info: add CURL_VERSION_THREADSAFE_INIT
This flag can be used to make sure that curl_global_init() is
thread-safe.

This can be useful for libraries that can't control what other
dependencies are doing with Curl.

Closes #8680
2022-06-07 13:34:03 +02:00
Boris Verkhovskiy
83ee5c428d
curl: re-enable --no-remote-name
Closes #8931
2022-05-31 13:23:22 +02:00
JustAnotherArchivist
10cd69623a tool_getparam: fix --parallel-max maximum value constraint
- Clamp --parallel-max to MAX_PARALLEL (300) instead of resetting to
  default value.

Previously, --parallel-max 300 would use 300 concurrent transfers, but
--parallel-max 301 would unexpectedly use only 50. This change clamps
higher values to the maximum (ie --parallel-max 301 would use 300).

Closes https://github.com/curl/curl/pull/8930
2022-05-28 03:23:57 -04:00
Viktor Szakats
2e769766ea
cmake: enable curl.rc for all Windows targets
Before this patch, it was only enabled for MSVC. This syncs this
configuration with libcurl.rc, which was already included with
every Windows compiler.

Closes #8918
2022-05-26 15:53:19 +00:00
Viktor Szakats
d67f41acd3
version: allow stricmp() for sorting the feature list
In CMakeLists.txt there is an attempt to detect `stricmp()`, and in
certain cases, this attempt is the only successful one to detect a
case-insensitive comparison function. `HAVE_STRICMP` is defined as
a result, but this macro wasn't used anywhere in the source. This
patch makes use of it as an alternative when alpha-sorting the
`--version` feature list.

Reviewed-by: Daniel Stenberg
Closes #8916
2022-05-25 15:24:42 +00:00
Viktor Szakats
16a58e9f93
Makefile.m32: delete obsolete options, improve -On [ci skip]
- `-D_AMD64_` has not been necessary for mingw-w64 builds for a long time now.
- `-fno-strict-aliasing` is mentioned for Intel C compiler in autotools, and
  I used this with VxWorks in another project, but otherwise this isn't
  necessary anymore as a default. If a target still needs it, it can be
  added with `CURL_CFLAG_EXTRAS=-fno-strict-aliasing`
- bump up default optimization level to `-O3` (from `-O2`), and also rearrange
  option order so the default can now be overridden via
  `CURL_CFLAG_EXTRAS`.
- delete `-g` (generate debug info) from `CFLAGS` and `-s` from `LDFLAGS`
  (strip debug info). They were working against each other. Now, if someone
  needs debug info, it can be enabled via `CURL_CFLAG_EXTRAS=-g`

Closes #8904
2022-05-24 17:04:38 +00:00
Daniel Stenberg
8f48b5d783
curl: add --rate to set max request rate per time unit
--rate "12/m" - for 12 per minute or
--rate "5/h" - for 5 per hour

Removed from TODO

Closes #8671
2022-05-23 17:59:56 +02:00
Daniel Stenberg
84052154f7
curl: deprecate --random-file and --egd-file
As libcurl no longer has any functionality for them, the tool now does
nothing with them.

Closes #8670
2022-05-17 11:06:07 +02:00
Daniel Gustafsson
bf327a9dfe macos9: remove partial support
The support for compiling on Mac OS 9 hasn't been modified since 2001
and has no active maintainer or packager, so it's time to remove it as
it's incredibly unlikely to work. If a maintainer re-emerges it can be
resurrected from Git history.

Closes: #8836
Reviewed-by: Daniel Stenberg <daniel@haxx.se>
2022-05-16 10:10:16 +02:00
Daniel Stenberg
0356804d13
tool_operate: make sure --fail-with-body works with --retry
... in the same way --fail already does.

Reported-by: Jakub Bochenski
Fixes #8845
Closes #8847
2022-05-16 10:04:06 +02:00
Daniel Stenberg
8c7ee9083d
post_per_transfer: remove the updated file name
When --remove-on-error is used with --no-clobber, it might have an
updated file name to remove.

Bug: https://curl.se/docs/CVE-2022-27778.html

CVE-2022-27778

Reported-by: Harry Sintonen

Closes #8824
2022-05-09 12:56:21 +02:00
Daniel Gustafsson
79bf349a50 tool_getparam: simplify conditional statement
param_place cannot be NULL here since we immediately efter this block
perform arithmetic on it (and use it in order to get here) so there is
little reason to check.

Closes: #8786
Reviewed-by: Daniel Stenberg <daniel@haxx.se>
2022-05-02 14:04:59 +02:00
Daniel Gustafsson
a7b29122cb curl: free resource in error path
If the new filename cannot be generated due to memory pressure, free
the allocated aname on the way out to avoid a small leak.

Closes: #8770
Reviewed-by: Daniel Stenberg <daniel@haxx.se>
2022-04-30 21:25:15 +02:00
Daniel Gustafsson
6d86193377 curl: guard against size_t wraparound in no-clobber code
When generating the new filename, make sure we aren't overflowing the
size_t limit when calculating the new length. This is mostly academic
but good code hygeine nonetheless.

Closes: #8771
Reviewed-by: Daniel Stenberg <daniel@haxx.se>
2022-04-30 21:17:40 +02:00
Daniel Stenberg
a09a12806e
tool_getparam: error out on missing -K file
Add test 411 to verify.

Reported-by: Median Median Stride
Bug: https://hackerone.com/reports/1542881
Closes #8731
2022-04-25 11:38:50 +02:00
Daniel Stenberg
4ec0549c39
misc: update copyright year ranges 2022-04-25 09:31:09 +02:00
Daniel Stenberg
60452236fa
c_escape: escape '?' in generated --libcurl code
In order to avoid the risk of it being used in an accidental trigraph in
the generated code.

Reported-by: Harry Sintonen
Bug: https://hackerone.com/reports/1548535
Closes #8742
2022-04-25 00:29:22 +02:00
Marc Hoersken
68035af29d
timediff.[ch]: add curlx helper functions for timeval conversions
Also move timediff_t definitions from timeval.h to timediff.h and
then make timeval.h include the new standalone-capable timediff.h.

Reviewed-by: Jay Satiro
Reviewed-by: Daniel Stenberg

Supersedes #5888
Closes #8595
2022-04-17 13:11:27 +02:00
Emanuele Torre
77a6bf8489
tool_paramhlp: use feof(3) to identify EOF correctly when using fread(3)
This loop was using the number of bytes read from the file as condition
to keep reading.

From Linux's fread(3) man page:
> On success, fread() and fwrite() return the number of items read or
> written. This number equals the number of bytes transferred only when
> size is 1. If an error occurs, or the end of the file is reached, the
> return value is a short item count (or zero).
>
> The file position indicator for the stream is advanced by the number
> of bytes successfully read or written.
>
> fread() does not distinguish between end-of-file and error, and
> callers must use feof(3) and ferror(3) to determine which occurred.

This means that nread!=0 doesn't make much sense as an end condition for
the loop: nread==0 doesn't necessarily mean that EOF has been reached or
an error has occured (but that is usually the case) and nread!=0 doesn't
necessarily mean that EOF has not been reached or that no read errors
have occured. feof(3) and ferror(3) should be uses when using fread(3).

Currently curl has to performs an extra fread(3) call to get a return
value equal to 0 to stop looping.

This usually "works" (even though nread==0 shouldn't be interpreted as
EOF) if stdin is a pipe because EOF usually marks the "real" end of the
stream, so the extra fread(3) call will return immediately and the extra
read syscall won't be noticeable:

    bash-5.1$ strace -e read curl -s -F file=@- 0x0.st <<< a 2>&1 |
    > tail -n 5
    read(0, "a\n", 4096)                    = 2
    read(0, "", 4096)                       = 0
    read(0, "", 4096)                       = 0
    http://0x0.st/oRs.txt
    +++ exited with 0 +++
    bash-5.1$

But this doesn't work if curl is reading from stdin, stdin is a
terminal, and the EOF is being emulated using a shell with ^D. Two
consecutive ^D will be required in this case to actually make curl stop
reading:

    bash-5.1$ curl -F file=@- 0x0.st
    a
    ^D^D
    http://0x0.st/oRs.txt
    bash-5.1$

A possible workaround to this issue is to use a program that handles EOF
correctly to indirectly send data to curl's stdin:

    bash-5.1$ cat - | curl -F file=@- 0x0.st
    a
    ^D
    http://0x0.st/oRs.txt
    bash-5.1$

This patch makes curl handle EOF properly when using fread(3) in
file2memory() so that the workaround is not necessary.

Since curl was previously ignoring read errors caused by this fread(3),
ferror(3) is also used in the condition of the loop: read errors and EOF
will have the same meaning; this is done to somewhat preserve the old
behaviour instead of making the command fail when a read error occurs.

Closes #8701
2022-04-17 11:36:28 +02:00
Daniel Stenberg
01a1697a79
curl: error out if -T and -d are used for the same URL
As one implies PUT and the other POST, both cannot be used
simultaneously.

Add test 378 to verify.

Reported-by: Boris Verkhovskiy
Fixes #8704
Closes #8715
2022-04-17 11:18:17 +02:00
Daniel Stenberg
36e09dc302
fail.d: tweak the description
Reviewed-by: Daniel Gustafsson
Suggested-by: Robert Charles Muir
Ref: https://twitter.com/rcmuir/status/1514915401574010887

Closes #8714
2022-04-15 23:50:35 +02:00
Daniel Stenberg
4a8f6869db
English: use American spelling consistently
Authorization, Initialization, Organization etc.

Closes #8673
2022-04-05 14:55:47 +02:00
Daniel Stenberg
f48a0ce814
tool_listhelp.c: uppercase URL 2022-04-04 14:43:33 +02:00
Daniel Stenberg
a3f4d7cee9
misc: spelling fixes
Mostly in comments but also in the -w documentation for headers_json.

Closes #8647
2022-03-30 10:49:06 +02:00
Ian Blanes
9e5bd9ba19
curl: fix segmentation fault for empty output file names.
Function glob_match_url set *result to NULL when called with filename =
"", producing an indirect NULL pointer dereference.

Closes #8606
2022-03-28 09:39:09 +02:00
Daniel Stenberg
e7793cb57b
curl/header_json: output the header names in lowercase
To better allow json[“header”].

Reported-by: Peter Korsgaard
Bug: https://daniel.haxx.se/blog/2022/03/24/easier-header-picking-with-curl/comment-page-1/#comment-25878
Closes #8633
2022-03-25 11:24:27 +01:00
Daniel Stenberg
8e22fc68e7
scripts: move three scripts from lib/ to scripts/
Move checksrc.pl, firefox-db2pem.sh and mk-ca-bundle.pl since they don't
particularly belong in lib/

Also created an EXTRA_DIST= in scripts/Makefile.am instead of specifying
those files in the root Makefile.am

Closes #8625
2022-03-23 15:26:11 +01:00
Jay Satiro
cabcf403ed docs/opts: Mention Schannel client cert type is P12
Schannel backend code behaves same as Secure Transport, it expects a P12
certificate file or the name of a certificate already in the user's OS
key store. Also, both backends ignore CURLOPT_SSLKEY (tool: --key)
because they expect the private key to already be available from the
keystore or P12 certificate.

Ref: https://github.com/curl/curl/discussions/8581#discussioncomment-2337260

Closes https://github.com/curl/curl/pull/8587
2022-03-22 14:24:06 -04:00
Daniel Stenberg
4133a69f2d
curl: add %{header_json} support in -w handling
Outputs all response headers as a JSON object.
2022-03-22 08:24:25 +01:00
Daniel Stenberg
2d45137e1e
curl: add %header{name} support in -w handling
Outputs the response header 'name'
2022-03-22 08:24:25 +01:00
Jay Satiro
d3cb3be520 lib: fix some misuse of curlx_convert_wchar_to_UTF8
curlx_convert_wchar_to_UTF8 must be freed by curlx_unicodefree, but
prior to this change some uses mistakenly called free.

I've reviewed all other uses of curlx_convert_wchar_to_UTF8 and
curlx_convert_UTF8_to_wchar.

Ref: https://github.com/curl/curl/commit/1d5d0ae

Closes https://github.com/curl/curl/pull/8521
2022-03-18 03:20:03 -04:00
Marc Hoersken
8b42d7b9d4
tool and tests: force flush of all buffers at end of program
On Windows data can be lost in buffers in case of abnormal program
termination, especially in process chains as seen due to flaky tests.
Therefore flushing all buffers manually should avoid this data loss.

In the curl tool we play the safe game by only flushing write buffers,
but in the testsuite where we manage all buffers, we flush everything.

This should drastically reduce Windows CI and testsuite flakiness.

Reviewed-by: Daniel Stenberg

Supersedes #7833 and #6064
Closes #8516
2022-03-13 13:29:28 +01:00
Dan Fandrich
3055c4c814 tool_cb_hdr: Turn the Location: into a terminal hyperlink
This turns even relative URLs into clickable hyperlinks in a supported
terminal when --styled-output is enabled. Many terminals already turn
URLs into clickable links but there is not enough information in a
relative URL to do this automatically otherwise.
2022-03-11 17:25:35 -08:00
HexTheDragon
1831a6e7f1
curl: add --no-clobber
Does not overwrite output files if they already exist

Closes #7708
Co-authored-by: Daniel Stenberg
2022-03-11 08:38:01 +01:00
Daniel Stenberg
08a96c6e4e
curl: add --remove-on-error
If a transfer returns an error, using this option makes curl remove the
leftover downloded (partial) local file before exiting.

Added test 376 to verify

Closes #8503
2022-03-10 19:57:55 +01:00
Daniel Stenberg
bec62e39d1
tool_operate: fix a scan-build warning
... and avoid the temp storing of the return code in a diff variable.

Closes #8565
2022-03-10 08:31:20 +01:00