Bug on ssh-agent (following my first report)

Frédéric Olivié alf at club-internet.fr
Thu Jan 5 11:58:14 EST 2006


Damien Miller a écrit :
> 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) == -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
> ===================================================================
> 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 = open(_PATH_DEVNULL, O_RDWR)) == -1) {
> +	if ((nullfd = dupfd = open(_PATH_DEVNULL, O_RDWR)) == -1) {
>  		fprintf(stderr, "Couldn't open /dev/null: %s", strerror(errno));
>  		exit(1);
>  	}
> -	while (nullfd < 2) {
> -		if (dup2(nullfd, nullfd + 1) == -1) {
> +	while (dupfd < 2) {
> +		/* Only clobber closed fds */
> +		if (fcntl(dupfd, F_GETFL, 0) >= 0)
> +			continue;
> +		if (dup2(nullfd, dupfd) == -1) {
>  			fprintf(stderr, "dup2: %s", strerror(errno));
>  			exit(1);
>  		}
> -		nullfd++;
> +		dupfd++;
>  	}
>  	if (nullfd > 2)
>  		close(nullfd);
>
>   




More information about the openssh-unix-dev mailing list