commit e703325484246468e4fd04707d759a8a9f35f948
parent 57635defdb885926135a920105c87d4704bb4acb
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Sun, 21 Apr 2019 11:54:44 +0200
util: keep brackets when parsing IPv6 addresses
Diffstat:
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/util.c b/util.c
@@ -48,10 +48,11 @@ parseuri(const char *s, struct uri *u, int rel)
/* IPv6 address */
if (*p == '[') {
/* bracket not found or host too long */
- if (!(b = strchr(p, ']')) || (size_t)(b - p) >= sizeof(u->host))
+ if (!(b = strchr(p, ']')) || (size_t)(b - p) < 3 ||
+ (size_t)(b - p) >= sizeof(u->host))
return -1;
- memcpy(u->host, p + 1, b - p - 1);
- u->host[b - p - 1] = '\0';
+ memcpy(u->host, p, b - p + 1);
+ u->host[b - p + 1] = '\0';
p = b + 1;
} else {
/* domain / host part, skip until port, path or end. */
@@ -125,7 +126,7 @@ absuri(char *buf, size_t bufsiz, const char *link, const char *base)
{
struct uri ulink, ubase;
char tmp[4096], *host, *p, *port;
- int r, c;
+ int c, r;
size_t i;
buf[0] = '\0';