Commit Graph

12401 Commits

Author SHA1 Message Date
vvb2060
5a1a892565
easy_lock.h: use __asm__ instead of asm to fix build
Closes #9056
2022-06-28 00:02:26 +02:00
Daniel Stenberg
e2e7f54b7b
easy_lock.h: include sched.h if available to fix build
Patched-by: Harry Sintonen

Closes #9054
2022-06-27 10:59:52 +02:00
Daniel Stenberg
d64115d7bb
hsts: use Curl_fopen() 2022-06-26 11:04:02 +02:00
Daniel Stenberg
fab970a5d1
altsvc: use Curl_fopen() 2022-06-26 11:04:02 +02:00
Daniel Stenberg
20f9dd6bae
fopen: add Curl_fopen() for better overwriting of files
Bug: https://curl.se/docs/CVE-2022-32207.html
CVE-2022-32207
Reported-by: Harry Sintonen
Closes #9050
2022-06-26 11:03:57 +02:00
Daniel Stenberg
48d7064a49
cookie: apply limits
- Send no more than 150 cookies per request
- Cap the max length used for a cookie: header to 8K
- Cap the max number of received Set-Cookie: headers to 50

Bug: https://curl.se/docs/CVE-2022-32205.html
CVE-2022-32205
Reported-by: Harry Sintonen
Closes #9048
2022-06-26 11:00:48 +02:00
Daniel Stenberg
3a09fbb7f2
content_encoding: return error on too many compression steps
The max allowed steps is arbitrarily set to 5.

Bug: https://curl.se/docs/CVE-2022-32206.html
CVE-2022-32206
Reported-by: Harry Sintonen
Closes #9049
2022-06-25 22:14:21 +02:00
Daniel Stenberg
6ecdf5136b
krb5: return error properly on decode errors
Bug: https://curl.se/docs/CVE-2022-32208.html
CVE-2022-32208
Reported-by: Harry Sintonen
Closes #9051
2022-06-25 22:13:09 +02:00
Daniel Stenberg
2b67a0a112
easy_lock.h: remove use of the deprecated ATOMIC_VAR_INIT macro
clang 14 warns about its use. It is being deprecated by the working
group for the programming language C: "The macro ATOMIC_VAR_INIT is
basically useless for the purpose for which it was designed"

Ref: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2886.htm

Reported-by: Tatsuhiro Tsujikawa
Fixes #9041
Closes #9042
2022-06-23 16:17:09 +02:00
Stefan Eissing
8135d420ee
ngtcp2: avoid supplying 0 length msg_control to sendmsg()
Testing on macOS 12.4, sendmsg() fails with EINVAL when a msg_control
buffer is provided in sengmsg(), even though msg_controllen was set to
0.

Initialize msg.msg_controllen just as needed and also perform the size
assertion only when needed.

Closes #9039
2022-06-23 16:11:32 +02:00
Tom Eccles
71bbabb167
ftp: restore protocol state after http proxy CONNECT
connect_init() (lib/http_proxy.c) swaps out the protocol state while
working on the proxy connection, this is then restored by
Curl_connect_done() after the connection completes.

ftp_do_more() extracted the protocol state pointer to a local variable
at the start of the function then calls Curl_proxy_connect(). If the proxy
connection completes, Curl_proxy_connect() will call Curl_connect_done()
(via Curl_proxyCONNECT()), which restores data->req.p to point to the ftp
protocol state instead of the http proxy protocol state, but the local
variable in ftp_do_more still pointed to the old value.

Ultimately this meant that the state worked on by ftp_do_more() was the
http proxy state not the ftp state initialised by ftp_connect(), but
subsequent calls to any ftp_ function would use the original state.

For my use-case, the visible consequence was that ftp->downloadsize was
never set and so downloaded data was never returned to the application.

This commit updates the ftp protocol state pointer in ftp_do_more() after
Curl_proxy_connect() returns, ensuring that the correct state pointer is
used.

Fixes #8737
Closes #9043
2022-06-23 16:07:20 +02:00
Jay Satiro
3733717509 curl_setup: include _mingw.h
Prior to this change _mingw.h needed to be included in each unit before
evaluating __MINGW{32,64}_xxx_VERSION macros since it defines them. It
is included only in some mingw headers (eg stdio.h) and not others
(eg windows.h) so it's better to explicitly include it once.

Closes https://github.com/curl/curl/pull/9036
2022-06-23 03:34:51 -04:00
Viktor Szakats
70adb81c6f
rand: stop detecting /dev/urandom in cross-builds
- Prevent CMake to auto-detect /dev/urandom when cross-building.
  Before this patch, it would detect it in a cross-build scenario on *nix
  hosts with this device present. This was a problem for example with
  Windows builds, but it could affect any target system with this device
  missing. This also syncs detection behaviour with autotools, which also
  skips it for cross-builds.
- Also, make sure to never use the file RANDOM_FILE as entropy for libcurl's
  fallback random number generator on Windows. Windows does not have the
  concept of reading a random stream from a filename, nor any guaranteed
  non-world-writable path on disk. With this, a manual misconfiguration or
  an overeager auto-detection can no longer result in a user-controllable
  seed source.

Reviewed-by: Daniel Stenberg
Closes #9038
2022-06-22 09:35:46 +00: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
Daniel Stenberg
d5dc3629eb
easy: remove dead code
Follow-up from 5912da253b

Detected by Coverity (CID 1506519)

Closes #9029
2022-06-20 10:44:28 +02:00
Glenn Strauss
7f43f3dc59
transfer: upload performance; avoid tiny send
Append to the upload buffer when only small amount remains in buffer
rather than performing a separate tiny send to empty buffer.

Avoid degenerative upload behavior which might cause curl to send mostly
1-byte DATA frames after exhausing the h2 send window size

Related discussion: https://github.com/nghttp2/nghttp2/issues/1722

Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
Closes #8965
2022-06-20 09:42:40 +02:00
Pierrick Charron
4bf2c231d7
urlapi: make curl_url_set(url, CURLUPART_URL, NULL, 0) clear all parts
As per the documentation :

> Setting a part to a NULL pointer will effectively remove that
> part's contents from the CURLU handle.

But currently clearing CURLUPART_URL does nothing and returns
CURLUE_OK. This change will clear all parts of the URL at once.

Closes #9028
2022-06-20 08:15:51 +02:00
Jay Satiro
a8a4abb2ae vtls: make curl_global_sslset thread-safe
.. and update some docs to explain curl_global_* is now thread-safe.

Follow-up to 23af112 which made curl_global_init/cleanup thread-safe.

Closes https://github.com/curl/curl/pull/9016
2022-06-16 03:18:40 -04:00
Daniel Stenberg
ef22d5c42a
libssh: skip the fake-close when libssh does the right thing
Starting in libssh 0.10.0 ssh_disconnect() will no longer close our
socket. Instead it will be kept alive as we want it, and it is our
responsibility to close it later.

Ref: #8718
Ref: https://gitlab.com/libssh/libssh-mirror/-/merge_requests/240
Closes #9021
2022-06-15 23:43:35 +02: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
Daniel Stenberg
be632e23df
easy_lock: add SPDX license identifier
Closes #8998
2022-06-13 09:36:25 +02: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
Viktor Szakats
dd94076947
ngtcp2: fix typo in preprocessor condition
Ref: 927ede7edc

Bug: https://github.com/curl/curl/pull/8981#discussion_r894312185
Reported-by: Emil Engler
Closes #8987
2022-06-10 23:07:15 +00:00
Tatsuhiro Tsujikawa
927ede7edc
ngtcp2: build without sendmsg
Closes #8981
2022-06-10 09:10:54 +02:00
Tatsuhiro Tsujikawa
d2c6d8be18
ngtcp2: use handshake helper funcs to simplify TLS handshake integration
Closes #8968
2022-06-10 09:07:33 +02:00
Daniel Stenberg
90a7017acb
url: URL encode the path when extracted, if spaces were set 2022-06-08 16:32:46 +02:00
Daniel Stenberg
c3fc406ebb
urlapi: support CURLU_URLENCODE for curl_url_get() 2022-06-08 16:32:46 +02:00
Daniel Stenberg
5912da253b
select: return error from "lethal" poll/select errors
Adds two new error codes: CURLE_UNRECOVERABLE_POLL and
CURLM_UNRECOVERABLE_POLL one each for the easy and the multi interfaces.

Reported-by: Harry Sintonen
Fixes #8921
Closes #8961
2022-06-08 11:07:01 +02:00
Daniel Stenberg
07058f6ad8
transfer: maintain --path-as-is after redirects
Reported-by: Marcus T
Fixes #8974
Closes #8975
2022-06-08 10:30:36 +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
Thomas Guillem
23af112f55
lib: make curl_global_init() threadsafe when possible
Use a posix pthread or a Windows SRWLOCK to lock curl_global_init*() and
curl_global_cleanup().

Closes #8680
2022-06-07 13:34:03 +02:00
Daniel Stenberg
6754f99398
ftp: when failing to do a secure GSSAPI login, fail hard
... instead of switching to cleartext. For the sake of security.

Reported-by: Harry Sintonen
Bug: https://hackerone.com/reports/1590102
Closes #8963
2022-06-06 11:55:39 +02:00
Daniel Stenberg
21ea13cfe1
http2: reject overly many push-promise headers
Getting more than a thousand of them is rather a sign of some kind of
attack.

Reported-by: Harry Sintonen
Bug: https://hackerone.com/reports/1589847
Closes #8962
2022-06-06 11:53:49 +02:00
Fabian Keil
9dbce9b3d0
misc: spelling improvements
Closes #8956
2022-06-05 12:15:23 +02:00
Tatsuhiro Tsujikawa
298c1dfc7b
ngtcp2: fix assertion failure on EMSGSIZE
Closes #8958
2022-06-05 12:12:26 +02:00
Daniel Stenberg
2bd75e5686
easy/transfer: fix cookie-disabled build
Follow-up from 45de940ceb
Reported-by: Marcel Raad
Fixes #8953
Closes #8954
2022-06-02 22:54:12 +02:00
Wolf Vollprecht
4d4eb8e587
netrc: check %USERPROFILE% as well on Windows
Closes #8855
2022-06-02 09:32:51 +02:00
michael musset
1544513958
libssh2: add CURLOPT_SSH_HOSTKEYFUNCTION
The callback set by CURLOPT_SSH_HOSTKEYFUNCTION is called to check
wether or not the connection should continue.

The host key is passed in argument with a custom handle for the
application.

It overrides CURLOPT_SSH_KNOWNHOSTS

Closes #7959
2022-06-02 08:34:31 +02:00
Evgeny Grin
f59508e6cd
digest: tolerate missing "realm"
Server headers may not define "realm", avoid NULL pointer dereference
in such cases.

Closes #8912
2022-06-02 08:18:54 +02:00
Evgeny Grin
807f440301
digest: added detection of more syntax error in server headers
Invalid headers should not be processed otherwise they may create
a security risk.

Closes #8912
2022-06-02 08:18:48 +02:00
Evgeny Grin
3a6fe0c767
digest: unquote realm and nonce before processing
RFC 7616 (and 2617) requires values to be "unquoted" before used for
digest calculations. The only place where unquoting can be done
correctly is header parsing function (realm="DOMAIN\\host" and
realm=DOMAN\\host are different realms).

This commit adds unquoting (de-escaping) of all values during header
parsing and quoting of the values during header forming. This approach
should be most straightforward and easy to read/maintain as all values
are processed in the same way as required by RFC.

Closes #8912
2022-06-02 08:18:34 +02:00
Daniel Stenberg
f810047f9d
headers: handle unfold of space-cleansed headers
Detected by OSS-fuzz

Bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=47767

Updated test 1274

Closes #8947
2022-06-01 15:24:49 +02:00
Daniel Stenberg
45de940ceb
lib: make more protocol specific struct fields #ifdefed
... so that they don't take up space if the protocols are disabled in
the build.

Closes #8944
2022-06-01 14:31:49 +02:00
Daniel Stenberg
8b1ae28509
urldata: store tcp_keepidle and tcp_keepintvl as ints
They can't be set larger than INT_MAX in the setsocket API calls.

Also document the max values in their respective man pages.

Closes #8940
2022-06-01 08:12:09 +02:00
Daniel Stenberg
4651945822
urldata: reduce size of a few struct fields
When the values are never larger than 32 bit, ints are better than longs.

Closes #8940
2022-06-01 08:12:09 +02:00
Daniel Stenberg
b1c1df0b6b
urldata: remove three unused booleans from struct UserDefined
- is_fwrite_set
- free_referer
- strip_path_slash

Closes #8940
2022-06-01 08:12:09 +02:00
Tatsuhiro Tsujikawa
3288e9c6d3
ngtcp2: enable Linux GSO
Enable Linux GSO in ngtcp2 QUIC.  In order to recover from the
EAGAIN/EWOULDBLOCK by sendmsg with multiple packets in one GSO write,
packet buffer is now held by struct quicsocket.  GSO write might fail in
runtime depending on NIC.  Disable GSO if sendmsg returns EIO.

Closes #8909
2022-05-31 16:04:12 +02:00
Daniel Stenberg
b7baa78451
headers_push: error out if a folded header has no previous header
As that would indicate an illegal header. The fuzzer reached the assert
in unfold_value() proving that this case can happen.

Follow-up to c9b60f0053

Closes #8939
2022-05-31 14:03:44 +02:00
Daniel Stenberg
eeaae10c0f
netrc: support quoted strings
The .netrc parser now accepts strings within double-quotes in order to
deal with for example passwords containing white space - which
previously was not possible.

A password that starts with a double-quote also ends with one, and
double-quotes themselves are escaped with backslashes, like \". It also
supports \n, \r and \t for newline, carriage return and tabs
respectively.

If the password does not start with a double quote, it will end at first
white space and no escaping is performed.

WARNING: this change is not entirely backwards compatible. If anyone
previously used a double-quote as the first letter of their password,
the parser will now get it differently compared to before. This is
highly unfortunate but hard to avoid.

Reported-by: ImpatientHippo on GitHub
Fixes #8908
Closes #8937
2022-05-31 09:04:56 +02:00
Daniel Stenberg
4d94fac9f0
headers api: remove EXPERIMENTAL tag
Closes #8900
2022-05-30 14:13:48 +02:00