curl-library
Re: cURL bug -- Segmentation Fault when timeout is 1 second
Date: Wed, 4 Feb 2009 13:11:17 -0500
On Wed, Feb 4, 2009 at 12:48 PM, Daniel Marschall
<info_at_daniel-marschall.de> wrote:
> 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?
char* is just a pointer, it does not guarantee anything about
0-termination or storage. If you use a char* buffer, you need to do
the management for buffer overruns and 0-termination.
>
> 2. The output of the buffer with printf() is not correct. Some foreign
> memory contents are in my string... The output is like:
>
That is because buffer was allocated but not initialized. You would
need to 0-terminate the array to get printf to stop at the correct
place.
>
> <HTML>
> <HEAD>
> <TITLE>Example Web Page</TITLE>
> </HEAD>
> <body>
> <p>You have reached this web page by typing "example.com",
> "example.net",
> or "example.org" 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 "example.com",
> "example.net",
> or "example.org" 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 "example.com",
> "example.net",
> or "example.org" 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