diff options
author | corvid <corvid@lavabit.com> | 2010-01-13 20:28:16 +0000 |
---|---|---|
committer | corvid <corvid@lavabit.com> | 2010-01-13 20:28:16 +0000 |
commit | 6ccd839d091c6e05c68cae7e6a9303aa05412543 (patch) | |
tree | 46ba37bde887dc52122ccae44e3ffcda004f53dd | |
parent | 9f12988b908768447998d46480a156b46e2797df (diff) |
cookies fix ipv6 check
-rw-r--r-- | dpi/cookies.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/dpi/cookies.c b/dpi/cookies.c index 7bef14ff..709f3be3 100644 --- a/dpi/cookies.c +++ b/dpi/cookies.c @@ -926,22 +926,24 @@ static uint_t Cookies_internal_dots_required(const char *host) */ static bool_t Cookies_domain_is_ip(const char *domain) { - bool_t ipv4 = TRUE, ipv6 = TRUE; + uint_t len; if (!domain) return FALSE; - while (*domain) { - if (*domain != '.' && !isdigit(*domain)) - ipv4 = FALSE; - if (*domain != ':' && !isxdigit(*domain)) - ipv6 = FALSE; - if (!(ipv4 || ipv6)) - return FALSE; - domain++; + len = strlen(domain); + + if (len == strspn(domain, "0123456789.")) { + MSG("an IPv4 address\n"); + return TRUE; } - MSG("an IP address\n"); - return TRUE; + if (*domain == '[' && + (len == strspn(domain, "0123456789abcdefABCDEF:.[]"))) { + /* The precise format is shown in section 3.2.2 of rfc 3986 */ + MSG("an IPv6 address\n"); + return TRUE; + } + return FALSE; } /* |