Commit Graph

13185 Commits

Author SHA1 Message Date
Daniel Stenberg
90aea8e2a9
schannel: add clarifying comment
Explaining how the PVS warning in #10929 is wrong: Dereferencing of the
null pointer 'backend->cred' might take place.

Closes #10931
2023-04-11 23:50:49 +02:00
Daniel Stenberg
b1b326ec50
cookie: clarify that init with data set to NULL reads no file
... and make Curl_cookie_add() require 'data' being set proper with an
assert.

The function has not worked with a NULL data for quite some time so this
just corrects the code and comment.

This is a different take than the proposed fixed in #10927

Reported-by: Kvarec Lezki
Ref: #10929
Closes #10930
2023-04-11 23:49:50 +02:00
Kvarec Lezki
a1763648a5
vtls: remove int typecast for sizeof()
V220 Suspicious sequence of types castings: memsize -> 32-bit integer ->
memsize. The value being cast: 'sizeof
(buf->data)'. curl\lib\vtls\vtls.c 2025

https://pvs-studio.com/en/docs/warnings/v220/

Closes #10928
2023-04-11 23:48:06 +02:00
Stefan Eissing
c59b5b3c87
http2: fix copynpaste error reported by coverity
- move all code handling HTTP/2 frames for a particular
  stream into a separate function to keep from confusing
  the call `data` with the stream `data`.

Closes #10924
2023-04-11 23:46:53 +02:00
Daniel Stenberg
452b8e39ef
http2: avoid possible null pointer dereference
Reported-by: Dan Fandrich
Fixes #10920
Closes #10923
2023-04-11 12:29:03 +02:00
Daniel Stenberg
826e8011d5
urlapi: prevent setting invalid schemes with *url_set()
A typical mistake would be to try to set "https://" - including the
separator - this is now rejected as that would then lead to
url_get(... URL...) would get an invalid URL extracted.

Extended test 1560 to verify.

Closes #10911
2023-04-09 23:23:54 +02:00
Biswapriyo Nath
5023d7c944
http2: remove unused Curl_http2_strerror function declaration
Curl_http2_strerror was renamed to http2_strerror in
05b100aee2 and then http2_strerror was removed in
5808a0d0f5

This also fixes the following compiler error

lib/http2.h:41:33: error: unknown type name 'uint32_t'
lib/http2.h:1:1: note: 'uint32_t' is defined in header '<stdint.h>'

Closes #10912
2023-04-09 23:21:42 +02:00
SuperIlu on github
92617713b6
config-dos.h: fix SIZEOF_CURL_OFF_T for MS-DOS/DJGPP
Fixes #10905
Closes #10910
2023-04-08 23:53:50 +02:00
Daniel Stenberg
5f307986a3
lib: remove CURLX_NO_MEMORY_CALLBACKS
The only user of this define was 'chkdecimalpoint' - a special purpose
test tool that was built but not used anymore (since 17c18fbc3 - Apr
2020).

Closes #10908
2023-04-08 17:47:10 +02:00
Daniel Stenberg
712e5f1e7f
CURLPROXY_HTTPS2: for HTTPS proxy that may speak HTTP/2
Setting this proxy type allows curl to negotiate and use HTTP/2 with
HTTPS proxies.

Closes #10900
2023-04-08 00:27:53 +02:00
Daniel Stenberg
772e28ff76
http2: remove check for !data after it was already dereferenced
Pointed out by Coverity

Closes #10906
2023-04-07 23:49:51 +02:00
Daniel Stenberg
887acb48e4
http_proxy: provide missing arg to infof() call
Pointed out by Coverity

Closes #10904
2023-04-07 23:48:38 +02:00
Daniel Stenberg
4033642930
content_encoding: only do tranfer-encoding compression if asked to
To reduce surprises. Update test 387 and 418 accordingly.

Closes #10899
2023-04-07 13:39:20 +02:00
Daniel Stenberg
4838863d27
lib/cmake: add HAVE_WRITABLE_ARGV check
Assisted-by: Jakub Zakrzewski
Closes #10896
2023-04-06 23:52:31 +02:00
Daniel Stenberg
0ba120e307
vtls: fix build error when proxy-disabled
Closes #10901
2023-04-06 23:50:48 +02:00
Stefan Eissing
632e0fbe70
http2: move HTTP/2 stream vars into local context
- remove NGHTTP2 members of `struct HTTP`
- add `void *h2_ctx` to `struct HTTP`
- add `void *h3_ctx` to `struct HTTP`
- separate h2/h3 pointers are needed for eyeballing
- manage local stream_ctx in http implementations

Closes #10877
2023-04-06 16:27:50 +02:00
Stefan Eissing
4ae2d9f24d
proxy: http2 proxy tunnel implementation
- currently only on debug build and when env variable
  CURL_PROXY_TUNNEL_H2 is present.
- will ALPN negotiate with the proxy server and switch
  tunnel filter based on the protocol negotiated.
- http/1.1 tunnel code moved into cf-h1-proxy.[ch]
- http/2 tunnel code implemented in cf-h2-proxy.[ch]
- tunnel start and ALPN set remains in http_proxy.c
- moving all haproxy related code into cf-haproxy.[ch]

VTLS changes
- SSL filters rely solely on the "alpn" specification they
  are created with and no longer check conn->bits.tls_enable_alpn.
- checks on which ALPN specification to use (or none at all) are
  done in vtls.c when creating the filter.

Testing
- added a nghttpx forward proxy to the pytest setup that
  speaks HTTP/2 and forwards all requests to the Apache httpd
  forward proxy server.
- extending test coverage in test_10 cases
- adding proxy tests for direct/tunnel h1/h2 use of basic auth.
- adding test for http/1.1 and h2 proxy tunneling to pytest

Closes #10780
2023-04-06 13:04:46 +02:00
Stefan Eissing
8f50e393ab
vtls and h2 improvements
- eliminate receive loop in vtls to fill buffer. This may
  lead to partial reads of data which is counter productive
- let http2 instead loop smarter to process pending network
  data without transfer switches

scorecard improvements
- do not start caddy when only httpd is requested
- allow curl -v to stderr file on --curl-verbose

Closes #10891
2023-04-06 09:41:54 +02:00
Daniel Stenberg
17a15d8846
urlapi: detect and error on illegal IPv4 addresses
Using bad numbers in an IPv4 numerical address now returns
CURLUE_BAD_HOSTNAME.

I noticed while working on trurl and it was originally reported here:
https://github.com/curl/trurl/issues/78

Updated test 1560 accordingly.

Closes #10894
2023-04-06 09:02:00 +02:00
Daniel Stenberg
f042e1e75d
urlapi: URL encoding for the URL missed the fragment
Meaning that it would wrongly still store the fragment using spaces
instead of %20 if allowing space while also asking for URL encoding.

Discovered when playing with trurl.

Added test to lib1560 to verify the fix.

Closes #10887
2023-04-05 08:30:12 +02:00
Daniel Stenberg
4399a532e9
rtsp: convert mallocs to dynbuf for RTP buffering
Closes #10786
2023-04-04 14:44:25 +02:00
Stefan Eissing
3797f1a4ca
rustls: fix error in recv handling
- when rustls is told to recieve more TLS data and its internal
  plaintext buffers are full, it returns an IOERROR
- avoid receiving TLS data while plaintext is not read empty

pytest:
- increase curl run timeout when invoking pytest with higher verbosity

Closes #10876
2023-03-31 16:05:15 +02:00
Stefan Eissing
544abeea83
http3: improvements across backends
- ngtcp2: using bufq for recv stream data
- internal stream_ctx instead of `struct HTTP` members
  for quiche, ngtcp2 and msh3
- no more QUIC related members in `struct HTTP`
- experimental use of recvmmsg(), disabled by default
  - testing on my old debian box shows no throughput improvements.
  - leaving it in, but disabled, for future revisit
- vquic: common UDP receive code for ngtcp2 and quiche
- vquic: common UDP send code for ngtcp2 and quiche
- added pytest skips for known msh3 failures
- fix unit2601 to survive torture testing
- quiche: using latest `master` from quiche and enabling large download
  tests, now that key change is supported
- fixing test_07_21 where retry handling of starting a stream
  was faulty
- msh3: use bufq for recv buffering headers and data
- msh3: replace fprintf debug logging with LOG_CF where possible
- msh3: force QUIC expire timers on recv/send to have more than
  1 request per second served

Closes #10772
2023-03-31 15:44:57 +02:00
Daniel Stenberg
2d59eb0035
rtsp: fix Value stored to 'skip_size' is never read
Pointed out by scan-build

Follow-up to 6c6306f300

Closes #10872
2023-03-30 23:59:26 +02:00
Stefan Eissing
744dcf22fa
http2: flow control and buffer improvements
- use bufq for send/receive of network data
- usd bufq for send/receive of stream data
- use HTTP/2 flow control with no-auto updates to control the
  amount of data we are buffering for a stream
  HTTP/2 stream window set to 128K after local tests, defined
  code constant for now
- elminiating PAUSEing nghttp2 processing when receiving data
  since a stream can now take in all DATA nghttp2 forwards

Improved scorecard and adjuste http2 stream window sizes
- scorecard improved output formatting and options default
- scorecard now also benchmarks small requests / second

Closes #10771
2023-03-30 23:11:26 +02:00
Matt Jolly
0ae0abbe72
hostip: refuse to resolve the .onion TLD
RFC 7686 states that:

> Applications that do not implement the Tor
> protocol SHOULD generate an error upon the use of .onion and
> SHOULD NOT perform a DNS lookup.

Let's do that.

https://www.rfc-editor.org/rfc/rfc7686#section-2

Add test 1471 and 1472 to verify

Fixes #543
Closes #10705
2023-03-30 15:51:06 +02:00
Jim King
34ef4fab22
openssl: interop with AWS-LC
* Configure changes to detect AWS-LC
* CMakeLists.txt changes to detect AWS-LC
* Compile-time branches needed to support AWS-LC
* Correctly set OSSL_VERSION and report AWS-LC release number
* GitHub Actions script to build with autoconf and cmake against AWS-LC

AWS-LC is a BoringSSL/OpenSSL derivative
For more information see https://github.com/awslabs/aws-lc/

Closes #10320
2023-03-30 10:56:14 +02:00
Stefan Eissing
b74bba9aad
vlts: use full buffer size when receiving data if possible
SSL backends like OpenSSL/wolfSSL and other return the content of one
TLS record on read, but usually there are more available.

Change the vtls cfilter recv() function to fill the given buffer until a
read would block.

Closes #10736
2023-03-30 10:04:20 +02:00
dengjfzh
6c6306f300
rtsp: skip malformed RTSP interleaved frame data
Some IP cameras send malformed RTSP interleaved frames sometimes, which
can cause curl_easy_perform return 1 (CURLE_UNSUPPORTED_PROTOCOL).  This
change attempts to skip clearly incorrect RTSP interleaving frame data.

Closes #10808
2023-03-30 09:59:09 +02:00
Stefan Eissing
61f52a97e9
lib: add bufq and dynhds
Adding `bufq`:
- at init() time configured to hold up to `n` chunks of `m` bytes each.
- various methods for reading from and writing to it.
- `peek` support to get access to buffered data without copy
- `pass` support to allow buffer flushing on write if it becomes full
- use case: IO buffers for dynamic reads and writes that do not blow up
- distinct from `dynbuf` in that:
  - it maintains a read position
  - writes on a full bufq return CURLE_AGAIN instead of nuking itself
- Init options:
  - SOFT_LIMIT: allow writes into a full bufq
  - NO_SPARES: free empty chunks right away
- a `bufc_pool` that can keep a number of spare chunks to
  be shared between different `bufq` instances

Adding `dynhds`:
- a straightforward list of name+value pairs as used for HTTP headers
- headers can be appended dynamically
- headers can be removed again
- headers can be replaced
- headers can be looked up
- http/1.1 formatting into a `dynbuf`
- configured at init() with limits on header counts and total string
  sizes
- use case: pass a HTTP request or response around without being version
  specific
- express a HTTP request without a curl easy handle (used in h2 proxy
  tunnels)
- future extension possibilities:
  - conversions of `dynhds` to nghttp2/nghttp3 name+value arrays

Closes #10720
2023-03-30 09:08:05 +02:00
Daniel Stenberg
8455013359
lib: use correct printf flags for sockets and timediffs
Introduces CURL_FORMAT_SOCKET_T for outputting socket numbers.

Fixes #10737
Reported-by: Gisle Vanem
Closes #10855
2023-03-29 13:12:29 +02:00
Daniel Stenberg
9a607fd728
telnet: make MSVC ignore warning for assignment within conditional
Follow-up to d92a5007b6

Closes #10859
2023-03-29 13:07:17 +02:00
Daniel Stenberg
b19cbebbb4
ws: handle reads before EAGAIN better
Reported-by: simplerobot on github
Fixes #10831
Closes #10856
2023-03-29 10:23:29 +02:00
Frank Gevaerts
abb9be36f1
lib/sha256.c: typo fix in comment (duplicated "is available")
Closes #10851
2023-03-28 17:52:41 +02:00
Kamil Dudka
d92a5007b6 telnet: simplify the implementation of str_is_nonascii()
There is no need to traverse the string twice.

Closes #10852
2023-03-28 15:41:55 +02:00
Daniel Stenberg
5a10f48778
dynbuf: never allocate larger than "toobig"
As dynbufs always have a fixed maximum size which they are not allowed
to grow larger than, making sure that it never allocates a larger buffer
makes sure the buffer does not allocate memory that will never be used.

Closes #10845
2023-03-28 10:22:53 +02:00
Daniel Stenberg
c1d6fe2aaa
ftplistparser: replace realloc with dynbuf
Closes #10844
2023-03-28 10:11:33 +02:00
Daniel Stenberg
2203bd13ff
ftplistparser: use ISDIGIT()
Closes #10844
2023-03-28 10:11:33 +02:00
Daniel Stenberg
01114f6efd
ftplistparser: move out private data from public struct
The public 'curl_fileinfo' struct contained three fields that are for
internal purposes only. This change makes them unused in the public
struct.

The new private struct fields are also renamed to make this separation
more obvious internally.

Closes #10844
2023-03-28 10:11:33 +02:00
Daniel Stenberg
e4cd1ffed1
openssl: fix indents - white space edits only
Closes #10840
2023-03-28 10:02:40 +02:00
Daniel Stenberg
5fec927374
url: remove call to Curl_llist_destroy in Curl_close
A list that is created with a NULL "destructor" does not need to be
destroyed. Not calling it is faster than calling it.

Closes #10846
2023-03-27 23:36:16 +02:00
Daniel Stenberg
843b3baa3e
multi: remove PENDING + MSGSENT handles from the main linked list
As they are not driving transfers or any socket activity, the main loop
does not need to iterate over these handles. A performance improvement.

They are instead only held in their own separate lists.

'data->multi' is kept a pointer to the multi handle as long as the easy
handle is actually part of it even when the handle is moved to the
pending/msgsent lists. It needs to know which multi handle it belongs
to, if for example curl_easy_cleanup() is called before the handle is
removed from the multi handle.

Alll 'data->multi' pointers of handles still part of the multi handle
gets cleared by curl_multi_cleanup() which "orphans" all previously
attached easy handles.

This is take 2. The first version was reverted for the 8.0.1 release.

Assisted-by: Stefan Eissing
Closes #10801
2023-03-26 17:43:28 +02:00
Daniel Stenberg
4528690cd5
cmake: set SONAME for SunOS too
Provided-by: Brian Lund

Closes #10816
2023-03-23 15:40:44 +01:00
Stefan Eissing
78f73f79ca
ngtcp2: adjust config and code checks for ngtcp2 without nghttp3
- make configure show on HTTP3 feature that both ngtcp2 and nghttp3
  are in play
- define ENABLE_QUIC only when USE_NGTCP2 and USE_NGHTTP3 are defined
- add USE_NGHTTP3 in the ngtcp2 implementation

Fixes #10793
Closes #10821
2023-03-23 15:39:13 +01:00
Daniel Stenberg
0c2fcb0f60
ntlm: clear lm and nt response buffers before use
To avoid the risk of MemorySanitizer: use-of-uninitialized-value

Closes #10814
2023-03-23 09:25:05 +01:00
Daniel Stenberg
955e2769f7
digest: clear target buffer
Closes #10814
2023-03-23 09:24:59 +01:00
Stefan Eissing
5d1ecbcbd2
multi: add handle asserts in DEBUG builds
For GOOD_EASY_HANDLE and GOOD_MULTI_HANDLE checks

- allow NULL pointers to "just" return an error as before
- fail hard on nun-NULL pointers that no longer show the MAGICs

Closes #10812
2023-03-22 13:57:20 +01:00
jonrumsey
8a83bda0a2
gskit: various compile errors in OS400
Various compile failures in gskit.c;

- pipe_ssloverssl() needs Curl_easy data parameter for
  Curl_conn_cf_get_socket(cf, data)
- key_passwd is in ssl_config, not conn_config
- close_on() has 2 parameters, not 4
- getsockopt() needs to call Curl_conn_cf_get_socket(), not
  cxn->sock[FIRSTSOCKET]

Fixes #10799
Closes #10800
2023-03-22 13:55:26 +01:00
Daniel Stenberg
c2df780a97
Revert "multi: remove PENDING + MSGSENT handles from the main linked list"
This reverts commit f6d6f3ce01.

The commits caused issues in the 8.0.0 release. Needs a retake.

Reported-by: Kamil Dudka
Closes #10795
2023-03-20 14:49:04 +01:00
Daniel Stenberg
138860576f
cf-socket: use port 80 when resolving name for local bind
It turns out c-ares returns an error when asked to resolve a host name with
ares_getaddrinfo using port number 0.

Reported as a c-ares bug here: https://github.com/c-ares/c-ares/issues/517

The work-around is to simply use port 80 instead, as the number typically does
not make a difference and a non-zero number works for c-ares.

Fixes #10759
Reported-by: Matt Jolly
Closes #10789
2023-03-17 22:55:31 +01:00
Daniel Stenberg
f5e0f52dd3
Revert "rtsp: use dynbuf instead of custom reallocs"
This reverts commit 1b9ea3239d because of OSS-fuzz reports.
I'll do another take after the pending release.

Closes #10785
2023-03-17 15:41:07 +01:00
Daniel Stenberg
f7a3fae4cb
libssh: use dynbuf instead of realloc
When building lines to show for SFTP directory listings.

Closes #10778
2023-03-16 23:32:22 +01:00
Daniel Stenberg
1b9ea3239d
rtsp: use dynbuf instead of custom reallocs
For the RTP buffering.

Closes #10776
2023-03-16 16:09:55 +01:00
Daniel Stenberg
d2d0e60012
libssh2: remove unused variable from libssh2's struct
Closes #10777
2023-03-16 13:44:48 +01:00
Daniel Stenberg
f6d6f3ce01
multi: remove PENDING + MSGSENT handles from the main linked list
As they are not driving transfers or any socket activity, the main loop
does not need to iterate over these handles. A performance improvement.

They are instead only held in their own separate lists.

Assisted-by: Stefan Eissing
Ref: #10743
Closes #10762
2023-03-15 10:37:49 +01:00
Daniel Stenberg
a208be3710
multi: turn link/unlinking easy handles into dedicated functions 2023-03-15 10:37:48 +01:00
Daniel Stenberg
18a45a51ba
http_aws_sigv4: fix scan-build "value stored to 'ret' is never read"
Follow-up to 495d09810a

Closes #10766
2023-03-15 07:32:01 +01:00
Daniel Stenberg
e5e8815532
lib: skip Curl_llist_destroy calls
Linked lists themselves do not carry any allocations, so for the lists
that do not have have a set destructor we can just skip the
Curl_llist_destroy() call and save CPU time.

Closes #10764
2023-03-15 00:10:21 +01:00
Casey Bodley
495d09810a
aws_sigv4: fall back to UNSIGNED-PAYLOAD for sign_as_s3
all s3 requests default to UNSIGNED-PAYLOAD and add the required
x-amz-content-sha256 header. this allows CURLAUTH_AWS_SIGV4 to correctly
sign s3 requests to amazon with no additional configuration

Signed-off-by: Casey Bodley <cbodley@redhat.com>

Closes #9995
2023-03-14 17:04:47 +01:00
Viktor Szakats
ebef55a61d
wolfssl: add quic/ngtcp2 detection in cmake, and fix builds
- add QUIC/ngtcp2 detection in CMake with wolfSSL.

  Because wolfSSL uses zlib if available, move compression detection
  before TLS detection. (OpenSSL might also need this in the future.)

- wolfSSL 5.5.0 started using C99 types in its `quic.h` header, but it
  doesn't #include the necessary C99 header itself, breaking builds
  (unless another dependency pulled it by chance.) Add local workaround
  for it. For this to work with all build tools, we had to fix our
  header detection first. Ref: #10745

  Ref: 6ad5f6ecc1

Closes #10739
2023-03-14 11:57:55 +00:00
Stefan Eissing
31889210b9
secure-transport: fix recv return code handling
Return code handling of recv calls were not always correct when an error
occured or the connection was closed.

Closes #10717
2023-03-14 09:59:27 +01:00
Stefan Eissing
06f65f771b http2: Use KEEP_SEND_HOLD for flow control in HTTP/2
- use the defined, but so far not used, KEEP_SEND_HOLD bit for flow
  control based suspend of sending in transfers.

Prior to this change KEEP_SEND_PAUSE bit was used instead, but that can
interfere with pausing streams from the user side via curl_easy_pause.

Fixes https://github.com/curl/curl/issues/10751
Closes https://github.com/curl/curl/pull/10753
2023-03-14 03:26:57 -04:00
Daniel Stenberg
bc90308328
multi: make multi_perform ignore/unignore signals less often
For improved performance

Reported-by: Jerome St-Louis
Ref: #10743
Closes #10750
2023-03-13 23:01:02 +01:00
Viktor Szakats
9f96537cc3
cmake: delete unused HAVE__STRTOI64
Also delete obsolete surrounding comments.

Reviewed-by: Daniel Stenberg
Closes #10756
2023-03-13 15:49:54 +00:00
Viktor Szakats
db073c9d88
build: fix stdint/inttypes detection with non-autotools
Fix `stdint.h` and `inttypes.h` detection with non-autotools builds on
Windows. (autotools already auto-detected them accurately.)

`lib/config-win32.h` builds (e.g. `Makefile.mk`):
- set `HAVE_STDINT_H` where supported.
- set `HAVE_INTTYPES_H` for MinGW.

CMake:
- auto-detect them on Windows. (They were both force-disabled.)
- delete unused `CURL_PULL_STDINT_H`.
- delete unused `CURL_PULL_INTTYPES_H`.
- stop detecting `HAVE_STDINT_H` twice.
  Present since the initial CMake commit: 4c5307b456

curl doesn't use these C99 headers, we need them now to workaround
broken wolfSSL builds. Ref: #10739

Once that clears up, we can delete these detections and macros (unless
we want to keep them for future us.)

Reviewed-by: Daniel Stenberg
Closes #10745
2023-03-13 10:47:21 +00:00
Daniel Stenberg
8f4608468b
ftp: add more conditions for connection reuse
Reported-by: Harry Sintonen
Closes #10730
2023-03-13 09:07:23 +01:00
Viktor Szakats
a285b22f8f
Makefile.mk: fix -g option in debug mode [ci skip]
Add it to `CFLAGS` (was: `LDFLAGS`).

Closes #10747
2023-03-13 00:16:30 +00:00
Dan Fandrich
ee521a1c88 http: don't send 100-continue for short PUT requests
This is already how curl is documented to behave in Everything curl, but
in actuality only short POSTs skip this. This should knock 30 seconds
off a full run of the test suite since the 100-continue timeout will no
longer be hit.

Closes #10740
2023-03-11 18:57:19 -08:00
Stefan Eissing
544a7f804d
http2: fix error handling during parallel operations
RST and connection close were not handled correctly during parallel
transfers, leading to aborted response bodies being reported complete.

Closes #10715
2023-03-10 23:52:53 +01:00
Daniel Stenberg
cb49e67303
url: only reuse connections with same GSS delegation
Reported-by: Harry Sintonen
Closes #10731
2023-03-10 23:30:34 +01:00
Viktor Szakats
b725fe1944
lib: silence clang/gcc -Wvla warnings in brotli headers
brotli v1.0.0 throughout current latest v1.0.9 and latest master [1]
trigger this warning.

It happened with CMake and GNU Make. autotools builds avoid it with
the `convert -I options to -isystem` macro.

llvm/clang:
```
In file included from ./curl/lib/content_encoding.c:36:
./brotli/x64-ucrt/usr/include/brotli/decode.h:204:34: warning: variable length array used [-Wvla]
    const uint8_t encoded_buffer[BROTLI_ARRAY_PARAM(encoded_size)],
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./brotli/x64-ucrt/usr/include/brotli/port.h:253:34: note: expanded from macro 'BROTLI_ARRAY_PARAM'
                                 ^~~~~~
In file included from ./curl/lib/content_encoding.c:36:
./brotli/x64-ucrt/usr/include/brotli/decode.h:206:48: warning: variable length array used [-Wvla]
    uint8_t decoded_buffer[BROTLI_ARRAY_PARAM(*decoded_size)]);
                           ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
./brotli/x64-ucrt/usr/include/brotli/port.h:253:35: note: expanded from macro 'BROTLI_ARRAY_PARAM'
                                 ~^~~~~
```

gcc:
```
In file included from ./curl/lib/content_encoding.c:36:
./brotli/x64-ucrt/usr/include/brotli/decode.h:204:5: warning: ISO C90 forbids variable length array 'encoded_buffer' [-Wvla]
  204 |     const uint8_t encoded_buffer[BROTLI_ARRAY_PARAM(encoded_size)],
      |     ^~~~~
./brotli/x64-ucrt/usr/include/brotli/decode.h:206:5: warning: ISO C90 forbids variable length array 'decoded_buffer' [-Wvla]
  206 |     uint8_t decoded_buffer[BROTLI_ARRAY_PARAM(*decoded_size)]);
      |     ^~~~~~~
```

[1] ed1995b6bd

Reviewed-by: Daniel Stenberg
Reviewed-by: Marcel Raad
Closes #10738
2023-03-10 22:24:24 +00:00
Daniel Stenberg
4e2b52b5f7
curl_path: create the new path with dynbuf
Closes #10729
2023-03-10 23:20:19 +01:00
Daniel Stenberg
f384d40718
url: remove dummy protocol handler
Just two added checks were needed saves a whole handler struct.

Closes #10727
2023-03-10 23:19:20 +01:00
Daniel Stenberg
af369db4d3
url: fix the SSH connection reuse check
Reported-by: Harry Sintonen
Closes #10735
2023-03-10 17:54:32 +01:00
Daniel Stenberg
538b1e79a6
telnet: only accept option arguments in ascii
To avoid embedded telnet negotiation commands etc.

Reported-by: Harry Sintonen
Closes #10728
2023-03-10 17:43:18 +01:00
Jay Satiro
b559ef6f36 url: fix cookielist memleak when curl_easy_reset
- Free set.cookelist in Curl_freeset instead of Curl_close.

Prior to this change the cookielist linked list wasn't freed by
curl_easy_reset which calls Curl_freeset to free all set.

Bug: https://github.com/curl/curl/issues/10694#issuecomment-1458619157
Reported-by: Sergey Ryabinin

Closes https://github.com/curl/curl/pull/10709
2023-03-10 03:49:16 -05:00
Stefan Eissing
940b67803a
wolfSSL: ressurect the BIO io_result
In pytest'ing the situation occored that wolfSSL reported an
IO error when the underlying BIO operation was returning an
CURLE_AGAIN condition.

Readding the `io_result` filter context member to detect such
situations.

Also, making sure that the returned CURLcode is initialized
on all recv operations outcome.

Closes #10716
2023-03-10 08:06:17 +01:00
Stefan Eissing
adaec5d1d0
gssapi: align global gss_OID_desc vars to silence ld warnings on macOS ventura
Refs #9975 which first reported this.

Closes #10718
2023-03-10 08:04:42 +01:00
Daniel Stenberg
8b5f100db3
libssh2: only set the memory callbacks when debugging
This makes us debug libssh2 less and libcurl more when for example
running torture tests that otherwise will spend a lot of time in libssh2
functions.

We leave libssh2 to test libssh2.

Closes #10721
2023-03-10 08:01:47 +01:00
Daniel Stenberg
05616379ee
headers: make curl_easy_header and nextheader return different buffers
By letting curl_easy_header() and curl_easy_nextheader() store the
header data in their own struct storage when they return a pointer to
it, it makes it possible for applications to use them both in a loop.
Like the curl tool does.

Reported-by: Boris Okunskiy
Fixes #10704
Closes #10707
2023-03-09 00:13:41 +01:00
rcombs
b1d735956f
urlapi: take const args in _dup and _get functions
Closes #10708
2023-03-08 15:38:26 +01:00
rcombs
95cb7d3166
urlapi: avoid mutating internals in getter routine
This was not intended.

Closes #10708
2023-03-08 15:38:18 +01:00
Daniel Stenberg
0a0c9b6dfa
urlapi: '%' is illegal in host names
Update test 1560 to verify

Ref: #10708
Closes #10711
2023-03-08 15:33:43 +01:00
Daniel Stenberg
0546ed54c2
ftp: make the 'ftpauth' a more normal 'char *'-array
Closes #10703
2023-03-08 15:32:16 +01:00
Viktor Szakats
75087c3baa
misc: fix typos
Closes #10706
2023-03-08 08:00:35 +00:00
Stefan Eissing
a26418cf14
ftp: active mode with SSL, add the damn filter
- since 7.87.0 we lost adding the SSL filter for an active
  FTP connection that uses SSL. This leads to hangers and timeouts
  as reported in #10666.

Reported-by: SandakovMM on github
Fixes #10666
Closes #10669
2023-03-07 15:22:22 +01:00
Stefan Eissing
7c5637b8b4
url: fix logic in connection reuse to deny reuse on "unclean" connections
- add parameter to `conn_is_alive()` cfilter method that returns
  if there is input data waiting on the connection
- refrain from re-using connnection from the cache that have
  input pending
- adapt http/2 and http/3 alive checks to digest pending input
  to check the connection state
- remove check_cxn method from openssl as that was just doing
  what the socket filter now does.
- add tests for connection reuse with special server configs

Closes #10690
2023-03-07 12:50:31 +01:00
Daniel Stenberg
6466071e8e
x509asn1: use plain %x, not %lx, when the arg is an int
Pointed out by Coverity.

Closes #10689
2023-03-06 23:59:12 +01:00
Stefan Eissing
48cd032623
http2: fix handling of RST and GOAWAY to recognize partial transfers
- a reset transfer (HTTP/2 RST) did not always lead to the proper
  error message on receiving its response, leading to wrong reports
  of a successful transfer
- test_05_02 was able to trigger this condition with increased transfer
  count. The simulated response errors did not carry a 'Content-Length'
  so only proper RST handling could detect the abort
- When doing such transfers in parallel, a connection could enter the
  state where
  a) it had been closed (GOAWAY received)
  b) the RST had not been "seen" for the transfer yet
  or c) the GOAWAY announced an error and the last successful
  stream id was not checked against ongoing transfers

Closes #10693
2023-03-06 23:58:24 +01:00
Stefan Eissing
257416023d
connect: fix time_connect and time_appconnect timer statistics
- time_connect was not updated when the overall connection failed,
  e.g. when SSL verification was unsuccessful, refs #10670
- rework gather those values to interrogate involved filters,
  also from all eyeballing attempts, to report the maximum of
  those values.
- added 3 test cases in test_06 to check reported values on
  successful, partially failed and totally failed connections.

Reported-by: Master Inspire
Fixes #10670
Closes #10671
2023-03-06 20:16:43 +01:00
Daniel Stenberg
45d4bf5af3
cookie: don't load cookies again when flushing
Reported-by: Sergio Mijatovic
Fixes #10677
Closes #10685
2023-03-06 15:51:56 +01:00
Harry Sintonen
755ddbe901
rand: use arc4random as fallback when available
Normally curl uses cryptographically strong random provided by the
selected SSL backend. If compiled without SSL support, a naive built-in
function was used instead.

Generally this was okay, but it will result in some downsides for non-
SSL builds, such as predictable temporary file names.

This change ensures that arc4random will be used instead, if available.

Closes #10672
2023-03-06 11:21:38 +01:00
Viktor Szakats
8cfc936f5c
cmake: fix enabling LDAPS on Windows
Before this patch, enabling LDAPS required a manual C flag:
c1cfc31cfc/curl-cmake.sh (L105)

Fix this and enable LDAPS automatically when using `wldap32` (and
when not explicitly disabled). This matches autotools and `Makefile.mk`
behavior. Also remove issue from KNOWN_BUGS.

Add workaround for MSVS 2010 warning triggered by LDAPS now enabled
in more CI tests:
`ldap.c(360): warning C4306: 'type cast' : conversion from 'int' to 'void *' of greater size`
Ref: https://ci.appveyor.com/project/curlorg/curl/builds/46408284/job/v8mwl9yfbmoeqwlr#L312

Reported-by: JackBoosY on github
Reviewed-by: Jay Satiro
Reviewed-by: Marcel Raad
Fixes #6284
Closes #10674
2023-03-05 19:55:14 +00:00
Viktor Szakats
8d0fa3a70d
Makefile.mk: delete redundant HAVE_LDAP_SSL macro [ci skip]
Since abebb2b893, we set this macro for
all Windows `wldap32` builds using `Makefile.mk`.

For OpenLDAP builds this macro is not enough to enable LDAPS, and
OpenLDAP is not an option in `Makefile.mk`. For Novell LDAP it might
have helped, but it's also not an option anymore in `Makefile.mk`.

The future for LDAPS is that we should enable it by default without
extra build knobs.

Reviewed-by: Marcel Raad
Closes #10681
2023-03-05 19:52:21 +00:00
Daniel Stenberg
e135bc9d31
schannel: loop over the algos to pick the selected one
Avoid using the funny macro and the extra buffer copy.

Closes #10647
2023-03-03 23:26:41 +01:00
Daniel Stenberg
56d5c07bbb
wildcard: remove files and move functions into ftplistparser.c 2023-03-03 23:25:30 +01:00
Daniel Stenberg
9c188e771c
ftp: allocate the wildcard struct on demand
The feature is rarely used so this frees up data for the vast majority
of easy handles that don't use it.

Rename "protdata" to "ftpwc" since it is always an FTP wildcard struct
pointer. Made the state struct field an unsigned char to save space.

Closes #10639
2023-03-03 23:25:23 +01:00
Brad Spencer
ad4997e5b2
urlapi: parse IPv6 literals without ENABLE_IPV6
This makes the URL parser API stable and working the same way
independently of libcurl supporting IPv6 transfers or not.

Closes #10660
2023-03-03 10:05:08 +01:00
Stefan Eissing
9fd2d5aa72
socket: detect "dead" connections better, e.g. not fit for reuse
- refs #10646 where reuse was attempted on closed connections in the
  cache, leading to an exhaustion of retries on a transfer
- the mistake was that poll events like POLLHUP, POLLERR, etc
  were regarded as "not dead".
- change cf-socket filter check to regard such events as inidication
  of corpsiness.
- vtls filter checks: fixed interpretation of backend check result
  when inconclusive to interrogate status further down the filter
  chain.

Reported-by: SendSonS on github
Fixes #10646
Closes #10652
2023-03-02 09:03:06 +01:00
Stefan Eissing
9deebd311b
lib: give source files cf-http.* better fitting names
Closes #10656
2023-03-02 08:48:34 +01:00
Stefan Eissing
8151d7babc http2: fix code indent
Closes https://github.com/curl/curl/pull/10655
2023-03-02 00:09:53 -05:00
Shankar Jadhavar
233810bb5f
cf-socket: if socket is already connected, return CURLE_OK
In 7.87.0, if callback method for CURLOPT_SOCKOPTFUNCTION returns
CURL_SOCKOPT_ALREADY_CONNECTED then curl library used to return
CURLE_OK.  n 7.88.0, now even if callback returns
CURL_SOCKOPT_ALREADY_CONNECTED, curl library still tries to connect to
socket by invoking method do_connect().

This is regression caused by commit
https://github.com/curl/curl/commit/71b7e0161032927cdfb

Fix: Check if we are already connected and return CURLE_OK.

Fixes #10626
Closes #10648
2023-03-01 11:52:18 +01:00
Jay Satiro
d36c632c86 DYNBUF.md: note Curl_dyn_add* calls Curl_dyn_free on failure
This is the existing behavior and it has been widely assumed in the
codebase.

Closes https://github.com/curl/curl/pull/10645
2023-03-01 04:18:15 -05:00
Stefan Eissing
d9ccc75b00 http2: fix upload busy loop
- Set KEEP_SEND_PAUSE when exhausting remote HTTP/2 window size of a
  stream.

- Clear KEEP_SEND_PAUSE when receiving HTTP/2 window updates on a paused
  stream.

- Also fix http2 send compiler warnings reported in #10449.

Prior to this change, starting in 71b7e016 which precedes 7.88.0,
libcurl may eat CPU during HTTP/2 upload.

Reported-by: Jay Satiro

Fixes https://github.com/curl/curl/issues/10449
Fixes https://github.com/curl/curl/issues/10618
Closes https://github.com/curl/curl/pull/10627
2023-03-01 04:13:49 -05:00
Daniel Stenberg
c50a6eee04
sectransp: make read_cert() use a dynbuf when loading
Closes #10632
2023-03-01 09:38:43 +01:00
Jay Satiro
0b84d0cf1b transfer: limit Windows SO_SNDBUF updates to once a second
- Change readwrite_upload() to call win_update_buffer_size() no more
  than once a second to update SO_SNDBUF (send buffer limit).

Prior to this change during an upload readwrite_upload() could call
win_update_buffer_size() anywhere from hundreds of times per second to
an extreme test case of 100k per second (which is likely due to a bug,
see #10618). In the latter case WPA profiler showed
win_update_buffer_size was the highest capture count in
readwrite_upload. In any case the calls were excessive and unnecessary.

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

Closes https://github.com/curl/curl/pull/10611
2023-03-01 01:15:28 -05:00
Stefan Eissing
cbe9d82c22
http2: fix for http2-prior-knowledge when reusing connections
- refs #10634 where errors in the HTTP/2 framing layer are observed.
- the bug was that on connection reuse, the code attempted to switch
  in yet another layer of HTTP/2 handling instead of detecting that
  this was already in place.
- added pytest testcase reproducing the issue.

Reported-by: rwmjones on github
Fixes #10634
Closes #10643
2023-02-28 23:04:00 +01:00
Stefan Eissing
efa1aba97c
cf-socket: fix handling of remote addr for accepted tcp sockets
- do not try to determine the remote address of a listen socket. There
  is none.
- Update remote address of an accepted socket by getpeername() if
  available.

Reported-by: Harry Sintonen
Fixes #10622
Closes #10642
2023-02-28 23:03:17 +01:00
Stefan Eissing
a4d015e69f
http: fix unix domain socket use in https connects
- when h2/h3 eyeballing was involved, unix domain socket
  configurations were not honoured
- configuring --unix-socket will disable HTTP/3 as candidate for eyeballing
- combinatino of --unix-socket and --http3-only will fail during initialisation
- adding pytest test_11 to reproduce

Reported-by: Jelle van der Waa
Fixes #10633
Closes #10641
2023-02-28 22:59:19 +01:00
Daniel Stenberg
c9c3ec482b
setopt: move the CURLOPT_CHUNK_DATA pointer to the set struct
To make duphandle work etc

Closes #10635
2023-02-28 08:44:28 +01:00
Viktor Szakats
51211a31a5
quic/schannel: fix compiler warnings
Fixes #10603
Closes #10616
2023-02-28 08:43:16 +01:00
Daniel Stenberg
252fce70b1
mqtt: on send error, return error
Reported-by: Maciej Domanski

Closes #10623
2023-02-28 08:11:55 +01:00
Daniel Stenberg
3b23dbeec1
ws: keep the socket non-blocking
Reported-by: marski on github
Fixes #10615
Closes #10625
2023-02-28 00:38:21 +01:00
Daniel Stenberg
788c6b3864
hostip: avoid sscanf and extra buffer copies
Also made create_hostcache_id() return the id length.

Closes #10601
2023-02-27 20:43:13 +01:00
Daniel Stenberg
a26547b2a2
easy: remove infof() debug leftover from curl_easy_recv
It said "reached [path]/easy.c:1231"

Closes #10628
2023-02-27 19:50:25 +01:00
Daniel Stenberg
cf3e6ce92f
idn: return error if the conversion ends up with a blank host
Some IDN sequences are converted into "" (nothing), which can make this
function end up with a zero length host name and we cannot consider that
a valid host to continue with.

Reported-by: Maciej Domanski
Closes #10617
2023-02-27 15:12:29 +01:00
Daniel Stenberg
22eec78027
x509asn1.c: use correct format specifier for infof() call
Detected by Coverity

Closes #10614
2023-02-27 08:26:01 +01:00
Daniel Stenberg
3b15ee1e34
rtsp: avoid sscanf for parsing
Closes #10605
2023-02-24 23:56:43 +01:00
Daniel Stenberg
3b8f5bb15b
http_proxy: parse the status line without sscanf
Closes #10602
2023-02-24 23:54:54 +01:00
Daniel Stenberg
cbd3fd7cbb
telnet: error correctly for WS set to "x[num]"
Follow-up to e4f93be9d5
Reported-by: Harry Sintonen
Closes #10606
2023-02-24 23:00:26 +01:00
Daniel Stenberg
5ed7417d2f
krb5: avoid sscanf for parsing
Closes #10599
2023-02-24 17:24:01 +01:00
Daniel Stenberg
835682661c
misc: remove support for curl_off_t < 8 bytes
Closes #10597
2023-02-24 17:05:33 +01:00
Daniel Stenberg
9672cc640c
telnet: parse NEW_ENVIRON without sscanf
Closes #10596
2023-02-24 16:45:58 +01:00
Daniel Stenberg
e4f93be9d5
telnet: parse the WS= argument without sscanf
Closes #10596
2023-02-24 16:45:56 +01:00
Daniel Stenberg
0c28ba2faa
telnet: parse telnet options without sscanf
Closes #10596
2023-02-24 16:45:42 +01:00
Daniel Stenberg
304b5183fd
ftp: replace sscanf for MDTM 213 response parsing
Closes #10590
2023-02-24 16:43:27 +01:00
Daniel Stenberg
dad74488fc
ftp: replace sscanf for PASV parsing
Closes #10590
2023-02-24 16:43:24 +01:00
Daniel Stenberg
b0f54f27a9
ftp: make the EPSV response parser not use sscanf
Closes #10590
2023-02-24 16:43:15 +01:00
Stefan Eissing
f6fe54e21e
ngtcp2: fix unwanted close of file descriptor 0
... causing macOS to hand out 0 as next socket handle and failing on
further operations.

Reported-by: Sergey Fionov
Fixes #10593
Closes #10595
2023-02-24 08:43:35 +01:00
Daniel Stenberg
0242eba06e
select: stop treating POLLRDBAND as an error
POLLRDBAND does not seem to be an general error and on Windows the value
for POLLIN is 768 and the value for POLLRDBAND is 512.

Fixes #10501
Reported-by: opensslonzos-github on github
Closes #10592
2023-02-23 23:41:44 +01:00
Daniel Stenberg
b2151fbc4f
http: rewrite the status line parser without sscanf
Closes #10585
2023-02-23 10:23:12 +01:00
Jay Satiro
47129b2b4b sectransp: fix compiler warning c89 mixed code/declaration
Since cbf57176 the Cirrus CI 'macOS arm64 SecureTransport http2' has
been failing due to c89 warnings mixed code/declaration. That commit is
not the cause so I assume something has changed in the CI outside of our
configuration. Anyway, we don't mix code/declaration so this is the fix
for that.

Closes https://github.com/curl/curl/pull/10574
2023-02-23 03:47:31 -05:00
Stefan Eissing
821f6e2a89
CURLOPT_PIPEWAIT: allow waited reuse also for subsequent connections
As tested in test_02_07, when firing off 200 urls with --parallel, 199
wait for the first connection to be established. if that is multiuse,
urls are added up to its capacity.

The first url over capacity opens another connection. But subsequent
urls found the same situation and open a connection too. They should
have waited for the second connection to actually connect and make its
capacity known.

This change fixes that by

- setting `connkeep()` early in the HTTP setup handler. as otherwise
  a new connection is marked as closeit by default and not considered
  for multiuse at all
- checking the "connected" status for a candidate always and continuing
  to PIPEWAIT if no alternative is found.

pytest:
- removed "skip" from test_02_07
- added test_02_07b to check that http/1.1 continues to work as before

Closes #10456
2023-02-21 11:12:48 +01:00
Daniel Stenberg
ac5ea7b6eb
cookie: parse without sscanf()
Saves us from using 2*4096 bytes buffers on stack, the extra copies and
more.

Closes #10550
2023-02-20 23:49:51 +01:00
Daniel Stenberg
5cc09a8479
parsedate: replace sscanf( for time stamp parsing
Closes #10547
2023-02-20 23:48:20 +01:00
Daniel Stenberg
ba9a4e9bd8
parsedate: parse strings without using sscanf()
- sscanf is slow and complex, avoid it
- give up already if the string is 12 bytes or longer as no valid string
  can be that long
- this can now be done without copy

Closes #10547
2023-02-20 23:48:14 +01:00
Daniel Stenberg
a6506f266c
socketpair: allow EWOULDBLOCK when reading the pair check bytes
Reported-by: Gunamoi Software
Co-authored-by: Jay Satiro
Fixes #10561
Closes #10562
2023-02-20 08:11:49 +01:00
Jay Satiro
cab040248d curl_setup: Suppress OpenSSL 3 deprecation warnings
- Define OPENSSL_SUPPRESS_DEPRECATED.

OpenSSL 3 has deprecated some of the functions libcurl uses such as
those with DES, MD5 and ENGINE prefix. We don't have replacements for
those functions so the warnings were disabled in autotools and cmake
builds, but still showed in other builds.

Closes https://github.com/curl/curl/pull/10543
2023-02-18 19:02:37 -05:00
Stefan Eissing
e187d69e48
urldata: remove now from struct SingleRequest - not needed
Closes #10549
2023-02-17 23:23:33 +01:00
Daniel Stenberg
8b27799f8c
urlapi: do the port number extraction without using sscanf()
- sscanf() is rather complex and slow, strchr() much simpler

- the port number function does not need to fully verify the IPv6 address
  anyway as it is done later in the hostname_check() function and doing
  it twice is unnecessary.

Closes #10541
2023-02-17 16:21:26 +01:00
Stefan Eissing
72bb489543
setopt: allow HTTP3 when HTTP2 is not defined
Reported-by: Karthikdasari0423 on github
Fixes #10538
Closes #10544
2023-02-17 16:12:24 +01:00
jonrumsey
85721574ed
os400: correct Curl_os400_sendto()
Add const qualifier to 5th argument of Curl_os400_sendto()

Make OS400 wrapper for sendto match the normal prototype of sendto()
with a const qualifier.

Fixes #10539
Closes #10548
2023-02-17 14:49:51 +01:00
Daniel Stenberg
6d860f1758
socks: allow using DoH to resolve host names
For SOCKS modes where a local host resolve is done.

It was previously disabled in 12d655d456, but a few local tests seem to
indicate that it works fine. Works now because of the SOCKS refactor of
4a4b63daaa that made it non-blocking.

Reported-by: roughtex on github
Fixes #10537
Closes #10540
2023-02-17 09:17:54 +01:00
Stefan Eissing
cc52bc45f6
connnect: fix timeout handling to use full duration
- connect timeout was used at half the configured value, if the
  destination had 1 ip version 4 and other version 6 addresses
  (or the other way around)
- extended test2600 to reproduce these cases

Reported-by: Michael Kaufmann
Fixes #10514
Closes #10517
2023-02-16 11:24:29 +01:00
Harry Sintonen
8c939453f5
http:: include stdint.h more readily
Closes #10516
2023-02-16 10:07:52 +01:00
Harry Sintonen
87ed650d04
http2: set drain on stream end
Ensure that on_frame_recv() stream end will trigger a read if there is
pending data. Without this it could happen that the pending data is
never consumed.

This combined with https://github.com/curl/curl/pull/10529 should fix
https://github.com/curl/curl/issues/10525

Ref: https://github.com/curl/curl/issues/10525
Closes #10530
2023-02-16 09:33:52 +01:00
Stefan Eissing
3103de2053
http2: buffer/pausedata and output flush fix.
* do not process pending input data when copying pausedata to the
   caller
 * return CURLE_AGAIN if the output buffer could not be completely
   written out.

Ref: #10525
Closes #10529
2023-02-16 09:33:01 +01:00
Marcel Raad
c1c969052f
krb5: silence cast-align warning
Add an intermediate cast to `void *`, as done everywhere else when
casting from `sockaddr *` to `sockaddr_in *`.

Closes https://github.com/curl/curl/pull/10528
2023-02-16 08:54:24 +01:00
Daniel Stenberg
964ff76863
openssl: rename 'errcode_t' to 'sslerr_t'
Turns out "/usr/include/et/com_err.h" typedefs this type (without proper
variable scoping).

comerr is the "common error description library" that apparently might be used
by krb5 code, which then makes this header get used in a curl build.

Reported-by: Bruno Henrique Batista Cruz da Silva
Fixed #10502
Closes #10500
2023-02-14 08:25:11 +01:00
Stefan Eissing
ce0cad713d
openssl: test and fix for forward proxy handling (non-tunneling).
- adding pytest test_10 cases for proxy httpd setup tests
- fixing openssl bug in https: proxy hostname verification that
  used the hostname of the request and not the proxy name.

Closes #10498
2023-02-13 20:54:57 +01:00
Patrick Monnerat
119fb18719
content_encoding: do not reset stage counter for each header
Test 418 verifies

Closes #10492
2023-02-13 17:06:19 +01:00
Jay Satiro
f438ce099b multi: stop sending empty HTTP/3 UDP datagrams on Windows
- Limit the 0-sized send procedure that is used to reset a SOCKET's
  FD_WRITE to TCP sockets only.

Prior to this change the reset was used on UDP sockets as well, but
unlike TCP sockets a 0-sized send actually sends out a datagram.

Assisted-by: Marc Hörsken

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

Fixes https://github.com/curl/curl/issues/9086
Closes https://github.com/curl/curl/pull/10430
2023-02-13 03:25:12 -05:00
Viktor Szakats
7ce140ba97
h3: silence compiler warnings
Reviewed-by: Daniel Stenberg
Fixes #10485
Closes #10486
2023-02-12 17:11:46 +00:00
Daniel Stenberg
efbf02111a
smb: return error on upload without size
The protocol needs to know the size ahead of time, this is now a known
restriction and not a bug.

Also output a clearer error if the URL path does not contain proper
share.

Ref: #7896
Closes #10484
2023-02-12 18:04:41 +01:00
Viktor Szakats
5309e32141
windows: always use curl's basename() implementation
The `basename()` [1][2] implementation provided by mingw-w64 [3] makes
assumptions about input encoding and may break with non-ASCII strings.

`basename()` was auto-detected with CMake, autotools and since
68fa9bf3f5 (2022-10-13), also in
`Makefile.mk` after syncing its behaviour with the mainline build
methods. A similar patch for curl-for-win broke official Windows
builds earlier, in release 7.83.1_4 (2022-06-15).

This patch forces all Windows builds to use curl's internal
`basename()` implementation to avoid such problems.

[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/basename.html
[2]: https://www.man7.org/linux/man-pages/man3/basename.3.html
[3]: https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/basename.c

Reported-by: UnicornZhang on Github
Assisted-by: Cherish98 on Github
Reviewed-by: Daniel Stenberg

Fixes #10261
Closes #10475
2023-02-12 12:52:59 +00:00
James Keast
635bf5a6b2 setopt: Address undefined behaviour by checking for null
This addresses undefined behaviour found using clang's UBsan:

curl/lib/setopt.c:177:14: runtime error: applying non-zero offset 1 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior curl/lib/setopt.c:177:14 in

Closes #10472
2023-02-11 10:13:38 -08:00
Jacob Hoffman-Andrews
38262c944d
rustls: improve error messages
Changes numeric error codes into verbose error codes in two places.
Adds a prefix indicating that the error came from rustls, and in some
places which function it came from.

Adds special handling for RUSTLS_RESULT_UNEXPECTED_EOF, since the
default message of "Unexpected EOF" is insufficiently explanatory.

Closes #10463
2023-02-11 10:11:08 +01:00
Daniel Stenberg
0a9488c7cc
openssl: remove dead code
Follow-up to e8b00fcd6a

Due to the new 'if(!nonblocking)' check on the block a level above,
there is no need to check for it again within the same conditional.

Detected by Coverity

Closes #10473
2023-02-11 09:50:23 +01:00
Daniel Stenberg
03ce27ae2f
ngtcp2: replace removed define and stop using removed function
They were removed upstream.

Reported-by: Karthikdasari0423 on github
Fixes #10469
Closes #10474
2023-02-11 09:49:13 +01:00
Stefan Eissing
c96f982166
vquic: stabilization and improvements
vquic stabilization
- udp send code shared between ngtcp2 and quiche
- quiche handling of data and events improved

ngtcp2 and pytest improvements
- fixes handling of "drain" situations, discovered in scorecard
  tests with the Caddy server.
- improvements in handling transfers that have already  data or
  are already closed to make an early return on recv

pytest
- adding caddy tests when available

scorecard improvemnts.
- using correct caddy port
- allowing tests for only httpd or caddy

Closes #10451
2023-02-10 10:26:40 +01:00
Daniel Stenberg
2e2e3d16c5
ws: fix recv of larger frames
+ remove 'oleft' from the struct
 + deal with "overflow data" in a separate dynbuf

Reported-by: Mike Duglas
Fixes #10438
Closes #10447
2023-02-10 08:28:58 +01:00
Stefan Eissing
3de3ea6a64
HTTP/[23]: continue upload when state.drain is set
- as reported in #10433, HTTP/2 uploads may stall when a response is
  received before the upload is done. This happens when the
  data->state.drain is set for such a transfer, as the special handling
  in transfer.c from then on only cared about downloads.
- add continuation of uploads, if applicable, in this case.
- add pytest case test_07_12_upload_seq_large to reproduce this scenario
  (although, current nghttp2 implementation is using drain less often)

Reported-by: Lucas Pardue

Fixes #10433
Closes #10443
2023-02-09 09:13:30 +01:00
Stefan Eissing
8c762f5998
http2: minor buffer and error path fixes
- use memory buffer in full available size
- fail receive of reset/errored streams early

pytest:
- make test_05 error cases more reliable

Closes #10444
2023-02-09 08:38:01 +01:00
Federico Pellegrin
cace68e299
openldap: fix missing sasl symbols at build in specific configs
If curl is built with openldap support (USE_OPENLDAP=1) but does not
have also some other protocol (IMAP/SMTP/POP3) enabled that brings
in Curl_sasl_* functions, then the build will fail with undefined
references to various symbols:

ld: ../lib/.libs/libcurl.so: undefined reference to `Curl_sasl_decode_mech'
ld: ../lib/.libs/libcurl.so: undefined reference to `Curl_sasl_parse_url_auth_option'
ld: ../lib/.libs/libcurl.so: undefined reference to `Curl_sasl_cleanup'
ld: ../lib/.libs/libcurl.so: undefined reference to `Curl_sasl_can_authenticate'
ld: ../lib/.libs/libcurl.so: undefined reference to `Curl_sasl_continue'
ld: ../lib/.libs/libcurl.so: undefined reference to `Curl_sasl_start'
ld: ../lib/.libs/libcurl.so: undefined reference to `Curl_sasl_init'

This was tracked down to these functions bein used in openldap.c but
defined in curl_sasl.c and then forward in two vauth/ files to have
a guard against a set of #define configurations that was now extended
to cover also this case.

Example configuration targeted that could reproduce the problem:

curl 7.87.1-DEV () libcurl/7.87.1-DEV .... OpenLDAP/2.6.3
Protocols: file ftp ftps http https ldap ldaps

Closes #10445
2023-02-09 08:17:20 +01:00
Daniel Stenberg
da8e97b5d0
ws: use %Ou for outputting curl_off_t with info()
Reported-by: Mike Duglas
Fixes #10439
Closes #10441
2023-02-09 08:15:24 +01:00
Jay Satiro
b4b6e4f1fa curl_setup: Disable by default recv-before-send in Windows
Prior to this change a workaround for Windows to recv before every send
was enabled by default. The way it works is a recv is called before
every send and saves the received data, in case send fails because in
Windows apparently that can wipe out the socket's internal received
data buffer.

This feature has led to several bugs because the way libcurl operates
it waits on a socket to read or to write, and may not at all times
check for buffered receive data.

Two recent significant bugs this workaround caused:
- Broken Schannel TLS 1.3 connections (#9431)
- HTTP/2 arbitrary hangs (#10253)

The actual code remains though it is disabled by default. Though future
changes to connection filter buffering could improve the situation IMO
it's just not tenable to manage this workaround.

Ref: https://github.com/curl/curl/issues/657
Ref: https://github.com/curl/curl/pull/668
Ref: https://github.com/curl/curl/pull/720

Ref: https://github.com/curl/curl/issues/9431
Ref: https://github.com/curl/curl/issues/10253

Closes https://github.com/curl/curl/pull/10409
2023-02-09 01:30:10 -05:00
Stefan Eissing
ead2b2d4f6
http2: aggregate small SETTINGS/PRIO/WIN_UPDATE frames
add a small buffer to nghttp2 session sending in order to aggregate
small SETTINGS/PRIO/WIN_UPDATE frames that nghttp2 "writes" to the
callback individually.

Ref: #10389
Closes #10432
2023-02-08 10:41:15 +01:00
Stefan Eissing
e8b00fcd6a
openssl: store the CA after first send (ClientHello)
move Curl_ssl_setup_x509_store() call after the first send (ClientHello)
this gives time to parse CA anchors while waiting on the server reply

Ref: #10389
Closes #10432
2023-02-08 10:41:11 +01:00
Anthony Hu
12e9186fc4
wolfssl: remove deprecated post-quantum algorithms
Closes #10440
2023-02-08 08:31:45 +01:00
John Bampton
0065b146eb
misc: fix spelling
Closes #10437
2023-02-08 08:30:05 +01:00
Daniel Stenberg
1c91ba3939
vtls: infof using %.*s needs to provide the length as int
Fixes a Coverity warning.

Closes #10436
2023-02-07 16:33:04 +01:00
Stefan Eissing
7dad86a03f
vrls: addressing issues reported by coverity
I believe the code was secure before this, but limiting the accepted
name length to what is used in the structures should help Coverity's
analysis.

Closes #10431
2023-02-07 14:05:21 +01:00
Daniel Stenberg
a0adda4b47
setopt: use >, not >=, when checking if uarg is larger than uint-max
Closes #10421
2023-02-06 23:42:27 +01:00
Daniel Stenberg
82123417ff
vtls: fix failf() format argument type for %.*s handling
Reported by Coverity

Closes #10422
2023-02-06 23:41:21 +01:00
Daniel Stenberg
b0b33fe71d
openssl: fix "Improper use of negative value"
By getting the socket first and returning error in case of bad socket.

Detected by Coverity.

Closes #10423
2023-02-06 23:40:20 +01:00
Mike Duglas
ad55b23634
ws: fix multiframe send handling
Fixes #10413
Closes #10420
2023-02-06 17:27:46 +01:00
Pronyushkin Petr
2b46ce0313
urlapi: fix part of conditional expression is always true: qlen
Closes #10408
2023-02-06 08:53:07 +01:00
Pronyushkin Petr
690c43b3ee
url: fix part of conditional expression is always true
Closes #10407
2023-02-06 08:51:31 +01:00
Kvarec Lezki
74040ddecb fopen: remove unnecessary assignment
[CWE-1164] V1048: The '* tempname' variable was assigned the same value.

Ref: https://pvs-studio.com/en/docs/warnings/v1048/

Closes https://github.com/curl/curl/pull/10398
2023-02-05 03:15:08 -05:00
Kvarec Lezki
97f7f668d6
http_aws_sigv4: remove typecasts from HMAC_SHA256 macro
V220: Suspicious sequence of types castings: memsize -> 32-bit integer -> memsize.

https://pvs-studio.com/en/docs/warnings/v220/

Closes #10400
2023-02-03 10:07:28 +01:00
Kvarec Lezki
80c98ef6d2
doh: ifdef IPv6 code
For disabled IPv6 a condition (conn->ip_version != CURL_IPRESOLVE_V4) is
always false. https://pvs-studio.com/en/docs/warnings/v560/

Closes #10397
2023-02-03 08:23:27 +01:00
Daniel Stenberg
37554d7c07
urlapi: remove pathlen assignment
"Value stored to 'pathlen' is never read"

Follow-up to 804d5293f8

Reported-by: Kvarec Lezki

Closes #10405
2023-02-03 08:20:21 +01:00
Kvarec Lezki
e1f78ce25b
http: fix "part of conditional expression is always false"
[CWE-570] V560: A part of conditional expression is always false: conn->bits.authneg.
[CWE-570] V560: A part of conditional expression is always false: conn->handler->protocol & (0 | 0).

https://pvs-studio.com/en/docs/warnings/v560/

Closes #10399
2023-02-03 08:17:18 +01:00
Daniel Stenberg
63c53ea627
urlapi: skip the extra dedotdot alloc if no dot in path
Saves an allocation for many/most URLs.

Updates test 1395 accordingly

Closes #10403
2023-02-02 22:34:32 +01:00
Stefan Eissing
671158242d
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
  the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
  succeed after 100ms (subject to change), a parallel attempt
  is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
  as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
  expires, the HTTPS-CONNECT filter checks if the QUIC filter
  has received any data from the server. If not, it will start
  the HTTP/2 attempt.

HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
  for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
  implementation into the udp socket cfilter. Because unconnected
  UDP sockets are weird. For example they error when adding to a
  pollset.

HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue

HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.

GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
  and closes immediately (so the local conn goes into DRAIN phase), the
  connection is torn down and a another attempt is made after a short grace
  period.
  This is the behaviour observed with nghttpx when we tell it to  shut
  down gracefully. Tested in pytest test_03_02.

TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
  copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
  and connection related things based on the negotiated protocol (or lack thereof).

- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
  Invoke:
    python3 tests/tests-httpd/scorecard.py --help
  for usage.

Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
  report connection statistics. This is triggered when the connection
  has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
  a timestamp of when it happend. This allows for updating timers
  "later", e.g. a connect statistic after full connectivity has been
  reached.
- in case of HTTP eyeballing, the previous changes will update
  statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
  by a filter chain.
  Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
  for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
  checks during the handshake are made.

HTTP/3 documentation on how https eyeballing works.

TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
  copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
  and connection related things based on the negotiated protocol (or lack thereof).

Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy

pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.

Closes #10349
2023-02-02 09:57:34 +01:00
Daniel Stenberg
7305ca63e2
urlapi: avoid Curl_dyn_addf() for hex outputs
Inspired by the recent fixes to escape.c, we should avoid calling
Curl_dyn_addf() in loops, perhaps in particular when adding something so
simple as %HH codes - for performance reasons. This change makes the
same thing for the URL parser's two URL-encoding loops.

Closes #10384
2023-02-01 23:05:51 +01:00
Daniel Stenberg
804d5293f8
urlapi: skip path checks if path is just "/"
As a miniscule optimization, treat a path of the length 1 as the same as
non-existing, as it can only be a single leading slash, and that's what
we do for no paths as well.

Closes #10385
2023-02-01 23:04:45 +01:00
Viktor Szakats
48eb71ade4
tls: fixes for wolfssl + openssl combo builds
1. Add `USE_WOLFSSL` to the TLS backend priority list in
   `lib/curl_ntlm_core.c`.

2. Fix `lib/curl_ntlm_core.h` to respect TLS backend priority, bringing
   it in sync with the above list and `lib/curl_ntlm_core.c` itself.

   Reported-by: Mark Roszko
   Ref: https://github.com/curl/curl/issues/10321

3. Allow enabling both wolfSSL and OpenSSL at the same time in
   `lib/Makefile.mk` bringing this in line with cmake/autotools builds.
   Update logic to select the crypto-specific lib for `ngtcp2`, which
   supports a single TLS backend at the same time.

Closes #10322
2023-02-01 09:47:16 +00:00
Kvarec Lezki
9caa7bc930
cookies: fp is always not NULL
Closes #10383
2023-02-01 07:57:06 +01:00
Daniel Stenberg
fc8ad0b23c
escape: use table lookup when adding %-codes to output
On my dev host, this code runs 7.8 times faster.

Closes #10377
2023-01-31 22:42:21 +01:00
Daniel Stenberg
f1f8acb3b9
escape: hex decode with a lookup-table
Makes the decoding 2.8 times faster in my tests.

Closes #10376
2023-01-31 15:03:19 +01:00
Daniel Stenberg
1ca483a40c
cf-socket: fix build error wo TCP_FASTOPEN_CONNECT
Follow-up to 5651a36d1a

Closes #10378

Reviewed-by: Stefan Eissing
2023-01-31 14:35:39 +01:00
Stefan Eissing
91eb197a9e
CI: add pytest github workflow to CI test/tests-httpd on a HTTP/3 setup
Closes #10317
2023-01-31 12:04:23 +01:00
Stefan Eissing
d55de24dce
connect: fix strategy testing for attempts, timeouts and happy-eyeball
- add test2600 as a unit test that triggers various connect conditions
  and monitors behaviour, available in a debug build only.

- this exposed edge cases in connect.c that have been fixed

Closes #10312
2023-01-31 11:28:14 +01:00
Stefan Eissing
5651a36d1a
cf-socket: improvements in socket I/O handling
- Curl_write_plain/Curl_read_plain have been eliminated. Last code use
  now uses Curl_conn_send/recv so that requests use conn->send/revc
  callbacks which defaults to cfilters use.
- Curl_recv_plain/Curl_send_plain have been internalized in cf-socket.c.
- USE_RECV_BEFORE_SEND_WORKAROUND (active on Windows) has been moved
  into cf-socket.c. The pre_recv buffer is held at the socket filter
  context.  `postponed_data` structures have been removed from
  `connectdata`.
- the hanger in HTTP/2 request handling was a result of read buffering
  on all sends and the multi handling is not prepared for this. The
  following happens:

   - multi preforms on a HTTP/2 easy handle
   - h2 reads and processes data
   - this leads to a send of h2 data
   - which receives and buffers before the send
   - h2 returns
   - multi selects on the socket, but no data arrives (its in the buffer already)
   the workaround now receives data in a loop as long as there is something in
   the buffer. The real fix would be for multi to change, so that `data_pending`
   is evaluated before deciding to wait on the socket.

io_buffer, optional, in cf-socket.c, http/2 sets state.drain if lower
filter have pending data.

This io_buffer is only available/used when the
-DUSE_RECV_BEFORE_SEND_WORKAROUND is active, e.g. on Windows
configurations. It also maintains the original checks on protocol
handler being HTTP and conn->send/recv not being replaced.

The HTTP/2 (nghttp2) cfilter now sets data->state.drain when it finds
out that the "lower" filter chain has still pending data at the end of
its IO operation. This prevents the processing from becoming stalled.

Closes #10280
2023-01-31 11:23:59 +01:00
Daniel Stenberg
a3bcfab4b5
openssl: only use CA_BLOB if verifying peer
Reported-by: Paul Groke
Bug: https://curl.se/mail/lib-2023-01/0070.html
Fixes #10351
Closes #10359
2023-01-31 11:10:42 +01:00
Daniel Stenberg
4c48fb4933
ws: unstick connect-only shutdown
As this mode uses blocking sockets, it must set them back to
non-blocking in disconnect to avoid the risk of getting stuck.

Closes #10366
2023-01-30 15:39:04 +01:00
Daniel Stenberg
097544959a
ws: remove bad assert
Reported-by: Stanley Wucw
Fixes #10347
Closes #10366
2023-01-30 15:38:55 +01:00
Daniel Stenberg
fc10d86011
openssl: adapt to boringssl's error code type
BoringSSL uses uint32_t, OpenSSL uses 'unsigned 'long'

Closes #10360
2023-01-29 22:35:40 +01:00
Daniel Stenberg
0c3d54269e
dict: URL decode the entire path always
Reported-by: dekerser on github
Fixes #10298
Closes #10354
2023-01-29 16:03:40 +01:00