From 1a6ba5edc0b4482182ec6603433435ff091f66b6 Mon Sep 17 00:00:00 2001 From: Yves Rutschle Date: Sat, 27 Jan 2018 22:59:52 +0100 Subject: [PATCH] fix IPv6 parse error introduced in 7bf3e12c30d0585743792982ed8bcfc44aecae34 --- common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common.c b/common.c index 225c28a..541bac1 100644 --- a/common.c +++ b/common.c @@ -456,19 +456,21 @@ int resolve_split_name(struct addrinfo **out, const char* ct_host, const char* s struct addrinfo hint; char *end; int res; - char* host; + char* host, *host_base; memset(&hint, 0, sizeof(hint)); hint.ai_family = PF_UNSPEC; hint.ai_socktype = SOCK_STREAM; /* Copy parameter so not to clobber data in libconfig */ - res = asprintf(&host, "%s", ct_host); + res = asprintf(&host_base, "%s", ct_host); if (res == -1) { log_message(LOG_ERR, "asprintf: cannot allocate memory"); return -1; } + host = host_base; + /* If it is a RFC-Compliant IPv6 address ("[1234::12]:443"), remove brackets * around IP address */ if (host[0] == '[') { @@ -483,7 +485,7 @@ int resolve_split_name(struct addrinfo **out, const char* ct_host, const char* s res = getaddrinfo(host, serv, &hint, out); if (res) log_message(LOG_ERR, "%s `%s:%s'\n", gai_strerror(res), host, serv); - free(host); + free(host_base); return res; }