cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Problem wirth libcurl and write_function

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Sun, 20 May 2007 21:14:42 -0700

On Mon, May 21, 2007 at 12:38:05AM +0200, Thaorius wrote:
> function. I wrote one. The problem is that if the HTTP server output is less
> than 8 bytes(without the headers), one of the following things happens:
>
> 1) Random characters appears til the 8 bytes al fulfilled.
> 2) The program crashes on the call to curl_easy_perform().
>
> This is my write function:
>
> size_t PlatformInterface::_curl_write(void *buffer, size_t size, size_t nmemb,
> void *userp)
> {
> char *temp = (char *)malloc((size * nmemb) + 1);
> memcpy(temp, buffer, (size * nmemb));
> temp[(size * nmemb) + 1] = '\0';
> ((std::string *)userp)->append((char *)temp);
>
> return size * nmemb;
> }

You have an off-by-one error whilst NUL-terminating the string and writing
past the end of the buffer.

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2007-05-21