cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: cURL bug -- Segmentation Fault when timeout is 1 second

From: Daniel Marschall <info_at_daniel-marschall.de>
Date: Wed, 4 Feb 2009 18:48:35 +0100

Hello.

Thank you for your answer.

With the malloc memory reservation the error disappears at the moment.

But there are 2 problems I still have:

1. I want to have an infinite big buffer, like a std::string in C++. If the
website-output is larger than the buffer size, then I get a
memory-access-error again.

Isn't "char*" an infinite c-string that waits for an 0x0 termination
sequence, is it?

2. The output of the buffer with printf() is not correct. Some foreign
memory contents are in my string... The output is like:

<HTML>
<HEAD>
  <TITLE>Example Web Page</TITLE>
</HEAD>
<body>
<p>You have reached this web page by typing &quot;example.com&quot;,
&quot;example.net&quot;,
  or &quot;example.org&quot; into your web browser.</p>
<p>These domain names are reserved for use in documentation and are not
available
  for registration. See <a
href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC
  2606</a>, Section 3.</p>
</BODY>
</HTML>

A
¨Ü·¨Ü·<HTML>
<HEAD>
  <TITLE>Example Web Page</TITLE>
</HEAD>
<body>
<p>You have reached this web page by typing &quot;example.com&quot;,
&quot;example.net&quot;,
  or &quot;example.org&quot; into your web browser.</p>
<p>These domain names are reserved for use in documentation and are not
available
  for registration. See <a
href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC
  2606</a>, Section 3.</p>
</BODY>
</HTML>

A
0<HTML>
<HEAD>
  <TITLE>Example Web Page</TITLE>
</HEAD>
<body>
<p>You have reached this web page by typing &quot;example.com&quot;,
&quot;example.net&quot;,
  or &quot;example.org&quot; into your web browser.</p>
<p>These domain names are reserved for use in documentation and are not
available
  for registration. See <a
href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC
  2606</a>, Section 3.</p>
</BODY>
</HTML>

PuTTYPuTTY

--------------------------------------------------
From: "Gisle Vanem" <gvanem_at_broadpark.no>
Sent: Wednesday, February 04, 2009 6:32 PM
To: "libcurl development" <curl-library_at_cool.haxx.se>
Subject: Re: cURL bug -- Segmentation Fault when timeout is 1 second

> "Daniel Marschall" <info_at_daniel-marschall.de> wrote:
>
>> Here is my current C-Code (because I have switched from C++ to C):
>>
>> Still the same error. Is there some mistake I made?
> ...
>> using namespace std;
>
> It's still C++ afaics.
>
> ... * in writer() *
>
>> strcat(buffer, data);
>>
>
> ... * http_call() *
>> char* buffer;
>> curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
>
> 'buffer' isn't initialised to something. So no wonder writer()
> crashes. With this patch:
>
> @@ -66,7 +66,7 @@
> char errorBuffer[CURL_ERROR_SIZE];
>
> curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, errorBuffer);
> - char *buffer;
> + char *buffer = (char*)malloc(12345);
>
> curl_easy_setopt (curl, CURLOPT_WRITEDATA, buffer);
> ------------------
>
> all works well here.
>
> --gv
>
Received on 2009-02-04