summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2019-04-21 11:54:44 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2019-04-21 11:54:44 +0200
commite703325484246468e4fd04707d759a8a9f35f948 (patch)
treef026b1e8e2aa937d6be903e4c089b11a5d97869f
parent57635defdb885926135a920105c87d4704bb4acb (diff)
util: keep brackets when parsing IPv6 addresses
-rw-r--r--util.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/util.c b/util.c
index 37beb44..48d01bb 100644
--- 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';