Skip to content

Commit

Permalink
cookie: Fix bug in export if any-domain cookie is present
Browse files Browse the repository at this point in the history
In 3013bb6 I had changed cookie export to ignore any-domain cookies,
however the logic I used to do so was incorrect, and would lead to a
busy loop in the case of exporting a cookie list that contained
any-domain cookies. The result of that is worse though, because in that
case the other cookies would not be written resulting in an empty file
once the application is terminated to stop the busy loop.
  • Loading branch information
jay committed Jun 18, 2015
1 parent 1c3811f commit ef0fdb8
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/cookie.c
Expand Up @@ -1274,9 +1274,8 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere)
"# http://curl.haxx.se/docs/http-cookies.html\n"
"# This file was generated by libcurl! Edit at your own risk.\n\n",
out);
co = c->cookies;

while(co) {
for(co = c->cookies; co; co = co->next) {
if(!co->domain)
continue;
format_ptr = get_netscape_format(co);
Expand All @@ -1288,7 +1287,6 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere)
}
fprintf(out, "%s\n", format_ptr);
free(format_ptr);
co=co->next;
}
}

Expand All @@ -1309,9 +1307,7 @@ struct curl_slist *Curl_cookie_list(struct SessionHandle *data)
(data->cookies->numcookies == 0))
return NULL;

c = data->cookies->cookies;

while(c) {
for(c = data->cookies->cookies; c; c = c->next) {
if(!c->domain)
continue;
line = get_netscape_format(c);
Expand All @@ -1326,7 +1322,6 @@ struct curl_slist *Curl_cookie_list(struct SessionHandle *data)
return NULL;
}
list = beg;
c = c->next;
}

return list;
Expand Down

1 comment on commit ef0fdb8

@jay
Copy link
Member Author

@jay jay commented on ef0fdb8 Jun 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bagder Though I had tested my initial changes in 3013bb6, which is obviously incorrect in hindsight, I didn't catch this. The only thing I can think of as plausible is I had assigned a domain to the Set-Cookie line at some point in my test project and then forgot about that later when I made and tested the export changes, but I just don't remember. As described in the commit message the bug is serious, unfortunately, if one uses CURLOPT_COOKIELIST with Set-Cookie and then tries to export the cookies. Sorry about this.

Please sign in to comment.