cURL / Mailing Lists / curl-library / Single Mail

curl-library

Yet another libcurl Broken Pipe (Ubuntu 14)

From: Wagner Patriota <wagner.patriota_at_gmail.com>
Date: Mon, 12 May 2014 17:37:38 -0300

The code below works fine on Windows and OS X. But curl_easy_perform()
crashes on Ubuntu 14.04

Is there anything in my code that I am missing that could cause this crash?

void uploadFile( const string & p_filename, const string & p_url, size_t
p_offset, size_t p_sizeOfChunk )
{
    FILE * file( fopen( p_filename.c_str(), "rb" ) );

    if ( !file )
    {
        // I take care...
    }

    if ( p_offset )
    {
        if ( fseek( file, (long)p_offset, SEEK_SET ) )
        {
            // I take care...
        }
    }

    CURL * curl( curl_easy_init() );

    if ( !curl )
    {
        // I take care...
    }

    // URL
    curl_easy_setopt( curl, CURLOPT_URL, p_url.c_str() );

    // PUT HTTP method
    string answer;
    curl_easy_setopt( curl, CURLOPT_UPLOAD, 1L );
    curl_easy_setopt( curl, CURLOPT_READFUNCTION, fread );
    curl_easy_setopt( curl, CURLOPT_READDATA, file );
    curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, writeToString );
    curl_easy_setopt( curl, CURLOPT_WRITEDATA, &answer );
    curl_easy_setopt( curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)p_sizeOfChunk );

    char errorBuffer[ CURL_ERROR_SIZE + 1 ];
    curl_easy_setopt( curl, CURLOPT_ERRORBUFFER, errorBuffer );

    // No signal handlers...
    curl_easy_setopt( curl, CURLOPT_NOSIGNAL, 1 );
    curl_easy_setopt( curl, CURLOPT_TIMEOUT_MS, 120000 );

    // HEADER
    char contentLength[ 512 ];
    snprintf( contentLength, sizeof( contentLength ), "Content-Length:
%zu", p_sizeOfChunk );

    struct curl_slist * headers( nullptr );
    headers = curl_slist_append( headers, contentLength );
    curl_easy_setopt( curl, CURLOPT_HTTPHEADER, headers );

    // SSL
    curl_easy_setopt( curl, CURLOPT_CAINFO, "path/to/cacert.pem" );

    CURLcode res( curl_easy_perform( curl ) );

    fclose( file );

    if ( res != CURLE_OK && res != CURLE_SEND_ERROR )
    {
        curl_easy_cleanup( curl );
        // I take care...
    }

    long httpResponseCode( 0 );
    curl_easy_getinfo( curl, CURLINFO_RESPONSE_CODE, &httpResponseCode );
    curl_easy_cleanup( curl );

    if ( ( httpResponseCode / 100 ) != 2 )
    {
        cout << answer << endl;
        I take care...
    }
}

writeToString() is not the problem. It also happens with fwrite or anything
similar.

Down here is the stack in the moment of crash! It seems to be related to
OpenSSL.

The versions I am using are:
- Curl 7.36.0
- OpenSSL 1.0.1f 6 Jan 2014

#0 0x00007ffff65ad35d in write () at ../sysdeps/unix/syscall-template.S:81
#1 0x00007ffff73187a6 in ?? () from
/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
#2 0x00007ffff731684b in BIO_write () from
/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
#3 0x00007ffff6ffcb72 in ?? () from /lib/x86_64-linux-gnu/libssl.so.1.0.0
#4 0x00007ffff6ffd273 in ?? () from /lib/x86_64-linux-gnu/libssl.so.1.0.0
#5 0x00007ffff76873e1 in ossl_send (conn=0x7ffef8013b28, sockindex=0,
mem=0x7ffef8005379, len=16384, curlcode=0x7fff127fa5c0) at
vtls/openssl.c:2720
#6 0x00007ffff762fe0f in Curl_write (conn=0x7ffef8013b28, sockfd=64,
mem=0x7ffef8005379, len=16384, written=0x7fff127fa608) at sendf.c:233
#7 0x00007ffff764fb01 in readwrite_upload (data=0x7ffef8000a78,
conn=0x7ffef8013b28, k=0x7ffef8000af0, didwhat=0x7fff127fa664) at
transfer.c:954
#8 0x00007ffff764fdd9 in Curl_readwrite (conn=0x7ffef8013b28,
done=0x7fff127fa6dc) at transfer.c:1059
#9 0x00007ffff765ced7 in multi_runsingle (multi=0x7ffef800a668, now=...,
data=0x7ffef8000a78) at multi.c:1484
#10 0x00007ffff765d60c in curl_multi_perform (multi_handle=0x7ffef800a668,
running_handles=0x7fff127fa870) at multi.c:1759
#11 0x00007ffff7652103 in easy_transfer (multi=0x7ffef800a668) at easy.c:705
#12 0x00007ffff7652311 in easy_perform (data=0x7ffef8000a78, events=false)
at easy.c:793
#13 0x00007ffff7652364 in curl_easy_perform (easy=0x7ffef8000a78) at
easy.c:812
#14 ...

Any help will be appreciated!
Thanks

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-05-12