From 746479adcbd2bba06077642fefe0414ad6e1e0ea Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Thu, 5 Apr 2018 15:55:59 +0300 Subject: cookie: case-insensitive hashing for the domains closes #2458 --- lib/cookie.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'lib/cookie.c') diff --git a/lib/cookie.c b/lib/cookie.c index ec3b1bf9a..5aa959690 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -90,7 +90,6 @@ Example set of cookies: #include "urldata.h" #include "cookie.h" -#include "hash.h" #include "strtok.h" #include "sendf.h" #include "slist.h" @@ -265,6 +264,22 @@ static const char *get_top_domain(const char * const domain, size_t *outlen) return first? first: domain; } +/* + * A case-insensitive hash for the cookie domains. + */ +static size_t cookie_hash_domain(const char *domain, const size_t len) +{ + const char *end = domain + len; + unsigned long h = 5381; + + while(domain < end) { + h += h << 5; + h ^= (unsigned long) Curl_raw_toupper(*domain++); + } + + return (h % COOKIE_HASH_SIZE); +} + /* * Hash this domain. */ @@ -277,7 +292,7 @@ static size_t cookiehash(const char * const domain) return 0; top = get_top_domain(domain, &len); - return Curl_hash_str((void *) top, len, COOKIE_HASH_SIZE); + return cookie_hash_domain(top, len); } /* -- cgit v1.2.3