cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_multi_remove_handle() crashes if called before transfer is complete (sftp only)

From: 蔡文凱 <angrlk_at_gmail.com>
Date: Tue, 23 Feb 2016 18:47:54 +0800

Hi Daniel :

I've updated libssh2 to 1.6.0, still got seg fault every time.

here is my test code (by referring Saqib Ali's mail
https://curl.haxx.se/mail/lib-2011-03/0066.html)
//---------------------------------------------
#include <curl/curl.h>
#include <iostream>
#include <unistd.h>
#include <sys/stat.h>

using namespace std;

int main()
{
CURLMcode retVal;
curl_global_init(CURL_GLOBAL_ALL);
CURLM* multiHandle = curl_multi_init();
CURL* newEasyHandle = curl_easy_init();
curl_easy_setopt(newEasyHandle, CURLOPT_USERPWD, "myUserName:myPassWord");
curl_easy_setopt(newEasyHandle, CURLOPT_UPLOAD, 1);
curl_easy_setopt(newEasyHandle, CURLOPT_VERBOSE, 1);
FILE* fd = fopen("MySourceFile", "r"); // open file to upload
curl_easy_setopt(newEasyHandle, CURLOPT_READDATA, fd);
curl_easy_setopt(newEasyHandle, CURLOPT_URL, "s
ftp://MyRemoteIP/~/MyTargetFileName");
curl_easy_setopt(newEasyHandle, CURLOPT_LOW_SPEED_LIMIT, (long)10240);
curl_easy_setopt(newEasyHandle, CURLOPT_LOW_SPEED_TIME, (long)10);
struct stat fileInfo;
stat("/media/USB1/arec/2016_02_18_11_05_01/2016_02_18_11_05_01.mp4",
&fileInfo);
curl_easy_setopt(newEasyHandle, CURLOPT_INFILESIZE, (long)fileInfo.st_size);

// BLOCK A: Now add the easyHandle to the multiStack
curl_multi_add_handle(multiHandle, newEasyHandle);
int stillRunning, retValcm;
retVal = curl_multi_perform(multiHandle, &stillRunning);
if (retVal != CURLM_OK)
cout << "curl_multi_perform() failed!" << endl;
// END BLOCK A

// BLOCK C: Now remove the easyHandle from the multiStack
sleep(2);
retVal = curl_multi_remove_handle(multiHandle, newEasyHandle);
if (retVal == CURLM_OK)
cout << "curl_multi_remove_handle() was successfull!" << endl;
else
cout << "curl_multi_remove_handle() failed!" << endl;
// END BLOCK C

// BLOCK B: Wait until the transfers are done.
while (stillRunning > 0)
{
sleep(1);
retValcm = curl_multi_perform(multiHandle, &stillRunning);
cout << "stillRunning = " << stillRunning << " curl_multi_perform() == " <<
retValcm << endl;
}
// END BLOCK B

return 0;

}
//----------------------------------------------
curl version
curl 7.47.1 (x86_64-pc-linux-gnu) libcurl/7.47.1 OpenSSL/1.0.1f zlib/1.2.8
libssh2/1.6.0
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp
scp sftp smb smbs smtp smtps telnet tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP UnixSockets

Thanks

2016-02-23 16:43 GMT+08:00 Daniel Stenberg <daniel_at_haxx.se>:

> On Tue, 23 Feb 2016, 蔡文凱 wrote:
>
> I'm doing a sftp uploading with CURLOPT_LOW_SPEED_LIMIT &
>> CURLOPT_LOW_SPEED_TIME set. If I call curl_multi_remove_handle() before
>> transfer is complete,there will be a segmentation fault.
>>
>> I also find out that crash only occurs when CURLOPT_LOW_SPEED_LIMIT &
>> CURLOPT_LOW_SPEED_TIME are set.
>>
>
> Thanks! Can you help us out and show us a complete example that repeats
> this problem?
>
> libssh2/1.4.3
>>
>
> Do note that this is a fairly old libssh2 version. I don't think this
> problem is because of the old libssh2 version, but lots of other problems
> have been fixed since...
>
> --
>
> / daniel.haxx.se
> -------------------------------------------------------------------
> List admin: https://cool.haxx.se/list/listinfo/curl-library
> Etiquette: https://curl.haxx.se/mail/etiquette.html
>

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-02-23