curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Use of cookies

From: Tomalak Geret'kal via curl-library <curl-library_at_cool.haxx.se>
Date: Mon, 6 Apr 2020 18:02:28 +0100

On 06/04/2020 17:41, Mac-Fly via curl-library wrote:
> I understand that and I was compiling a minimal example
> for you. While doing so I found the error!!!
> In the libCURL example (cookies_interface.c), you call:
> curl_easy_setopt([CURL_handle], CURLOPT_COOKIELIST, cookie);
> ...where "cookie" is a char buffer. What I did was something like:
> std::string cookie = "...";
> curl_easy_setopt([CURL_handle], CURLOPT_COOKIELIST, cookie.c_str());
> ...which does not raise an error but does also not apply the cookie. So it really must be a buffer you provide to the function.
>
> Changing into:
> char cookie_buffer[256]; snprintf(cookie_buffer, [...]);
> curl_easy_setopt([CURL_handle], CURLOPT_COOKIELIST, cookie_buffer);
> ...made it work!
> Problem solved. So, I put it here for other that might trap into th same issue. Settings cookies must be done through buffers. Period.
It is more likely that curl_east_setopt is expecting the
C-string you give it to live for the duration of the handle
(as it does with the request headers).

Thus, switching to a "buffer" may not be enough (the pointer
you were extracting from your std::string points to a
"buffer" too!) - you still have undefined behaviour if you
cannot guarantee the lifetime of the char array.

There are still not enough details to tell whether that's
the case for you. But be warned that this is about lifetime,
not about "buffers".

Cheers
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2020-04-06