Skip to content

transfer: drop a pending read rewind when a new transfer starts - #23505

Closed
1rhino2 wants to merge 1 commit into
curl:masterfrom
1rhino2:pretransfer-drop-stale-readers
Closed

1rhino2 wants to merge 1 commit into
curl:masterfrom
1rhino2:pretransfer-drop-stale-readers

Conversation

@1rhino2

@1rhino2 1rhino2 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Curl_req_hard_reset() keeps the client reader stack when a rewind is pending and clears the flag only afterwards, so when a redirect with a request body fails before the follow-up request gets set up (a 307 with a Location curl cannot parse, or a 307 with a header line without a colon, with FOLLOWLOCATION on), the readers of the previous body stay installed into the next transfer on the same easy handle. The next upload over a protocol that uses the generic reader (ftp, sftp, scp, file, tftp) reads through that stale stack instead of the new READDATA, and if the postfields were replaced in between the memory it reads is gone. Reproduced on 8.23.0 with one easy handle doing a COPYPOSTFIELDS POST that gets such a 307, then a file:// or ftp:// upload without curl_easy_reset(); with this change the second transfer reads its own data again and the full suite is unchanged (8.16.0 and later have the ordering).

Curl_req_hard_reset() keeps the client reader stack when a rewind is
pending and only clears the flag afterwards, so when a redirect with a
request body fails before the follow-up request is set up, the readers
of the previous body stay installed into the next transfer on the same
easy handle. An upload over a protocol that uses the generic reader
(ftp, sftp, scp, file, tftp) then reads through the stale stack, and if
the postfields were replaced in between that memory is gone.

Clear a pending rewind and reset the readers in Curl_pretransfer(), a
new transfer never wants a rewind of the previous body.

@icing icing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

@bagder bagder closed this in acf8a65 Oct 20, 2026
dkarpov1970 pushed a commit to dkarpov1970/curl that referenced this pull request Nov 18, 2026
Curl_req_hard_reset() keeps the client reader stack when a rewind is
pending and only clears the flag afterwards, so when a redirect with a
request body fails before the follow-up request is set up, the readers
of the previous body stay installed into the next transfer on the same
easy handle. An upload over a protocol that uses the generic reader
(ftp, sftp, scp, file, tftp) then reads through the stale stack, and if
the postfields were replaced in between that memory is gone.

Clear a pending rewind and reset the readers in Curl_pretransfer(), a
new transfer never wants a rewind of the previous body.

Closes curl#23505

(cherry picked from commit acf8a65)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants