summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2017-01-21 11:32:05 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2017-01-21 11:32:05 +0000
commitb025a593a7f3a0fe505e8ec32929bdc4fe2cb492 (patch)
treec2851b59914141ec276fa5f41f40364392ace7b5
parent4459c5ac6936d9fae7cf90f9f546e056dcc7e590 (diff)
The POSIX APIs that that sockaddrs all ignore the s*_len field in the
incoming socket, so userspace doesn't need to set it unless it has its own reasons for tracking the size along with the sockaddr. ok phessler@ deraadt@ florian@
-rw-r--r--usr.bin/netstat/inet6.c5
-rw-r--r--usr.bin/netstat/show.c7
-rw-r--r--usr.bin/rusers/rusers.c9
-rw-r--r--usr.bin/showmount/showmount.c3
-rw-r--r--usr.bin/ssh/mux.c6
-rw-r--r--usr.bin/systat/inetname.c8
-rw-r--r--usr.bin/tftp/main.c5
-rw-r--r--usr.sbin/httpd/server_fcgi.c11
-rw-r--r--usr.sbin/mrouted/rsrr.c8
-rw-r--r--usr.sbin/npppctl/npppctl.c3
10 files changed, 24 insertions, 41 deletions
diff --git a/usr.bin/netstat/inet6.c b/usr.bin/netstat/inet6.c
index 299d0bffb33..987becb808f 100644
--- a/usr.bin/netstat/inet6.c
+++ b/usr.bin/netstat/inet6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inet6.c,v 1.51 2016/12/22 11:04:44 rzalamena Exp $ */
+/* $OpenBSD: inet6.c,v 1.52 2017/01/21 11:32:04 guenther Exp $ */
/* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */
/*
* Copyright (c) 1983, 1988, 1993
@@ -983,7 +983,6 @@ inet6name(struct in6_addr *in6p)
strlcpy(line, cp, sizeof(line));
else {
memset(&sin6, 0, sizeof(sin6));
- sin6.sin6_len = sizeof(sin6);
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = *in6p;
#ifdef __KAME__
@@ -996,7 +995,7 @@ inet6name(struct in6_addr *in6p)
sin6.sin6_addr.s6_addr[3] = 0;
}
#endif
- if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
+ if (getnameinfo((struct sockaddr *)&sin6, sizeof(sin6),
hbuf, sizeof(hbuf), NULL, 0, niflag) != 0)
strlcpy(hbuf, "?", sizeof hbuf);
strlcpy(line, hbuf, sizeof(line));
diff --git a/usr.bin/netstat/show.c b/usr.bin/netstat/show.c
index dd42d5095a0..9641972f2f9 100644
--- a/usr.bin/netstat/show.c
+++ b/usr.bin/netstat/show.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: show.c,v 1.52 2016/09/03 14:23:14 phessler Exp $ */
+/* $OpenBSD: show.c,v 1.53 2017/01/21 11:32:04 guenther Exp $ */
/* $NetBSD: show.c,v 1.1 1996/11/15 18:01:41 gwr Exp $ */
/*
@@ -449,7 +449,6 @@ routename(struct sockaddr *sa)
memset(&sin6, 0, sizeof(sin6));
memcpy(&sin6, sa, sa->sa_len);
- sin6.sin6_len = sizeof(struct sockaddr_in6);
sin6.sin6_family = AF_INET6;
if (sa->sa_len == sizeof(struct sockaddr_in6) &&
(IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr) ||
@@ -520,7 +519,7 @@ routename6(struct sockaddr_in6 *sin6)
else
niflags |= NI_NOFQDN;
- if (getnameinfo((struct sockaddr *)sin6, sin6->sin6_len,
+ if (getnameinfo((struct sockaddr *)sin6, sizeof(*sin6),
line, sizeof(line), NULL, 0, niflags) != 0)
strncpy(line, "invalid", sizeof(line));
@@ -640,7 +639,7 @@ netname6(struct sockaddr_in6 *sa6, struct sockaddr_in6 *mask)
if (nflag)
flag |= NI_NUMERICHOST;
- error = getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
+ error = getnameinfo((struct sockaddr *)&sin6, sizeof(sin6),
hbuf, sizeof(hbuf), NULL, 0, flag);
if (error)
snprintf(hbuf, sizeof(hbuf), "invalid");
diff --git a/usr.bin/rusers/rusers.c b/usr.bin/rusers/rusers.c
index 089fa72d864..79699741850 100644
--- a/usr.bin/rusers/rusers.c
+++ b/usr.bin/rusers/rusers.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rusers.c,v 1.39 2016/08/05 10:34:18 jca Exp $ */
+/* $OpenBSD: rusers.c,v 1.40 2017/01/21 11:32:04 guenther Exp $ */
/*
* Copyright (c) 2001, 2003 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -418,7 +418,7 @@ retry:
msgp->acpted_rply.ar_results.where = (caddr_t)resp;
msgp->acpted_rply.ar_results.proc = xdr_rmtcallres;
- fromlen = sizeof(struct sockaddr);
+ fromlen = sizeof(raddr);
inlen = recvfrom(sock, inbuf, sizeof(inbuf), 0,
(struct sockaddr *)&raddr, &fromlen);
if (inlen < 0) {
@@ -534,7 +534,6 @@ allhosts(void)
outlen[1] = xdr_getpos(&xdr);
xdr_destroy(&xdr);
- baddr.sin_len = sizeof(struct sockaddr_in);
baddr.sin_family = AF_INET;
baddr.sin_port = htons(PMAPPORT);
baddr.sin_addr.s_addr = htonl(INADDR_ANY);
@@ -572,12 +571,12 @@ allhosts(void)
if (i & 1) {
if (sendto(sock[0], buf[0], outlen[0], 0,
(struct sockaddr *)&baddr,
- sizeof(struct sockaddr)) != outlen[0])
+ sizeof(baddr)) != outlen[0])
err(1, "can't send broadcast packet");
} else {
if (sendto(sock[1], buf[1], outlen[1], 0,
(struct sockaddr *)&baddr,
- sizeof(struct sockaddr)) != outlen[1])
+ sizeof(baddr)) != outlen[1])
err(1, "can't send broadcast packet");
}
}
diff --git a/usr.bin/showmount/showmount.c b/usr.bin/showmount/showmount.c
index 1c5ff28c5bb..05db23d7527 100644
--- a/usr.bin/showmount/showmount.c
+++ b/usr.bin/showmount/showmount.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: showmount.c,v 1.20 2016/03/16 15:41:11 krw Exp $ */
+/* $OpenBSD: showmount.c,v 1.21 2017/01/21 11:32:04 guenther Exp $ */
/* $NetBSD: showmount.c,v 1.7 1996/05/01 18:14:10 cgd Exp $ */
/*
@@ -150,7 +150,6 @@ main(int argc, char *argv[])
exit(1);
}
bzero(&clnt_sin, sizeof clnt_sin);
- clnt_sin.sin_len = sizeof clnt_sin;
clnt_sin.sin_family = AF_INET;
bcopy(hp->h_addr, (char *)&clnt_sin.sin_addr, hp->h_length);
clnt_sock = RPC_ANYSOCK;
diff --git a/usr.bin/ssh/mux.c b/usr.bin/ssh/mux.c
index ba45ef7a254..745526385f7 100644
--- a/usr.bin/ssh/mux.c
+++ b/usr.bin/ssh/mux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mux.c,v 1.63 2016/10/19 23:21:56 dtucker Exp $ */
+/* $OpenBSD: mux.c,v 1.64 2017/01/21 11:32:04 guenther Exp $ */
/*
* Copyright (c) 2002-2008 Damien Miller <djm@openbsd.org>
*
@@ -2163,8 +2163,6 @@ muxclient(const char *path)
memset(&addr, '\0', sizeof(addr));
addr.sun_family = AF_UNIX;
- addr.sun_len = offsetof(struct sockaddr_un, sun_path) +
- strlen(path) + 1;
if (strlcpy(addr.sun_path, path,
sizeof(addr.sun_path)) >= sizeof(addr.sun_path))
@@ -2174,7 +2172,7 @@ muxclient(const char *path)
if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
fatal("%s socket(): %s", __func__, strerror(errno));
- if (connect(sock, (struct sockaddr *)&addr, addr.sun_len) == -1) {
+ if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
switch (muxclient_command) {
case SSHMUX_COMMAND_OPEN:
case SSHMUX_COMMAND_STDIO_FWD:
diff --git a/usr.bin/systat/inetname.c b/usr.bin/systat/inetname.c
index 3503ce5b6b5..5b2d77ffe42 100644
--- a/usr.bin/systat/inetname.c
+++ b/usr.bin/systat/inetname.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inetname.c,v 1.2 2015/01/16 00:03:37 deraadt Exp $ */
+/* $OpenBSD: inetname.c,v 1.3 2017/01/21 11:32:04 guenther Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@@ -52,9 +52,8 @@ inet6name(struct in6_addr *in6)
return "*";
memset(&sin6, 0, sizeof(sin6));
sin6.sin6_family = AF_INET6;
- sin6.sin6_len = sizeof(struct sockaddr_in6);
sin6.sin6_addr = *in6;
- if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
+ if (getnameinfo((struct sockaddr *)&sin6, sizeof(struct sockaddr_in6),
line, sizeof(line), NULL, 0, flags) == 0)
return line;
return "?";
@@ -73,10 +72,9 @@ inetname(struct in_addr in)
memset(&si, 0, sizeof(si));
si.sin_family = AF_INET;
- si.sin_len = sizeof(struct sockaddr_in);
si.sin_addr = in;
- e = getnameinfo((struct sockaddr *)&si, si.sin_len,
+ e = getnameinfo((struct sockaddr *)&si, sizeof(struct sockaddr_in),
line, sizeof(line), NULL, 0, flags);
if (e == 0)
diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c
index 28560039fe7..546684b885a 100644
--- a/usr.bin/tftp/main.c
+++ b/usr.bin/tftp/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.40 2016/03/16 15:41:11 krw Exp $ */
+/* $OpenBSD: main.c,v 1.41 2017/01/21 11:32:04 guenther Exp $ */
/* $NetBSD: main.c,v 1.6 1995/05/21 16:54:10 mycroft Exp $ */
/*
@@ -232,8 +232,7 @@ setpeer(char *host, char *port)
memset(&ss, 0, sizeof(ss));
ss.ss_family = res->ai_family;
- ss.ss_len = res->ai_addrlen;
- if (bind(f, (struct sockaddr *)&ss, ss.ss_len) < 0) {
+ if (bind(f, (struct sockaddr *)&ss, res->ai_addrlen) < 0) {
cause = "bind";
close(f);
f = -1;
diff --git a/usr.sbin/httpd/server_fcgi.c b/usr.sbin/httpd/server_fcgi.c
index fc3e417ee28..c36c5a8af43 100644
--- a/usr.sbin/httpd/server_fcgi.c
+++ b/usr.sbin/httpd/server_fcgi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server_fcgi.c,v 1.73 2016/10/07 07:37:29 patrick Exp $ */
+/* $OpenBSD: server_fcgi.c,v 1.74 2017/01/21 11:32:04 guenther Exp $ */
/*
* Copyright (c) 2014 Florian Obser <florian@openbsd.org>
@@ -120,7 +120,6 @@ server_fcgi(struct httpd *env, struct client *clt)
goto fail;
} else {
struct sockaddr_un sun;
- size_t len;
if ((fd = socket(AF_UNIX,
SOCK_STREAM | SOCK_NONBLOCK, 0)) == -1)
@@ -128,13 +127,11 @@ server_fcgi(struct httpd *env, struct client *clt)
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
- len = strlcpy(sun.sun_path,
- srv_conf->socket, sizeof(sun.sun_path));
- if (len >= sizeof(sun.sun_path)) {
- errstr = "socket path too long";
+ if (strlcpy(sun.sun_path, srv_conf->socket,
+ sizeof(sun.sun_path)) >= sizeof(sun.sun_path)) {
+ errstr = "socket path to long";
goto fail;
}
- sun.sun_len = len;
if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1)
goto fail;
diff --git a/usr.sbin/mrouted/rsrr.c b/usr.sbin/mrouted/rsrr.c
index b038a851003..4bf8183ff8a 100644
--- a/usr.sbin/mrouted/rsrr.c
+++ b/usr.sbin/mrouted/rsrr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rsrr.c,v 1.14 2015/08/21 02:07:32 deraadt Exp $ */
+/* $OpenBSD: rsrr.c,v 1.15 2017/01/21 11:32:04 guenther Exp $ */
/* $NetBSD: rsrr.c,v 1.3 1995/12/10 10:07:14 mycroft Exp $ */
/*
@@ -83,7 +83,6 @@ static void rsrr_cache(struct gtable *gt, struct rsrr_rq *route_query);
void
rsrr_init(void)
{
- int servlen;
struct sockaddr_un serv_addr;
if ((rsrr_socket = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
@@ -93,11 +92,8 @@ rsrr_init(void)
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sun_family = AF_UNIX;
strlcpy(serv_addr.sun_path, RSRR_SERV_PATH, sizeof serv_addr.sun_path);
- servlen = offsetof(struct sockaddr_un, sun_path) +
- strlen(serv_addr.sun_path);
- serv_addr.sun_len = servlen;
- if (bind(rsrr_socket, (struct sockaddr *) &serv_addr, servlen) < 0)
+ if (bind(rsrr_socket, (struct sockaddr *)&serv_addr, sizeof serv_addr) < 0)
logit(LOG_ERR, errno, "Can't bind RSRR socket");
if (register_input_handler(rsrr_socket,rsrr_read) < 0)
diff --git a/usr.sbin/npppctl/npppctl.c b/usr.sbin/npppctl/npppctl.c
index ef6aaacf058..47edd69a801 100644
--- a/usr.sbin/npppctl/npppctl.c
+++ b/usr.sbin/npppctl/npppctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: npppctl.c,v 1.6 2015/12/05 13:19:32 claudio Exp $ */
+/* $OpenBSD: npppctl.c,v 1.7 2017/01/21 11:32:04 guenther Exp $ */
/*
* Copyright (c) 2012 Internet Initiative Japan Inc.
@@ -106,7 +106,6 @@ main(int argc, char *argv[])
err(EXIT_FAILURE, "socket");
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
- sun.sun_len = sizeof(sun);
strlcpy(sun.sun_path, npppd_ctlpath, sizeof(sun.sun_path));
if (connect(ctlsock, (struct sockaddr *)&sun, sizeof(sun)) < 0)
err(EXIT_FAILURE, "connect");