zsh-workers
 help / color / mirror / code / Atom feed
* Redirection bug -- fixed!
@ 1995-05-25  8:09 Zefram
  0 siblings, 0 replies; only message in thread
From: Zefram @ 1995-05-25  8:09 UTC (permalink / raw)
  To: Z Shell workers mailing list

-----BEGIN PGP SIGNED MESSAGE-----

I've fixed the redirection bug.  The problem is that subsh_close is set up in
exec.c to indicate which file descriptor a subshell should close.  In some
cases, such as when "true | true" is being executed, this cleanup is never
needed, so it is not done.  The variable remains set, however, and the next
time a shell function is executed the fd is refers to is closed.  The fd had
already been closed, without a reference to subsh_close, and without resetting
subsh_close to -1 -- and then that fd was reused for redirection.  The result
is that the saved stream gets rudely closed, the redup() after the redirection
fails, and the redirection is effectively permanent.

The fix is to reset subsh_close to -1 when the fd it refers to is closed.
That's a one-line addition to exec.c.  The patch below also adds some "can't
happen" error checking to movefd() and redup(), that is triggered by the bug.

 -zefram

      *** Src/exec.c.old	Thu May 25 05:23:19 1995
      --- Src/exec.c	Thu May 25 08:51:54 1995
      ***************
      *** 765,770 ****
      --- 765,771 ----
        	    execpline2(pline->right, how, pipes[0], output, last1);
        	    list_pipe = old_list_pipe;
        	    close(pipes[0]);
      + 	    subsh_close = -1;
        	}
            }
        
      *** Src/utils.c.old	Thu May 25 05:47:47 1995
      --- Src/utils.c	Thu May 25 08:57:21 1995
      ***************
      *** 1005,1011 ****
            if ((fe = dup(fd)) < 10)
        	fe = movefd(fe);
        #endif
      !     close(fd);
            return fe;
        }
        
      --- 1005,1014 ----
            if ((fe = dup(fd)) < 10)
        	fe = movefd(fe);
        #endif
      !     if (close(fd) == -1) {
      ! 	zerr("internal fd mixup!", NULL, 0);
      ! 	exit(13);
      !     }
            return fe;
        }
        
      ***************
      *** 1017,1023 ****
        {
            if (x != y) {
        	dup2(x, y);
      ! 	close(x);
            }
        }
        
      --- 1020,1029 ----
        {
            if (x != y) {
        	dup2(x, y);
      ! 	if (close(x) == -1) {
      ! 	    zerr("internal fd mixup!", NULL, 0);
      ! 	    exit(13);
      ! 	}
            }
        }
        

-----BEGIN PGP SIGNATURE-----
Version: 2.6.i

iQBVAgUBL8Q7MmWJ8JfKi+e9AQG1RwH/YHmSu3sSsqoLdmo+AnltRf4lnm+8cZdu
LiOs4Bg1odcDTSqOO1QPNG/CBcaXgl1YzFlBcwxt5E5zJRpyJPQeqQ==
=fBVS
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1995-05-25  8:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-05-25  8:09 Redirection bug -- fixed! Zefram

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).