From: yasuoka Date: Sun, 13 Jul 2014 21:34:35 +0000 (+0000) Subject: Some functions need to dup() before sending a socket by imsg and don't X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5789a5c98d0bf8493c4009afc4567c81a4320add;p=openbsd Some functions need to dup() before sending a socket by imsg and don't need to close() after sending socket since imsg_compose() closes the passing socket. --- diff --git a/usr.sbin/npppd/npppd/privsep.c b/usr.sbin/npppd/npppd/privsep.c index 5c79fa07b69..bdb5a1b64a7 100644 --- a/usr.sbin/npppd/npppd/privsep.c +++ b/usr.sbin/npppd/npppd/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.12 2014/07/12 20:07:07 yasuoka Exp $ */ +/* $OpenBSD: privsep.c,v 1.13 2014/07/13 21:34:35 yasuoka Exp $ */ /* * Copyright (c) 2010 Yasuoka Masahiko @@ -234,6 +234,9 @@ priv_bind(int sock, const struct sockaddr *name, socklen_t namelen) errno = EINVAL; return (-1); } + if ((sock = dup(sock)) == -1) + return (-1); + memcpy(&a.name, name, namelen); a.namelen = namelen; @@ -296,6 +299,8 @@ priv_sendto(int s, const void *msg, int len, int flags, errno = EINVAL; return (-1); } + if ((s = dup(s)) == -1) + return (-1); a.len = len; a.flags = flags; @@ -581,7 +586,6 @@ privsep_priv_dispatch_imsg(struct imsgbuf *ibuf) (void)imsg_compose(ibuf, PRIVSEP_OK, 0, 0, f, &r, sizeof(r)); imsg_flush(ibuf); - close(f); } break; case PRIVSEP_SOCKET: { @@ -603,7 +607,6 @@ privsep_priv_dispatch_imsg(struct imsgbuf *ibuf) (void)imsg_compose(ibuf, PRIVSEP_OK, 0, 0, s, &r, sizeof(r)); imsg_flush(ibuf); - close(s); } break; case PRIVSEP_UNLINK: {