diff options
author | Gilles Chehade <gilles@poolp.org> | 2019-09-19 18:05:56 +0200 |
---|---|---|
committer | Gilles Chehade <gilles@poolp.org> | 2019-09-19 18:05:56 +0200 |
commit | 30a0de4187bd961d99a3a413b8c26b60ce12e86e (patch) | |
tree | ea0cf1ef4c60e753924ccb577004848806d422e0 /smtpd/to.c | |
parent | Merge branch 'master' into portable (diff) | |
parent | sync (diff) | |
download | OpenSMTPD-30a0de4187bd961d99a3a413b8c26b60ce12e86e.tar.xz OpenSMTPD-30a0de4187bd961d99a3a413b8c26b60ce12e86e.zip |
Merge branch 'master' into portable
Diffstat (limited to 'smtpd/to.c')
-rw-r--r-- | smtpd/to.c | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: to.c,v 1.42 2019/09/02 21:59:27 gilles Exp $ */ +/* $OpenBSD: to.c,v 1.43 2019/09/19 16:00:59 gilles Exp $ */ /* * Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net> @@ -175,10 +175,9 @@ sa_to_text(const struct sockaddr *sa) const struct in6_addr *in6_addr; in6 = (const struct sockaddr_in6 *)sa; - (void)strlcpy(buf, "IPv6:", sizeof(buf)); - p = buf + 5; + p = buf; in6_addr = &in6->sin6_addr; - (void)bsnprintf(p, NI_MAXHOST, "%s", in6addr_to_text(in6_addr)); + (void)bsnprintf(p, NI_MAXHOST, "[%s]", in6addr_to_text(in6_addr)); } return (buf); @@ -281,6 +280,8 @@ text_to_netaddr(struct netaddr *netaddr, const char *s) struct sockaddr_in ssin; struct sockaddr_in6 ssin6; int bits; + char buf[NI_MAXHOST]; + size_t len; memset(&ssin, 0, sizeof(struct sockaddr_in)); memset(&ssin6, 0, sizeof(struct sockaddr_in6)); @@ -297,7 +298,21 @@ text_to_netaddr(struct netaddr *netaddr, const char *s) ss.ss_len = sizeof(struct sockaddr_in); #endif } else { - bits = inet_net_pton(AF_INET6, s, &ssin6.sin6_addr, + if (s[0] != '[') { + if ((len = strlcpy(buf, s, sizeof buf)) >= sizeof buf) + return 0; + } + else { + s++; + if (strncasecmp("IPv6:", s, 5) == 0) + s += 5; + if ((len = strlcpy(buf, s, sizeof buf)) >= sizeof buf) + return 0; + if (buf[len-1] != ']') + return 0; + buf[len-1] = 0; + } + bits = inet_net_pton(AF_INET6, buf, &ssin6.sin6_addr, sizeof(struct in6_addr)); if (bits == -1) { if (errno != EAFNOSUPPORT) |