dns_lookup_host() needs to remove brackets and IPv6: prefix when receiving
authorgilles <gilles@openbsd.org>
Wed, 28 Oct 2015 07:28:13 +0000 (07:28 +0000)
committergilles <gilles@openbsd.org>
Wed, 28 Oct 2015 07:28:13 +0000 (07:28 +0000)
a text representation otherwise getaddrinfo_async() will choke

ok eric@

usr.sbin/smtpd/dns.c

index 808a28c..d4dc267 100644 (file)
@@ -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 <gilles@poolp.org>
@@ -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;