Commit Graph

13753 Commits

Author SHA1 Message Date
Tobias Stoeckmann
6f32048200
libssh2: set length to 0 if strdup failed
Internally, libssh2 dereferences the NULL pointer if length is non-zero.
The callback function cannot return the error condition, so at least
prevent subsequent crash.

Closes #13213
2024-03-28 11:21:44 +01:00
Paul Howarth
c77bdf17f7
curl_sha512_255: fix detection of OpenSSL 1.1.1 or later
Use the same OPENSSL_VERSION_NUMBER comparison as in lib/vtls/openssl.c.

Closes #13208
2024-03-28 09:19:08 +01:00
Robert Moreton
d82869d7a5
cf-socket: remove references to l_ip, l_port
Fixes #13210
Closes #13211
2024-03-28 08:51:19 +01:00
Daniel Stenberg
c247827a8a
openssl: do not set SSL_MODE_RELEASE_BUFFERS
While it might save some memory, it causes OpenSSL to instead do a huge
amount of allocations.

Ref: #13136
Closes #13203
2024-03-28 08:48:51 +01:00
Daniel Stenberg
47da1f289c
http: remove stale comment about rewindbeforesend
... because that struct field exists no more.

Follow-up to 14bcea074a.

Closes #13187
2024-03-26 08:40:58 +01:00
Fabian Keil
0aaea582e0
wolfSSL: do not call the stub function wolfSSL_BIO_set_init()
Calling the function isn't necessary and causes the build
to fail when wolfSSL has been compiled with NO_WOLFSSL_STUB:

     Making all in opts
       CCLD     curl
     ld: error: undefined symbol: wolfSSL_BIO_set_init
     >>> referenced by wolfssl.c:235 (vtls/wolfssl.c:235)
     >>>               libcurl_la-wolfssl.o:(wolfssl_bio_cf_create) in archive ../lib/.libs/libcurl.a
     cc: error: linker command failed with exit code 1 (use -v to see invocation)
     *** Error code 1

Closes #13164
2024-03-25 13:29:46 +01:00
Stefan Eissing
98f67a6145
http2, http3: only return CURLE_PARTIAL_FILE when bytes were received
- should resolve spurious pytest failures when stream were reset
  right after response header were received

Clsoes #13151
2024-03-21 09:36:23 +01:00
Stefan Eissing
0f08b43557
http: separate response parsing from response action
- move code that triggers on end-of-response into separate function from
  parsing
- simplify some headp/headerlen usage
- add `httpversion` to SingleRequest to indicate the version of the
  current response

Closes #13134
2024-03-21 09:34:40 +01:00
Daniel Stenberg
0c820427f2
http2: remove the third (unused) argument from http2_data_done()
Closes #13154
2024-03-21 09:32:27 +01:00
Stefan Eissing
522ea5420f
http: improve response header handling, save cpu cycles
Saving some cpu cycles in http response header processing:
- pass the length of the header line along
- use string constant sizeof() instead of strlen()
- check line length if prefix is possible
- switch on first header char to limit checks

Closes #13143
2024-03-19 07:53:43 +01:00
Evgeny Grin
b6006381fb
curl_sha512_256: work around a NetBSD bug
Based on Michael Kaufmann analysis and suggestion

Closes #13133
2024-03-18 14:13:29 +01:00
Stefan Eissing
80a3b830cc
http: expect 100 rework
Move all handling of HTTP's `Expect: 100-continue` feature into a client
reader. Add sending flag `KEEP_SEND_TIMED` that triggers transfer
sending on general events like a timer.

HTTP installs a `CURL_CR_PROTOCOL` reader when announcing `Expect:
100-continue`. That reader works as follows:

- on first invocation, records time, starts the `EXPIRE_100_TIMEOUT`
  timer, disables `KEEP_SEND`, enables `KEEP_SEND_TIMER` and returns 0,
  eos=FALSE like a paused upload.

- on subsequent invocation it checks if the timer has expired. If so, it
  enables `KEEP_SEND` and switches to passing through reads to the
  underlying readers.

Transfer handling's `readwrite()` will be invoked when a timer expires
(like `EXPIRE_100_TIMEOUT`) or when data from the server arrives. Seeing
`KEEP_SEND_TIMER`, it will try to upload more data, which triggers
reading from the client readers again. Which then may lead to a new
pausing or cause the upload to start.

Flags and timestamps connected to this have been moved from
`SingleRequest` into the reader's context.

Closes #13110
2024-03-18 12:41:56 +01:00
Stefan Eissing
3d0fd382a2
mbedtls: fix pytest for newer versions
Fix the expectations in pytest for newer versions of mbedtls

Closes #13132
2024-03-18 12:37:00 +01:00
Stefan Eissing
77b0571cdc
http: revisit http_perhapsrewind()
- use facilities provided by client readers better
- work also for non-uploading requests like GET/HEAD
- update documentation

Closes #13117
2024-03-15 10:50:44 +01:00
Stefan Eissing
c765b04d11
TLS: start shutdown only when peer did not already close
- When curl sees a TCP close from the peer, do not start a TLS shutdown.
  TLS shutdown is a handshake and if the peer already closed the
  connection, it is not interested in participating.

Reported-by: dfdity on github
Assisted-by: Jiří Bok
Assisted-by: Pēteris Caune
Fixes #10290
Closes #13087
2024-03-15 09:19:58 +01:00
Jay Satiro
181f5f3369 vquic-tls: fix the error code returned for bad CA file
- Return CURLE_SSL_CACERT_BADFILE if wolfSSL encounters a problem
  reading the cert file or path.

This is a follow-up to the parent commit aedbbdf1.

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

Fixes https://github.com/curl/curl/issues/13115
2024-03-13 02:03:18 -04:00
Daniel Stenberg
aedbbdf18e
vquic-tls: return appropirate errors on wolfSSL errors
Reported-by: Dexter Gerig
Closes #13107
2024-03-12 16:44:16 +01:00
Viktor Szakats
14d9afdfe7
tidy-up: one comment and EOF newlines
Reviewed-by: Daniel Stenberg
Closes #13108
2024-03-12 15:38:44 +00:00
Jay Satiro
942896fdd1 mbedtls: properly cleanup the thread-shared entropy
- Store the state of the thread-shared entropy for global init/cleanup.

- Use curl's thread support of mbedtls for all Windows builds instead of
  just when the threaded resolver is used via USE_THREADS_WIN32.

Prior to this change on global cleanup curl builds that have curl thread
support for mbedtls freed the entropy (8b1d2298) but failed to mark that
it had been freed, which caused problems on subsequent init + transfer.

Bug: https://github.com/curl/curl/discussions/11919#discussioncomment-8687105
Reported-by: awesomekosm@users.noreply.github.com

Closes https://github.com/curl/curl/pull/13071
2024-03-12 03:09:37 -04:00
Stefan Eissing
4e4e8af1f6
lib: move 'done' parameter to SingleRequests
A transfer may do several `SingleRequest`s for its success. This happens
regularly for authentication, follows and retries on failed connections.
The "readwrite()" calls and functions connected to those carried a `bool
*done` parameter to indicate that the current `SingleRequest` is over.
This may happen before `upload_done` or `download_done` bits of
`SingleRequest` are set.

The problem with that is now `write_resp()` protocol handlers are
invoked in places where the `bool *done` cannot be passed up to the
caller. Instead of being a bool in the call chain, it needs to become a
member of `SingleRequest`, reflecting its state.

This removes the `bool *done` parameter and adds the `done` bit to
`SingleRequest` instead. It adds `Curl_req_soft_reset()` for using a
`SingleRequest` in a follow up, clearing `done` and other
flags/counters.

Closes #13096
2024-03-11 23:27:02 +01:00
Stefan Eissing
6aeb729b5c
request: clarify message when request has been sent off
Change the "uploaded and fine" message for requests without a body

Reported-by: Karthikdasari0423 on github
Fixes #13093
Closes #13095
2024-03-11 12:02:11 +01:00
Stefan Eissing
fcef00db1a
lib: keep conn IP information together
new struct ip_quadruple for holding local/remote addr+port

- used in data->info and conn and cf-socket.c
- copy back and forth complete struct
- add 'secondary' to conn
- use secondary in reporting success for ftp 2nd connection

Reported-by: DasKutti on github
Fixes #13084
Closes #13090
2024-03-09 23:24:58 +01:00
Stefan Eissing
a586b8ca40
lib: client reader polish
- seek_func/seek_client, use transfer values only
    - remove copies held in `struct connectdata`, use only
      ever `data->set.seek_func`
    - resolves possible issues in multiuse connections
    - new mime post reader eliminates need to ever overwriting this

- websockets, remove empty Curl_ws_done() function

Closes #13079
2024-03-08 13:11:17 +01:00
Daniel Stenberg
b4d73e67dc
http2: minor tweaks to optimize two struct sizes
- use BIT() instead of bool
- place the struct fields in (roughly) size order

Closes #13082
2024-03-07 23:00:45 +01:00
Daniel Stenberg
5267bf52d8
http2: memory errors in the push callbacks are fatal
Use the correct nghttp2 error code accordingly.

Closes #13081
2024-03-07 22:36:49 +01:00
Robert Moreton
835e4cb1d5
asyn-ares: fix data race warning
- Store the c-ares version during global init.

Prior to this change several threads could write the same data to a
static int variable at the same time. Though in practice it's not a
problem ThreadSanitizer may warn.

Reported-by: Nikita Taranov
Assisted-by: Jay Satiro

Fixes #13065
Closes #13000
2024-03-07 16:47:36 +01:00
Stefan Eissing
2c0f2e8163
hyper: implement unpausing via client reader
Just a tidy up to contain 'ifdef' pollution of common
code parts with implementation specifics.

- remove the ifdef hyper unpausing in easy.c
- add hyper client reader for CURL_CR_PROTOCOL phase
  that implements the unpause method for calling
  the hyper waker if it is set

Closes #13075
2024-03-07 15:58:30 +01:00
Stefan Eissing
8a9fbd6291
ngtcp2: no recvbuf for stream
- write response data directly to the transfer via
 `Curl_xfer_write_resp()` like we do in HTTP/2.

Closes #13073
2024-03-07 12:49:23 +01:00
Evgeny Grin (Karlson2k)
05268cf801
sha512_256: add support for GnuTLS and OpenSSL
This is a follow-up for PR #12897.

Add support for SHA-512/256 digest calculation by TLS backends.
Currently only OpenSSL and GnuTLS (actually, nettle) support
SHA-512/256.

Closes #13070
2024-03-07 10:25:11 +01:00
Evgeny Grin
1e517e9f5c
digest: add check for hashing error
Closes #13072
2024-03-07 10:24:27 +01:00
Stefan Eissing
deca803999
http2: push headers better cleanup
- provide common cleanup method for push headers

Closes #13054
2024-03-07 10:12:28 +01:00
Stefan Eissing
9978d40ddb
lib: add void *ctx to reader/writer instances
- `struct Curl_cwriter` and `struct Curl_creader` now carry a
  `void *ctx` member that points to the instance as allocated.
- using `r->ctx` and `w->ctx` as pointer to the instance specific
  struct that has been allocated

Reported-by: Rudi Heitbaum
Fixes #13035
Closes #13059
2024-03-06 14:38:12 +01:00
Stefan Eissing
2ca530d2fa
http: fix dead code in setting post client reader
- postsize was always 0, thus the check's else never happened
  after the mime client reader was introduced

Follow-up to 0ba47146f7
Closes #13060
2024-03-06 14:35:23 +01:00
Stefan Eissing
cc6f2f0064
http2: fix push discard
- fix logic in discarding a failed pushed stream so that
  stream context is properly cleaned up

Closes #13055
2024-03-06 14:34:21 +01:00
Stefan Eissing
db5c9f4f9e
transfer.c: break receive loop in speed limited transfers
- the change breaks looping in transfer.c receive for transfers that are
  speed limited on having gotten *some* bytes.
- the overall speed limit timing is done in multi.c

Reported-by: Dmitry Karpov
Bug: https://curl.se/mail/lib-2024-03/0001.html
Closes #13050
2024-03-06 08:07:37 +01:00
Stefan Eissing
0ba47146f7
mime: add client reader
Add `mime` client reader. Encapsulates reading from mime parts, getting
their length, rewinding and unpausing.

- remove special mime handling from sendf.c and easy.c
- add general "unpause" method to client readers
- use new reader in http/imap/smtp
- make some mime functions static that are now only used internally

In addition:
- remove flag 'forbidchunk' as no longer needed

Closes #13039
2024-03-06 00:17:37 +01:00
Tal Regev
8e741644a2
cmake: add USE_OPENSSL_QUIC support
Closes #13034
2024-03-05 17:07:57 +01:00
Stefan Eissing
c426277b59
TIMER_STARTTRANSFER: set the same for everyone
- set TIMER_STARTTRANSFER on seeing the first response bytes
  in the download client writer, not coming from a CONNECT
- initialized the timer the same way for all protocols
- remove explicit setting of TIMER_STARTTRANSFER in file.c
  and c-hyper.c

Closes #13052
2024-03-05 17:06:47 +01:00
Michael Kaufmann
df1fcb41e2
http: better error message for HTTP/1.x response without status line
If a response without a status line is received, and the connection is
known to use HTTP/1.x (not HTTP/0.9), report the error "Invalid status
line" instead of "Received HTTP/0.9 when not allowed".

Closes #13045
2024-03-05 16:02:44 +01:00
Sebastian Neubauer
a5dd9435ee
smpt: fix starttls
In cases where the connection was fast, curl sometimes failed to open a
connection. This fixes a regression of c2d973627b.

The regression triggered in these steps:

1. Create an smtp connection
2. Use STARTTLS
3. Receive the response
4. We are inside the loop in `smtp_statemachine`, calling
   `smtp_state_starttls_resp`
5. In the good flow, we exit the loop, re-enter `smtp_statemachine` and
   run `smtp_perform_upgrade_tls` at the start of the function.

   In the bad flow, we stay in the while loop, calling
   `Curl_pp_readresp`, which reads part of the TLS handshake and things
   go wrong.

The reason is that `Curl_pp_moredata` changed behavior and always
returns `true`, so we stay in the loop in `smtp_statemachine`. With a
slow connection `Curl_pp_readresp` cannot read new data and returns
`CURL_AGAIN`, so we leave the loop and re-enter `smtp_statemachine`.

With a fast connection, `Curl_pp_readresp` reads new data from the tcp
connection, which is part of the TLS handshake.

The fix is in `Curl_pp_moredata`, which needs to take the final line
into account and return `false` if only the final line is stored.

Closes #13048
2024-03-05 13:30:16 +01:00
Stefan Eissing
14bcea074a
lib: enhance client reader resume + rewind
- update client reader documentation
- client reader, add rewind capabilities
    - tell creader to rewind on next start
    - Curl_client_reset() will keep reader for future rewind if requested
    - add Curl_client_cleanup() for freeing all resources independent of
      rewinds
    - add Curl_client_start() to trigger rewinds
    - move rewind code from multi.c to sendf.c and make part of
      "cr-in"'s implementation
- http, move the "resume_from" handling into the client readers
    - the setup of a HTTP request is reshuffled to follow:
      * determine method, target, auth negotiation
      * install the client reader(s) for the request, including crlf
        conversions and "chunked" encoding
      * apply ranges to client reader
      * concat request headers, upgrades, cookies, etc.
      * complete request by determining Content-Length of installed
        readers in combination with method
      * send
    - add methods for client readers to
      * return the overall length they will generate (or -1 when unknown)
      * return the amount of data on the CLIENT level, so that
        expect-100 can decide if it want to apply itself
      * set a "resume_from" offset or fail if unsupported
    - struct HTTP has become largely empty now
- rename `Client_reader_*` to `Curl_creader_*`

Closes #13026
2024-03-05 13:26:05 +01:00
Viktor Szakats
9c7768cd88
openssl-quic: fix BIO leak and Windows warning
Caused by an accidentally duplicated line in
d6825df334.

```
.../lib/vquic/curl_osslq.c:1095:30: warning: implicit conversion loses integer precision: 'curl_socket_t' (aka 'unsigned long long') to 'int' [-Wshorten-64-to-32]
 1095 |   bio = BIO_new_dgram(ctx->q.sockfd, BIO_NOCLOSE);
      |         ~~~~~~~~~~~~~ ~~~~~~~^~~~~~
1 warning and 2 errors generated.
```

Reviewed-by: Stefan Eissing
Closes #13043
2024-03-05 10:54:08 +00:00
Viktor Szakats
065faf2f93
openssl-quic: fix unity build, casing, indentation
- rename static functions to avoid duplicate symbols in unity mode.
- windows -> Windows/window in error message and comment.
- fix indentation.

Reviewed-by: Stefan Eissing
Closes #13044
2024-03-05 10:54:08 +00:00
Daniel Stenberg
07b667567f
smtp: free a temp resource
The returned address needs to be freed.

Follow-up to e3905de819
Spotted by Coverity

Closes #13038
2024-03-04 22:44:55 +01:00
Daniel Stenberg
9454757508
cookie: if psl fails, reject the cookie
A libpsl install without data and no built-in database is now considered
bad enough to reject all cookies since they cannot be checked. It is
somewhat of a user error, but still.

Reported-by: Dan Fandrich
Closes #13033
2024-03-04 08:46:59 +01:00
Stefan Eissing
e3905de819
lib: further send/upload handling polish
- Move all the "upload_done" handling to request.c

  - add possibility to abort sending of a request
  - add `Curl_req_done_sending()` for checks
  - transfer.c: readwrite_upload() now clean

- removing data->state.ulbuf and data->req.upload_fromhere

  - as well as data->req.upload_present
  - set data->req.upload_done on having read all from
    the client and completely flushed the send buffer

- tftp, remove setting of data->req.upload_fromhere

  - serves no purpose as `upload_present` is not set
    and the data itself is directly `sendto()` anyway

- smtp, make upload EOB conversion a client reader
- xfer_ulbuf addition

  - add xfer_ulbuf for borrowing, similar to xfer_buf
  - use in file upload
  - use in c-hyper body sending

- h1-proxy, remove init of data->state.uilbuf that is never used
- smb, add own send_buf instead of using data->state.ulbuf

Closes #13010
2024-03-04 08:42:56 +01:00
kpcyrd
ae7ad31be2
rustls: fix two warnings related to number types
Reported-by: Gisle Vanem
Follow-up to #12989
Closes #13017
2024-03-03 18:22:03 +01:00
Stefan Eissing
b1005d127f
bufq: writing into a softlimit queue cannot be partial
- when unable to obtain a new chunk on a softlimit bufq,
  this is an allocation error and needs to be reported as
  such.
- writes into a soflimit bufq never must be partial success

Reported-by: Dan Fandrich
Fixes #13020
Closes #13023
2024-03-03 17:35:47 +01:00
Dan Fandrich
ddb87160f5 ftp: Mark a const buffer as const 2024-03-01 01:16:24 -08:00
RainRat
2cd78f525c misc: Fix typos in docs and lib
This fixes miscellaneous typos and duplicated words in the docs, lib
and test comments and a few user facing errorstrings.

Author: RainRat on Github
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Dan Fandrich <dan@coneharvesters.com>
Closes: #13019
2024-03-01 09:59:48 +01:00