cURL / Mailing Lists / curl-library / Single Mail

curl-library

HTTPS request with curl library gives "out of memory" error

From: Ambarish Mitra <ambarish_mitra_at_persistent.co.in>
Date: Thu, 10 Jan 2008 19:07:25 +0530

Hi all,

When sending a HTTPS traffic with CURL library (<http://curl.haxx.se/>) in a
C program, the curl API function "curl_easy_perform" throws an error code
CURLE_OUT_OF_MEMORY, which the 'curl_easy_strerror' translates to "out of
memory".

It is working in non-SSL mode, making me believe that there is some issue
with the SSL setup/config.

Moreover, it is working when we use the "curl" command in the command line:
[ambarish_at_ps2844 authzplugin]$ curl
https://secure-server:2443/home.html --cacert <file> // This works, the html
output is not shown.

I am on curl 7.12.1, and SSL support is enabled. Also, openssl version is:
OpenSSL 0.9.7a Feb 19 2003.

Any help/pointers will be very helpful.

Thanks, Ambarish Mitra.

Code snippet:

CURL* hCurl;
CURLcode res;
curl_slist* requestHeaders = NULL;

hCurl = curl_easy_init(); //Null checking done, not shown

// plethora of easy_setopt done, not shown here. Only the SSL options are
shown.
// if you think sending out all the options will be helpful, let me know,
and I will do that.

curl_easy_setopt(hCurl, CURLOPT_SSLVERSION, 3);

curl_easy_setopt(hCurl,CURLOPT_SSLCERTTYPE,"PEM");
curl_easy_setopt(hCurl,CURLOPT_SSLCERT,"/home/ambarish/project/client.crt");

curl_easy_setopt(hCurl,CURLOPT_SSLKEY,"/home/ambarish/project/client.key");
curl_easy_setopt(hCurl,CURLOPT_SSLKEYTYPE, "PEM");
curl_easy_setopt(hCurl,CURLOPT_SSLKEYPASSWD,"password");

curl_easy_setopt(hCurl, CURLOPT_SSL_VERIFYPEER, 0); // Verify Peer = 0, so
CA cert is not needed.

// CURL options to set/unset the request headers
requestHeaders = curl_slist_append(requestHeaders , "Pragma:" ) ;
//remove header
requestHeaders = curl_slist_append(requestHeaders , "Accept:" ) ;
//remove header
requestHeaders = curl_slist_append(requestHeaders ,
"Content-Type:text/xml");

curl_easy_setopt( hCurl , CURLOPT_HTTPHEADER , requestHeaders);
res = curl_easy_setopt(hCurl, CURLOPT_URL,
https://secure-server:2443/program.cgi); // the endpoint

res = curl_easy_perform(hCurl);
if (res == CURLE_OK)
{
// OK. Set the data. Not shown here.
}
else
{
fprintf(stderr,"CURL perform error:%s",curl_easy_strerror(res)); // This
gives "out of memory"
curl_slist_free_all(requestHeaders);
curl_easy_cleanup(hCurl); // cleanup

}

curl_slist_free_all(requestHeaders);
curl_easy_cleanup(hCurl); // cleanup

DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.
Received on 2008-01-10