From a706cb8941ccec4b20eb4759b4bc6a2dd2f35b6c Mon Sep 17 00:00:00 2001 From: gilles Date: Wed, 28 Oct 2015 07:28:13 +0000 Subject: [PATCH] dns_lookup_host() needs to remove brackets and IPv6: prefix when receiving a text representation otherwise getaddrinfo_async() will choke ok eric@ --- usr.sbin/smtpd/dns.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/usr.sbin/smtpd/dns.c b/usr.sbin/smtpd/dns.c index 808a28ccb1c..d4dc267bb08 100644 --- a/usr.sbin/smtpd/dns.c +++ b/usr.sbin/smtpd/dns.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dns.c,v 1.82 2015/10/17 13:30:47 gilles Exp $ */ +/* $OpenBSD: dns.c,v 1.83 2015/10/28 07:28:13 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -434,6 +434,8 @@ dns_lookup_host(struct dns_session *s, const char *host, int preference) { struct dns_lookup *lookup; struct addrinfo hints; + char hostcopy[HOST_NAME_MAX+1]; + char *p; void *as; lookup = xcalloc(1, sizeof *lookup, "dns_lookup_host"); @@ -441,6 +443,18 @@ dns_lookup_host(struct dns_session *s, const char *host, int preference) lookup->session = s; s->refcount++; + if (*host == '[') { + if (strncasecmp("[IPv6:", host, 6) == 0) + host += 6; + else + host += 1; + (void)strlcpy(hostcopy, host, sizeof hostcopy); + p = strchr(hostcopy, ']'); + if (p) + *p = 0; + host = hostcopy; + } + memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_ADDRCONFIG; hints.ai_family = PF_UNSPEC; -- 2.20.1