From fbc54f53c124f3b8dfe4b786a5744672be6c9b27 Mon Sep 17 00:00:00 2001 From: guenther Date: Sun, 11 Oct 2015 00:26:23 +0000 Subject: [PATCH] Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept sizeof(struct sockaddr_un), so do the simple, portable thing ok beck@ deraadt@ --- usr.bin/nc/netcat.c | 11 +++-------- usr.bin/tmux/client.c | 4 ++-- usr.bin/tmux/server.c | 4 ++-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c index ff9d3989d32..9fc825b5d8e 100644 --- a/usr.bin/nc/netcat.c +++ b/usr.bin/nc/netcat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netcat.c,v 1.138 2015/09/13 11:12:09 beck Exp $ */ +/* $OpenBSD: netcat.c,v 1.139 2015/10/11 00:26:23 guenther Exp $ */ /* * Copyright (c) 2001 Eric Jackson * Copyright (c) 2015 Bob Beck. All rights reserved. @@ -57,11 +57,6 @@ #include #include "atomicio.h" -#ifndef SUN_LEN -#define SUN_LEN(su) \ - (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) -#endif - #define PORT_MAX 65535 #define PORT_MAX_LEN 6 #define UNIX_DG_TMP_SOCKET_SIZE 19 @@ -646,7 +641,7 @@ unix_bind(char *path, int flags) return (-1); } - if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { + if (bind(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) { close(s); return (-1); } @@ -741,7 +736,7 @@ unix_connect(char *path) errno = ENAMETOOLONG; return (-1); } - if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { + if (connect(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) { close(s); return (-1); } diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c index 842fece1559..3c19ef2977b 100644 --- a/usr.bin/tmux/client.c +++ b/usr.bin/tmux/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.95 2015/09/24 12:06:20 nicm Exp $ */ +/* $OpenBSD: client.c,v 1.96 2015/10/11 00:26:23 guenther Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -119,7 +119,7 @@ retry: fatal("socket failed"); log_debug("trying connect"); - if (connect(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) { + if (connect(fd, (struct sockaddr *) &sa, sizeof(sa)) == -1) { log_debug("connect failed: %s", strerror(errno)); if (errno != ECONNREFUSED && errno != ENOENT) goto failed; diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c index bd479dc07d4..514bf109d17 100644 --- a/usr.bin/tmux/server.c +++ b/usr.bin/tmux/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.139 2015/09/01 10:01:56 nicm Exp $ */ +/* $OpenBSD: server.c,v 1.140 2015/10/11 00:26:23 guenther Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -145,7 +145,7 @@ server_create_socket(void) return (-1); mask = umask(S_IXUSR|S_IXGRP|S_IRWXO); - if (bind(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) + if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) == -1) return (-1); umask(mask); -- 2.20.1