From curl-tracker-owner@cool.haxx.se Tue Feb  3 20:01:54 2009
Date: Tue, 03 Feb 2009 20:01:49 +0100
From: curl-tracker-owner@cool.haxx.se
To: curl-tracker-owner@cool.haxx.se
Subject: curl-tracker post from info@daniel-marschall.de requires approval

As list administrator, your authorization is requested for the
following mailing list posting:

    List:    curl-tracker@cool.haxx.se
    From:    info@daniel-marschall.de
    Subject: Re: cURL Bug? -- Segmentation Fault (fwd)
    Reason:  Post to moderated list

At your convenience, visit:

    http://cool.haxx.se/cgi-bin/mailman/admindb/curl-tracker
        
to approve or deny the request.


    [ Part 2: "Included Message" ]

Date: Tue, 3 Feb 2009 20:01:42 +0100
From: Daniel Marschall <info@daniel-marschall.de>
To: Daniel Stenberg <daniel@haxx.se>, curl-library@cool.haxx.se, curl-tracker@cool.haxx.se
Subject: Re: cURL Bug? -- Segmentation Fault (fwd)

Hello.

I only entered "apd-get install libcurl3-dev" in the system without knowing 
how to update a specific version or how to upgrade manually. The command 
"curl -v" does tell me:

curl 7.15.5 (i486-pc-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8c zlib/1.2.3 
libidn/0.6.5
Protocols: tftp ftp telnet dict ldap http file https ftps
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz

I think, that is the newest that Debian supports as stable.

The writer function WAS included in my original 500 lines code. So, the same 
error came with and without the buffer-writer-function. Since I had to 
abstract the program code to make a minimal crashing program, so I removed 
every line that did not make the crash disappearing, to show you the minimal 
program code required.

And gdb did really output, that the curl_escape() function did make this 
memory-exception. I don't know the interna of the libCURL, I can only tell 
what the debugger tool wrote me.

Every time the program crashes inside GDB, I get following debug line:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1216652384 (LWP 23994)]
0xb7cf888a in curl_escape () from /usr/lib/libcurl.so.3

Here is my http function in the original case (before I did abstract to the 
minimal crash-demo-application - and it crashes with the same error):


// Copied this function from haxx.se
static int writer(char *data, size_t size, size_t nmemb, std::string 
*buffer)
{
	// What we will return
	int result = 0;

	// Is there anything in the buffer?
	if (buffer != NULL)
	{
		// Append the data to the buffer
		buffer->append(data, size * nmemb);

		// How much did we write?
		result = size * nmemb;
	}

	return result;
}

static bool http_call (string url) {
	CURL *curl;

	logEvent(VERBOSE_LEVEL_DEBUG, "Calling URL: " + url);

	curl = curl_easy_init();
	if(curl) {
		// URL übergeben
		curl_easy_setopt(curl, CURLOPT_URL, url.c_str());

		// Keine Kopfzeile einblenden
		curl_easy_setopt(curl, CURLOPT_HEADER, false);

		// Verbindung danach beenden
		curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, true);

		// Pufferoptionen
		char errorBuffer[CURL_ERROR_SIZE];
		curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
		string buffer;
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);

		// Benutzerdefinierter User-Agent-Name
		curl_easy_setopt(curl, CURLOPT_USERAGENT, "Hello World Browser");

		// Einen Timeout setzen
		curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1);

		// Weiterleitungen beachten, aber nur max. 50x
		curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
		curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50);

		// Einen HTTP-Fehler-Statuscode beachten
		curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);

		// SSL-Zertifikate nicht prüfen (Warnung! Sicherheitslücke)
		// http://ademar.name/blog/2006/04/curl-ssl-certificate-problem-v.html
		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);

		// Abfrage ausführen und Resultat speichern
		CURLcode res;
		res = curl_easy_perform(curl);

		// Clean up
		curl_easy_cleanup(curl);

		// Alles OK?
		if (res == CURLE_OK)
		{
			logEvent(VERBOSE_LEVEL_DEBUG, "URL successfully entered.");

			if (buffer != "\0") {
				logEvent(VERBOSE_LEVEL_DEBUG, "There was an output: " + buffer);
			} else {
				logEvent(VERBOSE_LEVEL_DEBUG, "There was no output.");
			}
			return true;
		}
		else
		{
			logEvent(VERBOSE_LEVEL_DEBUG, "Error while entering address: [" + 
IntToStr(res) + "] - " + errorBuffer);
			return false;
		}
	} else return false;
}



Best regards
Daniel Marschall

--------------------------------------------------
From: "Daniel Stenberg" <daniel@haxx.se>
Sent: Tuesday, February 03, 2009 7:45 PM
To: "libcurl development" <curl-library@cool.haxx.se>
Cc: "Daniel Marschall" <info@daniel-marschall.de>
Subject: Re: cURL Bug? -- Segmentation Fault (fwd)

> On Tue, 3 Feb 2009, Daniel Stenberg wrote:
>
>> I use G++ on a Linux Debian Etch with LibCURL3
>
> 3 is the ABI number, it is better to tell us the version number. No matter 
> what, the most recent ABI 3 version is 2.5 years old so you'd be wise to 
> upgrade...
>
>> curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
>
> With no write function set, this will clearly lead to crashes. The default 
> write function is fwrite() and fwrite() surely cannot deal with a pointer 
> to a 'string'...
>
>> With the GDB Tool I saw that the segmentation fault probably comes from 
>> curl_escape() everytime.
>
> I doubt that, as curl_escape() is never used by libcurl... it is only a 
> function its provides to the outside!
>
> -- 
>
>  / daniel.haxx.se
> 


    [ Part 3: "Included Message" ]

Date: Tue, 03 Feb 2009 20:01:49 +0100
From: curl-tracker-request@cool.haxx.se
Subject: confirm 0f17272b92a19839436abd3311888567ee1da333

If you reply to this message, keeping the Subject: header intact,
Mailman will discard the held message.  Do this if the message is
spam.  If you reply to this message and include an Approved: header
with the list password in it, the message will be approved for posting
to the list.  The Approved: header can also appear in the first line
of the body of the reply.