Damien Miller a =E9crit :
> Please don't send HTML mail.
> =


Sorry. Hope this is better (I asked Thunderbird to send text-only on =

this list).
>
> Please try this diff:
> =


It can't work. The "continue" statement causes "dupfd++" never to be =

evaluated thus resulting in an infinite loop. The following works better :

/* Only clobber closed fds */
if (fcntl(dupfd, F_GETFL, 0) < 0) {
if (dup2(nullfd, dupfd) =3D=3D -1) {
fprintf(stderr, "dup2: %s", strerror(errno));
exit(1);
}
}
dupfd++;

This solves the first problem. But not the second one though. FDs still =

get closed and re-duped to /dev/null (see the point 2) in my previous =

message).

Thanks.

> Index: misc.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D
> RCS file: /cvs/src/usr.bin/ssh/misc.c,v
> retrieving revision 1.40
> diff -u -p -r1.40 misc.c
> --- misc.c 2 Jan 2006 07:53:44 -0000 1.40
> +++ misc.c 4 Jan 2006 21:45:34 -0000
> @@ -601,18 +601,21 @@ tun_open(int tun, int mode)
> void
> sanitise_stdfd(void)
> {
> - int nullfd;
> + int nullfd, dupfd;
> =


> - if ((nullfd =3D open(_PATH_DEVNULL, O_RDWR)) =3D=3D -1) {
> + if ((nullfd =3D dupfd =3D open(_PATH_DEVNULL, O_RDWR)) =3D=3D -1) {
> fprintf(stderr, "Couldn't open /dev/null: %s", strerror(errno));
> exit(1);
> }
> - while (nullfd < 2) {
> - if (dup2(nullfd, nullfd + 1) =3D=3D -1) {
> + while (dupfd < 2) {
> + /* Only clobber closed fds */
> + if (fcntl(dupfd, F_GETFL, 0) >=3D 0)
> + continue;
> + if (dup2(nullfd, dupfd) =3D=3D -1) {
> fprintf(stderr, "dup2: %s", strerror(errno));
> exit(1);
> }
> - nullfd++;
> + dupfd++;
> }
> if (nullfd > 2)
> close(nullfd);
>
> =



_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
http://www.mindrot.org/mailman/listi...enssh-unix-dev