Re: Problem wirth libcurl and write_function
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.
-- http://www.MoveAnnouncer.com The web change of address service Let webmasters know that your web site has movedReceived on 2007-05-21