diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2019-04-21 11:54:44 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2019-04-21 11:54:44 +0200 |
commit | e703325484246468e4fd04707d759a8a9f35f948 (patch) | |
tree | f026b1e8e2aa937d6be903e4c089b11a5d97869f | |
parent | 57635defdb885926135a920105c87d4704bb4acb (diff) |
util: keep brackets when parsing IPv6 addresses
-rw-r--r-- | util.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -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'; |