mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
Skip any preceeding dots from the domain name of cookies when we keep them
in memory, only add it when we save the cookie. This makes all tailmatching and domain string matching internally a lot easier. This was also the reason for a remaining bug I introduced in my overhaul.
This commit is contained in:
parent
de9b76cef0
commit
465de793e8
24
lib/cookie.c
24
lib/cookie.c
@ -234,24 +234,29 @@ Curl_cookie_add(struct CookieInfo *c,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(dotcount < 3)
|
if(dotcount < 3) {
|
||||||
/* Received and skipped a cookie with a domain using too few
|
/* Received and skipped a cookie with a domain using too few
|
||||||
dots. */
|
dots. */
|
||||||
badcookie=TRUE; /* mark this as a bad cookie */
|
badcookie=TRUE; /* mark this as a bad cookie */
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
/* Now, we make sure that our host is within the given domain,
|
/* Now, we make sure that our host is within the given domain,
|
||||||
or the given domain is not valid and thus cannot be set. */
|
or the given domain is not valid and thus cannot be set. */
|
||||||
|
|
||||||
if(!domain || tailmatch(whatptr, domain)) {
|
if(!domain || tailmatch(whatptr, domain)) {
|
||||||
co->domain=strdup(whatptr);
|
char *ptr=whatptr;
|
||||||
|
if(ptr[0] == '.')
|
||||||
|
ptr++;
|
||||||
|
co->domain=strdup(ptr); /* dont prefix with dots internally */
|
||||||
co->tailmatch=TRUE; /* we always do that if the domain name was
|
co->tailmatch=TRUE; /* we always do that if the domain name was
|
||||||
given */
|
given */
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
/* we did not get a tailmatch and then the attempted set domain
|
/* we did not get a tailmatch and then the attempted set domain
|
||||||
is not a domain to which the current host belongs. Mark as
|
is not a domain to which the current host belongs. Mark as
|
||||||
bad. */
|
bad. */
|
||||||
badcookie=TRUE;
|
badcookie=TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(strequal("version", name)) {
|
else if(strequal("version", name)) {
|
||||||
@ -381,6 +386,8 @@ Curl_cookie_add(struct CookieInfo *c,
|
|||||||
ptr=strtok_r(NULL, "\t", &tok_buf), fields++) {
|
ptr=strtok_r(NULL, "\t", &tok_buf), fields++) {
|
||||||
switch(fields) {
|
switch(fields) {
|
||||||
case 0:
|
case 0:
|
||||||
|
if(ptr[0]=='.') /* skip preceeding dots */
|
||||||
|
ptr++;
|
||||||
co->domain = strdup(ptr);
|
co->domain = strdup(ptr);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
@ -453,14 +460,8 @@ Curl_cookie_add(struct CookieInfo *c,
|
|||||||
/* the names are identical */
|
/* the names are identical */
|
||||||
|
|
||||||
if(clist->domain && co->domain) {
|
if(clist->domain && co->domain) {
|
||||||
if(strequal(clist->domain, co->domain) ||
|
if(strequal(clist->domain, co->domain))
|
||||||
(co->tailmatch && /* only do the dot magic if tailmatching is OK */
|
/* The domains are identical */
|
||||||
((clist->domain[0]=='.' &&
|
|
||||||
strequal(&(clist->domain[1]), co->domain)) ||
|
|
||||||
(co->domain[0]=='.' &&
|
|
||||||
strequal(clist->domain, &(co->domain[1]))))) )
|
|
||||||
/* The domains are identical, or at least identical if you skip the
|
|
||||||
preceeding dot */
|
|
||||||
replace_old=TRUE;
|
replace_old=TRUE;
|
||||||
}
|
}
|
||||||
else if(!clist->domain && !co->domain)
|
else if(!clist->domain && !co->domain)
|
||||||
@ -550,7 +551,6 @@ Curl_cookie_add(struct CookieInfo *c,
|
|||||||
}
|
}
|
||||||
|
|
||||||
c->numcookies++; /* one more cookie in the jar */
|
c->numcookies++; /* one more cookie in the jar */
|
||||||
|
|
||||||
return co;
|
return co;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user