openssl: fix handling of buffered data

`SSL_pending()` only checks if the *current* TLS packet has more data.
There might be more data in SSL's buffers.

`SSL_has_pending()` only checks if there is data in buffers, but does
*not* check if there is a complete TLS packet that can be decoded.

If we only check the first, we will poll on socket events without having
processed all data and may stall. If we only check the second, we would
busy loop without SSL_read() ever giving something.

Add the flag `connssl->input_pending` that is set on incoming data in
the BIO receive. Clear the flag when encountering a CURLE_AGAIN on
the filters receive (via SSL_read()) or see an EOF.

Ref: #17596
Closes #17601
This commit is contained in:
Stefan Eissing 2025-06-12 08:45:20 +02:00 committed by Viktor Szakats
parent cbc062a7b8
commit 1cdac95e2e
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
3 changed files with 21 additions and 9 deletions

View file

@ -116,11 +116,15 @@ CURLcode Curl_pp_statemach(struct Curl_easy *data,
else if(!pp->sendleft && Curl_conn_data_pending(data, FIRSTSOCKET))
/* We are receiving and there is data ready in the SSL library */
rc = 1;
else
else {
DEBUGF(infof(data, "pp_statematch, select, timeout=%" FMT_TIMEDIFF_T
", sendleft=%zu",
timeout_ms, pp->sendleft));
rc = Curl_socket_check(pp->sendleft ? CURL_SOCKET_BAD : sock, /* reading */
CURL_SOCKET_BAD,
pp->sendleft ? sock : CURL_SOCKET_BAD, /* writing */
interval_ms);
}
if(block) {
/* if we did not wait, we do not have to spend time on this now */