Граф коммитов

13697 Коммитов

Автор SHA1 Сообщение Дата
Stefan Eissing 5929822114
lib: send rework
Curl_read/Curl_write clarifications

- replace `Curl_read()`, `Curl_write()` and `Curl_nwrite()` to 1clarify
  when and at what level they operate

- send/recv of transfer related data is now done via
  `Curl_xfer_send()/Curl_xfer_recv()` which no longer has
  socket/socketindex as parameter. It decides on the transfer setup of
  `conn->sockfd` and `conn->writesockfd` on which connection filter
  chain to operate.

- send/recv on a specific connection filter chain is done via
  `Curl_conn_send()/Curl_conn_recv()` which get the socket index as
  parameter.

- rename `Curl_setup_transfer()` to `Curl_xfer_setup()` for naming
  consistency

- clarify that the special CURLE_AGAIN handling to return `CURLE_OK`
  with length 0 only applies to `Curl_xfer_send()` and CURLE_AGAIN is
  returned by all other send() variants.

SingleRequest reshuffling

- move functions into request.[ch]
- differentiate between reset and free
- add Curl_req_done() to perform last actions
- add a send `bufq` to SingleRequest for future use in keeping upload data

Closes #12963
2024-02-27 08:58:10 +01:00
Daniel Stenberg 9c8968e43d
http_chunks: remove unused 'endptr' variable
Closes #12996
2024-02-26 17:20:51 +01:00
Louis Solofrizzo 57446b67ba
lib: initialize output pointers to NULL before calling strto[ff,l,ul]
In order to make MSAN happy:

    ==2200945==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x596f3b3ed246 in curlx_strtoofft [...]/libcurl/src/lib/strtoofft.c:239:11
    #1 0x596f3b402156 in Curl_httpchunk_read [...]/libcurl/src/lib/http_chunks.c:149:12
    #2 0x596f3b348550 in readwrite_data [...]/libcurl/src/lib/transfer.c:607:11
    [...]

    ==2202041==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x5a3fab66a72a in Curl_parse_port [...]/libcurl/src/lib/urlapi.c:547:8
    #1 0x5a3fab650645 in parse_authority [...]/libcurl/src/lib/urlapi.c:796:12
    #2 0x5a3fab6740f6 in parseurl [...]/libcurl/src/lib/urlapi.c:1176:16
    #3 0x5a3fab664fc5 in parseurl_and_replace [...]/libcurl/src/lib/urlapi.c:1342:12
    [...]

    ==2202320==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x569076a0d6b0 in ipv4_normalize [...]/libcurl/src/lib/urlapi.c:683:12
    #1 0x5690769f2820 in parse_authority [...]/libcurl/src/lib/urlapi.c:803:10
    #2 0x569076a160f6 in parseurl [...]/libcurl/src/lib/urlapi.c:1176:16
    #3 0x569076a06fc5 in parseurl_and_replace [...]/libcurl/src/lib/urlapi.c:1342:12
    [...]

Signed-off-by: Louis Solofrizzo <lsolofrizzo@scaleway.com>
Closes #12995
2024-02-26 17:19:27 +01:00
Stefan Eissing 463472a2d6
lib: move client writer into own source
Refactoring of the client writer that passes the data to the
client/application's callback functions.

- split out into own source cw-out.[ch] from sendf.c

- move tempwrite and tempcount from data->state into the context of the
  client writer

- redesign the 3 tempwrite dynbufs as a linked list of dynbufs. On
  paused transfers, this allows to "record" interleaved HEADER/BODY
  chunks to be "played back" in the same order on unpausing.

- keep the overall size limit of all buffered data to DYN_PAUSE_BUFFER.
  On exceeding that, return CURLE_TOO_LARGE instead of
  CURLE_OUT_OF_MEMORY as before.

- add method to be called when a transfer is DONE to allow writing of
  any data still buffered

- when paused, record HEADER writes exactly as they come for later
  playback. HEADERs are documented to be written one-by-one.

Closes #12898
2024-02-26 14:25:41 +01:00
Stefan Eissing 2254551403
urldata: move authneg bit from conn to Curl_easy
- from `conn->bits.authneg` to `data->req.authneg`
- this is a property of the request about to be made
  and not a property of the connection
- in multiuse connections, transfer could step on each others
  toes here potentially.

Closes #12949
2024-02-26 10:30:52 +01:00
Stefan Eissing e925d0d1ff
c-hyper: add header collection writer in hyper builds
Closes #12880
2024-02-26 09:44:24 +01:00
Stefan Eissing 2abfa3833b
http: move headers collecting to writer
- add a client writer that does "push" response
  headers written to the client if the headers api
  is enabled
- remove special handling in sendf.c
- needs to be installed very early on connection
  setup to catch CONNECT response headers

Closes #12880
2024-02-26 09:44:15 +01:00
Stefan Eissing 5b41fac587
sendf: Curl_client_write(), make passed in buf const 2024-02-26 09:43:47 +01:00
MAntoniak e26c362544
lib: remove curl_mimepart object when CURL_DISABLE_MIME
Remove curl_mimepart object from UserDefined structure when
CURL_DISABLE_MIME flag is active. Reduce size of UserDefined structure.

Also remove unreachable code: when CURL_DISABLE_MIME is set, httpreq can
never have HTTPREQ_POST_MIME value and the same goes for the
CURL_DISABLE_FORM_API flag and the HTTPREQ_POST_FORM value

Closes #12948
2024-02-26 09:22:34 +01:00
kpcyrd e3a4273c41
rustls: make curl compile with 0.12.0
Closes #12989
2024-02-26 08:59:43 +01:00
Daniel Stenberg e2bd0c111e
strtoofft: fix the overflow check
... to not rely on wrapping, since it is an undefined behavior that is
not what always might happen. This is in our private strtoff() parser
function, used only on platforms without a native version.

Reported-by: vulnerabilityspotter on hackerone
Closes #12990
2024-02-26 08:53:40 +01:00
Daniel Stenberg f47487c219
libssh/libssh2: return error on too big range
If trying to get the range 0 - 2^63 and the remote file is 2^63 bytes or
larger.

Fixes #12983
Closes #12984
2024-02-25 22:40:39 +01:00
Scott Talbert 7448054c38 setopt: fix check for CURLOPT_PROXY_TLSAUTH_TYPE value
Prior to this change CURLOPT_PROXY_TLSAUTH_TYPE would return
CURLE_BAD_FUNCTION_ARGUMENT on any type other than NULL. Since there is
only one type of TLS auth and it is also the default (SRP) the TLS auth
would work anyway.

Closes https://github.com/curl/curl/pull/12981
2024-02-24 03:56:15 -05:00
Jay Satiro e3a3bb371f mprintf: fix format prefix I32/I64 for windows compilers
- Support I32 & I64 (eg: %I64d) for all Win32 builds.

Prior to this change mprintf support for the I format prefix, which is a
Microsoft extension, was dependent on the compiler used.

When Borland compiler support was removed in fd7ef00f the prefix was
then no longer supported for that compiler; however since it's still
possible to build with Borland I'm restoring support for the prefix in
this way.

Reported-by: Paweł Witas

Fixes https://github.com/curl/curl/issues/12944
Closes https://github.com/curl/curl/pull/12950
2024-02-24 00:51:20 -05:00
Stefan Eissing f274fc5c68
multi: fix multi_sock handling of select_bits
- OR the event bitmask to data->state.select_bits instead of overwriting
  them. They are cleared again on use.

Reported-by: 5533asdg on github
Fixes #12971
Closes #12972
2024-02-22 14:15:27 +01:00
Daniel Stenberg cc04c73677
CURLINFO_USED_PROXY: return bool whether the proxy was used
Adds test536 to verify

Closes #12719
2024-02-22 08:38:53 +01:00
Daniel Stenberg d5b0fee39a
sha512_256: remove the cast macro, minor language/format edits
Follow-up to cbe41d151d

Closes #12966
2024-02-20 17:49:01 +01:00
Stefan Eissing f7e598791f
DoH: add trace configuration
- refs #12397 where it is dicussed how to en-/disable verbose output
  of DoH operations
- introducing `struct curl_trc_feat` to track a curl feature for
  tracing
- adding `data->state.feat` optionally pointing to the feature a
  transfer belongs to
- adding trace functions and verbosity checks on features
- using trace feature in DoH code
- documenting `doh` as feature for `--trace-config`

Closes #12411
2024-02-20 14:01:59 +01:00
Stefan Eissing f0c446ab57
websocket: fix curl_ws_recv()
- when data arrived in several chunks, the collection into
  the passed buffer always started at offset 0, overwriting
  the data already there.

adding test_20_07 to verify fix

- debug environment var CURL_WS_CHUNK_SIZE can be used to
  influence the buffer chunk size used for en-/decoding.

Closes #12945
2024-02-20 13:57:58 +01:00
Evgeny Grin e3461bbd05
digest: support SHA-512/256
Also fix the tests. New implementation tested with GNU libmicrohttpd.
The new numbers in tests are real SHA-512/256 numbers (not just some
random ;) numbers ).
2024-02-20 11:36:12 +01:00
Evgeny Grin cbe41d151d
SHA-512/256: implement hash algorithm
Closes #12897
2024-02-20 11:35:56 +01:00
Evgeny Grin 30a3880f6b
curl_setup.h: add curl_uint64_t internal type
The unsigned version of curl_off_t basically
2024-02-20 11:35:05 +01:00
Stefan Eissing bdff974f46
OpenSSL QUIC: adapt to v3.3.x
- set our idle timeout as transport parameter
- query negotiated idle timeout for connection alive checks
- query number of available bidi streams on a connection
- use write_ex2 with SSL_WRITE_FLAG_CONCLUDE to signal
  EOF on last chunk write, so stream close does not
  require an additional QUIC packet

Closes #12933
2024-02-20 10:00:37 +01:00
Stefan Eissing 59e2c78af3 http_chunks: fix the accounting of consumed bytes
Prior to this change chunks were handled correctly although in verbose
mode libcurl could incorrectly warn of "Leftovers after chunking" even
if there were none.

Reported-by: Michael Kaufmann

Fixes https://github.com/curl/curl/issues/12937
Closes https://github.com/curl/curl/pull/12939
2024-02-18 02:16:29 -05:00
Stefan Eissing 0e2ffa3632 file: use xfer buf for file:// transfers
- For file:// transfers use the multi handle's transfer buffer for
  up- and downloads.

Prior to this change a6c9a33 (precedes 8.6.0) changed the file://
transfers to use a smaller stack based buffer, and that caused a
significant performance decrease in Windows.

Bug: https://github.com/curl/curl/issues/12750#issuecomment-1920103086
Reported-by: edmcln@users.noreply.github.com

Closes https://github.com/curl/curl/pull/12932
2024-02-18 02:12:45 -05:00
Stefan Eissing e87751d69a vtls: fix tls proxy peer verification
- When verifying a proxy certificate for an ip address, use the correct
  ip family.

Prior to this change the "connection" ip family was used, which was not
necessarily the same.

Reported-by: HsiehYuho@users.noreply.github.com

Fixes https://github.com/curl/curl/issues/12831
Closes https://github.com/curl/curl/pull/12931
2024-02-16 18:00:21 -05:00
Jay Satiro 5691a6cf36 transfer: improve Windows SO_SNDBUF update limit
- Change the 1 second SO_SNDBUF update limit from per transfer to per
  connection.

Prior to this change many transfers over the same connection could cause
many SO_SNDBUF updates made to that connection per second, which was
unnecessary.

Closes https://github.com/curl/curl/pull/12911
2024-02-13 03:46:17 -05:00
Jay Satiro 24d6c2889f schannel: fix hang on unexpected server close
- Treat TLS connection close (either due to a close_notify from the
  server or just closed due to receiving 0) as pending data.

This is because in some cases schannel_recv knows the connection is
closed but has to return actual pending data so it can't return 0 or an
error to indicate no more data. In this case schannel_recv must be
called again, which only happens if readwrite_data sees that there is
still pending data.

Prior to this change if the total size of the body that libcurl expected
to receive from the server was unknown then it was possible under some
network conditions that libcurl would hang waiting to receive more data,
when in fact a close_notify alert indicating no more data would be sent
was already processed.

Fixes https://github.com/curl/curl/issues/12894
Closes https://github.com/curl/curl/pull/12910
2024-02-13 03:45:21 -05:00
MAntoniak f8bd04ec50
mbedtls: use mbedtls_ssl_conf_{min|max}_tls_version
... instead of the deprecated mbedtls_ssl_conf_{min|max}_version

Closes #12905
2024-02-10 14:21:50 +01:00
MAntoniak 07e5b3ea60
mbedtls: fix building when MBEDTLS_X509_REMOVE_INFO flag is defined
Closes #12904
2024-02-09 16:00:43 +01:00
Stefan Eissing d8f01e0985
ftp: fix socket wait activity in ftp_domore_getsock
- when waiting on the data connection, always add the control socket to
  the pollset on state STOP or let the pingpong add the socket according
  to its needs.

Reported-by: Fabian Vogt
Fixes #12901
Closes #12913
2024-02-09 15:57:06 +01:00
Stefan Eissing 476adfeac0
multi: add xfer_buf to multi handle
- can be borrowed by transfer during recv-write operation
- needs to be released before borrowing again
- adjustis size to `data->set.buffer_size`
- used in transfer.c readwrite_data()

Closes #12805
2024-02-09 09:43:50 +01:00
Stefan Eissing e7fd32b9ac
ftp: do lineend conversions in client writer
- remove the ftp special handling from sendf.c
- let ftp_do() add a client writer that does
  the linened conversions
- change the lineend conversion to no longer
  modify the passed buffer, but write smaller
  chunks to the next cwriter instead. The
  inefficiency of this will be mitigated once
  we add output buffering for all client writes.

Closes #12878
2024-02-08 23:20:56 +01:00
Stefan Eissing 6984aa3a45
ftp: tracing improvements
- trace socketindex for connection filters when not the first
- trace socket fd in tcp
- trace pollset adjusts in vtls

Closes #12902
2024-02-08 23:14:33 +01:00
Stefan Eissing ed09a99af5
vtls: revert "receive max buffer" + add test case
- add test_05_04 for requests using http/1.0, http/1.1 and h2 against an
  Apache resource that does an unclean TLS shutdown.
- revert special workarund in openssl.c for suppressing shutdown errors
  on multiplexed connections
- vlts.c restore to its state before 9a90c9dd64

Fixes #12885
Fixes #12844

Closes #12848
2024-02-07 14:46:41 +01:00
Daniel Stenberg 142ac257b3
lib: convert Curl_get_line to use dynbuf
Create the line in a dynbuf. Aborts the reading of the file on
errors. Avoids having to always allocate maximum amount from the
start. Avoids direct malloc.

Closes #12846
2024-02-07 09:22:10 +01:00
Stefan Eissing c177e1944c
https-proxy: use IP address and cert with ip in alt names
- improve info logging when peer verification fails to indicate
  if DNS name or ip address has been tried to match
- add test case for contacting https proxy with ip address
- add pytest env check on loaded credentials and re-issue
  when they are no longer valid
- disable proxy ip address test for bearssl, since not supported there

Ref: #12831
Closes #12838
2024-02-06 10:10:14 +01:00
Peter Krefting 174c89ec3f
version: allow building with ancient libpsl
The psl_check_version_number() API was added in libpsl 0.11.0. CentOS 7
ships with version 0.7.0 which lacks this API. Revert to using the older
versioning API if we detect an old libpsl version.

Follow-up to 72bd88adde
Bug: https://curl.se/mail/archive-2024-02/0004.html
Reported-by: Scott Mutter
Closes #12872
2024-02-06 09:50:35 +01:00
Stefan Eissing d6825df334
openssl-quic: check on Windows that socket conv to int is possible
Fixes #12861
Closes #12865
2024-02-05 23:45:01 +01:00
Daniel Stenberg 5cc2b016c3
md4: include strdup.h for the memdup proto
Reported-by: Erik Schnetter
Fixes #12849
Closes #12863
2024-02-05 23:38:12 +01:00
Stefan Eissing 0dc036225b
HTTP/2: write response directly
- use the new `Curl_xfer_write_resp()` to write incoming responses
  directly to the client
- eliminates `stream->recvbuf`
- memory consumption on parallel transfers minimized

Closes #12828
2024-02-05 22:29:21 +01:00
Faraz Fallahi a84ad94dd6
connect.c: fix typo
Closes #12858
2024-02-05 19:33:14 +01:00
Daniel Stenberg b8c003832d
sendf: ignore response body to HEAD
and mark the stream for close, but return OK since the response this far
was ok - if headers were received. Partly because this is what curl has
done traditionally.

Test 499 verifies. Updates test 689.

Reported-by: Sergey Bronnikov
Bug: https://curl.se/mail/lib-2024-02/0000.html
Closes #12842
2024-02-01 22:37:26 +01:00
Daniel Stenberg 10491957e3
ftp: treat a 226 arriving before data as a signal to read data
For active mode transfers.

Due to some interesting timing, curl can sometimes get the 226 (transfer
complete) over the control channel first, before the data connection
signals readability. If this happens, use that as a signal to check the
data connection.

Additionally, set the socket filter in listen mode *before* the
PORT/EPRT command is issued, to reduce the risk that the little time gap
could interfere.

This issue never reproduced for me on Debian and takes several hundred
rounds for me to trigger on my mac.

Reported-by: Stefan Eissing
Fixes #12823
Closes #12841
2024-02-01 22:32:38 +01:00
Daniel Stenberg 8243ad6458
asyn-thread: use wakeup_close to close the read descriptor
Reported-by: Dan Fandrich
Ref: #12834
Closes #12836
2024-02-01 13:42:48 +01:00
Stefan Eissing e75a48d2c3
ntml_wb: fix buffer type typo
Closes #12825
2024-02-01 13:04:56 +01:00
Daniel Stenberg 011325ff29
lib: error out on multissl + http3
Since the QUIC/h3 code has no knowledge or handling of multissl it might
bring unintended consequences if we allow it.

configure, cmake and curl_setup.h all now reject this combination.

Assisted-by: Viktor Szakats
Assisted-by: Gisle Vanem
Ref: #12806
Closes #12807
2024-01-29 16:37:08 +01:00
Viktor Szakats 5b286c2508
build: delete/replace clang warning pragmas
- delete redundant warning suppressions for `-Wformat-nonliteral`.
  This now relies on `CURL_PRINTF()` and it's theoratically possible
  that this macro isn't active but the warning is. We're ignoring this
  as a corner-case here.

- replace two pragmas with code changes to avoid the warnings.

Follow-up to aee4ebe591 #12803
Follow-up to 0923012758 #12540
Follow-up to 3829759bd0 #12489

Reviewed-by: Daniel Stenberg
Closes #12812
2024-01-27 21:19:41 +00:00
Daniel Stenberg 066ed4e514
http: only act on 101 responses when they are HTTP/1.1
For 101 responses claiming to be any other protocol, bail out. This
would previously trigger an assert.

Add test 1704 to verify.

Bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66184
Closes #12811
2024-01-27 21:49:20 +01:00
Stefan Eissing bdae275958
mqtt, remove remaining use of data->state.buffer
Closes #12799
2024-01-27 12:42:19 +01:00