transfer: avoid calling the read callback again after EOF

Regression since 7f43f3dc59 (7.84.0)

Bug: https://curl.se/mail/lib-2023-11/0017.html

Closes #12363
This commit is contained in:
Jiří Hruška 2023-11-20 09:26:59 +01:00 committed by Daniel Stenberg
parent db5bf23103
commit 6a095da1f3
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 13 additions and 5 deletions

View File

@ -163,9 +163,9 @@ CURLcode Curl_fillreadbuffer(struct Curl_easy *data, size_t bytes,
{
size_t buffersize = bytes;
size_t nread;
curl_read_callback readfunc = NULL;
void *extra_data = NULL;
int eof_index = 0;
#ifndef CURL_DISABLE_HTTP
if(data->state.trailers_state == TRAILERS_INITIALIZED) {
@ -223,6 +223,7 @@ CURLcode Curl_fillreadbuffer(struct Curl_easy *data, size_t bytes,
*/
readfunc = trailers_read;
extra_data = (void *)data;
eof_index = 1;
}
else
#endif
@ -231,10 +232,15 @@ CURLcode Curl_fillreadbuffer(struct Curl_easy *data, size_t bytes,
extra_data = data->state.in;
}
Curl_set_in_callback(data, true);
nread = readfunc(data->req.upload_fromhere, 1,
buffersize, extra_data);
Curl_set_in_callback(data, false);
if(!data->req.fread_eof[eof_index]) {
Curl_set_in_callback(data, true);
nread = readfunc(data->req.upload_fromhere, 1, buffersize, extra_data);
Curl_set_in_callback(data, false);
/* make sure the callback is not called again after EOF */
data->req.fread_eof[eof_index] = !nread;
}
else
nread = 0;
if(nread == CURL_READFUNC_ABORT) {
failf(data, "operation aborted by callback");

View File

@ -733,6 +733,8 @@ struct SingleRequest {
struct curltime last_sndbuf_update; /* last time readwrite_upload called
win_update_buffer_size */
#endif
char fread_eof[2]; /* the body read callback (index 0) returned EOF or
the trailer read callback (index 1) returned EOF */
#ifndef CURL_DISABLE_COOKIES
unsigned char setcookies;
#endif