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.

Empty file name in CURLOPT_COOKIEFILE optimization

From: Dmitry Karpov via curl-library <>
Date: Wed, 13 Dec 2023 21:49:07 +0000

Hi All,

As we know from the documentation, passing the empty string ("") to the CURLOPT_COOKIEFILE option allows to enable the cookie engine without reading any initial cookies.

While this is true, the Curl_cookie_init() function in \lib\cookie.c still tries to open a file using "" as a file name with fopen() and
giving the "failed to open cookie file" warning for such cases.

Besides giving a warning, the empty name "" also creates unnecessary performance penalty because of calling fopen()
(i.e. on Windows fopen() even with an empty name is very untrivial call).

I propose to add a simple check for the cookie file name length and call fopen() only if it is greater than zero like:

 lib/cookie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/cookie.c b/lib/cookie.c
index 9095cea3e..8f95b0a97 100644
--- a/lib/cookie.c
+++ b/lib/cookie.c
_at__at_ -1229,7 +1229,7 _at__at_ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
   if(data) {
     FILE *fp = NULL;
-    if(file) {
+    if(file && strlen(file) > 0) {
       if(!strcmp(file, "-"))
         fp = stdin;
       else {
Dmitry Karpov
Received on 2023-12-13