summaryrefslogtreecommitdiff
path: root/content/urldb.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2017-03-13 23:44:06 +0000
committerVincent Sanders <vince@kyllikki.org>2017-03-13 23:44:06 +0000
commit2406acfeb347da3d4957627cdb70e2583c03aee7 (patch)
tree58d97fc9a23ecc023fe575c8d89b1eccbfa9d61e /content/urldb.c
parent089179a5b1590e5519d53b5cb9bc9c78630b8290 (diff)
downloadnetsurf-2406acfeb347da3d4957627cdb70e2583c03aee7.tar.gz
netsurf-2406acfeb347da3d4957627cdb70e2583c03aee7.tar.bz2
fix urldb numerical v6 address handling
Diffstat (limited to 'content/urldb.c')
-rw-r--r--content/urldb.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/content/urldb.c b/content/urldb.c
index f386aa941..d702e581b 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -634,6 +634,7 @@ static bool urldb__host_is_ip_address(const char *host)
#ifndef NO_IPV6
struct in6_addr ipv6;
char ipv6_addr[64];
+ unsigned int ipv6_addr_len;
#endif
/**
* @todo FIXME Some parts of urldb.c make confusions between hosts
@@ -660,7 +661,7 @@ static bool urldb__host_is_ip_address(const char *host)
char *c = strdup(host);
c[slash - host] = '\0';
sane_host = c;
- host_len = slash - host - 1;
+ host_len = slash - host;
LOG("WARNING: called with non-host '%s'", host);
}
@@ -688,11 +689,18 @@ static bool urldb__host_is_ip_address(const char *host)
}
#ifndef NO_IPV6
- if (sane_host[0] != '[' || sane_host[host_len] != ']')
+ if ((host_len < 6) ||
+ (sane_host[0] != '[') ||
+ (sane_host[host_len - 1] != ']')) {
goto out_false;
+ }
- strncpy(ipv6_addr, sane_host + 1, sizeof(ipv6_addr));
- ipv6_addr[sizeof(ipv6_addr) - 1] = '\0';
+ ipv6_addr_len = host_len - 2;
+ if (ipv6_addr_len > sizeof(ipv6_addr)) {
+ ipv6_addr_len = sizeof(ipv6_addr);
+ }
+ strncpy(ipv6_addr, sane_host + 1, ipv6_addr_len);
+ ipv6_addr[ipv6_addr_len] = '\0';
if (inet_pton(AF_INET6, ipv6_addr, &ipv6) == 1)
goto out_true;