diff options
author | mestre <mestre@openbsd.org> | 2017-01-17 23:28:04 +0000 |
---|---|---|
committer | mestre <mestre@openbsd.org> | 2017-01-17 23:28:04 +0000 |
commit | 69eddaa6a539f373dc5bc0236663fcbd911c0de8 (patch) | |
tree | 6c5e16159f921f04445f3378073345e1be669bb5 /libexec/spamd | |
parent | Nuke some whitespace that keeps poking me in the eye as I try to (diff) | |
download | wireguard-openbsd-69eddaa6a539f373dc5bc0236663fcbd911c0de8.tar.xz wireguard-openbsd-69eddaa6a539f373dc5bc0236663fcbd911c0de8.zip |
- spamd(8)'s -l accepts an IP address as argument to bind(2) and it calls
inet_pton(3) to check if it's valid and since that function doesn't provide
a proper errno (POSIX doesn't mandate to do so) then if a string is given we
may get this message:
spamd: inet_pton: Undefined error: 0
- Instead replace that code to use getaddrinfo(3) from which is possible to get
a proper error message, and at the same time being able to parse IPs and
hostnames (if either the IP or host is not local then the next bind(2) will
fail)
- By default without arguments, spamd(8) will still bind(2) to 127.0.0.1 as
it did before
With feedback from deraadt@ and OK beck@
Diffstat (limited to 'libexec/spamd')
-rw-r--r-- | libexec/spamd/spamd.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/libexec/spamd/spamd.c b/libexec/spamd/spamd.c index 86a97ebed1b..22acebf2072 100644 --- a/libexec/spamd/spamd.c +++ b/libexec/spamd/spamd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spamd.c,v 1.147 2016/11/30 07:54:36 mestre Exp $ */ +/* $OpenBSD: spamd.c,v 1.148 2017/01/17 23:28:04 mestre Exp $ */ /* * Copyright (c) 2015 Henning Brauer <henning@openbsd.org> @@ -1236,6 +1236,10 @@ main(int argc, char *argv[]) const char *errstr; char *sync_iface = NULL; char *sync_baddr = NULL; + struct addrinfo hints, *res; + char *addr; + char portstr[6]; + int error; tzset(); openlog_r("spamd", LOG_PID | LOG_NDELAY, LOG_DAEMON, &sdata); @@ -1426,18 +1430,20 @@ main(int argc, char *argv[]) sizeof(one)) == -1) return (-1); - memset(&sin, 0, sizeof sin); - sin.sin_len = sizeof(sin); - if (bind_address) { - if (inet_pton(AF_INET, bind_address, &sin.sin_addr) != 1) - err(1, "inet_pton"); - } else - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - sin.sin_family = AF_INET; - sin.sin_port = htons(port); + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + addr = bind_address; + snprintf(portstr, sizeof(portstr), "%hu", port); - if (bind(smtplisten, (struct sockaddr *)&sin, sizeof sin) == -1) + if ((error = getaddrinfo(addr, portstr, &hints, &res)) != 0) { + errx(1, "getaddrinfo: %s", gai_strerror(error)); + } + + if (bind(smtplisten, res->ai_addr, res->ai_addrlen) == -1) { + freeaddrinfo(res); err(1, "bind"); + } + freeaddrinfo(res); memset(&lin, 0, sizeof sin); lin.sin_len = sizeof(sin); |