-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using curl_formadd to post file could not rewind correctly when redirection happens #11680
Comments
It looks like an entirely correct analysis. I made #11682 as a first attempt at a fix. |
Thank you very much for your reply, but we found a crash after applying your patch. Libcurl crashed at |
Can you show me a small example code that reproduces this problem so that I can better understand what's going on (and write a test case to repro) ? |
I'm very sorry, I can't provide detailed code due to privacy issues, but the specific details can be summarized as using curl_formadd() to send files, the server needs to return 307 redirection. The backbone of the code is shown below.
Perhaps I can share some of my findings with you. When the state machine is in the MSTATE_DO state, the multi_do function will store the form data in data->state.formp, data->state.formp will also make a copy to data->state.mimepost, and then the state machine will transfer to the MSTATE_DID state . This state will be further transferred to the MSTATE_PERFORMING state. In this state, if the location field is found in the response header, it will be redirected (data->req.newurl not NULL). But before the state machine transfers to MSTATE_CONNECT, the multi_done function will be executed, which will clean up data->state.formp. But data->state.formp and data->state.mimepost share the same piece of memory, and data->state.mimepost will be used in rewind, but the resources it points to have been released, resulting in wild pointers. Hope the clues I found can help you. Thanks. |
I improved #11682 a bit after your first comment and did a test to verify. It probably does not fully mimic your case but did it improve things for you? |
Thank you for your submission. There is no crash now, but I still have some questions to ask you, I didn't see where do data->state.formp initialization, according to my understanding, it will be a wild pointer, so when do setopt operation, execute Curl_mime_cleanpart(data->state.formp); will there be risks? |
The Lines 2382 to 2392 in 1662cc2
The data is allocated and |
Thank you for your answer, we will consider using a new way to do formpost. But when setopt, formp should not be initialized? So won't Curl_mime_cleanpart access wild pointers?
|
It is cleared. That's what |
Thanks again for your response, I've tested it and it's working fine, excellent work! |
When the legacy CURLOPT_HTTPPOST option is used, it gets converted into the modem mimpost struct at first use. This data is (now) kept for the entire transfer and not only per single HTTP request. This re-enables rewind in the beginning of the second request instead of in end of the first, as brought by 1b39731. The request struct is per-request data only. Extend test 650 to verify. Fixes curl#11680 Reported-by: yushicheng7788 on github Closes curl#11682
I did this
I am using curl_formadd to post MIME data to server, and server replies redirection. But it seems libcurl didn't rewind correctly.
I think this phenomenon was cause by this commit 1b39731
In the version before 7.87.0, libcurl will do rewind immediately, but in version 7.87.0, libcurl will only make a mark, and then do the rewind operation in the next round of state machine driving. But at that time, the cached req member seems to be reinitialized again, causing http->sendit to be empty, and when sending data with curl_formadd, mimepost is also empty, and rewind is not executed correctly.
I expected the following
I'm wondering if my understanding is correct or not. Would like get your confirmation.
curl/libcurl version
curl 8.1.2
operating system
Windows x86_64
The text was updated successfully, but these errors were encountered: