Relax domain matching to allow host a.com to match .a.com

svn path=/trunk/netsurf/; revision=2684
This commit is contained in:
John Mark Bell 2006-07-01 21:35:30 +00:00
parent 2dc65ac414
commit 28a7ed4989
1 changed files with 12 additions and 2 deletions

View File

@ -2554,6 +2554,7 @@ bool urldb_set_cookie(const char *header, const char *url)
/* Domain match fetch host with cookie domain */
if (strcasecmp(host, c->domain) != 0) {
int hlen, dlen;
char *domain = c->domain;
/* 4.3.2:iii */
if (host[0] >= '0' && host[0] <= '9') {
@ -2565,13 +2566,20 @@ bool urldb_set_cookie(const char *header, const char *url)
hlen = strlen(host);
dlen = strlen(c->domain);
if (hlen <= dlen) {
if (hlen <= dlen && hlen != dlen - 1) {
/* Partial match not possible */
urldb_free_cookie(c);
goto error;
}
if (strcasecmp(host + (hlen - dlen), c->domain)) {
if (hlen == dlen - 1) {
/* Relax matching to allow
* host a.com to match .a.com */
domain++;
dlen--;
}
if (strcasecmp(host + (hlen - dlen), domain)) {
urldb_free_cookie(c);
goto error;
}
@ -3313,6 +3321,8 @@ int main(void)
urldb_set_cookie("test=foo, bar, baz; path=/, quux=blah; path=/", "http://www.bbc.co.uk/");
urldb_set_cookie("a=b; path=/; domain=.a.com", "http://a.com/");
urldb_dump();
return 0;