mirror of
https://github.com/curl/curl.git
synced 2026-06-05 09:14:15 +03:00
cookie: fix and optimize 2nd top level domain name extraction
This fixes a segfault occurring when a name of the (invalid) form "domain..tld"
is processed.
test46 updated to cover this case.
Follow-up to commit c990ead.
Ref: https://github.com/curl/curl/pull/2440
This commit is contained in:
parent
256b80fe81
commit
82dfdac5f7
2 changed files with 21 additions and 24 deletions
17
lib/cookie.c
17
lib/cookie.c
|
|
@ -246,26 +246,23 @@ pathmatched:
|
|||
static const char *get_top_domain(const char * const domain, size_t *outlen)
|
||||
{
|
||||
size_t len;
|
||||
const char *first, *last;
|
||||
const char *first = NULL, *last;
|
||||
|
||||
if(!domain)
|
||||
return NULL;
|
||||
|
||||
len = strlen(domain);
|
||||
first = memchr(domain, '.', len);
|
||||
last = memrchr(domain, '.', len);
|
||||
if(last) {
|
||||
first = memrchr(domain, '.', (size_t) (last - domain));
|
||||
if(first)
|
||||
len -= (size_t) (++first - domain);
|
||||
}
|
||||
|
||||
if(outlen)
|
||||
*outlen = len;
|
||||
|
||||
if(first == last)
|
||||
return domain;
|
||||
|
||||
first = memrchr(domain, '.', (size_t)(last - domain - 1));
|
||||
if(outlen)
|
||||
*outlen = len - (size_t)(first - domain) - 1;
|
||||
|
||||
return first + 1;
|
||||
return first? first: domain;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue