summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2006-01-06 14:50:44 +1100
committerDamien Miller <djm@mindrot.org>2006-01-06 14:50:44 +1100
commit72c5b7d85d06d6f71960ff00e780b87ca9d33d78 (patch)
tree0a2d2be8e6d5ba782ded80d3d4a9450f9f49b9b9
parentc27f83a63c818b04f957a3225d6781526084c481 (diff)
- djm@cvs.openbsd.org 2006/01/05 23:43:53
[misc.c] check that stdio file descriptors are actually closed before clobbering them in sanitise_stdfd(). problems occurred when a lower numbered fd was closed, but higher ones weren't. spotted by, and patch tested by Frédéric Olivié
-rw-r--r--ChangeLog8
-rw-r--r--misc.c14
2 files changed, 15 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 08c2183d8..a994dcb07 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -29,6 +29,12 @@
29 - jmc@cvs.openbsd.org 2006/01/04 19:50:09 29 - jmc@cvs.openbsd.org 2006/01/04 19:50:09
30 [ssh.1] 30 [ssh.1]
31 -.Xr gzip 1 , 31 -.Xr gzip 1 ,
32 - djm@cvs.openbsd.org 2006/01/05 23:43:53
33 [misc.c]
34 check that stdio file descriptors are actually closed before clobbering
35 them in sanitise_stdfd(). problems occurred when a lower numbered fd was
36 closed, but higher ones weren't. spotted by, and patch tested by
37 Frédéric Olivié
32 38
3320060103 3920060103
34 - (djm) [channels.c] clean up harmless merge error, from reyk@ 40 - (djm) [channels.c] clean up harmless merge error, from reyk@
@@ -3663,4 +3669,4 @@
3663 - (djm) Trim deprecated options from INSTALL. Mention UsePAM 3669 - (djm) Trim deprecated options from INSTALL. Mention UsePAM
3664 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu 3670 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
3665 3671
3666$Id: ChangeLog,v 1.4081 2006/01/06 03:50:26 djm Exp $ 3672$Id: ChangeLog,v 1.4082 2006/01/06 03:50:44 djm Exp $
diff --git a/misc.c b/misc.c
index 0339cede4..b876c0030 100644
--- a/misc.c
+++ b/misc.c
@@ -24,7 +24,7 @@
24 */ 24 */
25 25
26#include "includes.h" 26#include "includes.h"
27RCSID("$OpenBSD: misc.c,v 1.40 2006/01/02 07:53:44 reyk Exp $"); 27RCSID("$OpenBSD: misc.c,v 1.41 2006/01/05 23:43:53 djm Exp $");
28 28
29#ifdef SSH_TUN_OPENBSD 29#ifdef SSH_TUN_OPENBSD
30#include <net/if.h> 30#include <net/if.h>
@@ -616,18 +616,20 @@ tun_open(int tun, int mode)
616void 616void
617sanitise_stdfd(void) 617sanitise_stdfd(void)
618{ 618{
619 int nullfd; 619 int nullfd, dupfd;
620 620
621 if ((nullfd = open(_PATH_DEVNULL, O_RDWR)) == -1) { 621 if ((nullfd = dupfd = open(_PATH_DEVNULL, O_RDWR)) == -1) {
622 fprintf(stderr, "Couldn't open /dev/null: %s", strerror(errno)); 622 fprintf(stderr, "Couldn't open /dev/null: %s", strerror(errno));
623 exit(1); 623 exit(1);
624 } 624 }
625 while (nullfd < 2) { 625 while (++dupfd <= 2) {
626 if (dup2(nullfd, nullfd + 1) == -1) { 626 /* Only clobber closed fds */
627 if (fcntl(dupfd, F_GETFL, 0) >= 0)
628 continue;
629 if (dup2(nullfd, dupfd) == -1) {
627 fprintf(stderr, "dup2: %s", strerror(errno)); 630 fprintf(stderr, "dup2: %s", strerror(errno));
628 exit(1); 631 exit(1);
629 } 632 }
630 nullfd++;
631 } 633 }
632 if (nullfd > 2) 634 if (nullfd > 2)
633 close(nullfd); 635 close(nullfd);